unsafe static void OnReadInStream (ref SoundIO.InStreamData stream, int min, int left) { // Recover the 'this' reference from the UserData pointer. var self = (InputDeviceHandle) GCHandle.FromIntPtr(stream.UserData).Target; while (left > 0) { // Start reading the buffer. var count = left; SoundIO.ChannelArea *areas; stream.BeginRead(out areas, ref count); // When getting count == 0, we must stop reading // immediately without calling InStream.EndRead. if (count == 0) { break; } if (areas == null) { // We must do zero-fill when receiving a null pointer. lock (self._ring) self._ring.WriteEmpty(stream.BytesPerFrame * count); } else { // Determine the memory span of the input data with // assuming the data is tightly packed. // TODO: Is this assumption always true? var span = new ReadOnlySpan <Byte> ((void *)areas[0].Pointer, areas[0].Step * count); // Transfer the data to the ring buffer. lock (self._ring) self._ring.Write(span); } stream.EndRead(); left -= count; } }
static void OnErrorInStream (ref SoundIO.InStreamData stream, SoundIO.Error error) => UnityEngine.Debug.LogWarning($"InStream error ({error})");
static void OnOverflowInStream(ref SoundIO.InStreamData stream) => UnityEngine.Debug.LogWarning("InStream overflow");