Beispiel #1
0
        public WaveEngine(WaveFormat format, int bufferLengthMs = 1000, bool restartOnFailure = false)
        {
            _restartOnFailure = restartOnFailure;

            // Audio engine
            Exception ex = null;

            try {
                _engine = SA.AudioEngine.CreateOpenAL();
                //_engine = SA.AudioEngine.CreateXAudio();
            } catch (Exception e) {
                ex = e;
            }
            if (_engine == null)
            {
                throw new WaveEngineException(ex, "Can't initialize Audio engine");
            }

            // Audio source
            _source = _engine.CreateSource();

            _format      = format;
            _audioFormat = new SA.AudioFormat {
                BitsPerSample = format.bytesPerSample * 8,
                SampleRate    = format.sampleRate,
                Channels      = format.channels,
            };

            // Buffer chain
            for (int i = 0; i < _audioBuffers.Length; ++i)
            {
                _audioBuffers[i] = _engine.CreateBuffer();
            }

            // Create sample buffer
            _bufferLengthMs = bufferLengthMs;
            _bufferSize     = _format.bytesPerSample
                              * _format.sampleRate
                              * _format.channels
                              * _bufferLengthMs / 1000;

            //!!! is it right validation?
            _bufferSize = _bufferSize & ~7;

            _buffer = new byte[_bufferSize];
            Debug.WriteLine("WaveEngine buffer length {0} ms; size {1} bytes; format {2}",
                            _bufferLengthMs, _bufferSize, _format);
        }
Beispiel #2
0
 public abstract void BufferData <T>(T[] buffer, AudioFormat format) where T : unmanaged;