Mercurial > hg > svapp
changeset 315:65b75e23bbd5 tonioni
interpolation, longer crossfades
author | Chris Cannam |
---|---|
date | Wed, 08 Jan 2014 13:41:57 +0000 |
parents | 817ad10f91d1 |
children | e86596839f27 |
files | audioio/AudioGenerator.cpp audioio/ContinuousSynth.cpp |
diffstat | 2 files changed, 20 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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 <QFile> 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,
--- 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; }