help-octave
[Top][All Lists]
Advanced

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

Re: audio problems


From: Paul Kienzle
Subject: Re: audio problems
Date: Thu, 6 Dec 2001 09:39:26 -0500

If you look at the source for playaudio you will see that it writes data
out to a file as "uchar" then cats this to /dev/dsp.  This means (a) that
your 16-bit data will be munged and (b) that it will be played back at the
default rate for /dev/dsp (probably 8kHz).

My solution is to write the audio out in au format and use sox to play it.  
I write it directly to a pipe so that I don't have to deal with temporary
files:

function sound(data,rate)
    fid=popen("play -t AU -", "w")
    fwrite(fid, toascii(".snd"), 'char');
    fwrite(fid, 24, 'long', 0, 'ieee-be');
    fwrite(fid, -1, 'long', 0, 'ieee-be');
    fwrite(fid, 3, 'long', 0, 'ieee-be');
    fwrite(fid, rate, 'long', 0, 'ieee-be');
    fwrite(fid, columns(data), 'long', 0, 'ieee-be');
    fwrite(fid, 32767*clip(data,[-1, 1])', 'short', 0, 'ieee-be');
    pclose(fid);

Note that my audio data is stored as real numbers in the range [-1,1],
and clip is a simple function to enforce that:

function x = clip(x, range)
    do_fortran_indexing = 1;
    x (find (x > range (2))) = range (2);
    x (find (x < range (1))) = range (1);

I use a functions auload/ausave to load/save data in .au, .wav or .aiff
files.  Both of them handle audio data as numbers in the range [-1,1]
along with an associated sample rate.  

All of these functions are available in octave-forge under main/audio
from http://octave.sf.net.

Paul Kienzle
address@hidden

On Wed, Dec 05, 2001 at 01:10:05PM -0800, Drew Krause wrote:
> I'm running Octave 2.0.16 on Redhat 7.0 with OSS installed. I 'sox' my
> pristine 16-bit wav files to au, then use 'loadaudio' to bring them in
> as a vector. Problem is, neither 'playaudio' or 'saveaudio' seem to give
> 
> me anything but garbage (even as output au files or after I convert back
> to wav). Has anyone else had this problem?
> 
> All help appreciated! Thanks,
> Drew Krause
> 
> 
> 
> 
> 
> -------------------------------------------------------------
> 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]