ossaudiodev problem: sawtooth noise

Peter Pearson ppearson at nowhere.invalid
Mon Jan 19 18:57:04 EST 2009


The following code uses ossaudiodev to read 1000 values from
my sound card at a rate of 12,000 samples per second:

*********** begin code ***********

import ossaudiodev as o
import struct

d = o.open( "r" )
_, _, _ = d.setparameters( o.AFMT_S16_LE,
                           1,       # channels
                           12000,   # samples/s
                           True )   # strict
n_samples = 1000
bytes = d.read( 2 * n_samples )
for x in struct.unpack( "<%dh" % n_samples, bytes ):
  print( "%d" % x )
d.close()

************* end code ************

When I select a sample rate that is not a power of 2 times
3000 samples/second, a strong and very regular sawtooth is
superimposed on the signal.  At some sampling frequencies,
it appears as a rising sawtooth, and at other sampling
frequencies it is a declining sawtooth, so I'm presumably
lost in some aliasing wilderness.  As best I can tell,
it's a 48 KHz sawtooth.

Am I doing something wrong?

Is ossaudiodev the wrong choice for capturing sound-card
data?

Thanks for any helpful comments.

-- 
To email me, substitute nowhere->spamcop, invalid->net.



More information about the Python-list mailing list