annotate aim-mat/tools/@signal/savewave.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 % method of class @signal
tomwalters@0 2 % savewave(sig,name[,ramp])
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 % name : name of the resulting sound file
tomwalters@0 5 % ramp: if given, then the signal is ramped with a linear ramp with
tomwalters@0 6 % that duration
tomwalters@0 7 % RETURN VALUE:
tomwalters@0 8 %
tomwalters@0 9 %
bleeck@3 10 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 11 % (c) 2011, University of Southampton
bleeck@3 12 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 13 % download of current version is on the soundsoftware site:
bleeck@3 14 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 15 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 16
tomwalters@0 17 function savewave(sig,name,ramp)
tomwalters@0 18 % does some things, to make a nice sound out of it
tomwalters@0 19
tomwalters@0 20 if nargin < 3
tomwalters@0 21 ramp=0.0; % default ramp is off
tomwalters@0 22 end
tomwalters@0 23 if nargin < 2
tomwalters@0 24 name='just saved';
tomwalters@0 25 end
tomwalters@0 26
tomwalters@0 27
tomwalters@0 28
tomwalters@0 29 sig=rampamplitude(sig,ramp);
tomwalters@0 30 sig=scaletomaxvalue(sig,0.999);
tomwalters@0 31 if isempty(strfind(name,'.wav'))
tomwalters@0 32 name=sprintf('%s.wav',name);
tomwalters@0 33 end
tomwalters@0 34
tomwalters@0 35 fid=fopen(name, 'w');
tomwalters@0 36 if fid==-1
tomwalters@0 37 disp(sprintf('can''t write file ''%s'', is file open in CoolEdit? If so please close!',name));
tomwalters@0 38 error('file open in CoolEdit... Cant write');
tomwalters@0 39 else
tomwalters@0 40 % TCW AIM 2006
tomwalters@0 41 fclose(fid); % Otherwise MATLAB leaves the file open for writing for ever!
tomwalters@0 42
tomwalters@0 43 writetowavefile(sig,name);
tomwalters@0 44 end