mirror of https://github.com/AxioDL/amuse.git
Better voice id allocation
This commit is contained in:
parent
338df76711
commit
022365030a
|
@ -24,6 +24,7 @@ class Engine
|
|||
std::list<Voice> m_activeVoices;
|
||||
std::list<Emitter> m_activeEmitters;
|
||||
std::list<Sequencer> m_activeSequencers;
|
||||
int m_nextVid = 0;
|
||||
Voice* _allocateVoice(int groupId, double sampleRate, bool dynamicPitch, bool emitter);
|
||||
AudioGroup* _findGroupFromSfxId(int sfxId, const AudioGroupSampleDirectory::Entry*& entOut) const;
|
||||
AudioGroup* _findGroupFromSongId(int songId) const;
|
||||
|
|
|
@ -15,7 +15,7 @@ Engine::Engine(IBackendVoiceAllocator& backend)
|
|||
|
||||
Voice* Engine::_allocateVoice(int groupId, double sampleRate, bool dynamicPitch, bool emitter)
|
||||
{
|
||||
m_activeVoices.emplace_back(*this, groupId, m_activeVoices.size(), emitter);
|
||||
m_activeVoices.emplace_back(*this, groupId, m_nextVid++, emitter);
|
||||
m_activeVoices.back().m_backendVoice =
|
||||
m_backend.allocateVoice(m_activeVoices.back(), sampleRate, dynamicPitch);
|
||||
return &m_activeVoices.back();
|
||||
|
@ -43,6 +43,12 @@ AudioGroup* Engine::_findGroupFromSongId(int songId) const
|
|||
/** Update all active audio entities and fill OS audio buffers as needed */
|
||||
void Engine::pumpEngine()
|
||||
{
|
||||
int maxVid = -1;
|
||||
for (Voice& vox : m_activeVoices)
|
||||
{
|
||||
maxVid = std::max(maxVid, vox.vid());
|
||||
}
|
||||
m_nextVid = maxVid + 1;
|
||||
}
|
||||
|
||||
/** Add audio group data pointers to engine; must remain resident! */
|
||||
|
|
|
@ -35,7 +35,7 @@ void SoundMacroState::initialize(const unsigned char* ptr)
|
|||
m_sampleEnd = false;
|
||||
m_loopCountdown = -1;
|
||||
m_lastPlayMacroVid = -1;
|
||||
memcpy(&m_header, ptr, sizeof(Header));
|
||||
m_header = *reinterpret_cast<const Header*>(ptr);
|
||||
m_header.swapBig();
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ void SoundMacroState::initialize(const unsigned char* ptr, float ticksPerSec,
|
|||
m_sampleEnd = false;
|
||||
m_loopCountdown = -1;
|
||||
m_lastPlayMacroVid = -1;
|
||||
memcpy(&m_header, ptr, sizeof(Header));
|
||||
m_header = *reinterpret_cast<const Header*>(ptr);
|
||||
m_header.swapBig();
|
||||
}
|
||||
|
||||
|
@ -235,8 +235,8 @@ bool SoundMacroState::advance(Voice& vox, float dt)
|
|||
int8_t addNote = cmd.m_data[0];
|
||||
int16_t macroId = *reinterpret_cast<int16_t*>(&cmd.m_data[1]);
|
||||
int16_t macroStep = *reinterpret_cast<int16_t*>(&cmd.m_data[3]);
|
||||
int8_t priority = cmd.m_data[5];
|
||||
int8_t maxVoices = cmd.m_data[6];
|
||||
//int8_t priority = cmd.m_data[5];
|
||||
//int8_t maxVoices = cmd.m_data[6];
|
||||
|
||||
Voice* sibVox = vox.startSiblingMacro(addNote, macroId, macroStep);
|
||||
if (sibVox)
|
||||
|
@ -254,13 +254,15 @@ bool SoundMacroState::advance(Voice& vox, float dt)
|
|||
if (m_lastPlayMacroVid != -1)
|
||||
{
|
||||
Voice* otherVox = vox.getEngine().findVoice(m_lastPlayMacroVid);
|
||||
otherVox->keyOff();
|
||||
if (otherVox)
|
||||
otherVox->keyOff();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Voice* otherVox = vox.getEngine().findVoice(m_variables[vid]);
|
||||
otherVox->keyOff();
|
||||
if (otherVox)
|
||||
otherVox->keyOff();
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue