Skip to content

Instantly share code, notes, and snippets.

@badescunicu
Last active August 29, 2015 14:03
Show Gist options
  • Save badescunicu/3b89f6eef2135c0ba8fa to your computer and use it in GitHub Desktop.
Save badescunicu/3b89f6eef2135c0ba8fa to your computer and use it in GitHub Desktop.
ramping coefs
void EngineFilterIIRBand::setFrequencyCorners(int sampleRate,
double freqCorner1,
double freqCorner2) {
m_sampleRate = sampleRate;
memcpy(m_oldCoef, m_coef, MAX_COEFS * sizeof(double));
m_coef[0] = fid_design_coef(m_coef + 1, 16, "BpBe8", m_sampleRate,
freqCorner1, freqCorner2, 0);
m_doRamping = true;
//initBuffers();
}
void EngineFilterIIRBand::process(const CSAMPLE* pIn, CSAMPLE* pOutput,
const int iBufferSize) {
if (m_doRamping) {
double cross_mix = 0.0;
double cross_inc = 2.0 / static_cast<double>(iBufferSize);
double coef[MAX_COEFS];
memcpy(coef, m_oldCoef, MAX_COEFS * sizeof(double));
for (int i = 0; i < iBufferSize; i += 2) {
pOutput[i] = _processBandpass(coef, m_buf1, pIn[i]);
pOutput[i+1] = _processBandpass(coef, m_buf2, pIn[i+1]);
for (int i = 0; i < MAX_COEFS; i++) {
coef[i] = m_oldCoef[i] * (1 - cross_mix) + m_coef[i] * cross_mix;
}
cross_mix += cross_inc;
}
m_doRamping = false;
} else {
for (int i = 0; i < iBufferSize; i += 2) {
pOutput[i] = _processBandpass(m_coef, m_buf1, pIn[i]);
pOutput[i+1] = _processBandpass(m_coef, m_buf2, pIn[i+1]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment