private void OnAudioFilterRead(float[] data, int channels) { if (st == 0f) { return; } // cache params for speed float pitchDec = voiceParams.PitchDecayRate, ampDec = voiceParams.AmpDecayRate, startFreq = voiceParams.StartFrequency, endFreq = voiceParams.EndFrequency, modInd = voiceParams.FMModIndex, modFreq = voiceParams.FMFrequency, sinSqM = voiceParams.SinSqMix; if (decay > 0f) { decay *= pitchDec; } if (Amp > 0f) { Amp *= ampDec; } if (decay < 0.0001f && Amp < 0.0001f) { decay = 0f; Amp = 0f; return; } carrierFrequency = scaleRange(decay, 1, 0, startFreq, endFreq); m_phasor.SetFrequency(carrierFrequency); float sq = 0f; float sin = 0f; float fmModFreq = 0f; float mix = 0f; float noise_fm = 0f; float fm_mix = 0f; float mod = 0f; float f = carrierFrequency * st; for (int j = 0; j < data.Length; j += channels) { for (int i = 0; i < channels; i++) { if (modInd != 0) { m_fmPhasor.SetFrequency(modFreq); fmModFreq = (float)m_sineFM.LinearLookup(m_fmPhasor.GetPhase()) * m_sineFM.GetSize() * Amp; mod = carrierFrequency + (fmModFreq * modInd); m_phasor.SetFrequency(mod); m_fmPhasor.Tick(); } sq = (float)m_square.LinearLookup(m_phasor.GetPhase() * m_square.GetSize()) * Amp; sin = (float)m_sine.LinearLookup(m_phasor.GetPhase() * m_sine.GetSize()) * Amp; // Mix sine square mix = (sin * (1 - sinSqM)) + (sq * sinSqM); data[j + i] = mix; m_phasor.Tick(); } } }