Example #1
0
        public override void SetSourcePosition(AudioSource source, Vector3 position)
        {
            ALSource alSource = (ALSource)source;

            AlNative.alSource3f(alSource._source, AlNative.AL_POSITION, position.X, position.Y, position.Z);
            ALEngine.checkAlError();
        }
Example #2
0
        public ALBuffer()
        {
            var buffers = new uint[1];

            AlNative.alGenBuffers(1, buffers);
            ALEngine.checkAlError();
            Buffer = buffers[0];
        }
Example #3
0
        public ALSource()
        {
            var sources = new uint[1];

            AlNative.alGenSources(1, sources);
            ALEngine.checkAlError();
            _source = sources[0];
        }
Example #4
0
        public override bool IsPlaying()
        {
            AlNative.alGetSourcei(_source, AlNative.AL_SOURCE_STATE, out int state);
            ALEngine.checkAlError();
            bool playing = state == AlNative.AL_PLAYING;

            return(playing);
        }
Example #5
0
        public override void QueueBuffer(AudioBuffer buffer)
        {
            RemoveProcessed();

            var alBuffer = (ALBuffer)buffer;

            AlNative.alSourceQueueBuffers(_source, 1, new uint[] { alBuffer.Buffer });
            ALEngine.checkAlError();
        }
Example #6
0
        private void RemoveProcessed()
        {
            //before querying new data check if sth was processed already:
            AlNative.alGetSourcei(_source, AlNative.AL_BUFFERS_PROCESSED, out int processed);
            ALEngine.checkAlError();

            while (processed > 0)
            {
                var bufs = new uint[] { 1 };
                AlNative.alSourceUnqueueBuffers(_source, 1, bufs);
                processed--;
            }
        }
Example #7
0
        public override unsafe void BufferData(IntPtr ptr, int sizeInBytes, AudioFormat format)
        {
            int fmt = (format.Channels == 2) ? AlNative.AL_FORMAT_STEREO8 : AlNative.AL_FORMAT_MONO8;

            if (format.BitsPerSample == 16)
            {
                fmt++;
            }

            AlNative.alBufferData(Buffer, fmt, ptr, sizeInBytes, format.SampleRate);
            ALEngine.checkAlError();

            _format = format;
        }
Example #8
0
        public override unsafe void BufferData <T>(T[] buffer, AudioFormat format)
        {
            int fmt         = (format.Channels == 2) ? AlNative.AL_FORMAT_STEREO8 : AlNative.AL_FORMAT_MONO8;
            int sizeInBytes = sizeof(T) * buffer.Length;

            if (format.BitsPerSample == 16)
            {
                fmt++;
            }

            var    handle = GCHandle.Alloc(buffer);
            IntPtr ptr    = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);

            AlNative.alBufferData(_buffer, fmt, ptr, sizeInBytes, format.SampleRate);
            ALEngine.checkAlError();

            handle.Free();
            _format = format;
        }
Example #9
0
 public ALSubmixer(ALEngine engine)
 {
 }
Example #10
0
 public override void Stop()
 {
     AlNative.alSourceStop(_source);
     ALEngine.checkAlError();
 }
Example #11
0
 public override void Play()
 {
     AlNative.alSourcePlay(_source);
     ALEngine.checkAlError();
 }
Example #12
0
 public override void Dispose()
 {
     AlNative.alDeleteSources(1, new uint[] { _source });
     ALEngine.checkAlError();
 }
Example #13
0
 public override void SetListenerOrientation(Vector3 top, Vector3 front)
 {
     float[] listenerOri = new float[] { front.X, front.Y, front.Z, top.X, top.Y, top.Z };
     AlNative.alListenerfv(AlNative.AL_ORIENTATION, listenerOri);
     ALEngine.checkAlError();
 }
Example #14
0
 public override void SetListenerPosition(Vector3 position)
 {
     AlNative.alListener3f(AlNative.AL_POSITION, position.X, position.Y, position.Z);
     ALEngine.checkAlError();
 }
Example #15
0
 public override void Dispose()
 {
     AlNative.alDeleteBuffers(1, new uint[] { Buffer });
     ALEngine.checkAlError();
 }