thanx for the example! somehow on juanty gui comes up but no sound .. anyway i shortened the script this way and could aplay it
import wave AMPLITUDE = 2 ** 15 w = wave.open( "out.wav", "w" ) w.setnchannels( 2 ) w.setsampwidth( 2 ) #BYTES w.setframerate( 22000 ) from array import array import math F = 261.626 F2 = F * (2 ** (5 / 12.)) ang = 0.0 ang2 = 0.0 delta = ( math.pi * 2 * F ) / 22000.0 delta2 = ( math.pi * 2 * F2 ) / 22000.0 for cycle in xrange( 4 ): data = array( 'h' ) for pos in xrange( 22000 ): amp = AMPLITUDE * (pos / 22000.0) amp2 = AMPLITUDE - amp if cycle & 1: amp, amp2 = amp2, amp data.append( int( ( amp * math.sin( ang ) ) ) ) data.append( int( ( amp2 * math.sin( ang2 ) ) ) ) ang += delta ang2 += delta2 w.writeframes( data.tostring() ) w.close() On Tue, Jun 02, 2009 at 05:13:59PM -0500, Rob Williscroft wrote: > '2+ wrote in news:mailman.1017.1243932401.8015.python-l...@python.org in > comp.lang.python: > > > would like to take advantage of the wave module > > found a good example here: > > http://www.python-forum.org/pythonforum/viewtopic.php?f=2&t=10644 > > > > hmm .. i don't get how to write a stereo .. i mean i can set nchannels > > .. but how do i actually take control of each ch individually? > > Interleave the channels, one sample for the left then one sample > for the right (or maybe its the other way around). > > > and what's the range(in float) of the data i can set in > > The range of a signed 16 bit int, -2**15 to 2**15 - 1. > > > wav_file.writeframes(struct.pack('h', data))? > > Example: > > import wave > from StringIO import StringIO > > out = StringIO() > > AMPLITUDE = 2 ** 15 > > w = wave.open( out, "w" ) > w.setnchannels( 2 ) > w.setsampwidth( 2 ) #BYTES > w.setframerate( 22000 ) > > from array import array > import math > > F = 261.626 > F2 = F * (2 ** (5 / 12.)) > ang = 0.0 > ang2 = 0.0 > delta = ( math.pi * 2 * F ) / 22000.0 > delta2 = ( math.pi * 2 * F2 ) / 22000.0 > > for cycle in xrange( 4 ): > data = array( 'h' ) > for pos in xrange( 22000 ): > amp = AMPLITUDE * (pos / 22000.0) > amp2 = AMPLITUDE - amp > if cycle & 1: > amp, amp2 = amp2, amp > > data.append( int( ( amp * math.sin( ang ) ) ) ) > data.append( int( ( amp2 * math.sin( ang2 ) ) ) ) > > ang += delta > ang2 += delta2 > > w.writeframes( data.tostring() ) > > w.close() > > sample = out.getvalue() > out.close() > > #a wx player > > import wx > > app = wx.PySimpleApp() > > class Frame( wx.Dialog ): > def __init__( self, *args ): > wx.Dialog.__init__( self, *args ) > b = wx.Button( self, -1, "Ok" ) > b.Bind( wx.EVT_BUTTON, self.button ) > > def button( self, event ): > self.sound = wx.SoundFromData( sample ) > self.sound.Play( wx.SOUND_ASYNC ) > > frame = Frame( None ) > frame.Show() > > app.MainLoop() > > Rob. > -- > http://www.victim-prime.dsl.pipex.com/ -- '2+ http://sarigama.namaste.jp/ is podcasting his microtuned music http://www002.upp.so-net.ne.jp/buyobuyo/micro/rss.xml -- http://mail.python.org/mailman/listinfo/python-list