combining multiple wav files into one multichannel matrix
4 views (last 30 days)
Show older comments
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
Accepted Answer
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
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?
More Answers (0)
See Also
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!