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

Re: [pygame] seeking in a .WAV with pygame.mixer.music? and "pynudge"



Below is a function which makes a new Sound from another one at a
different start_pos.

eg, called like this:
sound = pygame.mixer.Sound(os.path.join('data', 'car_door.wav'))
sound2 = sound_from_pos(sound, 0.2)

ps. I just commited this to examples/sound_array_demos.py in cvs.

So you can load up your .wav, and start playing it at any position.


Cheers.


def sound_from_pos(sound, start_pos, samples_per_second = None, inplace = 1):
    """  returns a sound which begins at the start_pos.
         start_pos - in seconds from the begining.
         samples_per_second - 
    """
    if inplace:
        a1 = pygame.sndarray.samples(sound)
    else:
        a1 = pygame.sndarray.array(sound)

    if samples_per_second is None:
        samples_per_second = pygame.mixer.get_init()[0]

    start_pos_in_samples = int(start_pos * samples_per_second)
    a2 = a1[start_pos_in_samples:]
    sound2 = pygame.sndarray.make_sound(a2)

    return sound2




On 7/19/05, James Hofmann <jwhinfinity@xxxxxxxxx> wrote:
> I looked for a way....also looked in the standard
> Python libraries for something along those lines.
> Nothing really seems to provide that kind of low-level
> interface. Pymedia might provide that but the
> documentation is very sketchy... I had a hard time
> trying to figure out what it is and isn't capable of.
> 
> I might work on my own problem some more today, and if
> I find out anything I'll post it.
> 
> > Is there any way to address and index the sound data
> > in a mixer
> > object?  I've tried dissecting it, but it seems like
> > there's no PyGame
> > interface...  soo, if I needed to access it, I'd
> > have to go to the SDL
> > level.
> >
> 
> 
> 
> 
> ____________________________________________________
> Start your day with Yahoo! - make it your home page
> http://www.yahoo.com/r/hs
> 
>