Sound programming: Tone production in Python?

Andrew McGregor andrew at indranet.co.nz
Thu Jan 23 05:21:23 EST 2003


--On Wednesday, January 22, 2003 21:06:15 -0800 Dennis Lee Bieber 
<wlfraed at ix.netcom.com> wrote:

> Peter Hansen fed this fish to the penguins on Wednesday 22 January 2003
> 07:05 pm:
>
>>
>> Just a stray question: what do you mean by zero-offset in this
>> context? I've written signal generators that can output arbitrary
>> periodic waveforms including sinewaves in this manner, but I don't
>> recall ever having to worry about anything I would have called the
>> "zero offset".
>>
>         As an bystander, I suspect what this refers to is that...
>
>         sin() (or cos() ) traditionally returns values from -1.0 to +1.0.
>
>         If you map that to an 8-bit unsigned integer, then
>                 -1.0    => 0
>                  0.0    => 127
>                 +1.0    => 255
>
>         sin(x) * 127 + 127 => 8-bit sample (note the loss of 1 value;
> 127+127=>254, not 255).

Yep, that's what I meant.  And I guess mutant things like a-law (it's 
nonlinear) deserve a mention too, although you'd not usually go there in 
anything but a VoIP app.

Andrew







More information about the Python-list mailing list