Sterio to mono conversion and vice versa in matlab



Function : strio2mono('wavfile.wav')

    This utility function converts the given stereo file in mono file and output file
wavfile_mono.wav will be created on the current working directory by default.

Function : mono2strio('wavfile.wav')

    This utility function converts the given mono file in to sterio file and output file
wavfile_sterio.wav will be created on the current working directory by default.

Fix Needed :

    The two sides of the mono2streio converted wav file should not be similar , As in
recorded streio files there should be some difference between the sampled data values.

comments and suggestions welcome

Code :
strio2mono('wavfile.wav')
 
 function stereo2mono(Filename) %---------------------------------------------- % STEREO WAV FILE INTO MONO FILE CONVERSION % Usage: % stereo2mono('urfilename.wav'); % Supports only for two channel wav files %----------------------------------------------     if(nargin == 0)         error('No input');     end     try       [AudioData,Fs,nBits] = wavread(Filename);     catch         error(['Cant read input wav file']);     end     index_AudioData = size(AudioData);     index = index_AudioData;     if(index ~= 2)         error('This is not a stereo file');     end     Audio_data_mono = AudioData(:,1); %side1     % Audio_data_stereo = AudioData; %side2(you can use this code also)(if u want to use this side, % comment the above line)     wavwrite(Audio_data_mono,Fs,nBits,[Filename,'_mono']);     disp(['WAV file ',Filename,'_mono.wav ',' .. is generated in current working directory']); end
 mono2strio('wavfile.wav')
function mono2stereo(Filename) %---------------------------------------------- % STEREO WAV FILE INTO MONO FILE CONVERSION % Usage: % mono2stereo('urfilename.wav'); % Creates only two channel output wav files %----------------------------------------------     if(nargin == 0)         error('No input');     end     try      [AudioData,Fs,nBits] = wavread(Filename);     catch         error('Cant read input wav file');     end      index_AudioData = size(AudioData);      index = index_AudioData;     if(index ~= 1)         error('This is not a mono file');     end     Audio_data_stereo(:,1) = AudioData; % side1     Audio_data_stereo(:,2) = AudioData; % side2     wavwrite(Audio_data_stereo,Fs,nBits,[Filename,'_stereo']);     disp(['WAV file ',Filename,'_stereo.wav',' is generated in current working directory']); end




Recommended DSP Maltab Books:

No comments: