annotate aux/stereo2mono.m @ 15:24be5e9ce25b tip

Update README
author Brecht De Man <brecht.deman@bcu.ac.uk>
date Thu, 20 Sep 2018 12:23:20 +0200
parents 22964a1dc292
children
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@11 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@13 28 audiowrite([files(k).name(1:end-4) '.L.wav'],audio(:,1),fs, 'BitsPerSample', 24);
b@13 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