wav error

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

wav error

Cesar Augusto Rodriguez
Hi...
|
| I need your help.
|
| I can't read .wav files using wavread.m. Octave starts into int then crashes
|
| the error is like that :
|
| [s1,fs]=wavread('H:/biovoz/delphi/ocho.wav')
| Input file 'H:/biovoz/delphi/ocho.wav' is RIFF format:
|        Total length = 48036 bytes
|        Number of channels = 1
|        Sampling rate = 12500 Hz
| error: *** 8000 bytes per second looks wrong. Expect 25000
| error: evaluating if command near line 48, column 1
| error: called from `wavread' in file `/usr/share/octave/2.1.36/m/audio/wavread.m'
|
| thanks for your help.

 
 
 
Reply | Threaded
Open this post in threaded view
|

Re: wav error

Bill Denney
2.1.36 is a very old version of octave.  I would suggest upgrading to the
most recent version.  If you're running windows, you can download cygwin
at http://www.cygwin.com, click on the install cygwin now link at the top
right, and select octave from the list of packages to install.

Bill

On Wed, 14 Dec 2005, Cesar Augusto Rodriguez wrote:

> Hi...
> |
> | I need your help.
> |
> | I can't read .wav files using wavread.m. Octave starts into int then crashes
> |
> | the error is like that :
> |
> | [s1,fs]=wavread('H:/biovoz/delphi/ocho.wav')
> | Input file 'H:/biovoz/delphi/ocho.wav' is RIFF format:
> |        Total length = 48036 bytes
> |        Number of channels = 1
> |        Sampling rate = 12500 Hz
> | error: *** 8000 bytes per second looks wrong. Expect 25000
> | error: evaluating if command near line 48, column 1
> | error: called from `wavread' in file `/usr/share/octave/2.1.36/m/audio/wavread.m'
> |
> | thanks for your help.
>
>
>
>

--
"Remember kids, Drunken Cowboy whiskey is as smooth as milk."
   -- Buck McCoy, The Simpsons



-------------------------------------------------------------
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 | Threaded
Open this post in threaded view
|

Re: wav error

Robert A. Macy
In reply to this post by Cesar Augusto Rodriguez
Here is a "recent" copy.  Someone updated it to accept new
formats, I think.  

The Header of your .wav file may be contradictory. Have you
checked it?

* * * * * *
function [sig, sf, bits]=wavread2(wavefile, siz, fmt24bit)

% WAVREAD  Load Microsoft Windows .WAV format sound files.
%
%  [sig, sf, bits] = wavread(wavfile [, siz])
%  
%        sig : signal
%         sf : sampling freq.
%       bits : the number of bits per sample (8, 16,
24bits)
%    wavfile : file name
%              (The ".wav" extension is appended if no
extension is given.)
%        siz : 'size' returns the size of the audio data
%            : [N1 N2] returns only samples N1 through N2
%            : N1 returns the first N1 samples
%   fmt24bit :  0 = digion format
%            :  1 =  2^23 format for 24 bit data
%            : Default is 1

% Modified By: Doug Stewart May 10, 5005

if nargin < 1
  help wavread;
  return;
end

if nargin < 3
   fmt24bit = 1;
end

% fmt24bit = 1; % fmt24bit =0: digion format, fmt24bit=1:
2^23 format for 24 bit data
if fmt24bit==1
  cnst = 1;
else
  cnst = 2;
end

if isempty(findstr(wavefile,'.'))
  wavefile=[wavefile,'.wav'];
end

fid=fopen(wavefile,'rb','ieee-le');
if fid == -1
  error('Can''t open .WAV file for input!');
end;

% read riff chunk ChunkID 4 bytes
RIFF_str=(char(fread(fid,4,'uchar')))';
if (strcmp(RIFF_str,'RIFF')==0)
  fclose(fid);
  error(sprintf('%s is not a WAV file',wavefile));
  return;
