This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void StartRecording () { | |
| // Start recording audio from the microphone | |
| IAudioDevice device = ...; | |
| device.StartRunning(OnSampleBuffer); | |
| } | |
| void OnSampleBuffer (float[] sampleBuffer, long timestamp) { | |
| // `sampleBuffer` is linear PCM, interleaved by channel | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Media device which provides media buffers. | |
| /// </summary> | |
| public interface IMediaDevice : IEquatable<IMediaDevice> { | |
| /// <summary> | |
| /// Device unique ID. | |
| /// </summary> | |
| string uniqueID { get; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Audio device which provides sample buffers. | |
| /// </summary> | |
| public interface IAudioDevice : IMediaDevice { | |
| /// <summary> | |
| /// Audio sample rate. | |
| /// </summary> | |
| int sampleRate { get; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using NatCorder; | |
| using NatExtractor; | |
| public class TranscodeDemo : MonoBehaviour { | |
| public string videoPath; // Path to video to be transcoded | |
| void Start () { | |
| // Create a frame extractor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * NatMic | |
| * Copyright (c) 2019 Yusuf Olokoba | |
| */ | |
| namespace NatMic.Recorders { | |
| using UnityEngine; | |
| using System; | |
| using System.Runtime.CompilerServices; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Get a hardware microphone | |
| var microphoneDevice = AudioDevice.GetDevices()[0]; | |
| // Create a virtual device from an AudioSource component in game | |
| var gameDevice = new VirtualDevice(audioSource); | |
| // Create a mixer device that mixes audio from both devices | |
| var audioDevice = new MixerDevice(microphoneDevice, gameDevice); | |
| // Use the audio device like any other NatMic device | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// An audio data receiver supplied by an audio device | |
| /// </summary> | |
| public interface IAudioProcessor { | |
| /// <summary> | |
| /// Delegate invoked when microphone reports a new sample buffer | |
| /// </summary> | |
| /// <param name="sampleBuffer">Audio sample buffer interleaved by channel</param> | |
| /// <param name="sampleRate">Audio sample rate</param> | |
| /// <param name="channelCount">Audio channel count</param> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// An audio input device | |
| /// </summary> | |
| public interface IAudioDevice { | |
| /// <summary> | |
| /// Is the device currently recording? | |
| /// </summary> | |
| bool IsRecording { get; } | |
| /// <summary> | |
| /// Start recording |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Start the camera preview | |
| /// </summary> | |
| /// <param name="camera">Camera that the preview should start from</param> | |
| /// <param name="startCallback">Callback invoked when the preview starts</param> | |
| /// <param name="frameCallback">Optional. Callback invoked when a new preview frame is available</param> | |
| public static void StartPreview (DeviceCamera camera, Action startCallback, Action frameCallback = null); | |
| /// <summary> | |
| /// Stop the camera preview |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| byte[] pixelBuffer; | |
| Mat previewMatrix; | |
| void Start () { | |
| // Start the camera preview | |
| NatCam.Play(DeviceCamera.RearCamera); | |
| // Register for preview events | |
| NatCam.OnStart += OnStart; | |
| NatCam.OnFrame += OnFrame; | |
| } |