Re: [pygame] varying sound playback rate
Miriam English said: OpenAL has some interesting 3D capabilities -- something that will be very useful for me later... but after a quick scan thru the documentation I can't see much else. Guess I have to sit down and really delve into the docs. Based on Alex's suggestion of looking at OpenAL and ctypes, I cobbled together the following little test: http://www.bigdicegames.com/Code/Samples/OpenALTest/openALTest.py which loads a WAV file, and plays it back in three voice harmony with each voice at a different pitch. I haven't yet fully familiarized myself with the ctypes tools to generate the function prototypes automatically, so I did it by hand for the functions I used. I was kind of surprised to find that loading a WAV file from disk isn't part of OpenAL itself (check out the ALUT libraries for that, I guess), so I used Python's built-in wave module to load my WAV files. I know you mentioned requiring an open source library, but if all you need is free for non-commercial use, you might also consider the BASS sound library: http://www.un4seen.com/ It doesn't have Python bindings, so you'd have to go through the ctypes process for it, too. -Dave LeCompte
Re: [pygame] varying sound playback rate
Greg Ewing wrote: Dave LeCompte (really) wrote: - alternately, you could ditch PyGame's mixer altogether and use an outside sound library. I've done something like this recently using OpenAL via PyOpenAL, and it works well. The only drawback might be that it seems PyOpenAL is no longer maintained, and I had to make some minor changes to get it to work with the version of OpenAL that comes with MacOSX 10.4. OpenAL can also be accessed directly using ctypes. For example, here's a simple generated wrapper: http://pyglet.googlecode.com/svn/trunk/pyglet/media/lib_openal.py http://pyglet.googlecode.com/svn/trunk/pyglet/media/lib_alc.py Alex.
Re: [pygame] varying sound playback rate
Alex Holkner wrote: Greg Ewing wrote: Dave LeCompte (really) wrote: - alternately, you could ditch PyGame's mixer altogether and use an outside sound library. I've done something like this recently using OpenAL via PyOpenAL, and it works well. The only drawback might be that it seems PyOpenAL is no longer maintained OpenAL can also be accessed directly using ctypes. For example, here's a simple generated wrapper: http://pyglet.googlecode.com/svn/trunk/pyglet/media/lib_openal.py http://pyglet.googlecode.com/svn/trunk/pyglet/media/lib_alc.py Interesting. Thanks Dave, Greg and Alex. I looked at PySonic, but it uses a closed source library, so that rules it out. PythonSound looks like an interesting project. It is a pretty-much complete synthetic music composition system. Very neat. I'm not sure how current it is though. Doesn't look like much has happened since 2002. Still, if it works that is enough. I have played with snack. It provides a very simple way for python to use, play, and filter sounds as well as generating tones. It can also convert formats on-the-fly. And it lets you view sounds graphically (waveform, spectrogram, energy section), which can be useful for some things I want to do in the future. OpenAL has some interesting 3D capabilities -- something that will be very useful for me later... but after a quick scan thru the documentation I can't see much else. Guess I have to sit down and really delve into the docs. MusicKit ( SndKit) looks very interesting, for building music, sound, signal processing MIDI applications. I haven't had time to investigate it properly yet. Also, of course, python itself has a very basic wave module with simple capabilities. Best wishes, - Miriam -- -=-=-=-=-=-=-- A life! Cool! Where can I download one of those from? -=-=-=-=-=-=-- Website: http://miriam-english.org Blog: http://www.livejournal.com/users/miriam_e/
Re: [pygame] varying sound playback rate
Dave LeCompte (really) wrote: - alternately, you could ditch PyGame's mixer altogether and use an outside sound library. I've done something like this recently using OpenAL via PyOpenAL, and it works well. The only drawback might be that it seems PyOpenAL is no longer maintained, and I had to make some minor changes to get it to work with the version of OpenAL that comes with MacOSX 10.4. -- Greg
Re: [pygame] varying sound playback rate
Miriam, To crack that nut using Pygame software in real-time as you described, you'd have to use a steam roller. I suggest using a simple brute-force less-than-perfect technique to solve this problem: Open up the original sound file in an editor and change its speed. Then, save the changed sound as a different file. Repeat ~20 times, incrementally changing the speed across the range of speeds that you need. In your Pygame program, load all of the sounds at the beginning of the program. In your game, play the one that is closest to the speed that you need. If this idea isn't good enough for your purpose, I won't be offended. Jason Marshall --- Miriam English [EMAIL PROTECTED] wrote: Hi, I'm new here. I've looked thru the archives, the pygame documentation, the site and tutorials, and I've tried experimenting myself, but I can't find a way to dynamically alter the rate of sound playback in pygame. For example, if I wanted to play a sound file back thru 4 different channels at 4 different rates to form a chord... is it possible? Another example: playing the sound of a train chuffing first at a low speed then at progressively higher rates to sound like it is pulling away from a station... is that possible in pygame? I know that it is possible to use numeric to read a sound into an array then manipulate it to create different sounds, but this seems a bit like using a steamroller to crack a walnut. I've used other applications where simply setting a different play rate is sufficient. This is effectively what all tracker music programs do. Can pygame do this? Thanks in advance for any info. Best wishes, - Miriam It's here! Your new message! Get new email alerts with the free Yahoo! Toolbar. http://tools.search.yahoo.com/toolbar/features/mail/
Re: [pygame] varying sound playback rate
Jason Marshall was not optimistic about being able to specify playback speeds: To crack that nut using Pygame software in real-time as you described, you'd have to use a steam roller. Hm, perhaps - is this a limitation of SDL's Audio system running at a fixed (and not exposed to PyGame) frequency? As the original poster suggested, it would be really nice to specify the playback rate at runtime (either dynamically, as the sound is playing, to achieve doppler effects, or statically, before the sound starts, to get polyphonic effects (or just to break up monotonous uniform sound effects, like footsteps). I've given some thought to this sort of thing over time, and I don't have any ready solutions, but perhaps one of these would be of use to you: - if you use WAV files, you could modify the header yourself. Python's standard library includes the wave module: http://docs.python.org/lib/module-wave.html To be practical, you'd probably want to be able to modify the headers on an in-memory version of the WAV file, or even better, PyGame's Sound object. - alternately, you could ditch PyGame's mixer altogether and use an outside sound library. All of my third-party audio library experience have been in the C/C++ world, so I can't comment on Python wrappers or implementations. I am interested to experiment with PySonic someday: http://pysonic.sourceforge.net/ Bottom line: I agree with the original poster - runtime frequency control would be really nice. -Dave LeCompte
Re: [pygame] varying sound playback rate
Hi Jason, Thanks for the quick response. Heheheh :) The less-than-perfect technique you suggested is what I was doing last night when I stopped and thought, hey, maybe I don't have to do this after all... maybe someone knows a better way. So, thanks, yes. I think I'll probably be doing that if I can't find a simpler way. Best wishes, - Miriam Jason Marshall wrote: Miriam, To crack that nut using Pygame software in real-time as you described, you'd have to use a steam roller. I suggest using a simple brute-force less-than-perfect technique to solve this problem: Open up the original sound file in an editor and change its speed. Then, save the changed sound as a different file. Repeat ~20 times, incrementally changing the speed across the range of speeds that you need. In your Pygame program, load all of the sounds at the beginning of the program. In your game, play the one that is closest to the speed that you need. If this idea isn't good enough for your purpose, I won't be offended. Jason Marshall
Re: [pygame] varying sound playback rate
Hi Dave, Looking at the SDL docs it does look like it's a limitation of that, as you say. Pygame relies upon SDL so it would appear to put the lid on it. And thanks for the cool suggestions. I particularly like the idea of altering the WAV header. It has been a while now, but I have a feeling the playback rate is kept in just a single word value. Alter that and I could have what I want. A bit hackish, but nice and simple. Time to hit the docs about WAV headers methinks. I am a little reluctant to force my end-users to have extra python libs, but if pysonic (or some other library) gives me much greater control I might end up going for that option. I'll look into that. Perhaps, in the end, using the sound array functions might turn out to be a usable (though far less than optimal) way to go. Some of the other things I want to do (later) require a sound to be filtered in realtime. It is just frustrating that modern sound cards provide a lot of this stuff in hardware nowadays, and it is sitting there unused and out of reach. Thanks again for the suggestions. Best wishes, - Miriam Dave LeCompte (really) wrote: Jason Marshall was not optimistic about being able to specify playback speeds: To crack that nut using Pygame software in real-time as you described, you'd have to use a steam roller. Hm, perhaps - is this a limitation of SDL's Audio system running at a fixed (and not exposed to PyGame) frequency? As the original poster suggested, it would be really nice to specify the playback rate at runtime (either dynamically, as the sound is playing, to achieve doppler effects, or statically, before the sound starts, to get polyphonic effects (or just to break up monotonous uniform sound effects, like footsteps). I've given some thought to this sort of thing over time, and I don't have any ready solutions, but perhaps one of these would be of use to you: - if you use WAV files, you could modify the header yourself. Python's standard library includes the wave module: http://docs.python.org/lib/module-wave.html To be practical, you'd probably want to be able to modify the headers on an in-memory version of the WAV file, or even better, PyGame's Sound object. - alternately, you could ditch PyGame's mixer altogether and use an outside sound library. All of my third-party audio library experience have been in the C/C++ world, so I can't comment on Python wrappers or implementations. I am interested to experiment with PySonic someday: http://pysonic.sourceforge.net/ Bottom line: I agree with the original poster - runtime frequency control would be really nice. -Dave LeCompte