how to remove audio from cache?

I had already posted a topic about this issue, but soon realized the issue has a different origin.

I read audio data not from disk, but from another source. So it’s possible that I’ll get an audio which has the same name as a previous one. AudioManager’s cache system doesn’t seem to allow this. I try to uncache old audio any way I can, but none seem to do what i think:

from panda3d.core import *
# change default audio engine
loadPrcFileData('', 'audio-library-name p3openal_audio')
import direct.directbase.DirectStart

import os
if os.path.isdir('ramdisk') == False: os.mkdir('ramdisk')

# get a file to -RAM- folder
data = open('musicbox.ogg', 'rb').read() # actually read from another source
file = open('ramdisk/music.ogg', 'wb')
file.write(data)
file.close()

# now load from -RAM- folder
music = loader.loadMusic('ramdisk/music.ogg')
music.play()

def loadAnother():
   global music
   
   # try to remove existing from -RAM- folder
   music.stop()
   base.musicManager.uncacheSound('ramdisk/music.ogg')
   loader.unloadSfx(music)
   
   # get a file to -RAM- folder
   data = open('openclose.ogg', 'rb').read() # actually read from another source
   file = open('ramdisk/music.ogg', 'wb')
   file.write(data)
   file.close()
   
   # now load from -RAM- folder, FAILS
   music = loader.loadMusic('ramdisk/music.ogg')
   music.play()

base.accept('enter', loadAnother)

run() 

And I get this error:

:movies:ffmpeg(warning): Codec not found

On the other hand, I get my RAM filled up really quickly like this. I really need to be able to remove audio from cache manually.

So is there any solution right now? If not, can somebody add a uncaching function to AudioManager?

For the record, even

AudioManager.clearCache()

fails to fix this issue.
Now I think there must be some bug in AudioManager’s caching system.

Can someone please look up the code? Same example works with FMOD.

I also had a memory problem with sounds recently. The sounds were not getting released from memory even after removing all references.

Any sound which is played will not get destroyed when its references are removed unless you call .stop() on it, and even then only if the sound is currently playing. This means when I want to destroy the sounds associated with an object when it is removed from the game I have to actually call .play() then .stop() on each of the sounds for them to get cleaned up. I use FMOD.

Hope this helps with tracking down the problem.

That’s weird. I’ll try to see how that workaround works for me.

BTW, do you mean you don’t use any of these functions, just unreference them?

base.musicManager.uncacheSound('filename')
loader.unloadSfx(musicobject) # does the same as above internally
AudioManager.clearCache()

That’s correct. I keep my sounds in a dictionary and when I want to unload it I just call .play() and .stop() on all the sounds and unreference the dictionary.

Hm, OK. One more question: are you reading your audio files from disk, or another source like me?

Hm, OK. One more question: are you reading your audio files from disk, or another source like me? Because the other part of my problem is getting an error if saving an audio “file” to “ramdisk”, removing it later and then storing another audio “file” in a “ramdsik” which has the same name as the previous one and trying to play it. So that info would be helpful.

I read all my sound files from disk.
Also I have set the “fmod-audio-preload-threshold -1” PRC setting which forces all sounds to load in memory instead of loading or streaming depending on the size. I think there is a similar setting for OpenAL.