Mercurial > hg > ape
diff aux/stereo2mono.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 | 0014c50188da |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aux/stereo2mono.m Thu Apr 24 23:53:31 2014 +0100 @@ -0,0 +1,34 @@ +function [] = stereo2mono(foldername) +% STEREO2MONO Turns all stereo WAV files in a specified folder into two +% mono WAV files, named origfilename_L.wav and origfilename_R.wav +% +% written by Brecht De Man at C4DM,QMUL on 26 April 2013 + +currentfolder = pwd; +cd(foldername); % go to specified folder +% go over all wav files in this folder +files = dir('*.wav'); + +% remove hidden files +% see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220 +for k = length(files):-1:1 + fname = files(k).name; + if fname(1) == '.' + files(k) = [ ]; + end +end + +for k=1:length(files) + disp(['Reading' files(k).name '...']); + + % TODO: check stereo without reading file + [audio,fs] = audioread(files(k).name); % read audio + % check if stereo; if so, get channels and save as separate wavfile + if size(audio,2)==2 + audiowrite([files(k).name(1:end-4) '_L.wav'],audio(:,1),fs, 'BitsPerSample', 24); + audiowrite([files(k).name(1:end-4) '_R.wav'],audio(:,2),fs, 'BitsPerSample', 24); + end +end +cd(currentfolder); % go back to original folder + +end \ No newline at end of file