Question

I got a beagleboard i'm trying to program. I'm using PyAlsaAudio to capture audio and plot it (and do sokme processing on it).

however, this is actually my first forray into python, and into computer audio. Normally i use daq systems and matlab so i've never had to deal with binary (i'm assuming) number.

pyalsa allows me to get outputs in a number of formats but the examples all use PCM_FORMAT_S16_LE so i'm sticking to it unless somebody says otherwise.

What i need to learn if how to go from PCM_FORMAT_S16_LE to an array of numbers. Should be simple but i haven't found an easy solution.

Thanks for reading, and helping. Mustafa

edit :1 Just wanted to add i tried

In [113]: aaa = numpy.fromstring(data)
In [112]: numpy.size(aaa)
Out[112]: 250

but the size is wrong because i've assigned 1000 as the period size. Please help.

No correct solution

OTHER TIPS

According to this, PCM_FORMAT_S16_LE is Signed 16 bit samples for each channel (Little Endian byte order). When you use numpy.fromstringwithout the dtype argument, it defaults to float, which is mapped to float64. So your 1000 samples of 16 bits get converted into only 250 samples of 64 bits.

What I think you should do is:

aaa = numpy.fromstring(data, dtype='<i2')

In the data type, < states the little endianess, i the signed integer type, and 2 the 16 bit, or 2 bytes, length.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top