How to generate all possible combinations of audio files?
Show older comments
Hello all,
Sorry for such a basic question, but would you be able to help me with putting together a code which would combine together multiple audio files from one folder? I want to create new audio files (2 channels) by combining audio samples I already have (all 1 channel, same bit rates, same fs, but different length) in a way that each sample is combined with each sample (i.e., generate all possible combinations of samples).
For example: sample1 + sample2, sample1 + sample3, sample2 + sample3...
This is how I read them into my workspace:
myFiles = dir(fullfile('MATLAB\SAMPLEsounds\*.wav'));
for i = 1:size(myFiles, 1)
SoundNames{i}=myFiles(i).name;
[audioIn,fs] = audioread(['MATLAB\SAMPLEsounds\' myFiles(i).name]);
end
I'm struggling with creating a code which would generate all possible combinations of sounds in that folder, add them together (with zero-padding the difference in length) and save them as new wav files.
I tried these to generate all possible combinations:
combinations = nchoosek(SoundNames, 2);
but this gives me only the list of sound names, not actual sounds; and
combinations = nchoosek(audioIn, 2);
bu this doesn't accept audio file as an input argument and gives the following error:
Error using zeros. Requested 1514508166x2 (22.6GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information.
Since they are not always the same length, I wanted to use catpad to add silence to the shorter ones, but again, I don't know how to feed 'each with each sample' into the function.
soundAdded(number) = catpad(2, sound1, sound2);
Could you please give some suggestions how to combine all these things together? I would appreciate your advice.
Thanks!
Accepted Answer
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!