annotate aux/stereo2mono.m @ 1:b64c9fb34bd0
Response folder included in package (put README in it).
author |
Brecht <b.deman@qmul.ac.uk> |
date |
Wed, 30 Jul 2014 12:38:47 +0100 |
parents |
4fd284285159 |
children |
0014c50188da |
rev |
line source |
b@0
|
1 function [] = stereo2mono(foldername)
|
b@0
|
2 % STEREO2MONO Turns all stereo WAV files in a specified folder into two
|
b@0
|
3 % mono WAV files, named origfilename_L.wav and origfilename_R.wav
|
b@0
|
4 %
|
b@0
|
5 % written by Brecht De Man at C4DM,QMUL on 26 April 2013
|
b@0
|
6
|
b@0
|
7 currentfolder = pwd;
|
b@0
|
8 cd(foldername); % go to specified folder
|
b@0
|
9 % go over all wav files in this folder
|
b@0
|
10 files = dir('*.wav');
|
b@0
|
11
|
b@0
|
12 % remove hidden files
|
b@0
|
13 % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220
|
b@0
|
14 for k = length(files):-1:1
|
b@0
|
15 fname = files(k).name;
|
b@0
|
16 if fname(1) == '.'
|
b@0
|
17 files(k) = [ ];
|
b@0
|
18 end
|
b@0
|
19 end
|
b@0
|
20
|
b@0
|
21 for k=1:length(files)
|
b@0
|
22 disp(['Reading' files(k).name '...']);
|
b@0
|
23
|
b@0
|
24 % TODO: check stereo without reading file
|
b@0
|
25 [audio,fs] = audioread(files(k).name); % read audio
|
b@0
|
26 % check if stereo; if so, get channels and save as separate wavfile
|
b@0
|
27 if size(audio,2)==2
|
b@0
|
28 audiowrite([files(k).name(1:end-4) '_L.wav'],audio(:,1),fs, 'BitsPerSample', 24);
|
b@0
|
29 audiowrite([files(k).name(1:end-4) '_R.wav'],audio(:,2),fs, 'BitsPerSample', 24);
|
b@0
|
30 end
|
b@0
|
31 end
|
b@0
|
32 cd(currentfolder); % go back to original folder
|
b@0
|
33
|
b@0
|
34 end |