コード例 #1
0
        private void INTERNAL_bufferData(
            byte[] data,
            uint sampleRate,
            uint channels,
            uint loopStart,
            uint loopEnd,
            bool isADPCM,
            uint formatParameter
            )
        {
            // FIXME: MSADPCM Duration
            Duration = TimeSpan.FromSeconds(data.Length / 2 / channels / ((double)sampleRate));

            // Generate the buffer now, in case we need to perform alBuffer ops.
            INTERNAL_buffer = AL.GenBuffer();

            ALFormat format;

            if (isADPCM)
            {
                format = (channels == 2) ? ALFormat.StereoMsadpcmSoft : ALFormat.MonoMsadpcmSoft;
                AL.Buffer(INTERNAL_buffer, ALBufferi.UnpackBlockAlignmentSoft, formatParameter);
            }
            else
            {
                if (formatParameter == 1)
                {
                    format = (channels == 2) ? ALFormat.Stereo16 : ALFormat.Mono16;
                }
                else
                {
                    format = (channels == 2) ? ALFormat.Stereo8 : ALFormat.Mono8;
                }
            }

            // Load it!
            AL.BufferData(
                INTERNAL_buffer,
                format,
                data,
                data.Length,
                (int)sampleRate
                );

            // Set the loop points, if applicable
            if (loopStart > 0 || loopEnd > 0)
            {
                AL.Buffer(
                    INTERNAL_buffer,
                    ALBufferiv.LoopPointsSoft,
                    new uint[]
                {
                    loopStart,
                    loopEnd
                }
                    );
            }
        }
コード例 #2
0
ファイル: SoundEffect.cs プロジェクト: TheDuderist/MonoGame
        private void INTERNAL_bufferData(
            byte[] data,
            uint sampleRate,
            uint channels,
            uint loopStart,
            uint loopEnd,
            bool isADPCM,
            uint formatParameter
            )
        {
            if (OpenALDevice.Instance == null)
            {
                throw new NoAudioHardwareException();
            }

            // Generate the buffer now, in case we need to perform alBuffer ops.
            INTERNAL_buffer = AL.GenBuffer();

            ALFormat format;

            if (isADPCM)
            {
                format = (channels == 2) ? ALFormat.StereoMsadpcmSoft : ALFormat.MonoMsadpcmSoft;
                AL.Buffer(INTERNAL_buffer, ALBufferi.UnpackBlockAlignmentSoft, formatParameter);
            }
            else
            {
                if (formatParameter == 1)
                {
                    format = (channels == 2) ? ALFormat.Stereo16 : ALFormat.Mono16;
                }
                else
                {
                    format = (channels == 2) ? ALFormat.Stereo8 : ALFormat.Mono8;
                }
            }

            // Load it!
            AL.BufferData(
                INTERNAL_buffer,
                format,
                data,
                data.Length,
                (int)sampleRate
                );

            // Calculate the duration now, after we've unpacked the buffer
            int bufLen, bits;

            AL.GetBuffer(INTERNAL_buffer, ALGetBufferi.Size, out bufLen);
            AL.GetBuffer(INTERNAL_buffer, ALGetBufferi.Bits, out bits);
            Duration = TimeSpan.FromSeconds(
                bufLen /
                (bits / 8) /
                channels /
                ((double)sampleRate)
                );

            // Set the loop points, if applicable
            if (loopStart > 0 || loopEnd > 0)
            {
                AL.Buffer(
                    INTERNAL_buffer,
                    ALBufferiv.LoopPointsSoft,
                    new uint[]
                {
                    loopStart,
                    loopEnd
                }
                    );
            }
        }