Problem duplicating sound sources

(Simone Pellegrini) #1

Hi all,
I’m tryng to reproduce the effect of a sound coming from another room. One of my task was to duplicate a sound coming from an adiacent room and append it to the door to simulate the occlusion of the wall. I have impemented my own class soundSource that let me handle some features that i needed for the game, like applyng filters, setting parameters and some other useful stuff.
On the door i have attached this script:

void Start ()
	StartCoroutine ("test");

IEnumerator test ()
	appendSoundSource (ssDoor);
	yield return new WaitForSeconds (1.1f);
	removeSoundSource (ssDoor);

public void appendSoundSource (FMOD_SoundSource originalSS)
	ssDoor = gameObject.AddComponent<FMOD_SoundSource> ();
	ssDoor.duplicateFrom (originalSS);
	ssDoor.applyFilter (1, 20000, 20);
	ssDoor.start ();

public void removeSoundSource (FMOD_SoundSource ssDoor)
	PVPair pvp = new PVPair ("EndTrigger", 1);
	ssDoor.setParameterValue (pvp);

For testing purpose i’ve created a coroutine that append the soundSource and then call remooveSoundSource that let the event go out of the loop region. Here’s a screenshoot of my fmod project:

My problem is that if i remove the yield instruction everything works as i expected to, but if i keep that line it does not. It looks strange because unity doesn’t give me errors, and it seems that the parameter “EndTrigger” is modified correctly, but i can’t figure out why it doesn’t go out of the loop region.

I hope that i have been clear enough and on the other hand also synthetic enough
Does somebody have any tips to solve my problem?


(Simone Pellegrini) #2

I had the method init() that created an instance of the event. This metod was called for initialization in the Start() of the SoundSource i created, and also in the start() function i created to let the event play (myEvent.start()). The thing i didn’t expect was that the method start() was called before the initialization metod Start() and so my init() created an event that was dereferentiated after the Start() was called.
I only had to reorganize the code and everything worked!

It’s a really specific case, but i hope this could help somebody…