annotate aim-mat/tools/rawfile2wavfile.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % tool
tomwalters@0 2 %
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 %
tomwalters@0 5 % RETURN VALUE:
tomwalters@0 6 %
tomwalters@0 7 %
bleeck@3 8 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 9 % (c) 2011, University of Southampton
bleeck@3 10 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 11 % download of current version is on the soundsoftware site:
bleeck@3 12 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 13 % documentation and everything is on http://www.acousticscale.org
bleeck@3 14
tomwalters@0 15
tomwalters@0 16 function [data,samplerate,endian]=rawfile2wavfile(datafile,samplerate,endian)
tomwalters@0 17 % usage: wavdata=rawfile2wavfile(datafile,samplerate,endian)
tomwalters@0 18 % input: the name of a datafile and the samplerate
tomwalters@0 19 % endian is little or big endian to indicate byte order
tomwalters@0 20 % output: the vector of the data
tomwalters@0 21 % and the file "datafile" with the extension "wav"
tomwalters@0 22
tomwalters@0 23 if nargin< 2
tomwalters@0 24 valid=0;
tomwalters@0 25 while ~valid
tomwalters@0 26 strsamplerate=input('please input samplerate (default: 20000) ','s');
tomwalters@0 27 if isempty(strsamplerate)
tomwalters@0 28 strsamplerate = '20000';
tomwalters@0 29 end
tomwalters@0 30 samplerate=sscanf(strsamplerate,'%f');
tomwalters@0 31 valid=(samplerate>0);
tomwalters@0 32 end
tomwalters@0 33 end
tomwalters@0 34
tomwalters@0 35 if nargin< 3
tomwalters@0 36 valid=0;
tomwalters@0 37 while ~valid
tomwalters@0 38 endian=input('please input endian: (l)ittle or (b)ig (default: l) ','s');
tomwalters@0 39 if isempty(endian)
tomwalters@0 40 endian = 'l';
tomwalters@0 41 end
tomwalters@0 42 valid=(size(endian,2)==1) & ((endian=='l') | (endian=='b'));
tomwalters@0 43 end
tomwalters@0 44 end
tomwalters@0 45
tomwalters@0 46 try
tomwalters@0 47 fid=fopen(datafile,'r',endian);
tomwalters@0 48 catch
tomwalters@0 49 disp('rawfile2wavfile: could not open file');
tomwalters@0 50 disp(datafile);
tomwalters@0 51 return;
tomwalters@0 52 end
tomwalters@0 53
tomwalters@0 54 data=fread(fid,'integer*2');
tomwalters@0 55
tomwalters@0 56 % data=data/max(data)*0.9999;
tomwalters@0 57 data=data/32768;
tomwalters@0 58
tomwalters@0 59 [path,name,ext,versn] = fileparts(datafile);
tomwalters@0 60 newfilename=sprintf('%s.wav',name);
tomwalters@0 61 newname=fullfile(path,newfilename);
tomwalters@0 62
tomwalters@0 63 wavwrite(data,samplerate,newname);
tomwalters@0 64