Пример #1
0
        /// <summary>
        /// Sets up a new OpenAL buffer for this AudioData. This will result in decompressing
        /// the Ogg Vorbis data and uploading it to OpenAL, unless the AudioData is streamed.
        /// </summary>
        public void SetupAlBuffer()
        {
            // No AudioData available
            if (this.data.Length == 0 || this.data == null)
            {
                this.DisposeAlBuffer();
                return;
            }

            // Streamed Audio
            if (this.IsStreamed)
            {
                this.DisposeAlBuffer();
                this.alBuffer = AlBuffer_StreamMe;
            }
            // Non-Streamed Audio
            else
            {
                if (this.alBuffer <= AlBuffer_NotAvailable && DualityApp.Sound.IsAvailable)
                {
                    this.alBuffer = AL.GenBuffer();
                    PcmData pcm = OggVorbis.LoadFromMemory(this.data);
                    AL.BufferData(
                        this.alBuffer,
                        pcm.channelCount == 1 ? ALFormat.Mono16 : ALFormat.Stereo16,
                        pcm.data.ToArray(),
                        pcm.dataLength * PcmData.SizeOfDataElement,
                        pcm.sampleRate);
                }
                else
                {
                    // Buffer already there? Do nothing.
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Sets up a new native buffer for this AudioData. This will result in decompressing
        /// the Ogg Vorbis data and uploading it to OpenAL, unless the AudioData is streamed.
        /// </summary>
        private void SetupNativeBuffer()
        {
            // No AudioData available
            if (this.data == null || this.data.Length == 0)
            {
                this.DisposeNativeBuffer();
                return;
            }

            // Streamed Audio
            if (this.IsStreamed)
            {
                this.DisposeNativeBuffer();
                this.native = null;
            }
            // Non-Streamed Audio
            else
            {
                if (this.native == null)
                {
                    this.native = DualityApp.AudioBackend.CreateBuffer();

                    PcmData pcm = OggVorbis.LoadFromMemory(this.data);
                    this.native.LoadData(
                        pcm.SampleRate,
                        pcm.Data,
                        pcm.DataLength,
                        pcm.ChannelCount == 1 ? AudioDataLayout.Mono : AudioDataLayout.LeftRight,
                        AudioDataElementType.Short);
                }
                else
                {
                    // Buffer already there? Do nothing.
                }
            }
        }