private void OnAudioFilterRead(float[] buffer, int numChannels) { try { audioDataMutex.WaitOne(); if (micStarted && hasServerConnection) { if (CheckForErrorOnCall(MicStream.MicGetFrame(buffer, buffer.Length, numChannels))) { int dataSize = buffer.Length * 4; if (micBuffer.Write(buffer, 0, dataSize) != dataSize) { Debug.LogError("Send buffer filled up. Some audio will be lost."); } } } } catch (Exception e) { Debug.LogError(e.Message); } finally { audioDataMutex.ReleaseMutex(); } }
/// <summary> /// method only used for holotoolkit-recording version. Callback to receive recorded data. /// </summary> /// <param name="buffer"></param> /// <param name="numChannels"></param> private void OnAudioFilterRead(float[] buffer, int numChannels) { if (useUnityMic) { return; } Debug.Log("OAFR." + buffer + "." + numChannels); // this is where we call into the DLL and let it fill our audio buffer for us CheckForErrorOnCall(MicStream.MicGetFrame(buffer, buffer.Length, numChannels)); if (_numChannels != numChannels) { _numChannels = numChannels; } if (audioBuffer == null) { audioBuffer = buffer; } else { audioBuffer = audioBuffer.Concat(buffer).ToArray(); } float sumOfValues = 0; // figure out the average amplitude from this new data for (int i = 0; i < buffer.Length; i++) { sumOfValues += Mathf.Abs(buffer[i]); } averageAmplitude = sumOfValues / buffer.Length; }
private void OnAudioFilterRead(float[] buffer, int numChannels) { if (!_isStart) return; lock (this) { CheckForErrorOnCall(MicStream.MicGetFrame(buffer, buffer.Length, numChannels)); foreach (var f in buffer) { samplingData.Add(FloatToInt16(f)); } } }
private void OnAudioFilterRead(float[] buffer, int numChannels) { // this is where we call into the DLL and let it fill our audio buffer for us CheckForErrorOnCall(MicStream.MicGetFrame(buffer, buffer.Length, numChannels)); float sumOfValues = 0; // figure out the average amplitude from this new data for (int i = 0; i < buffer.Length; i++) { sumOfValues += Mathf.Abs(buffer[i]); } averageAmplitude = sumOfValues / buffer.Length; }
private void OnAudioFilterRead(float[] buffer, int numChannels) { MicStream.MicGetFrame(buffer, buffer.Length, numChannels); }