Generating sin/square waves sound

Paulo da Silva p_s_d_a_s_i_l_v_a at netcabo.pt
Mon Jan 2 02:24:01 EST 2012


Em 30-12-2011 10:05, Dave Angel escreveu:
> On 12/30/2011 02:17 AM, Paulo da Silva wrote:
>> Hi,
>> Sorry if this is a FAQ, but I have googled and didn't find any
>> satisfatory answer.
>>
>> Is there a simple way, preferably multiplataform (or linux), of
>> generating sinusoidal/square waves sound in python?
>>
>> Thanks for any answers/suggestions.
> If you're willing to be Linux-only, then I believe you can do it without
> any extra libraries.
> 
> You build up a string (8 bit char, on Python 2.x)  of samples, and write
> it to  "/dev/audio".  When i experimented, I was only interested in a
> few seconds, so a single write was all I needed.
> 
> Note that the samples are 8 bits, and they are offset by 128.  So a zero
> signal would be a string of 128 values.  A very quiet square wave might
> be a bunch of 126, followed by a bunch of 130.  and so on.  And the
> loudest might be a bunch of 2's followed by a bunch of 253's.
> 
> You'll have to experiment with data rate;   The data is sent out at a
> constant rate from your string, but I don't know what that rate is.
> 
> 
This sounds nice, but then is 8 bits the limit for /dev/audio? What
about stereo? I don't need this one ... just for curiosity.
Thanks.



More information about the Python-list mailing list