How to generate all possible combinations of audio files?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Magdalena Kachlicka
el 13 de Feb. de 2020
Comentada: Magdalena Kachlicka
el 28 de Mzo. de 2020
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!
0 comentarios
Respuesta aceptada
Spencer Chen
el 13 de Feb. de 2020
If you have to use nchoose(), then something like this would work:
combinations = nchoosek(SoundNames, 2);
for i = 1:size(combinations,1)
% Load and add sound from combinations{i,1} and combinations{i,2}
end
I would personally do the nested for-loop:
for i = 1:numel(myFiles)
for j = (i+1):numel(myFiles)
% Load and add sound from myFiles(i).name and myFiles(j).name
end
end
But to be most efficient, I'll do a first pass to load all sound files (given we've got enought RAM), then do the nested for-loop for combining the sound.
I don't have catpad installed, so can't test it, but I can guess what it does. To hone in on my Matlab skills, I would personally just write the code to do this operation. It's not too hard, and it's a good exercise.
Blessings,
Spencer
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!