Re: [pygame] starting sound playback at offset
On Thu, May 8, 2008 at 8:09 PM, Ian Mallett [EMAIL PROTECTED] wrote: I suppose it is possible to play the sound at zero volume until the starting point, then pause, and restart when you need to start. This seems to me to be a decidedly low-tech solution though. Ian Although getting the timing right on this would be difficult - you would have to queue up a sound ahead of time at the low volume. Another low tech solution I can think of would be to chop up your music into set time intervals and only fade between them at an interval. 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. There are no high-level interfaces for seeking through a sound though. More sound control in pygame would be great. If you do figure out how to seek using a sndarray let me know, I'd be interested in such a thing as well.
Re: [pygame] starting sound playback at offset
yeah, you'll have to chop up the Sound samples yourself for that... which shouldn't be too hard. cheers,
Re: [pygame] starting sound playback at offset
From looking at SDL_mixer it's hard to tell if it would even support playing from an offset... Would adding support for playing from an offset in pygame just be a matter of manually making a new chunk object that would point to a place within the original chunk for the sample? On Fri, May 9, 2008 at 12:09 AM, René Dudfield [EMAIL PROTECTED] wrote: yeah, you'll have to chop up the Sound samples yourself for that... which shouldn't be too hard. cheers,
Re: [pygame] starting sound playback at offset
yeah, pretty much. Doing that from python is just as easy though. On Fri, May 9, 2008 at 5:16 PM, Brian Fisher [EMAIL PROTECTED] wrote: From looking at SDL_mixer it's hard to tell if it would even support playing from an offset... Would adding support for playing from an offset in pygame just be a matter of manually making a new chunk object that would point to a place within the original chunk for the sample? On Fri, May 9, 2008 at 12:09 AM, René Dudfield [EMAIL PROTECTED] wrote: yeah, you'll have to chop up the Sound samples yourself for that... which shouldn't be too hard. cheers,
Re: [pygame] starting sound playback at offset
I didn't mean copying the sound - I meant with SDL could you make a mixer chunk that pointed to a portion of some other chunk. or are you saying it's easy in pygame to make a sound that points to a subset of the content of another sound? (like a subsurface...) If so, how would you do that? On Fri, May 9, 2008 at 12:17 AM, René Dudfield [EMAIL PROTECTED] wrote: yeah, pretty much. Doing that from python is just as easy though. On Fri, May 9, 2008 at 5:16 PM, Brian Fisher [EMAIL PROTECTED] wrote: From looking at SDL_mixer it's hard to tell if it would even support playing from an offset... Would adding support for playing from an offset in pygame just be a matter of manually making a new chunk object that would point to a place within the original chunk for the sample? On Fri, May 9, 2008 at 12:09 AM, René Dudfield [EMAIL PROTECTED] wrote: yeah, you'll have to chop up the Sound samples yourself for that... which shouldn't be too hard. cheers,
Re: [pygame] starting sound playback at offset
You can get a buffer from Sound objects now. http://pygame.org/docs/ref/mixer.html#Sound.get_buffer Then combined with the constructor... pygame.mixer.Sound(buffer) should do the trick. http://pygame.org/docs/ref/mixer.html#pygame.mixer.Sound cheers, On Fri, May 9, 2008 at 5:20 PM, Brian Fisher [EMAIL PROTECTED] wrote: I didn't mean copying the sound - I meant with SDL could you make a mixer chunk that pointed to a portion of some other chunk. or are you saying it's easy in pygame to make a sound that points to a subset of the content of another sound? (like a subsurface...) If so, how would you do that? On Fri, May 9, 2008 at 12:17 AM, René Dudfield [EMAIL PROTECTED] wrote: yeah, pretty much. Doing that from python is just as easy though. On Fri, May 9, 2008 at 5:16 PM, Brian Fisher [EMAIL PROTECTED] wrote: From looking at SDL_mixer it's hard to tell if it would even support playing from an offset... Would adding support for playing from an offset in pygame just be a matter of manually making a new chunk object that would point to a place within the original chunk for the sample? On Fri, May 9, 2008 at 12:09 AM, René Dudfield [EMAIL PROTECTED] wrote: yeah, you'll have to chop up the Sound samples yourself for that... which shouldn't be too hard. cheers,
Re: [pygame] starting sound playback at offset
although it's probably not a huge thing, the sound constructor doc claims it won't share the buffer: Note: The buffer will be copied internally, no data will be shared between it and the Sound object. if that's correct it means that approach would make copies of the music But more importantly, how would you get a buffer that points to an offset within another buffer? On Fri, May 9, 2008 at 12:24 AM, René Dudfield [EMAIL PROTECTED] wrote: You can get a buffer from Sound objects now. http://pygame.org/docs/ref/mixer.html#Sound.get_buffer Then combined with the constructor... pygame.mixer.Sound(buffer) should do the trick. http://pygame.org/docs/ref/mixer.html#pygame.mixer.Sound cheers, On Fri, May 9, 2008 at 5:20 PM, Brian Fisher [EMAIL PROTECTED] wrote: I didn't mean copying the sound - I meant with SDL could you make a mixer chunk that pointed to a portion of some other chunk. or are you saying it's easy in pygame to make a sound that points to a subset of the content of another sound? (like a subsurface...) If so, how would you do that? On Fri, May 9, 2008 at 12:17 AM, René Dudfield [EMAIL PROTECTED] wrote: yeah, pretty much. Doing that from python is just as easy though. On Fri, May 9, 2008 at 5:16 PM, Brian Fisher [EMAIL PROTECTED] wrote: From looking at SDL_mixer it's hard to tell if it would even support playing from an offset... Would adding support for playing from an offset in pygame just be a matter of manually making a new chunk object that would point to a place within the original chunk for the sample? On Fri, May 9, 2008 at 12:09 AM, René Dudfield [EMAIL PROTECTED] wrote: yeah, you'll have to chop up the Sound samples yourself for that... which shouldn't be too hard. cheers,
Re: [pygame] starting sound playback at offset
Ah, we could probably have a better way of sharing data. Maybe something like a sub surface would be best. But for now, you can copy the sound data and chop it up yourself. cheers, On Fri, May 9, 2008 at 5:28 PM, Brian Fisher [EMAIL PROTECTED] wrote: although it's probably not a huge thing, the sound constructor doc claims it won't share the buffer: Note: The buffer will be copied internally, no data will be shared between it and the Sound object. if that's correct it means that approach would make copies of the music But more importantly, how would you get a buffer that points to an offset within another buffer? On Fri, May 9, 2008 at 12:24 AM, René Dudfield [EMAIL PROTECTED] wrote: You can get a buffer from Sound objects now. http://pygame.org/docs/ref/mixer.html#Sound.get_buffer Then combined with the constructor... pygame.mixer.Sound(buffer) should do the trick. http://pygame.org/docs/ref/mixer.html#pygame.mixer.Sound cheers, On Fri, May 9, 2008 at 5:20 PM, Brian Fisher [EMAIL PROTECTED] wrote: I didn't mean copying the sound - I meant with SDL could you make a mixer chunk that pointed to a portion of some other chunk. or are you saying it's easy in pygame to make a sound that points to a subset of the content of another sound? (like a subsurface...) If so, how would you do that? On Fri, May 9, 2008 at 12:17 AM, René Dudfield [EMAIL PROTECTED] wrote: yeah, pretty much. Doing that from python is just as easy though. On Fri, May 9, 2008 at 5:16 PM, Brian Fisher [EMAIL PROTECTED] wrote: From looking at SDL_mixer it's hard to tell if it would even support playing from an offset... Would adding support for playing from an offset in pygame just be a matter of manually making a new chunk object that would point to a place within the original chunk for the sample? On Fri, May 9, 2008 at 12:09 AM, René Dudfield [EMAIL PROTECTED] wrote: yeah, you'll have to chop up the Sound samples yourself for that... which shouldn't be too hard. cheers,
Re: [pygame] starting sound playback at offset
On Thu, May 8, 2008 at 11:54 PM, Patrick Mullen [EMAIL PROTECTED] 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
Re: [pygame] starting sound playback at offset
I suppose it is possible to play the sound at zero volume until the starting point, then pause, and restart when you need to start. This seems to me to be a decidedly low-tech solution though. Ian
[pygame] starting sound playback at offset
Is it possible to start sound playback at an offset from the beginning of the sound? I'm working on a simple system for game music that changes with the intensity of the game. The idea is to fade out one track while fading in the new one, matching the beats, as the game intensity changes. To get the beats to match up I need to start the new track at an offset. -- Nathan Whitehead