# HG changeset patch # User Rachel Bittner # Date 1389905366 18000 # Node ID ce2b123fc2ded65bd65215f1eb71b4b1d07a68c7 # Parent 5c69d40a0e30e29580c48dae8cab45ff59b816e6# Parent 4fdf70be6671b41133765d69ce112a1fe78a9f23 Merge diff -r 5c69d40a0e30 -r ce2b123fc2de audioio/ClipMixer.cpp --- a/audioio/ClipMixer.cpp Sun Jan 12 05:12:08 2014 -0500 +++ b/audioio/ClipMixer.cpp Thu Jan 16 15:49:26 2014 -0500 @@ -122,7 +122,10 @@ std::vector endingNotes) { foreach (NoteStart note, newNotes) { - m_playing.push_back(note); + if (note.frequency > 20 && + note.frequency < 5000) { + m_playing.push_back(note); + } } std::vector remaining; @@ -167,7 +170,8 @@ note.frequency, start < 0 ? -start : 0, start > 0 ? start : 0, - durationHere); + durationHere, + ending); } } @@ -189,13 +193,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 +224,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 5c69d40a0e30 -r ce2b123fc2de audioio/ClipMixer.h --- a/audioio/ClipMixer.h Sun Jan 12 05:12:08 2014 -0500 +++ b/audioio/ClipMixer.h Thu Jan 16 15:49:26 2014 -0500 @@ -81,7 +81,8 @@ float frequency, int sourceOffset, // within resampled note int targetOffset, // within target buffer - int sampleCount); + int sampleCount, + bool isEnd); };