/// <summary> /// Creates a new AudioBuffer. /// </summary> /// <param name="format">The AudioFormat.</param> /// <returns>OpenALAudioBuffer.</returns> internal OpenALAudioBuffer CreateAudioBuffer(OpenALAudioFormat format) { var audioBuffer = new OpenALAudioBuffer(format, this); lock (_audioBuffers) { _audioBuffers.Add(audioBuffer); } return(audioBuffer); }
/// <summary> /// Destroys the AudioBuffer. /// </summary> /// <param name="audioBuffer">The OpenALAudioBuffer.</param> internal void DestroyAudioBuffer(OpenALAudioBuffer audioBuffer) { if (_disposing) { return; //avoid deadlock } lock (_audioBuffers) { _audioBuffers.Remove(audioBuffer); } }
/// <summary> /// Initializes the audio provider with the given audio source. /// </summary> /// <param name="audioSource">The AudioSource.</param> public void Initialize(IAudioSource audioSource) { var openALAudioSource = audioSource as OpenALAudioSource; if (openALAudioSource == null) { throw new InvalidOperationException("The specified audio source does not match the AudioProvider type."); } //clean old playback if existent if (_audioBuffer != null) { _audioBuffer.Dispose(); } _audioSource = audioSource; var audioFormat = DetectAudioFormat(openALAudioSource.WaveFormat); _audioBuffer = OpenALDevice.DefaultDevice.CreateAudioBuffer(audioFormat); _audioBuffer.PlaybackChanged += AudioBufferPlaybackChanged; Volume = _volume; Pan = _pan; _audioBuffer.Initialize(openALAudioSource.WaveData, openALAudioSource.WaveFormat); }
/// <summary> /// Destroys the AudioBuffer. /// </summary> /// <param name="audioBuffer">The OpenALAudioBuffer.</param> internal void DestroyAudioBuffer(OpenALAudioBuffer audioBuffer) { if (_disposing) return; //avoid deadlock lock (_audioBuffers) { _audioBuffers.Remove(audioBuffer); } }
/// <summary> /// Creates a new AudioBuffer. /// </summary> /// <param name="format">The AudioFormat.</param> /// <returns>OpenALAudioBuffer.</returns> internal OpenALAudioBuffer CreateAudioBuffer(OpenALAudioFormat format) { var audioBuffer = new OpenALAudioBuffer(format, this); lock (_audioBuffers) { _audioBuffers.Add(audioBuffer); } return audioBuffer; }