what is the biggest number that i can send toWave_write.writeframes(data)

2

'2+

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?
and what's the range(in float) of the data i can set in
wav_file.writeframes(struct.pack('h', data))?

tia

--
SaRiGaMa's Oil Vending Orchestra
is podcasting:
http://sarigama.namaste.jp/podcast/rss.xml
and supplying oil.py for free:
http://oilpy.blogspot.com/
 
2

'2+

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()

'2+ wrote in in
comp.lang.python:


Interleave the channels, one sample for the left then one sample
for the right (or maybe its the other way around).


The range of a signed 16 bit int, -2**15 to 2**15 - 1.


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.
--
'2+
http://sarigama.namaste.jp/
is
podcasting his microtuned music
http://www002.upp.so-net.ne.jp/buyobuyo/micro/rss.xml
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top