Ejemplo n.º 1
0
        // Copie du buffer de son provenant du 6809 vers le buffer de la carte son
        // Cette fonction est lancée lorsque le buffer 6809 est plein
        public void PlaySound(byte[] soundBuffer)
        {
            for (var i = 0; i < NBytes; i++)
            {
                _data[i / 4] = soundBuffer[i];
            }

            var buffer = new SoundBuffer();

            buffer.BufferData(_data, ALFormat.Mono16, NBytes / 4, FrameRate);

            // Queue the buffer
            AL.SourceQueueBuffer(_source, buffer.Id);
            ALHelper.CheckError("Failed to queue buffer.");
            _queuedBuffers.Enqueue(buffer);

            // If the source has run out of buffers, restart it
            var sourceState = AL.GetSourceState(_source);

            if (sourceState == ALSourceState.Stopped || sourceState == ALSourceState.Initial)
            {
                AL.SourcePlay(_source);
                ALHelper.CheckError("Failed to resume source playback.");
            }
        }
Ejemplo n.º 2
0
        public void UpdateQueue()
        {
            // Get the completed buffers
            AL.GetError();
            AL.GetSource(_source, ALGetSourcei.BuffersProcessed, out int numBuffers);
            ALHelper.CheckError("Failed to get processed buffer count.");

            // Unqueue them
            if (numBuffers > 0)
            {
                AL.SourceUnqueueBuffers(_source, numBuffers);
                ALHelper.CheckError("Failed to unqueue buffers.");
                for (int i = 0; i < numBuffers; i++)
                {
                    var buffer = _queuedBuffers.Dequeue();
                    buffer.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        public Sound()
        {
            _device = Alc.OpenDevice(null);
            ALHelper.CheckError("Failed to OpenDevice.");
            _context = Alc.CreateContext(_device, (int[])null);
            ALHelper.CheckError("Failed to CreateContext.");
            Alc.MakeContextCurrent(_context);
            ALHelper.CheckError("Failed to MakeContextCurrent.");

            _source = AL.GenSource();
            ALHelper.CheckError("Failed to CheckError.");

            _data          = new byte[NBytes];
            _queuedBuffers = new Queue <SoundBuffer>();

            AL.Source(_source, ALSourceb.Looping, false);
            ALHelper.CheckError("Failed to set source loop state.");
            AL.SourcePlay(_source);
            ALHelper.CheckError("Failed to play the source.");
        }
Ejemplo n.º 4
0
 public void Dispose()
 {
     //Console.WriteLine("Del buf #" + _buffer);
     AL.DeleteBuffer(_id);
     ALHelper.CheckError("Failed to DeleteBuffer buffer.");
 }
Ejemplo n.º 5
0
 public void BufferData(byte[] data, ALFormat format, int size, int freq)
 {
     AL.BufferData(_id, format, data, size, freq);
     ALHelper.CheckError("Failed to fill buffer.");
 }
Ejemplo n.º 6
0
 public SoundBuffer()
 {
     _id = AL.GenBuffer();
     //Console.WriteLine("Gen buf #"+_buffer);
     ALHelper.CheckError("Failed to GenBuffers.");
 }