Mercurial > hg > ape
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4fd284285159 |
---|---|
1 function [] = batchResample(foldername, fsnew, bitDepth) | |
2 % BATCH RESAMPLE converts sample rate of all files in folder. | |
3 % | |
4 % by Brecht De Man at Centre for Digital Music on 13 April 2014 | |
5 | |
6 % TODO read sampling rate without reading whole file | |
7 | |
8 if nargin <3 | |
9 bitDepth = 24; | |
10 end | |
11 | |
12 currentfolder = pwd; | |
13 cd(foldername); % go to specified folder | |
14 % go over all wav files in this folder | |
15 files = dir('*.wav'); | |
16 | |
17 % remove hidden files from list | |
18 % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220 | |
19 for k = length(files):-1:1 | |
20 fname = files(k).name; | |
21 if fname(1) == '.' | |
22 files(k) = [ ]; | |
23 end | |
24 end | |
25 | |
26 for k=1:length(files) | |
27 disp(['Reading ' files(k).name '...']); | |
28 | |
29 [audio,fs] = audioread(files(k).name); % read audio | |
30 | |
31 if fs==fsnew | |
32 warning('Sampling rate of original audio file is equal to current sampling rate'); | |
33 else | |
34 resampledAudio = resample(audio, fsnew, fs); | |
35 audiowrite([files(k).name],resampledAudio, fsnew, 'BitsPerSample', bitDepth); | |
36 end | |
37 end | |
38 cd(currentfolder); % go back to original folder | |
39 | |
40 end |