public int PlayMusic(int ghsound, string eventPath, int bankid, float eventVolume, float soundVolume) { RESULT res; //lock (eventInstanceLock) //{ if (musicInstances.Count > 0 && musicInstances[0].ghsound == ghsound && musicInstances[0].stopped == false) { return(0); } if (musicInstances.Count > 0) { if (musicInstances[0].stopped == false) { musicInstances[0].stopped = true; musicInstances[0].instance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); } } EventDescription eventDescription; res = _system.getEvent(eventPath, out eventDescription); EventInstance eventInstance; res = eventDescription.createInstance(out eventInstance); GHSoundInstance ghinstance = new GHSoundInstance(); ghinstance.instance = eventInstance; ghinstance.ghsound = ghsound; ghinstance.normalEventVolume = eventVolume; ghinstance.normalSoundVolume = soundVolume; ghinstance.sound_type = 0; ghinstance.dialogue_mid = 0; musicInstances.Insert(0, ghinstance); res = eventInstance.setVolume(Math.Max(0.0f, Math.Min(1.0f, eventVolume * soundVolume))); if (musicInstances.Count >= 2) { GHSoundInstance ghsi = musicInstances[musicInstances.Count - 1]; if (ghsi.stopped == false) { ghsi.stopped = true; ghsi.instance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); } musicInstances.RemoveAt(musicInstances.Count - 1); } res = eventInstance.start(); //} res = _system.update(); return((int)res); }
public int PlayImmediateSound(int ghsound, string eventPath, int bankid, float eventVolume, float soundVolume, string[] parameterNames, float[] parameterValues, int arraysize, int sound_type, int play_group, uint dialogue_mid) { FMOD.Studio.EventDescription eventDescription; RESULT res = _system.getEvent(eventPath, out eventDescription); FMOD.Studio.EventInstance eventInstance; res = eventDescription.createInstance(out eventInstance); GHSoundInstance ghinstance = new GHSoundInstance(); ghinstance.instance = eventInstance; ghinstance.ghsound = ghsound; ghinstance.normalEventVolume = eventVolume; ghinstance.normalSoundVolume = soundVolume; ghinstance.sound_type = (immediate_sound_types)sound_type; ghinstance.dialogue_mid = dialogue_mid; ghinstance.queued = false; ghinstance.stopped = false; bool queue_sound = false; //lock (eventInstanceLock) //{ if (play_group == (int)sound_play_groups.SOUND_PLAY_GROUP_LONG) { queue_sound = (longImmediateInstances.Count > 0 && sound_type == (int)immediate_sound_types.IMMEDIATE_SOUND_DIALOGUE && longImmediateInstances[0].sound_type == immediate_sound_types.IMMEDIATE_SOUND_DIALOGUE && !longImmediateInstances[0].stopped); longImmediateInstances.Insert(0, ghinstance); if (sound_type == (int)immediate_sound_types.IMMEDIATE_SOUND_DIALOGUE) { res = longImmediateInstances[0].instance.setCallback(GNHEventCallback, EVENT_CALLBACK_TYPE.STOPPED | EVENT_CALLBACK_TYPE.START_FAILED); } /* Fallback if queued for too long */ if (longImmediateInstances.Count >= GHConstants.MaxLongImmediateSoundInstances && longImmediateInstances[GHConstants.MaxLongImmediateSoundInstances - 1].queued && !longImmediateInstances[GHConstants.MaxLongImmediateSoundInstances - 1].stopped) { longImmediateInstances[GHConstants.MaxLongImmediateSoundInstances - 1].queued = false; res = longImmediateInstances[GHConstants.MaxLongImmediateSoundInstances - 1].instance.start(); } } else { queue_sound = (immediateInstances.Count > 0 && sound_type == (int)immediate_sound_types.IMMEDIATE_SOUND_DIALOGUE && immediateInstances[0].sound_type == immediate_sound_types.IMMEDIATE_SOUND_DIALOGUE && !immediateInstances[0].stopped); immediateInstances.Insert(0, ghinstance); if (sound_type == (int)immediate_sound_types.IMMEDIATE_SOUND_DIALOGUE) { res = immediateInstances[0].instance.setCallback(GNHEventCallback, EVENT_CALLBACK_TYPE.STOPPED | EVENT_CALLBACK_TYPE.START_FAILED); } /* Fallback if queued for too long */ if (immediateInstances.Count >= GHConstants.MaxNormalImmediateSoundInstances && immediateInstances[GHConstants.MaxNormalImmediateSoundInstances - 1].queued && !immediateInstances[GHConstants.MaxNormalImmediateSoundInstances - 1].stopped) { immediateInstances[GHConstants.MaxNormalImmediateSoundInstances - 1].queued = false; res = immediateInstances[GHConstants.MaxNormalImmediateSoundInstances - 1].instance.start();; } } ghinstance.queued = queue_sound; res = eventInstance.setVolume(Math.Max(0.0f, Math.Min(1.0f, eventVolume * soundVolume))); for (int i = 0; i < arraysize; i++) { if (i < parameterNames.Length && i < parameterValues.Length) { string str = parameterNames[i]; if (str != null && str != "") { eventInstance.setParameterByName(str, parameterValues[i]); } else { break; } } } if (play_group == (int)sound_play_groups.SOUND_PLAY_GROUP_LONG) { if (longImmediateInstances.Count > GHConstants.MaxLongImmediateSoundInstances) { GHSoundInstance ghsi = longImmediateInstances[longImmediateInstances.Count - 1]; if (ghsi.stopped == false) { ghsi.stopped = true; ghsi.instance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); } ghsi.instance.release(); longImmediateInstances.RemoveAt(longImmediateInstances.Count - 1); } } else { if (immediateInstances.Count > GHConstants.MaxNormalImmediateSoundInstances) { GHSoundInstance ghsi = immediateInstances[immediateInstances.Count - 1]; if (ghsi.stopped == false) { ghsi.stopped = true; ghsi.instance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); } ghsi.instance.release(); immediateInstances.RemoveAt(immediateInstances.Count - 1); } } //} if (!queue_sound) { res = eventInstance.start(); } res = _system.update(); return((int)res); }