Backbone - Singer Tone
 
Loading...
Searching...
No Matches
MicToneDetector Class Reference
Inheritance diagram for MicToneDetector:

Public Member Functions

string[] ListDevices ()
 Lists available microphone device names.
 
void Awake ()
 Initializes detector and AudioSource defaults.
 
void OnEnable ()
 Optionally starts microphone on enable.
 
void OnDisable ()
 Stops microphone on disable.
 
void Update ()
 Captures audio, gates by level, detects pitch, emits events.
 
void EmitSilence ()
 Emits zero/empty values and updates last state.
 
void StartMic (string device=null)
 Starts microphone capture. Uses first device if device is null or empty.
 
void StopMic ()
 Stops microphone capture and playback.
 
IEnumerator CoStartMic (string device)
 Coroutine that requests permission, selects device, allocates buffers, and starts capture.
 
bool ReadFromOutput (float[] dst)
 Reads from the AudioSource output into dst .
 
bool ReadFromMicClip (float[] dst)
 Reads a contiguous block from the live microphone clip into dst .
 
void ResetLast ()
 Resets last reported values.
 
void PushModeSample (int midiNote)
 Appends a note to the mode window with a max of 50 entries.
 
int FindMode (List< int > window, int take)
 Returns the most frequent note among the last take items.
 

Public Attributes

bool autoStart = true
 
string deviceName = ""
 
int pitchWindowMs = 100
 
float minVolumeDB = -17f
 
int consecutiveDetections = 5
 
bool clearOnSilence = true
 
bool debugLogs = true
 
bool useClipRead = true
 
UnityEvent< float > OnPitchHz = new UnityEvent<float>()
 Raised with frequency in Hz.
 
UnityEvent< int > OnMidiNote = new UnityEvent<int>()
 Raised with MIDI note number.
 
UnityEvent< int > OnMidiCents = new UnityEvent<int>()
 Raised with cents offset [-50..50].
 
UnityEvent< string > OnNoteName = new UnityEvent<string>()
 Raised with formatted note name (e.g., "A# 4").
 
float LastFrequencyHz { get
 Last detected frequency in Hz. Zero means no tone.
 
int LastMidiNote { get
 Last detected MIDI note. Zero means no tone.
 
float LastMidiNotePrecise { get
 Last detected MIDI as float (note + cents/100).
 
int LastCents { get
 Last detected cents offset.
 
string LastNoteName { get
 Last detected formatted note name.
 
bool Active => _active
 True when microphone is running.
 
SingerToneDetector _detector
 
AudioSource _audio
 
float[] _buffer
 
int _sampleRate
 
int _maxFreq
 
int _minFreq
 
bool _active
 
readonly List< int > _modeWindow = new List<int>(50)
 
const float _refRms = 0.1f
 

Private Attributes

 set
 

Member Function Documentation

◆ Awake()

void MicToneDetector::Awake ( )

Initializes detector and AudioSource defaults.

◆ CoStartMic()

IEnumerator MicToneDetector::CoStartMic ( string device)

Coroutine that requests permission, selects device, allocates buffers, and starts capture.

◆ EmitSilence()

void MicToneDetector::EmitSilence ( )

Emits zero/empty values and updates last state.

◆ FindMode()

int MicToneDetector::FindMode ( List< int > window,
int take )

Returns the most frequent note among the last take items.

◆ ListDevices()

string[] MicToneDetector::ListDevices ( )

Lists available microphone device names.

◆ OnDisable()

void MicToneDetector::OnDisable ( )

Stops microphone on disable.

◆ OnEnable()

void MicToneDetector::OnEnable ( )

Optionally starts microphone on enable.

◆ PushModeSample()

void MicToneDetector::PushModeSample ( int midiNote)

Appends a note to the mode window with a max of 50 entries.

◆ ReadFromMicClip()

bool MicToneDetector::ReadFromMicClip ( float[] dst)

Reads a contiguous block from the live microphone clip into dst .

◆ ReadFromOutput()

bool MicToneDetector::ReadFromOutput ( float[] dst)

Reads from the AudioSource output into dst .

◆ ResetLast()

void MicToneDetector::ResetLast ( )

Resets last reported values.

◆ StartMic()

void MicToneDetector::StartMic ( string device = null)

Starts microphone capture. Uses first device if device is null or empty.

◆ StopMic()

void MicToneDetector::StopMic ( )

Stops microphone capture and playback.

◆ Update()

void MicToneDetector::Update ( )

Captures audio, gates by level, detects pitch, emits events.

Member Data Documentation

◆ _active

bool MicToneDetector::_active

◆ _audio

AudioSource MicToneDetector::_audio

◆ _buffer

float [] MicToneDetector::_buffer

◆ _detector

SingerToneDetector MicToneDetector::_detector

◆ _maxFreq

int MicToneDetector::_maxFreq

◆ _minFreq

int MicToneDetector::_minFreq

◆ _modeWindow

readonly List<int> MicToneDetector::_modeWindow = new List<int>(50)

◆ _refRms

const float MicToneDetector::_refRms = 0.1f

◆ _sampleRate

int MicToneDetector::_sampleRate

◆ Active

bool MicToneDetector::Active => _active

True when microphone is running.

◆ autoStart

bool MicToneDetector::autoStart = true

◆ clearOnSilence

bool MicToneDetector::clearOnSilence = true

◆ consecutiveDetections

int MicToneDetector::consecutiveDetections = 5

◆ debugLogs

bool MicToneDetector::debugLogs = true

◆ deviceName

string MicToneDetector::deviceName = ""

◆ LastCents

int MicToneDetector::LastCents { get

Last detected cents offset.

◆ LastFrequencyHz

float MicToneDetector::LastFrequencyHz { get

Last detected frequency in Hz. Zero means no tone.

◆ LastMidiNote

int MicToneDetector::LastMidiNote { get

Last detected MIDI note. Zero means no tone.

◆ LastMidiNotePrecise

float MicToneDetector::LastMidiNotePrecise { get

Last detected MIDI as float (note + cents/100).

◆ LastNoteName

string MicToneDetector::LastNoteName { get

Last detected formatted note name.

◆ minVolumeDB

float MicToneDetector::minVolumeDB = -17f

◆ OnMidiCents

UnityEvent<int> MicToneDetector::OnMidiCents = new UnityEvent<int>()

Raised with cents offset [-50..50].

◆ OnMidiNote

UnityEvent<int> MicToneDetector::OnMidiNote = new UnityEvent<int>()

Raised with MIDI note number.

◆ OnNoteName

UnityEvent<string> MicToneDetector::OnNoteName = new UnityEvent<string>()

Raised with formatted note name (e.g., "A# 4").

◆ OnPitchHz

UnityEvent<float> MicToneDetector::OnPitchHz = new UnityEvent<float>()

Raised with frequency in Hz.

◆ pitchWindowMs

int MicToneDetector::pitchWindowMs = 100

◆ set

MicToneDetector::set
private

◆ useClipRead

bool MicToneDetector::useClipRead = true

The documentation for this class was generated from the following file: