コード例 #1
0
        /// <summary>
        /// Appends an audio buffer to the tracks internal ring buffer
        /// </summary>
        /// <typeparam name="T">The audio sample type</typeparam>
        /// <param name="bufferTag">The unqiue tag of the buffer being appended</param>
        /// <param name="buffer">The buffer to append</param>
        public void AppendBuffer <T>(long bufferTag, T[] buffer) where T : struct
        {
            if (AudioStream == null)
            {
                return;
            }

            int sampleSize = Unsafe.SizeOf <T>();
            int targetSize = sampleSize * buffer.Length;

            // Do we need to downmix?
            if (_hardwareChannels != _virtualChannels)
            {
                if (sampleSize != sizeof(short))
                {
                    throw new NotImplementedException("Downmixing formats other than PCM16 is not supported!");
                }

                short[] downmixedBuffer;

                ReadOnlySpan <short> bufferPCM16 = MemoryMarshal.Cast <T, short>(buffer);

                if (_virtualChannels == 6)
                {
                    downmixedBuffer = Downmixing.DownMixSurroundToStereo(bufferPCM16);

                    if (_hardwareChannels == 1)
                    {
                        downmixedBuffer = Downmixing.DownMixStereoToMono(downmixedBuffer);
                    }
                }
                else if (_virtualChannels == 2)
                {
                    downmixedBuffer = Downmixing.DownMixStereoToMono(bufferPCM16);
                }
                else
                {
                    throw new NotImplementedException($"Downmixing from {_virtualChannels} to {_hardwareChannels} not implemented!");
                }

                targetSize = sampleSize * downmixedBuffer.Length;

                // Copy the memory to our ring buffer
                m_Buffer.Write(downmixedBuffer, 0, targetSize);

                // Keep track of "buffered" buffers
                m_ReservedBuffers.Enqueue(new SoundIoBuffer(bufferTag, targetSize));
            }
            else
            {
                // Copy the memory to our ring buffer
                m_Buffer.Write(buffer, 0, targetSize);

                // Keep track of "buffered" buffers
                m_ReservedBuffers.Enqueue(new SoundIoBuffer(bufferTag, targetSize));
            }
        }
コード例 #2
0
ファイル: SoundIoAudioTrack.cs プロジェクト: zpoo32/Ryujinx
        /// <summary>
        /// Appends an audio buffer to the tracks internal ring buffer
        /// </summary>
        /// <typeparam name="T">The audio sample type</typeparam>
        /// <param name="bufferTag">The unqiue tag of the buffer being appended</param>
        /// <param name="buffer">The buffer to append</param>
        public void AppendBuffer <T>(long bufferTag, T[] buffer)
        {
            if (AudioStream == null)
            {
                return;
            }

            // Calculate the size of the audio samples
            int size = Unsafe.SizeOf <T>();

            // Calculate the amount of bytes to copy from the buffer
            int bytesToCopy = size * buffer.Length;

            // Copy the memory to our ring buffer
            m_Buffer.Write(buffer, 0, bytesToCopy);

            // Keep track of "buffered" buffers
            m_ReservedBuffers.Enqueue(new SoundIoBuffer(bufferTag, bytesToCopy));
        }