예제 #1
0
        public override bool IsPlaying()
        {
            AlNative.alGetSourcei(_source, AlNative.AL_SOURCE_STATE, out int state);
            bool playing = state == AlNative.AL_PLAYING;

            return(playing);
        }
예제 #2
0
        protected override void PlatformDispose()
        {
            mutex.WaitOne();
            if (usingResource == 1)
            {
                if (_context != IntPtr.Zero)
                {
                    AlNative.alcSuspendContext(_context);
                    checkAlcError();
                }
                AlNative.alcMakeContextCurrent(IntPtr.Zero);
                checkAlcError();

                if (_context != IntPtr.Zero)
                {
                    AlNative.alcDestroyContext(_context);
                    checkAlcError();
                    _context = IntPtr.Zero;
                    AlNative.alcCloseDevice(_device);
                    checkAlcError();
                    _device = IntPtr.Zero;
                }
                usingResource = 0;
            }
            mutex.ReleaseMutex();
        }
예제 #3
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();
        }
예제 #4
0
        public ALBuffer()
        {
            var buffers = new uint[1];

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

            AlNative.alGenSources(1, sources);
            ALEngine.checkAlError();
            _source = sources[0];
        }
예제 #6
0
        public override void QueueBuffer(AudioBuffer buffer)
        {
            RemoveProcessed();

            var alBuffer = (ALBuffer)buffer;

            AlNative.alSourceQueueBuffers(_source, 1, new uint[] { alBuffer.Buffer });
            ALEngine.checkAlError();
        }
예제 #7
0
        private void checkAlcError()
        {
            int error = AlNative.alcGetError(_device);

            if (error != AlNative.ALC_NO_ERROR)
            {
                throw new SharpAudioException("OpenAL Error: " + error);
            }
        }
예제 #8
0
        internal static void checkAlError()
        {
            int error = AlNative.alGetError();

            if (error != AlNative.AL_NO_ERROR)
            {
                throw new SharpAudioException("OpenAL Error: " + error);
            }
        }
예제 #9
0
 protected override void PlatformDispose()
 {
     AlNative.alcMakeContextCurrent((IntPtr)0);
     checkAlcError();
     AlNative.alcDestroyContext(_context);
     checkAlcError();
     AlNative.alcCloseDevice(_device);
     checkAlcError();
 }
예제 #10
0
 public ALEngine(AudioEngineOptions options)
 {
     _device = AlNative.alcOpenDevice(null);
     checkAlcError();
     _context = AlNative.alcCreateContext(_device, null);
     checkAlcError();
     AlNative.alcMakeContextCurrent(_context);
     checkAlcError();
     _floatSupport = AlNative.alIsExtensionPresent("AL_EXT_FLOAT32");
 }
예제 #11
0
        private void checkAlcError()
        {
            int error = AlNative.alcGetError(_device);

            if (error != AlNative.ALC_NO_ERROR)
            {
                string formatErrMsg = string.Format("OpenALc Error: {0} - {1}", Marshal.PtrToStringAuto(AlNative.alcGetString(_device, error)), AlNative.alcGetCurrentContext().ToString());
                throw new SharpAudioException(formatErrMsg);
            }
        }
예제 #12
0
        internal static void checkAlError()
        {
            int error = AlNative.alGetError();

            if (error != AlNative.AL_NO_ERROR)
            {
                string formatErrMsg = string.Format("OpenAL Error: {0} - {1}", Marshal.PtrToStringAuto(AlNative.alGetString(error)), AlNative.alcGetCurrentContext().ToString());
                throw new SharpAudioException(formatErrMsg);
            }
        }
예제 #13
0
 public ALCapture(AudioCaptureOptions options)
 {
     mutex.WaitOne();
     usingResource++;
     if (usingResource == 1)
     {
         // opens the default device.
         _device = AlNative.alcCaptureOpenDevice(null, (uint)options.SampleRate, AlNative.AL_FORMAT_MONO16, 128);
         checkAlcError();
     }
     mutex.ReleaseMutex();
 }
예제 #14
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--;
            }
        }
예제 #15
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;
        }
예제 #16
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;
        }
예제 #17
0
        public ALEngine(AudioEngineOptions options)
        {
            mutex.WaitOne();
            usingResource++;
            if (usingResource == 1)
            {
                int[] argument = new int[] { AlNative.ALC_FREQUENCY, options.SampleRate };
                // opens the default device.
                _device = AlNative.alcOpenDevice(null);
                checkAlcError();
                _context = AlNative.alcCreateContext(_device, argument);
                checkAlcError();

                //
                AlNative.alcMakeContextCurrent(_context);
                checkAlcError();
                _floatSupport = AlNative.alIsExtensionPresent("AL_EXT_FLOAT32");
                checkAlError();
            }
            mutex.ReleaseMutex();
        }
예제 #18
0
 public override void Dispose()
 {
     AlNative.alDeleteBuffers(1, new uint[] { Buffer });
 }
예제 #19
0
 public override void Dispose()
 {
     AlNative.alDeleteBuffers(1, new uint[] { Buffer });
     ALEngine.checkAlError();
 }
예제 #20
0
 public override void Stop()
 {
     AlNative.alSourceStop(_source);
     ALEngine.checkAlError();
 }
예제 #21
0
 protected override void PlatformDispose()
 {
     AlNative.alcDestroyContext(_context);
     AlNative.alcCloseDevice(_device);
 }
예제 #22
0
 public override void Play()
 {
     AlNative.alSourcePlay(_source);
     ALEngine.checkAlError();
 }
예제 #23
0
 public override void SetListenerPosition(Vector3 position)
 {
     AlNative.alListener3f(AlNative.AL_POSITION, position.X, position.Y, position.Z);
     ALEngine.checkAlError();
 }
예제 #24
0
 public override void Dispose()
 {
     AlNative.alDeleteSources(1, new uint[] { _source });
     ALEngine.checkAlError();
 }
예제 #25
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();
 }