Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hi How can I stop irrklang from dropping a sound file. I am loading the files I want into an array and then using an alias when i need to play them. After a while, my game crashes with "could not open sounds file lalala.wav". Is there anyway I can stop irrklang from dropping the sound file if it hasn't been used for a while? |
||||
|
It doesn't do this. There must be another reason for you getting this effect. Are you talking about ISound's or ISoundSources? |
||||
|
Doesn't do what? and it's ISoundSource. The error doesn't happen for a while - it all works fine for maybe 10 or 15 minutes, then it throws the error. Because of the nature of the error, it seems like the Originally loaded sound is being dropped because it's not being used. So to clarify, to load the sounds initially I am using: irrklang::ISoundSource * theSoundSource = soundEngine->addSoundSourceFromFile("something.wav"); and then to make the Aliases: ISoundSource * weaponSound = soundEngine->addSoundSourceAlias(theSoundSource); Also, I am confused concerning the 'grab()' ...From the documentation it seems like this is what I need to stop the original sound from being unloaded though the documentation doesn't say very much on the subject. In case you are wondering, the reason I am using Aliases, is because I need to use the same sound, an unknown amount of times and often simultaneously. Hope that gives more clarity. |
||||
|
Can no-one shed any light on this? |
||||
|
I meant it won't drop a sound source because it is not being used. It doesn't do that, so there must be another reason why you get this problem. It seems you are likely dropping() or grabbing() somewhere to much, causing this. Just don't drop() your aliases and sound sources anywhere, unless you are somewhere also calling grab() to them. This likely fixes your problem. |
||||
|
I'm afraid not as i'm not using grab() or drop() at all anywhere. |
||||
|
Hm, that sounds strange. Any details of the crash? Where does it crash? What error does it give? |
||||
|
I will try to illustrate. struct SOUND_SOURCE { irrklang::ISoundSource * TheSoundSource; }; irrklang::ISoundSource * weaponSound; irrklang::ISound * soundRetVal; //Define Array: SOUND_SOURCE * soundList[0]; void loadSounds { //Load Original Sound: soundsList[0].TheSoundSource = soundEngine->addSoundSourceFromFile("mySound.wav"); } void loadWeaponSounds { //Create Alias For The Sound: weaponSound = soundEngine->addSoundSourceAlias(soundsList[0]."strNewName"); } void sndPlaySound() { soundRetVal = soundEngine->play2D(weaponSound,true,true,true); soundRetVal->setPlayPosition(0); <--- This is where is error'd last time; soundRetVal->setIsPaused(false); return; } void sndStopSound() { soundRetVal->setIsPaused(true); return; } /////////// The Code Above Is Just to illustrate, soundRetVal has a value of 0 when the error occurs and the console reports "Could not open sound file: mySound.wav". This is all I can tell you. |
||||
|
Are you sure it's soundList[0]; That's zero size? Also, you are never assigning soundRetVal in your code. |
||||
|
Hi, sorry that was a typo. It's soundsList[50]; And i'm not sure what you mean about assigning the RetVal... Isn't that this line?: soundRetVal = soundEngine->play2D(weaponSound,true,true,true); It was difficult to understand clearly how to implement this method of use (using the same sound multiple times, so i had to just try and muddle through.) |
||||
|
Hm, It's now the complete source, so you might have an error in there somewhere. For example, I also cannot see where you are dropping that soundRetVal somewhere. Maybe you are not doing it, and having a lot o memory leaks because of that? |
||||
|
ok, so i still need some help with this... my code is considerable and way too much to post here. Instead, can I get an example of using Aliases properly as I am obviously confused about their implementation. My application here is for weapons sounds... multiple characters will have the same type of weapon, therefore needing the same sound which can overlap in their playing. This is why i am trying to use aliases. So, my current process is: I load all the original sounds I want to use, at application start up into a library array holding the sounds thusly: struct SOUND_SOURCE { irrklang::ISoundSource * TheSoundSource; core::stringw soundName; }; struct WP { irrklang::ISoundSource * weaponSound; irrklang::ISound * soundRetVal; }; SOUND_SOURCE soundsList[50]; soundsList[50] WP Weaps[10]; //Load Original Sounds In The Library Array: soundsList[0].TheSoundSource = soundEngine->addSoundSourceFromFile("sounds/beam01.wav"); //When a weapon object is created for a player, i create a unique alias name for that sound and create the alias which is never changed again: Weaps[w].weaponSound = soundEngine->addSoundSourceAlias(soundsList[0].TheSoundSource,newSoundName.c_str()); //Then, When I wish to play one of the aliases: void sndPlayWeaponSound(int wp) { Weaps[wp].soundRetVal = soundEngine->play2D(Ships[s].Weaps[wp].weaponSound,false,true,true); Weaps[wp].soundRetVal->setPlayPosition(0); Weaps[wp].soundRetVal->setIsPaused(false); return; } //when I wish to stop an alias: void sndStopWeaponSound(int s, int wp) { if(Ships[s].Weaps[wp].soundRetVal->isFinished() == false) { Ships[s].Weaps[wp].soundRetVal->setIsPaused(true); return; } } As you can see, I am not grabbing or dropping, I also need to be able to stop an alias sound playing at any time (the weapon firing time can be variable) Also, are you saying that the 'soundRetVal' needs to be dropped each time I want to stop a sound so that it can be played again? |
||||
|
UPDATE: I added the soundRetVal->drop() into my sndStopWeaponSound function and now everything seems fine. I am going to leave the game running for an hour to be sure, but the bug usually takes about 15 minutes to appear. |
|