tomwalters@0: % tool tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % tomwalters@0: % RETURN VALUE: tomwalters@0: % tomwalters@0: % bleeck@3: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: tomwalters@0: tomwalters@0: function [data,samplerate,endian]=rawfile2wavfile(datafile,samplerate,endian) tomwalters@0: % usage: wavdata=rawfile2wavfile(datafile,samplerate,endian) tomwalters@0: % input: the name of a datafile and the samplerate tomwalters@0: % endian is little or big endian to indicate byte order tomwalters@0: % output: the vector of the data tomwalters@0: % and the file "datafile" with the extension "wav" tomwalters@0: tomwalters@0: if nargin< 2 tomwalters@0: valid=0; tomwalters@0: while ~valid tomwalters@0: strsamplerate=input('please input samplerate (default: 20000) ','s'); tomwalters@0: if isempty(strsamplerate) tomwalters@0: strsamplerate = '20000'; tomwalters@0: end tomwalters@0: samplerate=sscanf(strsamplerate,'%f'); tomwalters@0: valid=(samplerate>0); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: if nargin< 3 tomwalters@0: valid=0; tomwalters@0: while ~valid tomwalters@0: endian=input('please input endian: (l)ittle or (b)ig (default: l) ','s'); tomwalters@0: if isempty(endian) tomwalters@0: endian = 'l'; tomwalters@0: end tomwalters@0: valid=(size(endian,2)==1) & ((endian=='l') | (endian=='b')); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: try tomwalters@0: fid=fopen(datafile,'r',endian); tomwalters@0: catch tomwalters@0: disp('rawfile2wavfile: could not open file'); tomwalters@0: disp(datafile); tomwalters@0: return; tomwalters@0: end tomwalters@0: tomwalters@0: data=fread(fid,'integer*2'); tomwalters@0: tomwalters@0: % data=data/max(data)*0.9999; tomwalters@0: data=data/32768; tomwalters@0: tomwalters@0: [path,name,ext,versn] = fileparts(datafile); tomwalters@0: newfilename=sprintf('%s.wav',name); tomwalters@0: newname=fullfile(path,newfilename); tomwalters@0: tomwalters@0: wavwrite(data,samplerate,newname); tomwalters@0: