Mercurial > hg > ape
comparison aux/batchResample.m @ 8:2afd6ff39f08
prepare2listen fixes
author | Brecht De Man <b.deman@qmul.ac.uk> |
---|---|
date | Fri, 28 Nov 2014 00:52:12 +0000 |
parents | 5e72201496c8 |
children | 866c5da4d357 |
comparison
equal
deleted
inserted
replaced
7:d113f0626fe3 | 8:2afd6ff39f08 |
---|---|
8 end | 8 end |
9 | 9 |
10 if nargin < 3 | 10 if nargin < 3 |
11 bitdepthnew = 24; | 11 bitdepthnew = 24; |
12 end | 12 end |
13 | 13 |
14 currentfolder = pwd; | |
15 cd(foldername); % go to specified folder | |
16 % go over all wav files in this folder | 14 % go over all wav files in this folder |
17 files = dir('*.wav'); | 15 files = dir([foldername '/*.wav']); |
18 | 16 |
19 % remove hidden files from list | 17 % remove hidden files from list |
20 % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220 | 18 % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220 |
21 for k = length(files):-1:1 | 19 for k = length(files):-1:1 |
22 fname = files(k).name; | 20 fname = files(k).name; |
24 files(k) = []; | 22 files(k) = []; |
25 end | 23 end |
26 end | 24 end |
27 | 25 |
28 for k=1:length(files) | 26 for k=1:length(files) |
29 info = audioinfo(files(k).name); | 27 info = audioinfo([foldername '/' files(k).name]); |
30 bitdepth = info.BitsPerSample; | 28 bitdepth = info.BitsPerSample; |
31 fs = info.SampleRate; | 29 fs = info.SampleRate; |
32 | 30 |
33 if fs==fsnew && bitdepth == bitdepthnew | 31 if fs==fsnew && bitdepth == bitdepthnew |
34 disp([files(k).name ' already at ' num2str(fs) ' Hz, ' num2str(bitdepth) ' bit.']); | 32 disp([files(k).name ' already at ' num2str(fs) ' Hz, ' num2str(bitdepth) ' bit.']); |
35 else | 33 else |
36 [audio,fs] = audioread(files(k).name); % read audio | 34 [audio,fs] = audioread([foldername '/' files(k).name]); % read audio |
37 disp([files(k).name ' was ' num2str(fs) ' Hz, ' num2str(bitdepth) ' bit.']); | 35 disp([files(k).name ' was ' num2str(fs) ' Hz, ' num2str(bitdepth) ' bit.']); |
38 if fs ~= fsnew | 36 if fs ~= fsnew |
39 audio = resample(audio, fsnew, fs); | 37 audio = resample(audio, fsnew, fs); |
40 end | 38 end |
41 audiowrite([files(k).name], audio, fsnew, ... | 39 audiowrite([foldername '/' files(k).name], audio/max(max(abs(audio))), ... |
42 'BitsPerSample', bitdepthnew); | 40 fsnew, 'BitsPerSample', bitdepthnew); |
43 end | 41 end |
44 end | 42 end |
45 | |
46 cd(currentfolder); % go back to original folder | |
47 | 43 |
48 end | 44 end |