# HG changeset patch # User matthiasm # Date 1389721913 0 # Node ID 7105604e9803368843e238402c7df1325d46668d # Parent ccd3c927638be6c68aaa396fce24b6974d073447 note release is now a ramp diff -r ccd3c927638b -r 7105604e9803 audioio/ClipMixer.cpp --- a/audioio/ClipMixer.cpp Thu Jan 09 21:31:54 2014 +0000 +++ b/audioio/ClipMixer.cpp Tue Jan 14 17:51:53 2014 +0000 @@ -167,7 +167,8 @@ note.frequency, start < 0 ? -start : 0, start > 0 ? start : 0, - durationHere); + durationHere, + ending); } } @@ -189,13 +190,19 @@ float frequency, int sourceOffset, int targetOffset, - int sampleCount) + int sampleCount, + bool isEnd) { if (!m_clipData) return; float ratio = getResampleRatioFor(frequency); - //!!! todo: release time + float releaseTime = 0.01; + int releaseSampleCount = round(releaseTime * m_sampleRate); + if (releaseSampleCount > sampleCount) { + releaseSampleCount = sampleCount; + } + float releaseFraction = 1.f/releaseSampleCount; for (int i = 0; i < sampleCount; ++i) { @@ -214,7 +221,11 @@ if (osi + 1 < m_clipLength) { value += (m_clipData[osi + 1] - m_clipData[osi]) * (os - osi); } - + + if (isEnd && i + releaseSampleCount > sampleCount) { + value *= releaseFraction * (sampleCount - i); // linear ramp for release + } + for (int c = 0; c < m_channels; ++c) { toBuffers[c][targetOffset + i] += levels[c] * value; } diff -r ccd3c927638b -r 7105604e9803 audioio/ClipMixer.h --- a/audioio/ClipMixer.h Thu Jan 09 21:31:54 2014 +0000 +++ b/audioio/ClipMixer.h Tue Jan 14 17:51:53 2014 +0000 @@ -81,7 +81,8 @@ float frequency, int sourceOffset, // within resampled note int targetOffset, // within target buffer - int sampleCount); + int sampleCount, + bool isEnd); };