public void Shutdown() { this.StopAllSounds(); Channel.shutdown(); AL.DeleteBuffers(this.buffers.Length, this.buffers); if (OpenTkSound.efx) { EFX.DeleteEffect(OpenTkSound.efxEffectGeneric); EFX.DeleteEffect(OpenTkSound.efxEffectUnderwater); EFX.DeleteAuxiliaryEffectSlot(OpenTkSound.efxSlot); } Cmd.RemoveCommand("play"); Cmd.RemoveCommand("stopsound"); Cmd.RemoveCommand("soundlist"); Cmd.RemoveCommand("soundinfo"); // free all sounds for (var i = 0; i < OpenTkSound.num_sfx; i++) { if (OpenTkSound.known_sfx[i].name == null) { continue; } OpenTkSound.known_sfx[i].clear(); } OpenTkSound.num_sfx = 0; }
public void Dispose() { var state = AL.GetSourceState(alSourceId); if (state == ALSourceState.Playing || state == ALSourceState.Paused) { StopPlayback(); } lock (prepareMutex) { OggStreamer.Instance.RemoveStream(this); if (state != ALSourceState.Initial) { Empty(); } Close(); underlyingStream.Dispose(); } AL.DeleteSource(alSourceId); AL.DeleteBuffers(alBufferIds); ALHelper.Check(); #if TRACE ALHelper.TraceMemoryUsage(LogHandler); #endif }
private void Destroy_() { this.state_ = AudioStreamSourceState.DESTROYED; AL.DeleteSource(this.sourceId_); AL.DeleteBuffers(this.bufferIds_.ToArray()); this.bufferIds_.Clear(); }
public static void Cleanup() { lock (sources) { foreach (var source in sources) { //Clean out processed buffers int processed; AL.GetSource(source, ALGetSourcei.BuffersProcessed, out processed); if (processed > 0) { int[] buffersToDispose = AL.SourceUnqueueBuffers(source, processed); AL.DeleteBuffers(buffersToDispose); } //Cleanup source if over int state; AL.GetSource(source, ALGetSourcei.SourceState, out state); if ((ALSourceState)state == ALSourceState.Stopped) { AL.DeleteSource(source); //TODO: call sound over event } } } }
public long GetReleasedAudioOutBuffer(ServiceCtx Context) { long TempKey = 0; if (KeysQueue.Count > 0) { TempKey = KeysQueue.Dequeue(); } AMemoryHelper.WriteBytes(Context.Memory, Context.Request.ReceiveBuff[0].Position, BitConverter.GetBytes(TempKey)); Context.ResponseData.Write((int)TempKey); if (OpenALInstalled) { if (AudioCtx == null) //Needed to call the instance of AudioContext() { return(0); } AL.SourcePlay(Source); int[] FreeBuffers = AL.SourceUnqueueBuffers(Source, 1); AL.DeleteBuffers(FreeBuffers); } return(0); }
public void Dispose() { var state = AL.GetSourceState(alSourceId); if (state == ALSourceState.Playing || state == ALSourceState.Paused) { StopPlayback(); } lock (prepareMutex) { RAudioStreamer.Instance.RemoveStream(this); if (state != ALSourceState.Initial) { Empty(); } Close(); underlyingStream.Dispose(); } AL.DeleteSource(alSourceId); AL.DeleteBuffers(alBufferIds); if (ALHelper.Efx.IsInitialized) { ALHelper.Efx.DeleteFilter(alFilterId); } ALHelper.Check(); }
private void Dispose(bool disposing) { if (SourceHandle == null) { return; } if (!disposing) { // We can't run this code inside the finalizer thread so tell Clyde to clear it up later. _master.DeleteBufferedSourceOnMainThread(SourceHandle.Value); for (var i = 0; i < BufferHandles.Length; i++) { _master.DeleteAudioBufferOnMainThread(BufferHandles[i]); } } else { AL.DeleteSource((int)SourceHandle.Value); AL.DeleteBuffers(BufferHandles); _master._bufferedAudioSources.Remove(SourceHandle.Value); _checkAlError(); } SourceHandle = null; }
// free OpenAL resources if any public void ALStop() { if (AL.IsSource(openalSource)) { AL.SourceStop(openalSource); AL.Source(openalSource, ALSourcei.Buffer, 0); soundSystemLocal.FreeOpenALSource(openalSource); } if (openalStreamingBuffer[0] != 0 && openalStreamingBuffer[1] != 0 && openalStreamingBuffer[2] != 0) { AL.GetError(); AL.DeleteBuffers(3, ref openalStreamingBuffer[0]); if (AL.GetError() == ALError.NoError) { openalStreamingBuffer[0] = openalStreamingBuffer[1] = openalStreamingBuffer[2] = 0; } } if (lastopenalStreamingBuffer[0] != 0 && lastopenalStreamingBuffer[1] != 0 && lastopenalStreamingBuffer[2] != 0) { AL.GetError(); AL.DeleteBuffers(3, ref lastopenalStreamingBuffer[0]); if (AL.GetError() == ALError.NoError) { lastopenalStreamingBuffer[0] = lastopenalStreamingBuffer[1] = lastopenalStreamingBuffer[2] = 0; } } }
public void CleanUpBuffer() { if (AL.IsBuffer(openALDataBuffer)) { AL.DeleteBuffers(1, ref openALDataBuffer); } }
private void ClearBuffers(SourceDescription source, int count) { if (_context == null) { return; } int[] freedbuffers; if (count == 0) { int buffersProcessed; AL.GetSource(source.Id, ALGetSourcei.BuffersProcessed, out buffersProcessed); if (buffersProcessed == 0) { return; } freedbuffers = AL.SourceUnqueueBuffers(source.Id, buffersProcessed); } else { freedbuffers = AL.SourceUnqueueBuffers(source.Id, count); } AL.DeleteBuffers(freedbuffers); }
public void Dispose() { var state = AL.GetSourceState(alSourceId); if (state == ALSourceState.Playing || state == ALSourceState.Paused) { StopPlayback(); } lock (prepareMutex) { OggStreamer.Instance.RemoveStream(this); if (state != ALSourceState.Initial) { Empty(); } Close(); underlyingStream.Dispose(); } AL.DeleteSource(alSourceId); AL.DeleteBuffers(alBufferIds); if (ALHelper.Efx.IsInitialized) { ALHelper.Efx.DeleteFilter(alFilterId); } ALHelper.Check(); Logger.Log(LogEventSingle.MemoryUsage, () => GC.GetTotalMemory(true)); }
public void Dispose() { var state = AL.GetSourceState(alSourceId); ALHelper.CheckError("Failed to get the source state."); if (state == ALSourceState.Playing || state == ALSourceState.Paused) { StopPlayback(); } lock (prepareMutex) { OggStreamer.Instance.RemoveStream(this); if (state != ALSourceState.Initial) { Empty(); } Close(); } AL.Source(alSourceId, ALSourcei.Buffer, 0); ALHelper.CheckError("Failed to free source from buffers."); OpenALSoundController.GetInstance.RecycleSource(alSourceId); AL.DeleteBuffers(alBufferIds); ALHelper.CheckError("Failed to delete buffer."); if (OggStreamer.Instance.Efx.IsInitialized) { OggStreamer.Instance.Efx.DeleteFilter(alFilterId); ALHelper.CheckError("Failed to delete EFX filter."); } }
/// <summary> /// Dispose. Release worker thread, semaphore and audio context. /// </summary> /// <param name="disposing">Indicates if the user called the dispose method or the finalizer did it.</param> protected virtual void Dispose(bool disposing) { // Release the worker thread and semaphore if needed. if (_threadActive) { _threadActive = false; _workerThread.Join(2000); _workerThread = null; } if (disposing) { if (_audioSource != 0) { AL.SourceStop(_audioSource); //Console.WriteLine("AL.SourceStop: {0}", AL.GetErrorString(AL.GetError())); AL.DeleteSource(_audioSource); //Console.WriteLine("AL.DeleteSource: {0}", AL.GetErrorString(AL.GetError())); _audioSource = 0; } if (_buffers != null) { AL.DeleteBuffers(_buffers); //Console.WriteLine("AL.DeleteBuffers: {0}", AL.GetErrorString(AL.GetError())); _buffers = null; } } }
/// <summary> /// Dispose of the player safely /// </summary> public override void Dispose() { try { this.Stop(); AL.DeleteBuffers(m_Buffers); if (!DestroySource()) { throw new OggPlayerSourceException("Source destruction failed"); } if (m_Context != null) { m_Context.Dispose(); m_Context = null; } if (m_CurrentFile != null) { m_CurrentFile.Dispose(); m_CurrentFile = null; } } catch { } }
public void Dispose() { StopImmediate(); AL.DeleteBuffers(buffers); AL.DeleteSource(source); }
public void Dispose() { var state = AL.GetSourceState(alSourceId); ALHelper.CheckError("Failed to get the source state."); if (state == ALSourceState.Playing || state == ALSourceState.Paused) { StopPlayback(); } lock (prepareMutex) { OggStreamer.Instance.RemoveStream(this); if (state != ALSourceState.Initial) { Empty(); } Close(); } OpenALSoundController.Instance.RecycleSource(alSourceId); AL.DeleteBuffers(alBufferIds); ALHelper.CheckError("Failed to delete buffer."); }
static void Main(string[] args) { using (var _ = new AudioContext()) { var(bytes, alFormat, sampleRate) = WavReader.ReadWav(File.OpenRead("assets/pew.wav")); var buffers = AL.GenBuffers(bytes.Count); for (var i = 0; i < buffers.Length; i++) { AL.BufferData(buffers[i], alFormat, bytes[i], bytes[i].Length, sampleRate); } var source = AL.GenSource(); AL.SourceQueueBuffers(source, buffers.Length, buffers); AL.Source(source, ALSourceb.Looping, true); Console.WriteLine("Press button to play sound"); Console.ReadKey(); AL.SourcePlay(source); Console.WriteLine("Sound playing. Press button to exit"); Console.ReadKey(); AL.DeleteSource(source); AL.DeleteBuffers(buffers); } }
public void DisposeAll() { AL.DeleteSources(mySources); // free Handles AL.DeleteBuffers(myBuffers); // free previously reserved Handles AC.Dispose(); }
public void Dispose() { AL.SourceStop(m_SourceId); AL.DeleteSource(m_SourceId); AL.DeleteBuffers(m_BufferIds); m_AudioContext.Dispose(); s_Instance = null; }
/// <summary>Unloads the specified microphone buffer.</summary> /// <param name="source"></param> /// <param name="number"></param> private static void UnloadMicBuffers(int source, int number) { if (number > 0) { int[] buffers = AL.SourceUnqueueBuffers(source, number); AL.DeleteBuffers(buffers); } }
public void CleanUpBuffer() { if (AL.IsBuffer(this.openALDataBuffer)) { AL.DeleteBuffers(1, ref this.openALDataBuffer); } this.pcmDataBuffer = (byte[])null; }
public void DeleteBuffers(int[] bufferHandles) { uint[] buffers = new uint[bufferHandles.Length]; for (int num = 0; num < bufferHandles.Length; num++) { buffers[num] = (uint)bufferHandles[num]; } AL.DeleteBuffers(bufferHandles.Length, buffers); }
public void Tick() { if (Capture == null) { return; } int asamps = Capture.AvailableSamples; if (asamps > 0) { Capture.ReadSamples(buffer, asamps); Array.Copy(buffer, 0, tempbuf, tempasamps * 2, asamps * 2); tempasamps += asamps; stat_bytes += asamps * 2; int b = 0; while ((tempasamps - b) >= 960) { AddSection(b, 960); b += 960; } // Are the below while loops needed? while ((tempasamps - b) >= 320) { AddSection(b, 320); b += 320; } while ((tempasamps - b) >= 80) { AddSection(b, 80); b += 80; } while ((tempasamps - b) >= 40) { AddSection(b, 40); b += 40; } if (tempasamps - b > 0) { byte[] tbuf = new byte[tempbuf.Length]; Array.Copy(tempbuf, b, tbuf, 0, tempasamps - b); tempbuf = tbuf; } tempasamps -= b; int bufc; AL.GetSource(PlaybackSrc, ALGetSourcei.BuffersProcessed, out bufc); if (bufc > 0) { int[] bufs = AL.SourceUnqueueBuffers(PlaybackSrc, bufc); AL.DeleteBuffers(bufs); } if (AL.GetSourceState(PlaybackSrc) != ALSourceState.Playing) { AL.SourcePlay(PlaybackSrc); } } }
// --- unloading buffers --- /// <summary>Unloads the specified sound buffer.</summary> /// <param name="buffer"></param> internal static void UnloadBuffer(SoundBuffer buffer) { if (buffer.Loaded) { AL.DeleteBuffers(1, ref buffer.OpenAlBufferName); buffer.OpenAlBufferName = 0; buffer.Loaded = false; buffer.Ignore = false; } }
internal static void Dispose() { if (_audioContext == null) { return; } StopAllSounds(); AL.DeleteSources(_source); //delete multiple sources AL.DeleteBuffers(_buffer); //delete multiple buffers _audioContext.Dispose(); }
/// <summary> /// Disposes the channel, freeing its hardware resources. /// </summary> public void Dispose() { AL.SourceStop(Source); if (Buffers != null) { AL.DeleteBuffers(Buffers); } Buffers = null; CurrentClip = null; }
// unuse sound buffer private static void UnuseSoundBuffer(int SoundBufferIndex) { if (OpenAlContext != ContextHandle.Zero) { if (SoundBuffers[SoundBufferIndex].OpenAlBufferIndex.Valid) { AL.DeleteBuffers(1, ref SoundBuffers[SoundBufferIndex].OpenAlBufferIndex.Index); SoundBuffers[SoundBufferIndex].OpenAlBufferIndex = new OpenAlIndex(0, false); } } }
public void Dispose() { if (!isDisposed) { Stop(true); AL.DeleteBuffers(bufferIds); AL.DeleteSource(sourceId); bufferIdsToFill = null; hasSourceId = false; isDisposed = true; } }
private void DecodeAudio() { // The number of AL buffers to queue into the source. const int NUM_BUFFERS = 4; // Generate the source. audioSourceIndex = AL.GenSource(); UpdateVolume(); // Generate the alternating buffers. int[] buffers = AL.GenBuffers(NUM_BUFFERS); // Fill and queue the buffers. for (int i = 0; i < NUM_BUFFERS; i++) { if (!StreamAudio(buffers[i])) { break; } } AL.SourceQueueBuffers(audioSourceIndex, NUM_BUFFERS, buffers); // We now have some audio to start with. Go! audioStarted = true; while (State != MediaState.Stopped) { // When a buffer has been processed, refill it. int processed; AL.GetSource(audioSourceIndex, ALGetSourcei.BuffersProcessed, out processed); while (processed-- > 0) { int buffer = AL.SourceUnqueueBuffer(audioSourceIndex); if (!StreamAudio(buffer)) { break; } AL.SourceQueueBuffer(audioSourceIndex, buffer); } } // Force stop the OpenAL source and destroy it with the buffers. if (AL.GetSourceState(audioSourceIndex) != ALSourceState.Stopped) { AL.SourceStop(audioSourceIndex); } AL.DeleteSource(audioSourceIndex); AL.DeleteBuffers(buffers); // Audio is done. audioStarted = false; audioSourceIndex = -1; }
protected override bool Cleanup(bool dispose_unmanaged_objects) { if (dispose_unmanaged_objects) { Stop(); AL.DeleteBuffers(buffers); AL.DeleteSource(source); return(true); } return(false); }