예제 #1
0
        public OpenALAudioLayer(string name, OpenALAudioAdapter parent) : base(name)
        {
            if (_openALFormatId == 0)
            {
                _openALFormatId = _openALAudioFormat.BitsPerSample switch
                {
                    32 => Al.FORMAT_STEREO32F,
                    16 => _openALAudioFormat.Channels == 2 ? Al.FORMAT_STEREO16 : Al.FORMAT_MONO16,
                    8 => _openALAudioFormat.Channels == 2 ? Al.FORMAT_STEREO8 : Al.FORMAT_MONO8,
                    _ => _openALFormatId
                }
            }
            ;

            if (_frameRequestSize == 0)
            {
                _frameRequestSize  = _openALAudioFormat.GetFrameCount(BackendBufferExpectedAhead / 1000f);
                _frameRequestSize /= BUFFER_COUNT;
            }

            _parent = parent;
            Al.GenSource(out _source);

            _buffers    = new uint[BUFFER_COUNT];
            _bufferBusy = new bool[BUFFER_COUNT];
            for (var i = 0; i < _buffers.Length; i++)
            {
                Al.GenBuffer(out _buffers[i]);
            }

            _uploadBuffer = new byte[_frameRequestSize * _openALAudioFormat.FrameSize];
        }