From 3f0ea233bb6ea1e77616260965a125d3b4e1f096 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 22 May 2016 13:08:28 -1000 Subject: [PATCH] More reliable voice management in Sequencer --- include/amuse/Voice.hpp | 2 +- lib/Sequencer.cpp | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/amuse/Voice.hpp b/include/amuse/Voice.hpp index 26100f1..37aa1fe 100644 --- a/include/amuse/Voice.hpp +++ b/include/amuse/Voice.hpp @@ -61,7 +61,7 @@ class Voice : public Entity int16_t m_prev2 = 0; /**< DSPADPCM prev-prev sample */ double m_sampleRate = 32000.0; /**< Current sample rate computed from relative sample key or SETPITCH */ double m_voiceTime = 0.0; /**< Current seconds of voice playback (per-sample resolution) */ - uint32_t m_voiceSamples = 0; /**< Count of samples processed over voice's lifetime */ + uint64_t m_voiceSamples = 0; /**< Count of samples processed over voice's lifetime */ float m_lastLevel = 0.f; /**< Last computed level ([0,1] mapped to [-10,0] clamped decibels) */ float m_nextLevel = 0.f; /**< Next computed level used for lerp-mode amplitude */ diff --git a/lib/Sequencer.cpp b/lib/Sequencer.cpp index 7dfdc16..70611e5 100644 --- a/lib/Sequencer.cpp +++ b/lib/Sequencer.cpp @@ -156,19 +156,22 @@ std::shared_ptr Sequencer::ChannelState::keyOn(uint8_t note, uint8_t velo std::shared_ptr ret = m_parent.m_engine._allocateVoice(m_parent.m_audioGroup, m_parent.m_groupId, 32000.0, true, false, m_submix); - m_chanVoxs[note] = ret; - ret->installCtrlValues(m_ctrlVals); - if (!ret->loadSoundObject(SBig(m_page->objId), 0, 1000.f, note, velocity, m_ctrlVals[1])) + if (ret) { - m_parent.m_engine._destroyVoice(ret.get()); - return {}; - } - ret->setVolume(m_parent.m_curVol * m_curVol); - ret->setPan(m_curPan); - ret->setPitchWheel(m_curPitchWheel); + m_chanVoxs[note] = ret; + ret->installCtrlValues(m_ctrlVals); + if (!ret->loadSoundObject(SBig(m_page->objId), 0, 1000.f, note, velocity, m_ctrlVals[1])) + { + m_parent.m_engine._destroyVoice(ret.get()); + return {}; + } + ret->setVolume(m_parent.m_curVol * m_curVol); + ret->setPan(m_curPan); + ret->setPitchWheel(m_curPitchWheel); - if (m_ctrlVals[64] > 64) - ret->setPedal(true); + if (m_ctrlVals[64] > 64) + ret->setPedal(true); + } return ret; } @@ -302,8 +305,12 @@ void Sequencer::setTempo(double ticksPerSec) void Sequencer::ChannelState::allOff() { - for (const auto& vox : m_chanVoxs) - vox.second->keyOff(); + for (auto it = m_chanVoxs.begin() ; it != m_chanVoxs.end() ;) + { + it->second->keyOff(); + m_keyoffVoxs.emplace(std::move(it->second)); + it = m_chanVoxs.erase(it); + } } void Sequencer::allOff(bool now) @@ -358,6 +365,9 @@ void Sequencer::ChannelState::killKeygroup(uint8_t kg, bool now) continue; } vox->keyOff(); + m_keyoffVoxs.emplace(std::move(it->second)); + it = m_chanVoxs.erase(it); + continue; } ++it; }