b@0: function [] = batchResample(foldername, fsnew, bitDepth) b@0: % BATCH RESAMPLE converts sample rate of all files in folder. b@0: % b@0: % by Brecht De Man at Centre for Digital Music on 13 April 2014 b@0: b@0: % TODO read sampling rate without reading whole file b@0: b@0: if nargin <3 b@0: bitDepth = 24; b@0: end b@0: b@0: currentfolder = pwd; b@0: cd(foldername); % go to specified folder b@0: % go over all wav files in this folder b@0: files = dir('*.wav'); b@0: b@0: % remove hidden files from list b@0: % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220 b@0: for k = length(files):-1:1 b@0: fname = files(k).name; b@0: if fname(1) == '.' b@0: files(k) = [ ]; b@0: end b@0: end b@0: b@0: for k=1:length(files) b@0: disp(['Reading ' files(k).name '...']); b@0: b@0: [audio,fs] = audioread(files(k).name); % read audio b@0: b@0: if fs==fsnew b@0: warning('Sampling rate of original audio file is equal to current sampling rate'); b@0: else b@0: resampledAudio = resample(audio, fsnew, fs); b@0: audiowrite([files(k).name],resampledAudio, fsnew, 'BitsPerSample', bitDepth); b@0: end b@0: end b@0: cd(currentfolder); % go back to original folder b@0: b@0: end