Exemple #1
0
        /// <summary>
        /// Processes audio data in format Single and plays it
        /// </summary>
        /// <param name="audioData">audio data to process</param>
        /// <param name="audioDataOffset">audio data start index</param>
        /// <param name="audioDataCount">audio data amount to process</param>
        /// <param name="info">data info</param>
        public override void ReceiveAudioData(float[] audioData, int audioDataOffset, int audioDataCount, VoicePacketInfo info)
        {
            if (cyclicAudioBuffer == null)
            {
                cyclicAudioBuffer = new float[Settings.MaxFrequency / 4];
            }

            //if given audio data is already configured the same as the output source copy elements directly into internal cyclic buffer
            if (info.Frequency == OutputBaseFrequency && info.Channels == OutputBaseChannels)
            {
                writeIndex = ByteManipulator.WriteToCycle(audioData, audioDataOffset, cyclicAudioBuffer, writeIndex, audioDataCount);
                return;
            }

            //operations to convert the given audio data stored at tot frequency and tot channels into audio data with Frequency and Channels compatible with output source, inserting results into internal cyclic buffer
            float frequencyPerc = OutputBaseFrequencyInverse * info.Frequency;
            float channelsPerc  = OutputBaseChannels / (float)info.Channels;

            int   bufferLength = cyclicAudioBuffer.Length;
            float index        = writeIndex;

            for (float i = 0; i < audioDataCount; i += frequencyPerc)
            {
                cyclicAudioBuffer[(int)index] = audioData[(int)i + audioDataOffset];

                index += channelsPerc;
                if (index >= bufferLength)
                {
                    index -= bufferLength;
                }
            }
            writeIndex = (int)index;
        }
Exemple #2
0
    public void TestWriteArrayByteToCycleNewOffsetRedLight()
    {
        byte[] first  = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        byte[] second = new byte[10];
        int    n      = ByteManipulator.WriteToCycle(first, 0, second, 8, 9);

        Assert.That(n, Is.Not.EqualTo(3));
    }
Exemple #3
0
    public void TestWriteArrayByteToCycle2()
    {
        byte[] first  = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        byte[] second = new byte[10];
        int    n      = ByteManipulator.WriteToCycle(first, 1, second, 8, 9);

        Assert.That(second[3], Is.EqualTo(6));
    }