diff aux/batchResample.m @ 0:4fd284285159

Adding listening test plus some helpful functions and scripts.
author Brecht <b.deman@qmul.ac.uk>
date Thu, 24 Apr 2014 23:53:31 +0100
parents
children 5e72201496c8
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aux/batchResample.m	Thu Apr 24 23:53:31 2014 +0100
@@ -0,0 +1,40 @@
+function [] = batchResample(foldername, fsnew, bitDepth)
+% BATCH RESAMPLE 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 <3
+        bitDepth = 24;
+    end
+
+    currentfolder = pwd;
+    cd(foldername); % go to specified folder
+    % go over all wav files in this folder
+    files = dir('*.wav');
+
+    % remove hidden files from list
+    % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220
+    for k = length(files):-1:1
+        fname = files(k).name;
+        if fname(1) == '.'
+            files(k) = [ ];
+        end
+    end
+
+    for k=1:length(files)
+            disp(['Reading ' files(k).name '...']);
+
+            [audio,fs] = audioread(files(k).name); % read audio
+            
+            if fs==fsnew
+                warning('Sampling rate of original audio file is equal to current sampling rate');
+            else
+                resampledAudio = resample(audio, fsnew, fs);
+                audiowrite([files(k).name],resampledAudio, fsnew, 'BitsPerSample', bitDepth);
+            end
+    end
+    cd(currentfolder); % go back to original folder
+
+end
\ No newline at end of file