public void SingleToneAnalysisTest() { const int FFT_SIZE = 256; const double SNR = 40; double noiseLevel = Math.Pow(10, SNR / (-20.0)); Random rnd = new Random(); double amplitude = 1.0; double freq = (rnd.NextDouble() * (FFT_SIZE / 2.0 - 4.0) + 2.0) / FFT_SIZE / 4.0; //double freq = 8.5 / FFT_SIZE; double phase = rnd.NextDouble() * 2.0 * Math.PI; //double phase = 0.375 * 2.0 * Math.PI; double[] noise = Generate.Normal(FFT_SIZE, 0.0, noiseLevel); double[] wave = Generate.Sinusoidal(FFT_SIZE, 1.0, freq, amplitude, 0.0, phase); for (int i = 0; i < FFT_SIZE; i++) { wave[i] += noise[i]; } ToneInfo toneInfo = ToneAnalyzer.SingleToneAnalysis(wave); Assert.IsTrue(Math.Abs(toneInfo.Frequency - freq) < 1.0E-3, "Frequency not equal."); double phaseErr = (toneInfo.Phase - phase) / (2.0 * Math.PI); phaseErr -= Math.Round(phaseErr); Assert.IsTrue(Math.Abs(phaseErr) < 1.0E-3, "Phase not equal."); Assert.IsTrue(Math.Abs(toneInfo.Amplitude - amplitude) < 1.0E-2, "Amplitude not equal."); }
public void RecordToneInfo(ToneInfo toneInfo) { if (PlayedTonesCache.Count == PlayedTonesCacheSize) { PlayedTonesCache.RemoveAt(0); } PlayedTonesCache.Add(toneInfo); }
// PLAYS A SPECIFIC TONE public void PlayTone(string instrument, ToneDuration duration, MusicTone tone, int octave) { string toneClipName = instrument + Underline + duration.ToString() + Underline + tone + Underline + octave; Debug.Log(toneClipName); ToneInfo info = new ToneInfo() { Tone = tone, Octave = octave, Duration = duration, TimeOfPlaySinceStartup = Time.realtimeSinceStartup }; RecordToneInfo(info); AudioController.Play(toneClipName); }
internal ToneReceivedEvent(ToneInfo toneInfo, string callLegId) { ToneInfo = toneInfo; CallLegId = callLegId; }
public static ToneReceivedEvent ToneReceivedEvent(ToneInfo toneInfo = default, string callConnectionId = default) { return(new ToneReceivedEvent(toneInfo, callConnectionId)); }