how to run my conversion program using loops

Hi
I have a program of resampling and conversion wav to pcm
so I have a main folder that contains several subfolders
and each subfolder contains a wav file and a text file
I want to run my program on all wav files in all subfolders, I can not do it,Thank you very much for your help.
here is my program:
[x, fs] = audioread(a_filename);
% resample:
fsin = fs;
fsout = 22050;
m = lcm(fsin,fsout);
up = m/fsin;
down = m/fsout;
x_22 = resample(x, up, down);
audiowrite([a_filename,'_22050','.wav'], x_22, fsout);
% convert to PCM 16 bit
precision = 'int16';
fidr = fopen([a_filename(1:11), '_22050','.wav'], 'r'); % open .wav file to read
fidw = fopen([a_filename(1:11), '_22050','.pcm'], 'wb'); % open .pcm file to write
w = int16(fread(fidr, inf, precision));% read .wav file
fwrite(fidw, w, precision); % write .pcm file
fclose(fidr);
fclose(fidw);
thank you in advance

Respuestas (1)

per isakson
per isakson el 29 de Jun. de 2019
Editada: per isakson el 29 de Jun. de 2019
Try this
%%
main_folder = 'c:\whatever\mainfolder';
sad = dir( fullfile( main_folder, '**', '*.wav' );
sad = reshape( sad, 1,[] );
for wav = sad
ffs = fullfile( wav.folder, wav.name );
disp( ffs )
end
If recursive dir call, "**", is not avaiable in your Matlab release try Recursive directory listing - Enhanced RDIR . (There are several rdir() in the File Exchange.)

3 comentarios

Rik
Rik el 29 de Jun. de 2019
Editada: Rik el 30 de Jun. de 2019
Just to confirm: the ** syntax was not available in the R2014a dir function.
per isakson
per isakson el 30 de Jun. de 2019
Recursive directory listing by Gus Brown is "Created with R2007a, Compatible with any release". I've used it for a long time and cannot remember it having caused me any problem.
Rik
Rik el 30 de Jun. de 2019
I just meant you do indeed need to use such a function, instead of using built-in Matlab tools. I'll edit the comment to make it more clear.

Iniciar sesión para comentar.

Categorías

Más información sobre Audio Processing Algorithm Design en Centro de ayuda y File Exchange.

Productos

Versión

R2014a

Preguntada:

el 29 de Jun. de 2019

Editada:

Rik
el 30 de Jun. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by