Esempio n. 1
0
        public BigArray <float> DecodeFrame(VoicePacketWrapper data)
        {
            int          frameSize = frameSizes[data.Frequency * 1000];
            codecWrapper codec     = encoders[data.Frequency * 1000];

            short[] decodedFrame16Bit = TempArray <short> .Obtain(frameSize * 4);

            int decoded = codec.decoder.Decode(data.RawData, 0, data.RawData.Length, decodedFrame16Bit, 0, false);

            if (tempOutputArray.Length != decoded)
            {
                tempOutputArray.Resize(decoded);
            }

            for (int i = 0; i < decoded; i++)
            {
                float val = (float)decodedFrame16Bit[i];
                val /= short.MaxValue;
                tempOutputArray[i] = val;
            }

            TempArray <short> .Release(decodedFrame16Bit);

            return(tempOutputArray);
        }
Esempio n. 2
0
        public static void Resample(BigArray <float> samples, int oldFrequency, int newFrequency)
        {
            if (oldFrequency == newFrequency)
            {
                return;
            }

            temp.Clear();
            float ratio     = (float)oldFrequency / (float)newFrequency;
            int   outSample = 0;

            while (true)
            {
                int inBufferIndex = (int)(outSample++ *ratio);
                if (inBufferIndex < samples.Length)
                {
                    temp.Add(samples[inBufferIndex]);
                }
                else
                {
                    break;
                }
            }

            samples.Resize(temp.Count);
            samples.CopyFrom(temp.Items, 0, 0, temp.Count * 4);
        }
Esempio n. 3
0
 void resample(float[] tempArray)
 {
     //resampleBuffer = new BigArray<float>( tempArray.Length, tempArray.Length );
     resampleBuffer.Resize(tempArray.Length);
     resampleBuffer.CopyFrom(tempArray, 0, 0, tempArray.Length * 4);
     //Debug.Log( "Resampling from: " + recordedAudio.frequency + ", to: " + this.recordingFrequency );
     AudioUtils.Resample(resampleBuffer, recordedAudio.frequency, this.recordingFrequency);
 }
        public override void StartRecording()
        {
            float[] data = new float[testClip.samples * testClip.channels];
            testClip.GetData(data, 0);

            BigArray <float> d = new BigArray <float>(data.Length, 0);

            d.Resize(data.Length);
            d.CopyFrom(data, 0, 0, data.Length * 4);

            //AudioUtils.Resample( d, testClip.frequency, AudioUtils.GetFrequency( ResampleFrequency ) );

            //bufferReady( d, AudioUtils.GetFrequency( ResampleFrequency ) );
            StartCoroutine(yieldChunks(d, testClip.frequency, 1f));
        }
        private IEnumerator yieldChunks(BigArray <float> data, int chunkSize, float chunkDuration)
        {
            int readHead = 0;

            while (readHead < data.Length)
            {
                int remainder = chunkSize;
                if (readHead + chunkSize >= data.Length)
                {
                    remainder = data.Length - readHead;
                }

                BigArray <float> temp = new BigArray <float>(remainder, 0);
                temp.Resize(remainder);
                temp.CopyFrom(data.Items, readHead * 4, 0, remainder * 4);
                AudioUtils.Resample(temp, testClip.frequency, AudioUtils.GetFrequency(ResampleFrequency));

                bufferReady(temp, AudioUtils.GetFrequency(ResampleFrequency));

                readHead += remainder;

                yield return(new WaitForSeconds(chunkDuration));
            }
        }