private AudioSource FindAudioSource(AudioVoice audioVoice) { int num = _allocatedList.IndexOf(audioVoice); if (num >= 0) { return(_allocatedList[num]._audioSource); } return(null); }
public void Free(AudioSource audioSource, bool callStop = false) { if (audioSource != null) { AudioVoice audioVoice = FindAudioVoiceFromSource(audioSource); if (audioVoice != null && _allocatedList.Remove(audioVoice)) { audioVoice.Stop(_fadeOutTime, callStop); _freeingVoicesList.Add(audioVoice); } } }
public AudioSource Alloc(Fabric.Component component) { if (_audioVoicePool == null || _audioVoicePool.Count == 0) { return(null); } AudioVoice audioVoice = _audioVoicePool.Dequeue(); if (audioVoice == null) { return(null); } _allocatedList.Add(audioVoice); Generic.SetGameObjectActive(audioVoice.gameObject, active: true); audioVoice.Set(component, _fadeInTime); return(audioVoice._audioSource); }
public void CreateVoicePool(int count) { int num = 0; while (true) { if (num >= count) { return; } GameObject gameObject = null; AudioVoice audioVoice = null; bool addAudioSource = true; if (FabricManager.Instance._VRAudioManager != null && FabricManager.Instance._VRAudioManager._vrSolutions.Count > 0) { gameObject = FabricManager.Instance._VRAudioManager.GetAudioSource(); if ((bool)gameObject) { addAudioSource = false; } else { gameObject = new GameObject(); } } else { gameObject = new GameObject(); } gameObject.name = "AudioVoice_" + num; audioVoice = gameObject.AddComponent <AudioVoice>(); if (audioVoice == null || gameObject == null) { break; } audioVoice.Init(addAudioSource); audioVoice.transform.parent = base.transform; Generic.SetGameObjectActive(audioVoice.gameObject, active: false); _audioVoicePool.Enqueue(audioVoice); num++; } DebugLog.Print("Failed to allocate audio source in the pool!", DebugLevel.Error); }
public void LoadAudio(params AwcStream[] audios) { if (xAudio2 == null) { xAudio2 = new XAudio2(); masteringVoice = new MasteringVoice(xAudio2); } if ((voices == null) || (voices.Length != audios.Length)) { voices = new AudioVoice[audios.Length]; for (int i = 0; i < audios.Length; i++) { voices[i] = new AudioVoice(); } } trackLength = 0; for (int i = 0; i < audios.Length; i++) { var voice = voices[i]; var audio = audios[i]; if (audio != voice.audio) { voice.audio = audio; voice.trackLength = audio.Length; trackLength = Math.Max(trackLength, voice.trackLength); var wavStream = audio.GetWavStream(); var soundStream = new SoundStream(wavStream); voice.soundStream = soundStream; voice.audioBuffer = new AudioBuffer { Stream = soundStream.ToDataStream(), AudioBytes = (int)soundStream.Length, Flags = BufferFlags.EndOfStream }; soundStream.Close(); wavStream.Close(); } } }
public void Update() { if (_freeingVoicesList != null) { for (int i = 0; i < _freeingVoicesList.Count; i++) { AudioVoice audioVoice = _freeingVoicesList[i]; audioVoice.UpdateInternal(); if (!audioVoice.IsPlaying()) { Generic.SetGameObjectActive(audioVoice.gameObject, active: false); _freeingVoicesList.Remove(audioVoice); _audioVoicePool.Enqueue(audioVoice); } } } if (_allocatedList != null) { for (int j = 0; j < _allocatedList.Count; j++) { _allocatedList[j].UpdateInternal(); } } }