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); }
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)); } }