[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] starting sound playback at offset



On Thu, May 8, 2008 at 11:54 PM, Patrick Mullen <saluk64007@xxxxxxxxx> wrote:
> ... A more high tech
> solution may be to use a sndarray, but I am completely unfamiliar with how
> these array objects can be used exactly.  but it may be that you can make an
> array, and then slive it from where you want to start, and it will modify
> the sound such as to start from where you want. ...
> If you do figure out how to "seek" using a sndarray let me know, I'd be
> interested in such a thing as well.

Thanks for the suggestion to use sndarray, works great.  Here's my function:

def play_offset(snd, offset):
    """play a sound starting at a sample offset

    returns channel new offset sound is playing on
    """
    samps = pygame.sndarray.samples(snd)[offset:]
    newsnd = pygame.sndarray.make_sound(samps)
    return newsnd.play()

Also, the offset is measured in samples after resampling.  If the
mixer frequency is 44100, then 44100 samples is one second offset.
--
Nathan Whitehead