Thanks to you both, it was indeed straightforward (but then I forgot
to post the resulting code back).
Jon


#################################
import pyglet.media.procedural

class PygletArrSound(pyglet.media.procedural.ProceduralSource):
    """    Create a pyglet.StaticSource from a numpy array.
    """
    def __init__(self, data, sample_rate=44800, sample_size=16):
        """Array data should be float (-+1.0)
        sample_size (16 or 8) determines the number of bits used for
internal storage"""
        duration = data.shape[1]/float(sample_rate) #determine
duration from data
        super(_pygletArrSound, self).__init__(duration,sample_rate,
sample_size)
        self.sample_rate = sample_rate

        if sample_size==8:          #ubyte
            self.allData = (data*127+127).astype(numpy.uint8)
        elif sample_size==16:      #signed int16
            self.allData = (data*32767).astype(numpy.int16)
        print "create pyglet sound"
    def _generate_data(self, bytes, offset):
        if self._bytes_per_sample == 1:#ubyte
            start = offset
            samples = bytes
        else:                               #signed int16
            start = offset >> 1
            samples = bytes >> 1
        return (self.allData[start:(start+samples)]).tostring()
--~--~---------~--~----~------------~-------~--~----~
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