help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: wavread problems update


From: Hall, Benjamin
Subject: RE: wavread problems update
Date: Mon, 9 May 2005 13:45:44 -0400

>In the section
>
>id = fread(fpi, 1,'int32');
>if (strcmp(id,'RIFF')!=0)
>
>we are reading a 32 bit number from the file and in the "if strcmp" we 


Would it be more appropriate to do the following:

id = char( fread( fpi, 4, "char") );
if ( strcmp(id,"RIFF")!=0)




-----Original Message-----
From: Doug Stewart [mailto:address@hidden
Sent: Monday, May 09, 2005 1:10 PM
To: address@hidden
Cc: address@hidden
Subject: wavread problems update


While modifying wavread.m I came across an issue with strcmp
here is part of wavread:

fpi = fopen(infile,'r');
id = fread(fpi, 1,'int32');

if (strcmp(id,'RIFF')!=0)
  error(sprintf('%s not a WAV file',infile));
end
disp(sprintf('Input file \'%s\' is RIFF format:',infile));
nbytes = fread(fpi, 1,'int32');
disp(sprintf('\tTotal length = %d bytes',nbytes));

subfmt = fread(fpi, 1,'int32');

s(4)=round(subfmt/(256^3));
sb=subfmt-s(4)*256^3;
s(3)=round(sb/256^2);
sb=sb-s(3)*256^2;
s(2)=round(sb/256^1);
sb=sb-s(2)*256^1;
s(1)=round(sb);
ss=setstr(s);

  disp(sprintf('Subformat = \'%s\' ',ss));
if (strcmp(subfmt,'WAVE')!=0)
  error('*** Cannot handle subformat %s',subfmt);
end




In the section

id = fread(fpi, 1,'int32');
if (strcmp(id,'RIFF')!=0)

we are reading a 32 bit number from the file and in the "if strcmp" we 
are assuming it is a string.
But this does not work. Should strcmp  handle this? 

To make it work I took the 32 bit number apart into 8 bit numbers and 
made a string then it works.

this code is not elegant yet and is not a finished product.

I just wanted to know if I should make strcmp handle this?
also is there a function that will do what I have done in the following? 
( take a number and assume it is some ascii chars)


s(4)=round(subfmt/(256^3));
sb=subfmt-s(4)*256^3;
s(3)=round(sb/256^2);
sb=sb-s(3)*256^2;
s(2)=round(sb/256^1);
sb=sb-s(2)*256^1;
s(1)=round(sb);
ss=setstr(s);

Doug Stewart





-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]