Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18201

Re: Generating sin/square waves sound

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'preferably': 0.03; 'python': 0.08; '128': 0.09; 'googled': 0.09; 'libraries.': 0.09; 'am,': 0.12; 'python?': 0.15; "2's": 0.16; '2.x)': 0.16; 'bits,': 0.16; 'char,': 0.16; 'faq,': 0.16; 'paulo': 0.16; 'seconds,': 0.16; 'waves': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'string,': 0.18; 'cc:no real name:2**0': 0.20; '(or': 0.22; 'header:In-Reply-To:1': 0.22; 'values.': 0.23; 'string': 0.24; 'cc:2**0': 0.24; 'sound': 0.28; 'bit': 0.28; 'constant': 0.29; 'cc:addr:python.org': 0.29; 'thanks': 0.31; "didn't": 0.31; 'hi,': 0.32; 'header:User-Agent:1': 0.33; 'there': 0.33; 'subject:/': 0.35; 'offset': 0.37; 'skip:" 10': 0.37; 'but': 0.37; 'received:192': 0.37; 'bunch': 0.38; 'signal': 0.38; 'might': 0.40; 'received:192.168': 0.40; 'your': 0.61; 'believe': 0.65; 'square': 0.67; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; '02:17': 0.84; 'experiment': 0.84
Date Fri, 30 Dec 2011 05:05:01 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15
MIME-Version 1.0
To Paulo da Silva <p_s_d_a_s_i_l_v_a@netcabo.pt>
Subject Re: Generating sin/square waves sound
References <jdjohn$ttr$1@speranza.aioe.org>
In-Reply-To <jdjohn$ttr$1@speranza.aioe.org>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:+oU/hnuHVFpFwoX2Z5Ic+L5DWmmZ6BFSlzNBGLiZDRM IWStHpcAbJlta/721nFQMPN5XyeP/a6jWJtcVM2zr+YX3p/1o6 JFIf1lyUTHt2BM3UQP5rSnh6gDfXESZNvUpekju14Ez1fYsr1W QX7smLFviKYljBownVUvOyMuYmJXZPNjvpKVL8w5gTmMaD8nVZ XYRMka2Kl2c6LoicO+in5rfk1A/B5CCinpWdZYPQbikBnUnxpq ooTwFROQrqzFqTuljyGgWX/QwFGRC9SIX2vSSUqJS/0LkPBKz4 zf/cZT7ecHWvdpwj5UGkHNOXaqvVfojjLrefad2yZN7SeYfTg5 nQT9Ab7+tZcpDtOPNU8E=
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4239.1325239510.27778.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1325239510 news.xs4all.nl 6892 [2001:888:2000:d::a6]:44322
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18201

Show key headers only | View raw


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.


-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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