Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
Sound Lost after a while

davros
Registered User
Quote
2016-06-18 20:02:57

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?


niko
Moderator
Quote
2016-06-19 08:36:01

It doesn't do this. There must be another reason for you getting this effect. Are you talking about ISound's or ISoundSources?


davros
Registered User
Quote
2016-06-19 19:49:38

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.


davros
Registered User
Quote
2016-06-22 16:35:32

Can no-one shed any light on this?


niko
Moderator
Quote
2016-06-23 03:45:06

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.


davros
Registered User
Quote
2016-06-23 11:03:10

I'm afraid not as i'm not using grab() or drop() at all anywhere.


niko
Moderator
Quote
2016-06-23 16:53:27

Hm, that sounds strange. Any details of the crash? Where does it crash? What error does it give?


davros
Registered User
Quote
2016-06-30 14:20:29

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.


niko
Moderator
Quote
2016-07-01 04:35:04

Are you sure it's
soundList[0];

That's zero size?

Also, you are never assigning soundRetVal in your code.


davros
Registered User
Quote
2016-07-01 09:19:52

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.)


niko
Moderator
Quote
2016-07-03 10:00:13

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?


davros
Registered User
Quote
2016-10-31 16:39:43

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?


davros
Registered User
Quote
2016-10-31 17:35:13

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.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internati?nal" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact