Ok, this seems to work:

from pyglet.media import Source, AudioFormat, AudioData
from pyglet.media.procedural import ProceduralSource
import ctypes, os, math

class mSine(ProceduralSource):
        def __init__(self, duration, frequencies, **kwargs):
                super(mSine, self).__init__(duration, **kwargs)
                self.frequencies=frequencies
        def _generate_data(self, bytes, offset):
                if self._bytes_per_sample == 1:
                        start = offset
                        samples = bytes
                        bias = 127
                        amplitude = 127.0/len(self.frequencies)
                        data = (ctypes.c_ubyte * samples)()
                else:
                        start = offset >> 1
                        samples = bytes >> 1
                        bias = 0
                        amplitude = 32767.0/len(self.frequencies)
                        data = (ctypes.c_short * samples)()
                for frequency in self.frequencies:
                        step = frequency * (math.pi * 2) / 
self.audio_format.sample_rate
                        for i in range(samples):
                                data[i] = data[i]+int(math.sin(step * (i + 
start)) * amplitude +
bias)
                return data

beep=mSine(1,(200,600))
beep.play()
beep=mSine(1,(200,300,400,500,600))
beep.play()

On Jan 7, 1:44 am, Mike Lawrence <[EMAIL PROTECTED]> wrote:
> Thanks Alex, I just found the Sine class so I'll give it a shot.
>
> On Jan 7, 1:20 am, "Alex Holkner" <[EMAIL PROTECTED]> wrote:
>
> > On Jan 7, 2008 4:11 PM, Mike Lawrence <[EMAIL PROTECTED]> wrote:
>
> > > > You can achieve the same outcome by playing the two sources
> > > > simultaneously
>
> > > Maybe a little more background would clarify my problem. I'll actually
> > > be looking to play a dozen or so pure tones continuously for an
> > > unspecified amount of time, then as quickly as possible turn them all
> > > off and turn on another set of a dozen or so pure tones that again
> > > play continuously for an unspecified amount of time. I can see that
> > > for each tone I can set up a player, cue the tone, and set eos_action
> > > for that player to 'loop', then once all the players are initialized,
> > > tell each to play, but it strikes me that with increasing numbers of
> > > players I'll soon be able to notice the difference in start time
> > > between the first tone and the last tone, and a similar differences
> > > during the transition to the second set of tones. I was hoping that by
> > > simply getting the aggregate waveforms I would only have to deal with
> > > 2 players, one for each tone set.
>
> > An easy solution is to create your own Sine-derived class that creates
> > the tone mix to begin with, rather than mixing samples later (which is
> > only tricky because of the ctypes array).
>
> > Alex.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to