I believe I may have stumbled across a small glitch in the Ogg Vorbis audio handler. I don’t know if this has been uncovered before; if not, let me know and I’ll see if I can track it down in the source code and fix it!
The issue is that audio files that are Ogg formatted seem to ignore the “audio-cache-limit” directive when they are loaded; regardless of the setting in the Config.prc file, they adhere to a “no more than fifteen simultaneously” rule while playing. Don’t ask why I was trying to play sixteen Ogg files simultaneously; it’s a long story
One viable solution appears to be to force the “audio-cache-limit” setting at the top of your main code body. I’m not sure why, but doing this does seem to allow you to play more than fifteen Oggs simultaneously.
What follows is an example program to demonstrate the issue. To use it, create four sound files that you could distinguish easily while they are simultaneously playing. I used four guitar plucks, each of which starts a second after the last one (so the audio files compare as follows):
c5 ---------------o--- g ------------o------- e -------o------------ c --o-----------------
Now, run the program shown below, and flick your fingers across the “p,” “f,” “g,” “h,” and “j” keys. You would expect a five-note sequence: c-c-c-c-c, e-e-e-e-e, g-g-g-g-g, c5-c5-c5-c5-c5. Instead, you’re likely to hear c-c-c-c, e-e-e-e, g-g-g-g, c5-c5-c5. Uncommenting the top four lines in the source code will give you the expected sequence.
If someone could double-check my results, I’d appreciate it. Thanks to everyone for their help on this issue!
##Uncomment the lines below to get all the notes to play ##from pandac.PandaModules import ConfigVariableInt ## ##SOUND = ConfigVariableInt("audio-cache-limit") ##SOUND.setValue(40) import direct.directbase.DirectStart from direct.showbase import DirectObject from pandac.PandaModules import * from direct.task import Task from direct.actor import Actor from direct.interval.IntervalGlobal import* from direct.gui.DirectGui import * class World(DirectObject): ## The sound files you want to load. If these are all oggs, they ## seem to ignore the audio-cache-limit without warning, ## unless the audio-cache-limit directive is specified at the top of ## this file. sounds=["c.ogg","e.ogg","g.ogg","c5.ogg"] def __init__(self): self.loadedMusic= self.loadedSounds= self.loadedMusic2= self.loadedSounds2= self.loadedSounds3= for sound in self.sounds: s=loader.loadMusic(sound) self.loadedMusic.append(s) s=loader.loadSfx(sound) self.loadedSounds.append(s) s=loader.loadMusic(sound) self.loadedMusic2.append(s) s=loader.loadSfx(sound) self.loadedSounds2.append(s) s=loader.loadSfx(sound) self.loadedSounds3.append(s) self.accept("p",self.fireAll,[self.loadedSounds]) self.accept("f",self.fireAll,[self.loadedMusic]) self.accept("g",self.fireAll,[self.loadedMusic2]) self.accept("h",self.fireAll,[self.loadedSounds2]) self.accept("j",self.fireAll,[self.loadedSounds3]) def fireAll(self,whichStream): for aMusic in whichStream: aMusic.play() w=World() run() ## Now, press pfghj to hear fifteen notes simultaneously. Uncomment the lines above to hear twenty-five notes simultaneously.