Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between paInt32, paInt16, paInt24, paFloat32, etc.?

Tags:

python

pyaudio

I am using Python 2.7.12 on Ubuntu 16.04 LTS while I am trying (learning) about the pyaudio module. I have to mention which type of format I should require for recording the audio from a microphone. I would like to know difference between

papaInt32,paInt16,paInt24,paFloat32,paInt8,paUInt8

and when to use each format. I am trying (learning) pyaudio from Python pyaudio.PyAudio Examples.

like image 898
shiva Avatar asked Oct 17 '25 07:10

shiva


1 Answers

PortAudio supports audio input and output in a variety of sample formats: 8, 16, 24 and 32 bit integer formats and 32 bit floating point, irrespective of the formats supported by the native audio API.

A type used to specify one or more sample formats. Each value indicates a possible format for sound data passed to and from the stream callback, Pa_ReadStream and Pa_WriteStream.

Reference

The standard formats paFloat32, paInt16, paInt32, paInt24, paInt8 and aUInt8 are usually implemented by all implementations.

The floating point representation (paFloat32) uses +1.0 and -1.0 as the maximum and minimum respectively.

paUInt8 is an unsigned 8 bit format where 128 is considered "ground"

The paNonInterleaved flag indicates that audio data is passed as an array of pointers to separate buffers, one buffer for each channel. Usually, when this flag is not used, audio data is passed as a single buffer with all channels interleaved.

Reference

If you are using Float32, then code should be fine. If you are using paInt32 (or 24/16/8), then you need to make sure to cast back to an int (or a short, char, etc) after you do the multiplication

like image 95
RaminNietzsche Avatar answered Oct 18 '25 23:10

RaminNietzsche



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!