end
first=RIFF_str
disp(sprintf('Input file \'%s\' is RIFF
format:',wavefile));

% ChunkSize 4 bytes
nbytes=fread(fid,1,'ulong');
disp(sprintf('\tTotal length = %d bytes',nbytes));

% Format 4 bytes
WAVE_str=(char(fread(fid,4,'uchar')))';
disp(sprintf('Subformat = \'%s\' ',WAVE_str));
if (strcmp(WAVE_str,'WAVE')==0)
  fclose(fid);
  error('*** Cannot handle subformat %s',WAVE_str);
  return;
end


% read format subchunk1ID 4 bytes "fmt "
fmt_str=(char(fread(fid,4,'uchar')))';
if (strcmp(fmt_str,'fmt ')==0)
  fclose(fid);
  error(sprintf('*** Expected \'fmt \' in header, but got
\'', fmt_str));
  return;
end

% Subchunk1Size 4 bytes should be 16 for PCM
fslen=fread(fid,1,'ulong');

% audioformat 2 byts    1 = PCM, other than 1 is some form
of compresion
audioformat=fread(fid,1,'ushort');                %
AudioFormat

if (audioformat != 1)
  fclose(fid);
  disp(sprintf('*** This Version does not support audio
compresion'));
  error(sprintf('*** Expected 01 in audio format, but got
%d',audioformat));

end

ch=fread(fid,1,'ushort');                % NumChannels  2
bytes
disp(sprintf('\tNumber of chanels = %d ', ch));
sf=fread(fid,1,'ulong');                 % Samples per
second 4 bytes
ByteRate=fread(fid,1,'ulong');             % ByteRate  ==
SampleRate * NumChannels * BitsPerSample/8  4 bytes
block=fread(fid,1,'ushort');              % BlockAlign  ==
NumChannels * BitsPerSample/8 2 bytes
bits=fread(fid,1,'ushort');                % Bits per
sample   2 bytes
disp(sprintf('\tBits per sample = %d ', bits));

% throw away the rest of this chunk  
if fslen-16 > 0
  dum = fread(fid, fslen-16, 'uchar');
end


% now look for the data chunk.

do
id = char( fread( fid, 4, "uchar") );
if (strcmp(id,'data')==0) % if not 'data' then read size
and throw away this section
   cl2 = fread(fid,1,'ulong');
   cl3 = fread(fid,cl2,'uchar');
endif
until (strcmp(id,'data')!=0)

if (strcmp(id,'data')==0)
  fclose(fid);
  error(sprintf('Did not find \'data\' ID where
expected'));
end

%  now read the data chunk size  4 bytes
nbyteforsamples=fread(fid,1,'ulong');

nsamples=nbyteforsamples/block;
disp(sprintf('\tData length = %d samples', nsamples));


if(nargin < 2)
  siz = [1 nsamples];
end

if(strcmp(siz, 'size'))
  sig = [nsamples, ch];
  fclose(fid);
  return;
end

if length(siz)==1
     st = 1;
     et = siz;
  else
     st = siz(1);  %  start of data to return
     et = siz(2);  % end of data to return
end

if bits == 8
  fseek(fid, (st-1)*ch, 0);
  [sig, cnt] = fread(fid, [ch, et-st+1],'uchar');
  sig = (sig-128)/128;
end

if bits == 16
  fseek(fid, (st-1)*2*ch, 0);
  [sig, cnt] = fread(fid, [ch, et-st+1], 'short');
  sig = sig/32768;     % MATLAB compatible
%  sig = (sig+32768)/32767.5-1;
end

if bits == 24
  fseek(fid, (st-1)*3*ch, 0);
  len = et-st+1;
  tmpsig = fread(fid, [1, (et-st+1)*3*ch], 'uchar');
  for k=1:ch
    idx = (0:len-1)*3*ch+(k-1)*3+1;
    signm = tmpsig(idx+2) > 127;
    sig(k,:) =
-signm.*((255-tmpsig(idx+2))*2^16+cnst+(255-tmpsig(idx))+(255-tmpsig(idx+1))*2^8)+(1-signm).*(tmpsig(idx+2)*2^16+tmpsig(idx)+tmpsig(idx+1)*2^8);
  end
  if fmt
    sig = sig/2^23;
  else
    sig = (sig+2^23)/(2^23-0.5)-1;
  end
end


sig = sig'; % transpose for Matlab compatability
fclose(fid);


* * * * * *


On Wed, 14 Dec 2005 14:04:48 -0500
 "Cesar Augusto Rodriguez" <[hidden email]>
wrote:

> Hi...
> |
> | I need your help.
> |
> | I can't read .wav files using wavread.m. Octave starts
> into int then crashes
> |
> | the error is like that :
> |
> | [s1,fs]=wavread('H:/biovoz/delphi/ocho.wav')
> | Input file 'H:/biovoz/delphi/ocho.wav' is RIFF format:
> |        Total length = 48036 bytes
> |        Number of channels = 1
> |        Sampling rate = 12500 Hz
> | error: *** 8000 bytes per second looks wrong. Expect
> 25000
> | error: evaluating if command near line 48, column 1
> | error: called from `wavread' in file
> `/usr/share/octave/2.1.36/m/audio/wavread.m'
> |
> | thanks for your help.
>
>
>



-------------------------------------------------------------
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 | Threaded
Open this post in threaded view
|

Re: wav error

Bill Denney
In reply to this post by Bill Denney
I guess wavread is part of octave forge.  You will need to install that as
well.

It's best to respond to the list instead of individuals so that you can
get the fastest help, and if someone in the future has the same problem,
they can find it just by searching for their problem.

Bill

On Wed, 14 Dec 2005, Cesar Augusto Rodriguez wrote:

> hi
> from CGWIN I can not to use wavread fucntion
>
> [s,fs]=wavread ('c:\ocho.wav')
>
> sintax error near unexpected token 'c:\ocho.wav'
>
> please help me
>
> thank you
>

--
"A Perl script looks like an explosion in an ASCII factory."  -- unknown



-------------------------------------------------------------
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 | Threaded
Open this post in threaded view
|

Re: wav error

John W. Eaton-6
On 14-Dec-2005, Bill Denney wrote:

| I guess wavread is part of octave forge.  You will need to install that as
| well.

There are now wavread and wavwrite functions in the current CVS Octave
(2.9.x branch).  Both functions are m-files though, and I think they
will work with older versions of Octave.

| It's best to respond to the list instead of individuals so that you can
| get the fastest help, and if someone in the future has the same problem,
| they can find it just by searching for their problem.
|
| Bill
|
| On Wed, 14 Dec 2005, Cesar Augusto Rodriguez wrote:
|
| > hi
| > from CGWIN I can not to use wavread fucntion
| >
| > [s,fs]=wavread ('c:\ocho.wav')
| >
| > sintax error near unexpected token 'c:\ocho.wav'

Does Octave with Cygwin know anything about Windows file names?  I
suspect you should be using

  [s,fs]=wavread ('/cygdrive/c/ocho.wav')

instead.  Or, if Windows filenames do work, then with older versions
of Octave, you will have to use

  [s,fs]=wavread ('c:\\ocho.wav')

because "\" is an escape character in Octave characters strings
(though this has changed in the 2.9.x branch of Octave for
single-quoted strings, for compatibility with the other leading
brand).

jwe



-------------------------------------------------------------
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 | Threaded
Open this post in threaded view
|

Re: wav error

Stéfan van der Walt
In reply to this post by Cesar Augusto Rodriguez
On Wed, Dec 14, 2005 at 02:04:48PM -0500, Cesar Augusto Rodriguez wrote:

> | I can't read .wav files using wavread.m. Octave starts into int then crashes
> |
> | the error is like that :
> |
> | [s1,fs]=wavread('H:/biovoz/delphi/ocho.wav')
> | Input file 'H:/biovoz/delphi/ocho.wav' is RIFF format:
> |        Total length = 48036 bytes
> |        Number of channels = 1
> |        Sampling rate = 12500 Hz
> | error: *** 8000 bytes per second looks wrong. Expect 25000
> | error: evaluating if command near line 48, column 1
> | error: called from `wavread' in file `/usr/share/octave/2.1.36/m/audio/
> wavread.m'

This has been fixed in the latest octave-forge version.

Regards
Stéfan



-------------------------------------------------------------
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
-------------------------------------------------------------