Skip to content

Commit

Permalink
Some tweaks from porting to SC (#13)
Browse files Browse the repository at this point in the history
1. An out of order assert
2. A wrong type on guarantee group
3. Some more useful logging
4. A bad type for map vs unordered_map
  • Loading branch information
baconpaul authored Nov 5, 2024
1 parent 3f930c1 commit 5bd3ab5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
22 changes: 14 additions & 8 deletions include/sst/voicemanager/voicemanager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ static constexpr bool vmLog{false};
{ \
if constexpr (vmLog) \
{ \
std::cout << "include/sst/voicemanager/voicemanager_impl.h:" << __LINE__ << " " \
<< __VA_ARGS__ << std::endl; \
std::cout << __FILE__ << ":" << __LINE__ << " " << __VA_ARGS__ << std::endl; \
} \
}

Expand Down Expand Up @@ -90,10 +89,11 @@ struct VoiceManager<Cfg, Responder, MonoResponder>::Details
float inceptionVelocity{0.f};
bool heldBySustain{false};
};
using keyState_t = std::array<std::array<std::map<uint64_t, IndividualKeyState>, 128>, 16>;
std::map<int32_t, keyState_t> keyStateByPort{};
using keyState_t =
std::array<std::array<std::unordered_map<uint64_t, IndividualKeyState>, 128>, 16>;
std::unordered_map<int32_t, keyState_t> keyStateByPort{};

void guaranteeGroup(int groupId)
void guaranteeGroup(uint64_t groupId)
{
if (polyLimits.find(groupId) == polyLimits.end())
polyLimits[groupId] = Cfg::maxVoiceCount;
Expand Down Expand Up @@ -527,8 +527,10 @@ bool VoiceManager<Cfg, Responder, MonoResponder>::processNoteOnEvent(int16_t por
}
}

VML("- About to call beginVoiceCreationTransaction");
auto voicesToBeLaunched = responder.beginVoiceCreationTransaction(
details.voiceBeginWorkingBuffer, port, channel, key, noteid, velocity);
VML("- Post begin transaction: voicesToBeLaunched=" << voicesToBeLaunched << " voices");

if (voicesToBeLaunched == 0)
{
Expand Down Expand Up @@ -558,13 +560,14 @@ bool VoiceManager<Cfg, Responder, MonoResponder>::processNoteOnEvent(int16_t por
{
const auto &vbb = details.voiceBeginWorkingBuffer[i];
auto polyGroup = vbb.polyphonyGroup;
assert(details.polyLimits.find(polyGroup) != details.polyLimits.end());
assert(details.playMode.find(polyGroup) != details.playMode.end());

auto pm = details.playMode.at(polyGroup);
if (pm == PlayMode::MONO_NOTES)
continue;

assert(details.polyLimits.find(polyGroup) != details.polyLimits.end());

VML("Poly Stealing:");
VML("- Voice " << i << " group=" << polyGroup << " mode=" << (int)pm);
VML("- Checking polygroup " << polyGroup);
Expand Down Expand Up @@ -692,6 +695,7 @@ bool VoiceManager<Cfg, Responder, MonoResponder>::processNoteOnEvent(int16_t por
<< " at pckn=" << port << "/" << channel << "/" << key
<< "/" << noteid << " pg=" << vi.polyGroup);

assert(details.usedVoices.find(vi.polyGroup) != details.usedVoices.end());
++details.usedVoices.at(vi.polyGroup);
++details.totalUsedVoices;

Expand Down Expand Up @@ -750,17 +754,19 @@ void VoiceManager<Cfg, Responder, MonoResponder>::processNoteOffEvent(int16_t po
{
if (vi.gated)
{
VML("- Terminating voice at " << vi.polyGroup << " "
<< vi.activeVoiceCookie);
bool anyOtherOption =
details.anyKeyHeldFor(port, vi.polyGroup, channel, key);
if (anyOtherOption)
{
VML("- Hard Terminate voice with other away " << vi.polyGroup << " "
<< vi.activeVoiceCookie);
responder.terminateVoice(vi.activeVoiceCookie);
retriggerGroups.insert(vi.polyGroup);
}
else
{
VML("- Release voice with other away " << vi.polyGroup << " "
<< vi.activeVoiceCookie);
responder.releaseVoice(vi.activeVoiceCookie, velocity);
}
vi.gated = false;
Expand Down
14 changes: 10 additions & 4 deletions tests/stealing_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "sst/voicemanager/voicemanager.h"
#include "test_player.h"
#include <limits>

TEST_CASE("Stealing Groups - global group")
{
Expand Down Expand Up @@ -139,10 +140,13 @@ TEST_CASE("Stealing Groups are Independentt")
{
SECTION("Single Voice")
{
// Make sure we preserve the uint64_t
auto hgid = std::numeric_limits<uint64_t>::max() - 72431;

TestPlayer<32> tp;
auto &vm = tp.voiceManager;
tp.polyGroupForKey = [](auto k) { return (k % 2 == 0 ? 643 : 887); };
vm.setPolyphonyGroupVoiceLimit(643, 8);
tp.polyGroupForKey = [hgid](auto k) { return (k % 2 == 0 ? hgid : 887); };
vm.setPolyphonyGroupVoiceLimit(hgid, 8);
vm.setPolyphonyGroupVoiceLimit(887, 4);

auto oddKey = [](auto &v) { return v.key() % 2 == 1; };
Expand All @@ -162,10 +166,12 @@ TEST_CASE("Stealing Groups are Independentt")
{
DYNAMIC_SECTION("Double Voice " << off)
{
auto hgid = std::numeric_limits<uint64_t>::max() - 172431;

TestPlayer<64> tp;
auto &vm = tp.voiceManager;
tp.polyGroupForKey = [](auto k) { return (k % 2 == 0 ? 643 : 887); };
vm.setPolyphonyGroupVoiceLimit(643, 12 + off);
tp.polyGroupForKey = [hgid](auto k) { return (k % 2 == 0 ? hgid : 887); };
vm.setPolyphonyGroupVoiceLimit(hgid, 12 + off);
vm.setPolyphonyGroupVoiceLimit(887, 9 + off);

auto oddKey = [](auto &v) { return v.key() % 2 == 1; };
Expand Down

0 comments on commit 5bd3ab5

Please sign in to comment.