Mercurial > hg > ape
diff aux/batchResample.m @ 2:5e72201496c8
Bug fixes, added stripzeros function, added new loudness function, moved general documentation to top level, MATLAB_R2014b compatibility
author | Brecht De Man <b.deman@qmul.ac.uk> |
---|---|
date | Mon, 17 Nov 2014 19:43:43 +0000 |
parents | 4fd284285159 |
children | 2afd6ff39f08 |
line wrap: on
line diff
--- a/aux/batchResample.m Wed Jul 30 12:38:47 2014 +0100 +++ b/aux/batchResample.m Mon Nov 17 19:43:43 2014 +0000 @@ -1,12 +1,14 @@ -function [] = batchResample(foldername, fsnew, bitDepth) -% BATCH RESAMPLE converts sample rate of all files in folder. -% +function [] = batchresample(foldername, fsnew, bitdepthnew) +% BATCHRESAMPLE converts sample rate of all files in folder. +% % by Brecht De Man at Centre for Digital Music on 13 April 2014 -% TODO read sampling rate without reading whole file + if nargin < 2 + fsnew = 96000; + end - if nargin <3 - bitDepth = 24; + if nargin < 3 + bitdepthnew = 24; end currentfolder = pwd; @@ -19,22 +21,28 @@ for k = length(files):-1:1 fname = files(k).name; if fname(1) == '.' - files(k) = [ ]; + files(k) = []; end end for k=1:length(files) - disp(['Reading ' files(k).name '...']); - - [audio,fs] = audioread(files(k).name); % read audio + info = audioinfo(files(k).name); + bitdepth = info.BitsPerSample; + fs = info.SampleRate; - if fs==fsnew - warning('Sampling rate of original audio file is equal to current sampling rate'); + if fs==fsnew && bitdepth == bitdepthnew + disp([files(k).name ' already at ' num2str(fs) ' Hz, ' num2str(bitdepth) ' bit.']); else - resampledAudio = resample(audio, fsnew, fs); - audiowrite([files(k).name],resampledAudio, fsnew, 'BitsPerSample', bitDepth); + [audio,fs] = audioread(files(k).name); % read audio + disp([files(k).name ' was ' num2str(fs) ' Hz, ' num2str(bitdepth) ' bit.']); + if fs ~= fsnew + audio = resample(audio, fsnew, fs); + end + audiowrite([files(k).name], audio, fsnew, ... + 'BitsPerSample', bitdepthnew); end end + cd(currentfolder); % go back to original folder end \ No newline at end of file