Added master volume API for entire engine

This commit is contained in:
Jack Andersen 2016-07-13 20:16:00 -10:00
parent 2dcb9dd1c7
commit d602fbacd3
6 changed files with 20 additions and 9 deletions

View File

@ -169,7 +169,7 @@ struct AppCallback : boo::IApplicationCallback
m_seq->kill();
}
m_seq = m_engine->seqPlay(m_groupId, setupId, nullptr);
m_seq->setVolume(m_volume);
m_engine->setVolume(m_volume);
if (m_arrData)
m_seq->playSong(m_arrData->m_data.get(), false);
@ -963,19 +963,13 @@ void EventCallback::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods,
case boo::ESpecialKey::Up:
if (m_app.m_volume < 1.f)
m_app.m_volume = amuse::clamp(0.f, m_app.m_volume + 0.05f, 1.f);
if (m_app.m_vox)
m_app.m_vox->setVolume(m_app.m_volume);
if (m_app.m_seq)
m_app.m_seq->setVolume(m_app.m_volume);
m_app.m_engine->setVolume(m_app.m_volume);
m_app.m_updateDisp = true;
break;
case boo::ESpecialKey::Down:
if (m_app.m_volume > 0.f)
m_app.m_volume = amuse::clamp(0.f, m_app.m_volume - 0.05f, 1.f);
if (m_app.m_vox)
m_app.m_vox->setVolume(m_app.m_volume);
if (m_app.m_seq)
m_app.m_seq->setVolume(m_app.m_volume);
m_app.m_engine->setVolume(m_app.m_volume);
m_app.m_updateDisp = true;
break;
case boo::ESpecialKey::Esc:

View File

@ -130,6 +130,7 @@ public:
void register5MsCallback(std::function<void(double)>&& callback);
AudioChannelSet getAvailableSet();
void pumpAndMixVoices();
void setVolume(float vol);
};
}

View File

@ -107,6 +107,9 @@ public:
return seqPlay(groupId, songId, arrData, m_defaultStudio);
}
/** Set total volume of engine */
void setVolume(float vol);
/** Find voice from VoiceId */
std::shared_ptr<Voice> findVoice(int vid);

View File

@ -56,6 +56,9 @@ public:
/** Amuse flushes voice samples to the backend this way */
virtual void pumpAndMixVoices() = 0;
/** Set volume of main mix out */
virtual void setVolume(float vol) = 0;
/** Amuse may request callbacks 200-updates-per-second virtually */
virtual void register5MsCallback(std::function<void(double dt)>&& callback) = 0;
};

View File

@ -288,4 +288,6 @@ void BooBackendVoiceAllocator::register5MsCallback(std::function<void(double)>&&
AudioChannelSet BooBackendVoiceAllocator::getAvailableSet() { return AudioChannelSet(m_booEngine.getAvailableSet()); }
void BooBackendVoiceAllocator::pumpAndMixVoices() { m_booEngine.pumpAndMixVoices(); }
void BooBackendVoiceAllocator::setVolume(float vol) { m_booEngine.setVolume(vol); }
}

View File

@ -384,6 +384,14 @@ std::shared_ptr<Sequencer> Engine::seqPlay(int groupId, int songId, const unsign
return {};
}
extern "C" const float VolumeLUT[];
/** Set total volume of engine */
void Engine::setVolume(float vol)
{
m_backend.setVolume(VolumeLUT[int(vol * 65536)]);
}
/** Find voice from VoiceId */
std::shared_ptr<Voice> Engine::findVoice(int vid)
{