combining multiple wav files into one multichannel matrix

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 件のコメント

Jan
Jan 2018 年 5 月 10 日
編集済み: Jan 2018 年 5 月 10 日
What is coming after 036z? Do all signals have the same length? Do you know the list of numbers in advance?
Jiri Zurek
Jiri Zurek 2018 年 5 月 11 日
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 2018 年 5 月 11 日
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.

サインインしてコメントする。

 採用された回答

Jan
Jan 2018 年 5 月 10 日
編集済み: Jan 2018 年 5 月 10 日

0 投票

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 件のコメント

Jiri Zurek
Jiri Zurek 2018 年 5 月 11 日
THank you again, Jan, you seem to be a genius. You know answer to all the questions. I will test this solution today.
Nassylbekova Aiym
Nassylbekova Aiym 2019 年 11 月 15 日
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 2019 年 11 月 15 日
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.

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2018 年 5 月 10 日

コメント済み:

2019 年 11 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by