b@0: function [] = stereo2mono(foldername) b@0: % STEREO2MONO Turns all stereo WAV files in a specified folder into two b@0: % mono WAV files, named origfilename_L.wav and origfilename_R.wav b@0: % b@0: % written by Brecht De Man at C4DM,QMUL on 26 April 2013 b@0: b@0: currentfolder = pwd; b@0: cd(foldername); % go to specified folder b@0: % go over all wav files in this folder b@0: files = dir('*.wav'); b@0: b@0: % remove hidden files b@0: % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220 b@0: for k = length(files):-1:1 b@0: fname = files(k).name; b@0: if fname(1) == '.' b@0: files(k) = [ ]; b@0: end b@0: end b@0: b@0: for k=1:length(files) b@11: disp(['Reading ' files(k).name '...']); b@0: b@0: % TODO: check stereo without reading file b@0: [audio,fs] = audioread(files(k).name); % read audio b@0: % check if stereo; if so, get channels and save as separate wavfile b@0: if size(audio,2)==2 b@13: audiowrite([files(k).name(1:end-4) '.L.wav'],audio(:,1),fs, 'BitsPerSample', 24); b@13: audiowrite([files(k).name(1:end-4) '.R.wav'],audio(:,2),fs, 'BitsPerSample', 24); b@0: end b@0: end b@0: cd(currentfolder); % go back to original folder b@0: b@0: end