Example #1
0
        public void Apply3D(AudioListener listener, AudioEmitter emitter)
        {
            if (INTERNAL_alSource == 0)
            {
                return;
            }

            // Set up orientation matrix
            Matrix orientation = Matrix.CreateWorld(Vector3.Zero, listener.Forward, listener.Up);

            // Set up our final position according to orientation of listener
            position = Vector3.Transform(emitter.Position - listener.Position, orientation);
            if (position != Vector3.Zero)
            {
                position.Normalize();
            }

            // Set the position based on relative positon
            AL10.alSource3f(
                INTERNAL_alSource,
                AL10.AL_POSITION,
                position.X,
                position.Y,
                position.Z
                );

            // We positional now
            INTERNAL_positionalAudio = true;
        }
Example #2
0
 public void SetSourcePosition(IALSource source, Vector3 pos)
 {
     AL10.alSource3f(
         (source as OpenALSource).Handle,
         AL10.AL_POSITION,
         pos.X,
         pos.Y,
         pos.Z
         );
 }
Example #3
0
 public void SetSourcePan(IALSource source, float pan)
 {
     AL10.alSource3f(
         (source as OpenALSource).Handle,
         AL10.AL_POSITION,
         pan,
         0.0f,
         (float)Math.Sqrt(1 - Math.Pow(pan, 2))
         );
 }
Example #4
0
        public void SetSourcePosition(IALSource source, Vector3 pos)
        {
            AL10.alSource3f(
                (source as OpenALSource).Handle,
                AL10.AL_POSITION,
                pos.X,
                pos.Y,
                pos.Z
                );
#if VERBOSE_AL_DEBUGGING
            CheckALError();
#endif
        }
Example #5
0
        public void SetSourcePan(IALSource source, float pan)
        {
            AL10.alSource3f(
                (source as OpenALSource).Handle,
                AL10.AL_POSITION,
                pan,
                0.0f,
                (float)-Math.Sqrt(1 - Math.Pow(pan, 2))
                );
#if VERBOSE_AL_DEBUGGING
            CheckALError();
#endif
        }
Example #6
0
        protected OpenAlSound(uint source, bool looping, bool relative, WPos pos, float volume, int sampleRate)
        {
            Source     = source;
            SampleRate = sampleRate;
            Volume     = volume;

            AL10.alSourcef(source, AL10.AL_PITCH, 1f);
            AL10.alSource3f(source, AL10.AL_POSITION, pos.X, pos.Y, pos.Z);
            AL10.alSource3f(source, AL10.AL_VELOCITY, 0f, 0f, 0f);
            AL10.alSourcei(source, AL10.AL_LOOPING, looping ? 1 : 0);
            AL10.alSourcei(source, AL10.AL_SOURCE_RELATIVE, relative ? 1 : 0);

            AL10.alSourcef(source, AL10.AL_REFERENCE_DISTANCE, 6826);
            AL10.alSourcef(source, AL10.AL_MAX_DISTANCE, 136533);
        }
Example #7
0
        public OpenAlSound(uint source, uint buffer, bool looping, bool relative, WPos pos, float volume)
        {
            Source = source;
            Volume = volume;

            AL10.alSourcef(source, AL10.AL_PITCH, 1f);
            AL10.alSource3f(source, AL10.AL_POSITION, pos.X, pos.Y, pos.Z);
            AL10.alSource3f(source, AL10.AL_VELOCITY, 0f, 0f, 0f);
            AL10.alSourcei(source, AL10.AL_BUFFER, (int)buffer);
            AL10.alSourcei(source, AL10.AL_LOOPING, looping ? 1 : 0);
            AL10.alSourcei(source, AL10.AL_SOURCE_RELATIVE, relative ? 1 : 0);

            AL10.alSourcef(source, AL10.AL_REFERENCE_DISTANCE, 6826);
            AL10.alSourcef(source, AL10.AL_MAX_DISTANCE, 136533);
            AL10.alSourcePlay(source);
        }
Example #8
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 #9
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);
        }
Example #10
0
 public void SetPosition(WPos pos)
 {
     AL10.alSource3f(Source, AL10.AL_POSITION, pos.X, pos.Y, pos.Z);
 }