pygame mixer findings #40
Replies: 2 comments
-
Hi there @fergusdeffely! I'm glad you're enjoying using this, it definitely encourages me to go back to working on it (there are many new features stuck somewhere in development...) In this library I tried to focus on the audio editing aspects, and relegate hardware interface to other libraries as much as possible. This is because working with hardware is annoying (as you can see, even now we don't have a single robust audio playback library for Python). Therefore, I'm not too familiar with how the various output libraries operate. That said, here is some possibly relevant information:
Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Hey - thanks for this. I did a bit more hacking around and I noticed that it's the call to mixer.quit() that was leading to the behaviour I was seeing. This, of course makes sense - mixer.quit() halts playback of any current sounds. I maybe didn't mention in the last post, but when I was calling pygame.init(), I had commented out the call to mixer.quit(). So that's why the two sounds played in parallel. I've added some code so the mixer only reinitialises if the audio properties have changed from the previous playback. |
Beta Was this translation helpful? Give feedback.
-
Hey there,
So firstly, thank you. I've spent all morning exploring your module and building a bunch of synth sounds. I now know what a Low Pass Filter is. And all those ADSR envelopes I've been seeing in LMMS finally make some sense.
I intend to use gensound for a game I'm building, which has mechanics including audio features. I don't know yet, if I will use gensound in the game itself, or as a toolkit for building wavs, and then use those in the game with the pygame mixer. But, gensound is a find - it solves some problems I had (and a few I didn't realise I had :) )
In my tinkering, I noticed one thing I found interesting and felt it might be worth a mention. So just briefly...
Say I have two short wavs - one for a kick drum and one for a synthbass. And I want to play them at the same time.
Note: when I same the same time, I mean that the time during which these sounds are playing overlaps. In the examples below, it's exactly the same time, but, for example, one might begin, 20/50/100ms after the other...
If I do this in pygame only, I hear the two sounds play over each other - i.e. they are mixed.
But, if I do it in gensound, like this...
Then, I only hear the most recent sound played. In the code here, that would be the kick drum, but if the bass is played after the kick drum, I only hear the bass.
So, because it was working in pygame, as an experiment, I edited the gensound code - removing the call to pygame.mixer.init() in IO._IO_pygame, and just calling pygame.init() instead. With this change the two wavs are mixed.
Now, I do understand that if I do:
Then, yes, the two signals are mixed.
But, just curious is all - do you know why pygame is behaving like this? Also, do you know if there are any gotchas that might result from not calling pygame.mixer.init()?
Beta Was this translation helpful? Give feedback.
All reactions