Title: audioop module - request to add a note
Type: Stage:
Components: Documentation Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, ncryptor, rhettinger
Priority: normal Keywords:

Created on 2007-04-14 23:07 by ncryptor, last changed 2008-03-24 09:34 by georg.brandl. This issue is now closed.

Messages (3)
msg31788 - (view) Author: ncryptor (ncryptor) Date: 2007-04-14 23:07
The audioop function lin2lin converts sample sizes of linear pcm fragments.
However, when converting to 8-bit, there is a pitfall (that wasted for me a few hours).
In some audio formats, such as .WAV files, 16 and 32 bit samples are signed, but 8 bit samples are unsigned. So when converting from 2 to 1 byte wide samples, you need to also add 128 to the result.
Example code:

new_frames = audioop.lin2lin(frames, old_width, new_width)
if 1 == new_width:
   new_frames = audioop.bias(new_frames, 1, 128)

the same, in reverse, has to be applied when converting from 8 to 16 or 32 bit width samples.

This wasted so much time for me and is hardly documented.
msg31789 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-04-19 06:45
I will add a note.
msg64408 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-03-24 09:34
Fixed in r61842.
Date User Action Args
2008-03-24 09:34:51georg.brandlsetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg64408
2008-03-23 21:28:11rhettingersetassignee: rhettinger -> georg.brandl
nosy: + georg.brandl
2007-04-14 23:07:14ncryptorcreate