This file contains 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
async void StartPreview () { | |
// Start the camera preview | |
ICameraDevice device = ...; | |
Texture2D previewTexture = await device.StartRunning(); | |
// Display the preview texture on a UI panel | |
rawImage.texture = previewTexture; | |
} |
This file contains 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> | |
/// Camera device which provides pixel buffers. | |
/// </summary> | |
public interface ICameraDevice : IMediaDevice { | |
/// <summary> | |
/// Is the camera front facing? | |
/// </summary> | |
bool frontFacing { get; } |
This file contains 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 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 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 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 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 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 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 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 |