public void TestWriteArrayByteFromCycle2() { byte[] first = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; byte[] second = new byte[10]; int n = ByteManipulator.WriteFromCycle(first, 7, second, 0, 9); Assert.That(second[3], Is.EqualTo(0)); }
public void TestWriteArrayByteFromCycleNewOffsetRedLight() { byte[] first = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; byte[] second = new byte[10]; int n = ByteManipulator.WriteFromCycle(first, 6, second, 1, 9); Assert.That(n, Is.Not.EqualTo(6)); }
/// <summary> /// Gets recorded data and stores it in format Single /// </summary> /// <param name="buffer">buffer to fill with audio data recorded</param> /// <param name="bufferOffset">buffer start index</param> /// <param name="dataCount">amount of data to store</param> /// <param name="effectiveDataCount">effective amount of data stored</param> /// <returns>data info</returns> public override VoicePacketInfo GetMicData(float[] buffer, int bufferOffset, int dataCount, out int effectiveDataCount) { effectiveDataCount = Mathf.Min(Mathf.Min(dataCount, buffer.Length - bufferOffset), MicDataAvailable); if (effectiveDataCount <= 0) { return(VoicePacketInfo.InvalidPacket); } readIndex = ByteManipulator.WriteFromCycle(this.cyclicAudioBuffer, readIndex, buffer, bufferOffset, dataCount); return(new VoicePacketInfo((ushort)clip.frequency, (byte)clip.channels, AudioDataTypeFlag.Single)); }
private void OnAudioFilterRead(float[] data, int channels)//this method fills the unity audiosource audio data with the stored data { if (cyclicAudioBuffer == null) { return; } //current total number of audio data stored int count = readIndex > writeIndex ? (cyclicAudioBuffer.Length - readIndex) + writeIndex : writeIndex - readIndex; //total number of elements to supply to the audiosource count = Mathf.Min(count, data.Length); if (count <= 0) { return; } //supply data to the audiosource readIndex = ByteManipulator.WriteFromCycle(cyclicAudioBuffer, readIndex, data, 0, count); }