combining multiple wav files into one multichannel matrix

4 views (last 30 days)
Having a bunch of stereo wav files with the structure:
036a.wav, 036b.wav, 036c.wav ...
037a.wav, 037b.wav, 037c.wav ...
...
I wish to load them one by one and concatenate them into a structure so that the files starting with the same number (such as 036) would all be combined into a "multichannel" matrix where the 036a.wav would occupy the first two columns, 036b.wav the column no. 3 and 4, the 036c.wav the colums 5 and 6 etc.
The files 037a.wav ... 037b.wav ... 037c.wav would follow the same scheme, forming another branch of the struct.
How is this best done in Matlab, please?
  3 Comments
Jiri Zurek
Jiri Zurek on 11 May 2018
Well, there was never a case that whole alphabet would be used. There are not so many files, therefore we do not need to solve this question, fortunately.
Jiri Zurek
Jiri Zurek on 11 May 2018
For the length: yes, they are supposed to be of the same length, of course, a casual error may happen from time to time. I will look into padding.
And for the numbers knowing in advance - I could eventually read it from the list of the files in advance, but that would only replicate a need for a loop, I think.

Sign in to comment.

Accepted Answer

Jan
Jan on 10 May 2018
Edited: Jan on 10 May 2018
Perhaps by something like this:
S = struct();
iS = 0;
Folder = 'C.:\Your\Folder\';
for k = 1:1000
str = sprintf('%03d', k);
if exist(fullfile(Folder, [str, 'a.wav']), 'file')
List = dir(fullfile(Folder, [str, '*.wav']));
Data = cell(1, numel(List));
for iFile = 1:numel(List)
File = fullfile(Folder, List(iFile).name);
Data{iFile} = wavread(File);
end
iS = iS + 1;
S(is).Data = cat(2, Data{:});
S(iS).Key = str;
end
end
This assumes, that all signals have the same length. Otherwise you can pad the signals e.g. by FileExchange: padcat .
  3 Comments
Nassylbekova Aiym
Nassylbekova Aiym on 15 Nov 2019
Hello, I just wanted to ask, how can I use 'sound' after combining? I mean I want ho hear all files in one wav.file, is it possible?
Jiri Zurek
Jiri Zurek on 15 Nov 2019
Some audio editors support multichannel wav files, some of them split the multichannel wav onto several tracks, and then you can route various channels to various output as you like. If I am correct, even freeware like Audacity is capable of dealing with multichannels wavs, Reaper as well. In Matlab, I do not listen to the sound, I only process it.

Sign in to comment.

More Answers (0)

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!