示例#1
0
        public void Process(CommandList context)
        {
            HardwareDevice device = context.OutputDevice;

            if (device.GetSampleRate() == RendererConstants.TargetSampleRate)
            {
                int  channelCount = (int)device.GetChannelCount();
                uint bufferCount  = Math.Min(device.GetChannelCount(), InputCount);

                const int sampleCount = RendererConstants.TargetSampleCount;

                short[] outputBuffer = new short[bufferCount * sampleCount];

                for (int i = 0; i < bufferCount; i++)
                {
                    ReadOnlySpan <float> inputBuffer = GetBuffer(InputBufferIndices[i], sampleCount);

                    for (int j = 0; j < sampleCount; j++)
                    {
                        outputBuffer[i + j * channelCount] = PcmHelper.Saturate(inputBuffer[j]);
                    }
                }

                device.AppendBuffer(outputBuffer, InputCount);
            }
            else
            {
                // TODO: support resampling for device only supporting something different
                throw new NotImplementedException();
            }
        }
        public void Process(CommandList context)
        {
            const int targetChannelCount = 2;

            ulong currentOffset = CurrentOffset;

            if (CircularBufferSize > 0)
            {
                for (int i = 0; i < InputCount; i++)
                {
                    ReadOnlySpan <float> inputBuffer = context.GetBuffer(Input[i]);

                    ulong targetOffset = CircularBuffer + currentOffset;

                    for (int y = 0; y < context.SampleCount; y++)
                    {
                        context.MemoryManager.Write(targetOffset + (ulong)y * targetChannelCount, PcmHelper.Saturate(inputBuffer[y]));
                    }

                    currentOffset += context.SampleCount * targetChannelCount;

                    if (currentOffset >= CircularBufferSize)
                    {
                        currentOffset = 0;
                    }
                }
            }
        }