Пример #1
0
        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;
        }
Пример #2
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
        }
Пример #3
0
 private void Destroy_()
 {
     this.state_ = AudioStreamSourceState.DESTROYED;
     AL.DeleteSource(this.sourceId_);
     AL.DeleteBuffers(this.bufferIds_.ToArray());
     this.bufferIds_.Clear();
 }
Пример #4
0
        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
                    }
                }
            }
        }
Пример #5
0
        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);
        }
Пример #6
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();
        }
Пример #7
0
            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;
            }
Пример #8
0
 // 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;
         }
     }
 }
Пример #9
0
 public void CleanUpBuffer()
 {
     if (AL.IsBuffer(openALDataBuffer))
     {
         AL.DeleteBuffers(1, ref openALDataBuffer);
     }
 }
Пример #10
0
        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);
        }
Пример #11
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);

            if (ALHelper.Efx.IsInitialized)
            {
                ALHelper.Efx.DeleteFilter(alFilterId);
            }

            ALHelper.Check();

            Logger.Log(LogEventSingle.MemoryUsage, () => GC.GetTotalMemory(true));
        }
Пример #12
0
        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.");
            }
        }
Пример #13
0
        /// <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;
                }
            }
        }
Пример #14
0
        /// <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
            {
            }
        }
Пример #15
0
        public void Dispose()
        {
            StopImmediate();

            AL.DeleteBuffers(buffers);
            AL.DeleteSource(source);
        }
Пример #16
0
        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.");
        }
Пример #17
0
        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);
            }
        }
Пример #18
0
        public void DisposeAll()
        {
            AL.DeleteSources(mySources); // free Handles

            AL.DeleteBuffers(myBuffers); // free previously reserved Handles
            AC.Dispose();
        }
Пример #19
0
 public void Dispose()
 {
     AL.SourceStop(m_SourceId);
     AL.DeleteSource(m_SourceId);
     AL.DeleteBuffers(m_BufferIds);
     m_AudioContext.Dispose();
     s_Instance = null;
 }
Пример #20
0
 /// <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);
     }
 }
Пример #21
0
 public void CleanUpBuffer()
 {
     if (AL.IsBuffer(this.openALDataBuffer))
     {
         AL.DeleteBuffers(1, ref this.openALDataBuffer);
     }
     this.pcmDataBuffer = (byte[])null;
 }
Пример #22
0
 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);
 }
Пример #23
0
        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);
                }
            }
        }
Пример #24
0
        // --- 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;
            }
        }
Пример #25
0
 internal static void Dispose()
 {
     if (_audioContext == null)
     {
         return;
     }
     StopAllSounds();
     AL.DeleteSources(_source);             //delete multiple sources
     AL.DeleteBuffers(_buffer);             //delete multiple buffers
     _audioContext.Dispose();
 }
Пример #26
0
        /// <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;
        }
Пример #27
0
 // 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);
         }
     }
 }
Пример #28
0
 public void Dispose()
 {
     if (!isDisposed)
     {
         Stop(true);
         AL.DeleteBuffers(bufferIds);
         AL.DeleteSource(sourceId);
         bufferIdsToFill = null;
         hasSourceId     = false;
         isDisposed      = true;
     }
 }
Пример #29
0
        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;
        }
Пример #30
0
            protected override bool Cleanup(bool dispose_unmanaged_objects)
            {
                if (dispose_unmanaged_objects)
                {
                    Stop();
                    AL.DeleteBuffers(buffers);
                    AL.DeleteSource(source);
                    return(true);
                }

                return(false);
            }