} //END GetAudioFormat #endif #if NATMIC //-------------------------------------------------------// private void OnSampleRecieved( AudioEvent audioEvent, float[] sampleBuffer, long timestamp, Format format ) //-------------------------------------------------------// { if( audioEvent == AudioEvent.OnInitialize ) { if( RecordToFile() ) { // Create a WAV recorder to record the audio to a file if( recordingFileType == RecordingFileType.WAV ) { micRecorder = new WAVRecorder(format); } else { micRecorder = new WAVRecorder(format); } micRecorder.StartRecording( OnRecordToFileComplete ); } //if (onRecordingStart != null) { onRecordingStart.Invoke(); } } else if( audioEvent == AudioEvent.OnSampleBuffer ) { if( RecordToFile() ) { // Commit the sample buffer to the WAV recorder micRecorder.CommitSamples( sampleBuffer, timestamp ); } //Disabled, this method runs in a coroutine so we can't call a UnityEvent method from it! //if (onPlaybackBufferEvent != null) { onPlaybackBufferEvent.Invoke(audioEvent, sampleBuffer, timestamp, format); } } else if( audioEvent == AudioEvent.OnFinalize ) { if( RecordToFile() ) { // Stop recording the WAV file and dispose the recorder micRecorder.Dispose(); } } } //END OnSampleRecieved
private void OnSampleBuffer(AudioEvent audioEvent, float[] sampleBuffer, long timestamp, Format format) { switch (audioEvent) { case AudioEvent.OnInitialize: // Create a WAV recorder to record the audio to a file recorder = new WAVRecorder(format); recorder.StartRecording(OnAudioRecording); break; case AudioEvent.OnSampleBuffer: // Commit the sample buffer to the WAV recorder recorder.CommitSamples(sampleBuffer, timestamp); break; case AudioEvent.OnFinalize: // Stop recording the WAV file and dispose the recorder recorder.Dispose(); break; } }