Example #1
0
        public void StopAndDisposeSource(IALSource source)
        {
            uint handle = (source as OpenALSource).Handle;

            AL10.alSourceStop(handle);
            AL10.alDeleteSources((IntPtr)1, ref handle);
        }
Example #2
0
 internal void DeleteSource(AlSource source)
 {
     if (!_sources.Remove(source))
     {
         throw new InvalidOperationException("Context does not own the given source.");
     }
     AL10.alDeleteSources(1, ref source.Name);
     AlHelper.AlCheckError("Call to alDeleteSources failed.");
     _sources.Remove(source);
 }
Example #3
0
 protected override void Dispose(bool disposeManagedResources)
 {
     if (_handle > 0)
     {
         Stop();
         AL10.alDeleteSources(1, ref _handle);
         _handle = 0;
     }
     base.Dispose(disposeManagedResources);
 }
Example #4
0
        public void StopAndDisposeSource(IALSource source)
        {
            uint handle = (source as OpenALSource).Handle;

            AL10.alSourceStop(handle);
#if VERBOSE_AL_DEBUGGING
            CheckALError();
#endif
            AL10.alDeleteSources(1, ref handle);
#if VERBOSE_AL_DEBUGGING
            CheckALError();
#endif
        }
Example #5
0
 public void Stop()
 {
     if (INTERNAL_delayMS > 0)
     {
         INTERNAL_timer.Stop();
         INTERNAL_timer.Reset();
     }
     if (INTERNAL_alSource != 0)
     {
         AL10.alSourceStop(INTERNAL_alSource);
         AL10.alDeleteSources((IntPtr)1, ref INTERNAL_alSource);
         INTERNAL_alSource = 0;
     }
 }
Example #6
0
        public static void Shutdown()
        {
            // Destroy the sources
            AL10.alDeleteSources(MAX_SOURCE_COUNT, s_allSources);
            ALUtils.CheckALError("unable to free audio sources");
            s_availableSources.Clear();
            s_usedSources.Clear();

            // Destroy the context, and then close the device
            ALC10.alcMakeContextCurrent(IntPtr.Zero);
            ALUtils.CheckALCError();
            ALC10.alcDestroyContext(Context);
            ALUtils.CheckALCError();
            Context = IntPtr.Zero;
            ALC10.alcCloseDevice(Device);
            ALUtils.CheckALCError();
            Device = IntPtr.Zero;

            IsShutdown = true;

            // Report
            LINFO("Shutdown OpenAL audio engine.");
        }
Example #7
0
        public override void Play()
        {
            if (State != SoundState.Stopped)
            {
                return;                 // No-op if we're already playing.
            }

            if (INTERNAL_alSource != 0)
            {
                // The sound has stopped, but hasn't cleaned up yet...
                AL10.alSourceStop(INTERNAL_alSource);
                AL10.alDeleteSources((IntPtr)1, ref INTERNAL_alSource);
                INTERNAL_alSource = 0;
            }
            while (queuedBuffers.Count > 0)
            {
                availableBuffers.Enqueue(queuedBuffers.Dequeue());
            }

            AL10.alGenSources((IntPtr)1, out INTERNAL_alSource);
            if (INTERNAL_alSource == 0)
            {
                System.Console.WriteLine("WARNING: AL SOURCE WAS NOT AVAILABLE. SKIPPING.");
                return;
            }

            // Queue the buffers to this source
            while (buffersToQueue.Count > 0)
            {
                uint nextBuf = buffersToQueue.Dequeue();
                queuedBuffers.Enqueue(nextBuf);
                AL10.alSourceQueueBuffers(
                    INTERNAL_alSource,
                    (IntPtr)1,
                    ref nextBuf
                    );
            }

            // Apply Pan/Position
            if (INTERNAL_positionalAudio)
            {
                INTERNAL_positionalAudio = false;
                AL10.alSource3f(
                    INTERNAL_alSource,
                    AL10.AL_POSITION,
                    position.X,
                    position.Y,
                    position.Z
                    );
            }
            else
            {
                Pan = Pan;
            }

            // Reassign Properties, in case the AL properties need to be applied.
            Volume   = Volume;
            IsLooped = IsLooped;
            Pitch    = Pitch;

            // Finally.
            AL10.alSourcePlay(INTERNAL_alSource);
            OpenALDevice.Instance.dynamicInstancePool.Add(this);

            // ... but wait! What if we need moar buffers?
            if (PendingBufferCount <= 2 && BufferNeeded != null)
            {
                BufferNeeded(this, null);
            }
        }
Example #8
0
        public virtual void Play()
        {
            if (State != SoundState.Stopped && INTERNAL_alSource != 0)             // FIXME: alSource check part of timer hack!
            {
                // FIXME: Is this XNA4 behavior?
                Stop();
            }

            if (INTERNAL_delayMS != 0 && !INTERNAL_timer.IsRunning)
            {
                INTERNAL_timer.Start();
            }
            if (INTERNAL_timer.ElapsedMilliseconds < INTERNAL_delayMS)
            {
                return;                 // We'll be back...
            }
            INTERNAL_timer.Stop();
            INTERNAL_timer.Reset();

            if (INTERNAL_alSource != 0)
            {
                // The sound has stopped, but hasn't cleaned up yet...
                AL10.alSourceStop(INTERNAL_alSource);
                AL10.alDeleteSources((IntPtr)1, ref INTERNAL_alSource);
                INTERNAL_alSource = 0;
            }

            AL10.alGenSources((IntPtr)1, out INTERNAL_alSource);
            if (INTERNAL_alSource == 0)
            {
                System.Console.WriteLine("WARNING: AL SOURCE WAS NOT AVAILABLE. SKIPPING.");
                return;
            }

            // Attach the buffer to this source
            AL10.alSourcei(
                INTERNAL_alSource,
                AL10.AL_BUFFER,
                (int)INTERNAL_parentEffect.INTERNAL_buffer
                );

            // Apply Pan/Position
            if (INTERNAL_positionalAudio)
            {
                INTERNAL_positionalAudio = false;
                AL10.alSource3f(
                    INTERNAL_alSource,
                    AL10.AL_POSITION,
                    position.X,
                    position.Y,
                    position.Z
                    );
            }
            else
            {
                Pan = Pan;
            }

            // Reassign Properties, in case the AL properties need to be applied.
            Volume   = Volume;
            IsLooped = IsLooped;
            Pitch    = Pitch;

            // Apply EFX
            if (INTERNAL_alEffectSlot != 0)
            {
                AL10.alSource3i(
                    INTERNAL_alSource,
                    EFX.AL_AUXILIARY_SEND_FILTER,
                    (int)INTERNAL_alEffectSlot,
                    0,
                    0
                    );
            }

            AL10.alSourcePlay(INTERNAL_alSource);
        }