I have a class within my python + pygame game that handles sound - it worked well until I tried use pygame.mixer.music to switch between streaming .ogg music files. The class switches between them on the pause event.
The issue I'm having is that the music will play, and even switch between tracks fine, but about half the time I'm getting a quiet, regular clicking noise over the sound track. I've checked, and the pygame mixer is set to the same bitrate as my .ogg files. I've tried playing with number of channels and tracks, all to no avail. I'm not sure what the root cause of the clicking is - whether I've chosen a poor file encoding / bitrate, or just not initialized/called pygame mixer correctly.
Here is the problimatic code:
class SoundMgr():
def __init__(self): pygame.mixer.init(22050, -8, 4, 4096) self.musicFilename = "" self.musicPos = 0 self.musicVolume = .35 self.musicMuteVolume = .1 def playMusicTrack(self, which): pygame.mixer.music.load("data/music/" + which + ".ogg") pygame.mixer.music.set_volume(self.musicVolume) pygame.mixer.music.play(-1) self.musicFilename = which def dampenMusic(self): mark = pygame.mixer.music.get_pos() * 0.001 self.musicPos += mark pygame.mixer.music.load("data/music/" + self.musicFilename + "b.ogg") pygame.mixer.music.play(-1, self.musicPos) pygame.mixer.music.set_volume(self.musicMuteVolume) def undampenMusic(self): mark = pygame.mixer.music.get_pos() * 0.001 self.musicPos += mark pygame.mixer.music.load("data/music/" + self.musicFilename + ".ogg") pygame.mixer.music.play(-1, self.musicPos) pygame.mixer.music.set_volume(self.musicVolume) </code>
When I call dampenMusic / undampenMusic the track plays correctly, but about half the time it has a clicking sound over it. The other half of the time it plays perfectly. I've tested, and I can't discover any pattern to when it will / won't have the static.
The clicking noise is about 2 times a second, and is about 50% the volume of the track.
Anyone who is more experienced with pygame / sound encoding able to give me any tips?