Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18333
| Date | 2012-01-02 12:12 -0500 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: Generating sin/square waves sound |
| References | <jdjohn$ttr$1@speranza.aioe.org> <mailman.4239.1325239510.27778.python-list@python.org> <jdrm2g$le0$1@speranza.aioe.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4315.1325524362.27778.python-list@python.org> (permalink) |
On 01/02/2012 02:24 AM, Paulo da Silva wrote: > 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. I don't even remember where I got the information, but it sufficed for my needs. I wanted to be able to generate arbitrary tones at a high volume, bypassing any volume control system settings. I assume there's some way (ioctl ?) to tell the device to interpret differently. It's even possible that it's already stereo (left/right samples stored in adjacent 16bit locations -- it wouldn't change the effect I hear, except for the frequency being cut in half. Interesting link from1991, it's from Guido, but doesn't mention Python http://wiretap.area.com/Gopher/Library/Techdoc/Misc/audiofor.faq Also, a lot has changed since then. Now I wonder whether I should be sending u-law values, rather than linear ones. I'm generating sine waves, and they don't really sound flutelike. This link probably has all our answers. http://www.faqs.org/docs/Linux-HOWTO/Sound-HOWTO.html I suspect that my approach will simply use the latest setup values (eg. sampling rate) and thus runs the risk of sometimes not working. That hasn't been my experience, The only problem I see is that sometimes the device is "busy". When that happens, other programs don't seem to work either. I need to find the rogue process which is hogging the device, using fuser. -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Generating sin/square waves sound Paulo da Silva <p_s_d_a_s_i_l_v_a@netcabo.pt> - 2011-12-30 07:17 +0000
Re: Generating sin/square waves sound 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-30 01:51 -0800
Re: Generating sin/square waves sound Dave Angel <d@davea.name> - 2011-12-30 05:05 -0500
Re: Generating sin/square waves sound Paulo da Silva <p_s_d_a_s_i_l_v_a@netcabo.pt> - 2012-01-02 07:24 +0000
Re: Generating sin/square waves sound Dave Angel <d@davea.name> - 2012-01-02 12:12 -0500
Re: Generating sin/square waves sound mblume <foobar@invalid.invalid> - 2011-12-30 11:23 +0000
Re: Generating sin/square waves sound Paulo da Silva <p_s_d_a_s_i_l_v_a@netcabo.pt> - 2012-01-02 07:31 +0000
Re: Generating sin/square waves sound Peter Billam <peter@www.pjb.com.au> - 2012-01-02 10:05 +0000
Re: Generating sin/square waves sound K Richard Pixley <rich@noir.com> - 2011-12-30 17:19 -0800
Re: Generating sin/square waves sound Paulo da Silva <p_s_d_a_s_i_l_v_a@netcabo.pt> - 2012-01-02 07:34 +0000
Re: Generating sin/square waves sound Paulo da Silva <p_s_d_a_s_i_l_v_a@netcabo.pt> - 2012-01-02 18:09 +0000
csiph-web