# HG changeset patch # User Chris Cannam # Date 1389188517 0 # Node ID 65b75e23bbd5f36fcc1bbc9073bbc12bddd34a78 # Parent 817ad10f91d1089e39cc9bb444006568d11da2e0 interpolation, longer crossfades diff -r 817ad10f91d1 -r 65b75e23bbd5 audioio/AudioGenerator.cpp --- a/audioio/AudioGenerator.cpp Wed Jan 08 13:19:50 2014 +0000 +++ b/audioio/AudioGenerator.cpp Wed Jan 08 13:41:57 2014 +0000 @@ -38,7 +38,7 @@ #include const size_t -AudioGenerator::m_processingBlockSize = 2048; +AudioGenerator::m_processingBlockSize = 1024; QString AudioGenerator::m_sampleDir = ""; @@ -652,7 +652,7 @@ } } - cerr << "f0 = " << f0 << endl; +// cerr << "f0 = " << f0 << endl; synth->mix(bufferIndexes, gain, diff -r 817ad10f91d1 -r 65b75e23bbd5 audioio/ContinuousSynth.cpp --- a/audioio/ContinuousSynth.cpp Wed Jan 08 13:19:50 2014 +0000 +++ b/audioio/ContinuousSynth.cpp Wed Jan 08 13:41:57 2014 +0000 @@ -50,7 +50,7 @@ return; } - int fadeLength = 20; // samples + int fadeLength = 100; // samples float *levels = new float[m_channels]; @@ -62,20 +62,30 @@ levels[1] *= pan + 1.0; } - double phasor = (f0 * 2 * M_PI) / m_sampleRate; - double p = m_phase; - - cerr << "ContinuousSynth::mix: f0 = " << f0 << " (from " << m_prevF0 << "), phase = " << m_phase << ", phasor = " << phasor << endl; +// cerr << "ContinuousSynth::mix: f0 = " << f0 << " (from " << m_prevF0 << "), phase = " << m_phase << endl; for (int i = 0; i < m_blockSize; ++i) { - p = m_phase + i * phasor; + double fHere = (nowOn ? f0 : m_prevF0); + + if (wasOn && nowOn && (f0 != m_prevF0) && (i < fadeLength)) { + // interpolate the frequency shift + fHere = m_prevF0 + ((f0 - m_prevF0) * i) / fadeLength; + } + + double phasor = (fHere * 2 * M_PI) / m_sampleRate; + +// cerr << "phasor = " << phasor << endl; + + m_phase = m_phase + phasor; - double v = sin(p); + double v = sin(m_phase); - if (!wasOn && i < fadeLength) { // fade in + if (!wasOn && i < fadeLength) { + // fade in v = v * (i / double(fadeLength)); } else if (!nowOn) { + // fade out if (i > fadeLength) v = 0; else v = v * (1.0 - (i / double(fadeLength))); } @@ -86,7 +96,6 @@ } m_prevF0 = f0; - m_phase = p; delete[] levels; }