Re: [pygame] music module bindings for python
Hi Greg and others, - Original Message From: Greg Ewing <[EMAIL PROTECTED]> To: pygame-users@seul.org Cc: [EMAIL PROTECTED] Sent: Thursday, 24 May, 2007 6:10:56 PM Subject: Re: [pygame] music module bindings for python René Dudfield wrote: > pygame has mod support through sdl_mixer. That's true. Note that you need to use pygame.mixer.music rather than a pygame.mixer.Sound object, though. I just tried the following on MacOSX and it worked: from time import sleep from pygame import mixer mixer.init() music = mixer.music music.load("bigjapan.mod") music.play() sleep(1) (The mod file I used is from http://www.df.lth.se/~fernbom/music/mods/files/bigjapan.zip). -- Greg Thanks for telling me about the mod support. I assumed that pygame didn't have mod support because I'd heard of PySonic, which led me on the wrong track. I have tested (with pygame's mixer) not only mods, but also more complex "mod" formats, including IT and XM. They all work, but I've had some trouble with playback. The worst problem is that of the music hissing. The same music plays perfectly with SoundTracker (on my Linux box) and also perfectly on Windows. I have experimented with the mixing speed and also the buffer size, but such changes make no difference. You may recall that I was the one with the "sound crackling" woes when I couldn't get Ogg files to play. Someone pointed me to SDL environment variables, and a line like: export SDLAUDIODRIVER=dsp did the trick: no more crackling. But I still get hiss with modules. Seems to be an OS problem. If anyone knows more detail about setting SDL variables, please tell me, as I'd like to get modules playing perfectly, if possible. The other problem is that I can't set the volume of the modules very high (100% is not very loud). Any ideas? Cheers, Andrew. _ How would you spend $50,000 to create a more sustainable environment in Australia? Go to Yahoo!7 Answers and share your idea. http://advision.webevents.yahoo.com/aunz/lifestyle/answers/y7ans-babp_reg.html
Re: [pygame] music module bindings for python
René Dudfield wrote: pygame has mod support through sdl_mixer. That's true. Note that you need to use pygame.mixer.music rather than a pygame.mixer.Sound object, though. I just tried the following on MacOSX and it worked: from time import sleep from pygame import mixer mixer.init() music = mixer.music music.load("bigjapan.mod") music.play() sleep(1) (The mod file I used is from http://www.df.lth.se/~fernbom/music/mods/files/bigjapan.zip). -- Greg
Re: [pygame] music module bindings for python
hi, pygame has mod support through sdl_mixer. On 5/24/07, Andrew Pape <[EMAIL PROTECTED]> wrote: Hi Greg and others, For the last few weeks I have been trying to get MODule format music to work with Python. I have found a fair bit of MODule playing code written in other languages, mostly c, c++, and assembler, but no code or bindings for Python, except PySonic. I have tried to get PySonic to work with my linux box, but I can't get it to work. I've heard that people have got it to work for linux, but I've had no luck. Greg wrote below: - Original Message From: Greg Ewing <[EMAIL PROTECTED]> It has a setup.py file, so you should be able to compile it with distutils instead of invoking gcc yourself. From the setup.py, on Unix systems it expects the fmod distribution to be in a subdirectory called "fmod" under the directory where the .pyx files etc are. Then you should just be able to say python setup.py install At least that's the way it looks like it's mean to work. I don't have a Linux system handy to try it on right now. If it can't find Python.h, check whether you have a directory called /usr/include/pythonX.Y (where X.Y is whatever Python version you're using) containing Python.h and the other .h files that it uses. If not, you may have to tracl down and install the appropriate "developer" package for Python (it will be called something like "python-X.Y-devel"). You shouldn't have to install the complete Python source. -- I have followed the advice above, but still got hundreds of compilation or linking errors. Sorry I'm not specific about the errors, but I don't have the technical expertise to get the installation working. I'm almost totally new to Python, and so I'm not up to extending and embedding with Pyrex, SWIG, etc. Has anyone got PySonic (and hence Fmod) to work under linux? Another MODule player I know of is called MikMod, which is Open Source, unlike FMod. I've searched the web for Python bindings to MikMod, and almost had success. Specifically, I searched for "mikmod binding for python". I got a result titled "Lateral Opinion: 13.10.2004". The page's links are all dead, but the author had the following to say: MOD me up! MOD files are like MIDI files, only the MOD includes it's own instrument set, called samples, and instructions on how to repeat and alter those samples to make a tune. Good news: there are nice-sounding, funny MOD files that are about 30KB in size. Better news: There is a popular library to play them! It's called Mikmod, and your distro has it (and it's a dependency for KDE's multimedia packages too). Even better news: It has support for playing simple sounds (samples in mod lingo) by calling a couple of functions. Awesome news: It includes a software mixer so you can just tell it to play this, then play that, then that, and a tune in the background, and everything sounds at the same time. So, we have a winner. This baby can handle everything I need for the game! But... is that a snake in your pocket? I can't find a Python binding for it. I am sure as soon as I post this article someone is going to come up and tell me, here they are, moron! But I just can't find any. So, I decided to do something I wanted to do already and learn to use Pyrex. Pyrex is a tool to write python extensions, with almost-free access to C libraries, in an almost-python language (only minor syntax differences). That way, I could write a Python module to use Mikmod. You know what? It was almost scarily simple 2. I didn't wrap all of Mikmod 3 because I don't need it, but now I can do stuff for games and apps almost trivially. Even more: Pyrex has awesome distutils support, so building the extensions, usually a pain in the rear, is trivial (mostly you just copy and delete stuff, with some search and replace). One thing I found I did nicely is this: Mikmod requires you to call Mikmod_Update every once in a while so it fills the soundcard's buffer with stuff to play. If you don't, it skips. So, I just started a thread that loops and takes care of it. You don't even have to know about it to use the extension. Oh, sure, if your Mikmod is not threadsafe, it breaks. Well, get a decent Mikmod package, then. How does it look? Here's a whole noisy proggie #Load the modules import mikmod, time #Init the library mikmod.init() #40 voices, 20 for music, 20 for random sounds (overkill) mikmod.setNumVoices(20,20) #Enable sound, starts the thread that pushes sound, too mikmod.enableOutput() #Create a module, that is, a music track module=mikmod.Module("BasicInstinct.mod") #Load two samples, just a couple of noises s1=mikmod.Sample("lost.wav") s2=mikmod.Sample("swap.wav") #Start playing the song module.play() #For the duration of the song, each second, make some noise while module.active(): s1.play() time.sleep(0.5) s2.play() time.sleep(0.5) #Close the mikmod library, stop the thread, etc. As you can see,
[pygame] music module bindings for python
Hi Greg and others, For the last few weeks I have been trying to get MODule format music to work with Python. I have found a fair bit of MODule playing code written in other languages, mostly c, c++, and assembler, but no code or bindings for Python, except PySonic. I have tried to get PySonic to work with my linux box, but I can't get it to work. I've heard that people have got it to work for linux, but I've had no luck. Greg wrote below: - Original Message From: Greg Ewing <[EMAIL PROTECTED]> It has a setup.py file, so you should be able to compile it with distutils instead of invoking gcc yourself. From the setup.py, on Unix systems it expects the fmod distribution to be in a subdirectory called "fmod" under the directory where the .pyx files etc are. Then you should just be able to say python setup.py install At least that's the way it looks like it's mean to work. I don't have a Linux system handy to try it on right now. If it can't find Python.h, check whether you have a directory called /usr/include/pythonX.Y (where X.Y is whatever Python version you're using) containing Python.h and the other .h files that it uses. If not, you may have to tracl down and install the appropriate "developer" package for Python (it will be called something like "python-X.Y-devel"). You shouldn't have to install the complete Python source. -- I have followed the advice above, but still got hundreds of compilation or linking errors. Sorry I'm not specific about the errors, but I don't have the technical expertise to get the installation working. I'm almost totally new to Python, and so I'm not up to extending and embedding with Pyrex, SWIG, etc. Has anyone got PySonic (and hence Fmod) to work under linux? Another MODule player I know of is called MikMod, which is Open Source, unlike FMod. I've searched the web for Python bindings to MikMod, and almost had success. Specifically, I searched for "mikmod binding for python". I got a result titled "Lateral Opinion: 13.10.2004". The page's links are all dead, but the author had the following to say: MOD me up! MOD files are like MIDI files, only the MOD includes it's own instrument set, called samples, and instructions on how to repeat and alter those samples to make a tune. Good news: there are nice-sounding, funny MOD files that are about 30KB in size. Better news: There is a popular library to play them! It's called Mikmod, and your distro has it (and it's a dependency for KDE's multimedia packages too). Even better news: It has support for playing simple sounds (samples in mod lingo) by calling a couple of functions. Awesome news: It includes a software mixer so you can just tell it to play this, then play that, then that, and a tune in the background, and everything sounds at the same time. So, we have a winner. This baby can handle everything I need for the game! But... is that a snake in your pocket? I can't find a Python binding for it. I am sure as soon as I post this article someone is going to come up and tell me, here they are, moron! But I just can't find any. So, I decided to do something I wanted to do already and learn to use Pyrex. Pyrex is a tool to write python extensions, with almost-free access to C libraries, in an almost-python language (only minor syntax differences). That way, I could write a Python module to use Mikmod. You know what? It was almost scarily simple 2. I didn't wrap all of Mikmod 3 because I don't need it, but now I can do stuff for games and apps almost trivially. Even more: Pyrex has awesome distutils support, so building the extensions, usually a pain in the rear, is trivial (mostly you just copy and delete stuff, with some search and replace). One thing I found I did nicely is this: Mikmod requires you to call Mikmod_Update every once in a while so it fills the soundcard's buffer with stuff to play. If you don't, it skips. So, I just started a thread that loops and takes care of it. You don't even have to know about it to use the extension. Oh, sure, if your Mikmod is not threadsafe, it breaks. Well, get a decent Mikmod package, then. How does it look? Here's a whole noisy proggie #Load the modules import mikmod, time #Init the library mikmod.init() #40 voices, 20 for music, 20 for random sounds (overkill) mikmod.setNumVoices(20,20) #Enable sound, starts the thread that pushes sound, too mikmod.enableOutput() #Create a module, that is, a music track module=mikmod.Module("BasicInstinct.mod") #Load two samples, just a couple of noises s1=mikmod.Sample("lost.wav") s2=mikmod.Sample("swap.wav") #Start playing the song module.play() #For the duration of the song, each second, make some noise while module.active(): s1.play() time.sleep(0.5) s2.play() time.sleep(0.5) #Close the mikmod library, stop the thread, etc. As you can see, the author has been successful in getting mikmod to work by writing his own bi