Пример #1
0
        public AudioBuffer(IDecoder decoder)
        {
            if (decoder == null)
                throw new ArgumentNullException("decoder");

            Buffer = AL.GenBuffer();
            Util.CheckOpenAlErrors();

            var data = new float[decoder.TotalSamples];
            var castData = new short[decoder.TotalSamples];

            int read = 0;
            while (read < data.Length)
            {
                read += decoder.ReadSamples(data, read, data.Length - read);
            }

            Util.CastBuffer(data, castData, data.Length);

            AL.BufferData(Buffer, Util.ToOpenAL(decoder.Format), castData, castData.Length * sizeof(short), decoder.Frequency);
            Util.CheckOpenAlErrors();

            decoder.Dispose();
        }