annotate aim-mat/tools/SBReadAiff.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 %
bleeck@3 7 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 8 % (c) 2011, University of Southampton
bleeck@3 9 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 10 % download of current version is on the soundsoftware site:
bleeck@3 11 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 12 % documentation and everything is on http://www.acousticscale.org
bleeck@3 13
tomwalters@0 14
tomwalters@0 15 function ret=SBReadAiff(aifffile,echo)
tomwalters@0 16 % usage SBReadAiff(aifffile,echo)
tomwalters@0 17 %
tomwalters@0 18 % returns all info in a struct
tomwalters@0 19 % if echo =0, than no screen output is created
tomwalters@0 20 if nargin<2
tomwalters@0 21 echo=1;
tomwalters@0 22 end
tomwalters@0 23
tomwalters@0 24
tomwalters@0 25 aiffstruct=getAIFFinfo(aifffile);
tomwalters@0 26 if echo
tomwalters@0 27 fprintf('read %d frames with %d channels...',aiffstruct.numWindowFrames,aiffstruct.numChannels);end
tomwalters@0 28
tomwalters@0 29 ende=0;
tomwalters@0 30 n=0;
tomwalters@0 31 nap=zeros(aiffstruct.numChannels,aiffstruct.frameLength,aiffstruct.numWindowFrames);
tomwalters@0 32
tomwalters@0 33 if aiffstruct.littleEndian
tomwalters@0 34 fid=fopen(aifffile,'r','l');
tomwalters@0 35 else
tomwalters@0 36 fid=fopen(aifffile,'r','b');
tomwalters@0 37 end
tomwalters@0 38
tomwalters@0 39 while ~ende
tomwalters@0 40 von=n*30+1;
tomwalters@0 41 bis=(n+1)*30;
tomwalters@0 42 n=n+1;
tomwalters@0 43 if bis>aiffstruct.numWindowFrames
tomwalters@0 44 bis=aiffstruct.numWindowFrames;
tomwalters@0 45 ende=1;
tomwalters@0 46 end
tomwalters@0 47
tomwalters@0 48 status = fseek(fid, aiffstruct.soundPosition, 'bof');
tomwalters@0 49 tnap = ReadWinFrame2(fid, von:bis, aiffstruct.numWindowFrames,...
tomwalters@0 50 aiffstruct.numChannels,aiffstruct.frameLength, aiffstruct.wordSize,echo);
tomwalters@0 51
tomwalters@0 52 if bis>=aiffstruct.numWindowFrames;
tomwalters@0 53 ende=1;
tomwalters@0 54 end
tomwalters@0 55
tomwalters@0 56 if echo
tomwalters@0 57 fprintf('\n'); end
tomwalters@0 58
tomwalters@0 59 tnap = tnap .* aiffstruct.scale;
tomwalters@0 60
tomwalters@0 61 % tnap = myReadAIFF(aifffile,von:bis);
tomwalters@0 62 nap(:,:,von:bis)=tnap;
tomwalters@0 63 end
tomwalters@0 64
tomwalters@0 65 [nr_channels,nr_points,nr_frames]=size(nap);
tomwalters@0 66
tomwalters@0 67 high=-inf;low=inf;
tomwalters@0 68 sumhigh=-inf;
tomwalters@0 69 frehigh=-inf;
tomwalters@0 70 % do some controlling of the values
tomwalters@0 71 for i=1:nr_frames
tomwalters@0 72 vals=nap(:,:,i);
tomwalters@0 73 fr=frame(vals,aiffstruct); % construct the frame
tomwalters@0 74 ret(i)=fr;
tomwalters@0 75
tomwalters@0 76 % find the maximum and the minimum values of each frame. this is useful for scaling
tomwalters@0 77 ma=getmaximumvalue(fr);
tomwalters@0 78 high=max([high ma]);
tomwalters@0 79 mi=getminimumvalue(fr);
tomwalters@0 80 low=min([low mi]);
tomwalters@0 81
tomwalters@0 82
tomwalters@0 83 maxs=max(getsum(fr));
tomwalters@0 84 sumhigh=max([maxs sumhigh]);
tomwalters@0 85
tomwalters@0 86 maxf=max(getfrequencysum(fr));
tomwalters@0 87 frehigh=max([maxf frehigh]);
tomwalters@0 88
tomwalters@0 89 end
tomwalters@0 90
tomwalters@0 91 % sr=getsr(ret(1));
tomwalters@0 92
tomwalters@0 93 for i=1:nr_frames
tomwalters@0 94 ret(i)=setallmaxvalue(ret(i),high);
tomwalters@0 95 ret(i)=setallminvalue(ret(i),low);
tomwalters@0 96 ret(i)=setnrframestotal(ret(i),nr_frames);
tomwalters@0 97 ret(i)=setscalesumme(ret(i),sumhigh);
tomwalters@0 98 ret(i)=setscalefrequency(ret(i),frehigh);
tomwalters@0 99 ret(i)=setcurrentframenumber(ret(i),i);
tomwalters@0 100 frame_duration=aiffstruct.frameLength/aiffstruct.sampleRate;
tomwalters@0 101 ret(i)=setcurrentframestarttime(ret(i),(i-1)*frame_duration);
tomwalters@0 102 end