[Tutor] Converting audio samples from 16-bit signed int to float?

Adam Bark adam.jtm30 at gmail.com
Mon Jun 21 01:03:42 CEST 2010


On 20 June 2010 23:52, Joe Veldhuis <electroblog at gmail.com> wrote:

> Hello all. I'm writing a program that needs to capture audio from a
> soundcard and run FFTs to determine peak frequency for further processing.
> The soundcard's native capture format is 16-bit little-endian signed integer
> samples (values 0-65535), and of course the FFT function requires
> floating-point values (-1.0 - +1.0).
>
> So, what is the most efficient way to do the necessary conversion? I'm
> using the pyalsaaudio module to access the soundcard, if it matters.
>
> -Joe Veldhuis
>

Not sure it's the best way but the most obvious to me would be divide by
32767.5 (ie half 65535) and minus 1 puts you into the right range:

>>> 65535/32767.5-1
1.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100621/a80849b7/attachment-0001.html>


More information about the Tutor mailing list