private uint Write(IVirtualMemoryManager memoryManager, ulong outBufferAddress, uint countMax, ReadOnlySpan <int> buffer, uint count, uint writeOffset, uint updateCount) { if (countMax == 0 || outBufferAddress == 0) { return(0); } uint targetWriteOffset = writeOffset + AuxiliaryBufferInfo.GetWriteOffset(memoryManager, BufferInfo.SendBufferInfo); if (targetWriteOffset > countMax) { return(0); } uint remaining = count; uint inBufferOffset = 0; while (remaining != 0) { uint countToWrite = Math.Min(countMax - targetWriteOffset, remaining); memoryManager.Write(outBufferAddress + targetWriteOffset * sizeof(int), MemoryMarshal.Cast <int, byte>(buffer.Slice((int)inBufferOffset, (int)countToWrite))); targetWriteOffset = (targetWriteOffset + countToWrite) % countMax; remaining -= countToWrite; inBufferOffset += countToWrite; } if (updateCount != 0) { uint newWriteOffset = (AuxiliaryBufferInfo.GetWriteOffset(memoryManager, BufferInfo.SendBufferInfo) + updateCount) % countMax; AuxiliaryBufferInfo.SetWriteOffset(memoryManager, BufferInfo.SendBufferInfo, newWriteOffset); } return(count); }
private uint Write(IVirtualMemoryManager memoryManager, ulong outBufferAddress, uint countMax, ReadOnlySpan <int> buffer, uint count, uint writeOffset, uint updateCount) { if (countMax == 0 || outBufferAddress == 0) { return(0); } uint targetWriteOffset = writeOffset + AuxiliaryBufferInfo.GetWriteOffset(memoryManager, DspBufferInfoAddress); if (targetWriteOffset > countMax) { return(0); } uint remaining = count; uint inBufferOffset = 0; while (remaining != 0) { uint countToWrite = Math.Min(countMax - targetWriteOffset, remaining); memoryManager.Write(outBufferAddress + targetWriteOffset * sizeof(int), MemoryMarshal.Cast <int, byte>(buffer.Slice((int)inBufferOffset, (int)countToWrite))); targetWriteOffset = (targetWriteOffset + countToWrite) % countMax; remaining -= countToWrite; inBufferOffset += countToWrite; } if (updateCount != 0) { uint dspTotalSampleCount = AuxiliaryBufferInfo.GetTotalSampleCount(memoryManager, DspBufferInfoAddress); uint cpuTotalSampleCount = AuxiliaryBufferInfo.GetTotalSampleCount(memoryManager, CpuBufferInfoAddress); uint totalSampleCountDiff = dspTotalSampleCount - cpuTotalSampleCount; if (totalSampleCountDiff >= countMax) { uint dspLostSampleCount = AuxiliaryBufferInfo.GetLostSampleCount(memoryManager, DspBufferInfoAddress); uint cpuLostSampleCount = AuxiliaryBufferInfo.GetLostSampleCount(memoryManager, CpuBufferInfoAddress); uint lostSampleCountDiff = dspLostSampleCount - cpuLostSampleCount; uint newLostSampleCount = lostSampleCountDiff + updateCount; if (lostSampleCountDiff > newLostSampleCount) { newLostSampleCount = cpuLostSampleCount - 1; } AuxiliaryBufferInfo.SetLostSampleCount(memoryManager, DspBufferInfoAddress, newLostSampleCount); } uint newWriteOffset = (AuxiliaryBufferInfo.GetWriteOffset(memoryManager, DspBufferInfoAddress) + updateCount) % countMax; AuxiliaryBufferInfo.SetWriteOffset(memoryManager, DspBufferInfoAddress, newWriteOffset); uint newTotalSampleCount = totalSampleCountDiff + newWriteOffset; AuxiliaryBufferInfo.SetTotalSampleCount(memoryManager, DspBufferInfoAddress, newTotalSampleCount); } return(count); }