Integrate -10dB volume curve

This commit is contained in:
Jack Andersen 2016-05-20 15:15:31 -10:00
parent 64ed5e2ea5
commit e2ee8c550f
3 changed files with 43 additions and 29 deletions

View File

@ -10,8 +10,6 @@
#include <thread> #include <thread>
#include <map> #include <map>
#define VOL_FACTOR 0.25
static logvisor::Module Log("amuseplay"); static logvisor::Module Log("amuseplay");
static amuse::IntrusiveAudioGroupData LoadFromArgs(int argc, const boo::SystemChar** argv, static amuse::IntrusiveAudioGroupData LoadFromArgs(int argc, const boo::SystemChar** argv,
@ -210,7 +208,7 @@ struct AppCallback : boo::IApplicationCallback
m_seq->kill(); m_seq->kill();
} }
m_seq = m_engine->seqPlay(m_groupId, setupId, nullptr); m_seq = m_engine->seqPlay(m_groupId, setupId, nullptr);
m_seq->setVolume(m_volume * VOL_FACTOR); m_seq->setVolume(m_volume);
if (m_arrData) if (m_arrData)
m_seq->playSong(m_arrData.get(), false); m_seq->playSong(m_arrData.get(), false);
@ -218,8 +216,7 @@ struct AppCallback : boo::IApplicationCallback
UpdateSongDisplay(); UpdateSongDisplay();
} }
void SongLoop(const amuse::AudioGroup& group, void SongLoop(const amuse::SongGroupIndex& index)
const amuse::SongGroupIndex& index)
{ {
printf("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" printf("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"
"░░░ ████ ████ ┃ ████ ████ ████ ┃ ████ ████ ░░░\n" "░░░ ████ ████ ┃ ████ ████ ████ ┃ ████ ████ ░░░\n"
@ -344,8 +341,7 @@ struct AppCallback : boo::IApplicationCallback
UpdateSFXDisplay(); UpdateSFXDisplay();
} }
void SFXLoop(const amuse::AudioGroup& group, void SFXLoop(const amuse::SFXGroupIndex& index)
const amuse::SFXGroupIndex& index)
{ {
printf("<space>: keyon/keyoff, <left/right>: cycle SFX, <up/down>: volume, <Q>: quit\n"); printf("<space>: keyon/keyoff, <left/right>: cycle SFX, <up/down>: volume, <Q>: quit\n");
@ -775,9 +771,9 @@ struct AppCallback : boo::IApplicationCallback
/* Enter playback loop */ /* Enter playback loop */
if (m_sfxGroup) if (m_sfxGroup)
SFXLoop(*group, *proj.getSFXGroupIndex(m_groupId)); SFXLoop(*proj.getSFXGroupIndex(m_groupId));
else else
SongLoop(*group, *proj.getSongGroupIndex(m_groupId)); SongLoop(*proj.getSongGroupIndex(m_groupId));
return 0; return 0;
} }
@ -818,18 +814,18 @@ void EventCallback::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods,
if (m_app.m_volume < 1.f) if (m_app.m_volume < 1.f)
m_app.m_volume = amuse::clamp(0.f, m_app.m_volume + 0.05f, 1.f); m_app.m_volume = amuse::clamp(0.f, m_app.m_volume + 0.05f, 1.f);
if (m_app.m_vox) if (m_app.m_vox)
m_app.m_vox->setVolume(m_app.m_volume * VOL_FACTOR); m_app.m_vox->setVolume(m_app.m_volume);
if (m_app.m_seq) if (m_app.m_seq)
m_app.m_seq->setVolume(m_app.m_volume * VOL_FACTOR); m_app.m_seq->setVolume(m_app.m_volume);
m_app.m_updateDisp = true; m_app.m_updateDisp = true;
break; break;
case boo::ESpecialKey::Down: case boo::ESpecialKey::Down:
if (m_app.m_volume > 0.f) if (m_app.m_volume > 0.f)
m_app.m_volume = amuse::clamp(0.f, m_app.m_volume - 0.05f, 1.f); m_app.m_volume = amuse::clamp(0.f, m_app.m_volume - 0.05f, 1.f);
if (m_app.m_vox) if (m_app.m_vox)
m_app.m_vox->setVolume(m_app.m_volume * VOL_FACTOR); m_app.m_vox->setVolume(m_app.m_volume);
if (m_app.m_seq) if (m_app.m_seq)
m_app.m_seq->setVolume(m_app.m_volume * VOL_FACTOR); m_app.m_seq->setVolume(m_app.m_volume);
m_app.m_updateDisp = true; m_app.m_updateDisp = true;
break; break;
default: break; default: break;
@ -887,7 +883,7 @@ int main(int argc, const boo::SystemChar** argv)
logvisor::RegisterConsoleLogger(); logvisor::RegisterConsoleLogger();
AppCallback app(argc, argv); AppCallback app(argc, argv);
int ret = boo::ApplicationRun(boo::IApplication::EPlatformType::Auto, int ret = boo::ApplicationRun(boo::IApplication::EPlatformType::Auto,
app, _S("amuseplay"), _S("Amuse Player"), argc, argv); app, _S("amuseplay"), _S("Amuse Player"), argc, argv, false);
printf("IM DYING!!\n"); printf("IM DYING!!\n");
return ret; return ret;
} }

View File

@ -114,12 +114,23 @@ BooBackendMIDIReader::BooBackendMIDIReader(Engine& engine, const char* name)
{ {
BooBackendVoiceAllocator& voxAlloc = static_cast<BooBackendVoiceAllocator&>(engine.getBackend()); BooBackendVoiceAllocator& voxAlloc = static_cast<BooBackendVoiceAllocator&>(engine.getBackend());
if (!name) if (!name)
{
auto devices = voxAlloc.m_booEngine.enumerateMIDIDevices();
for (const auto& dev : devices)
{
m_midiIn = voxAlloc.m_booEngine.newRealMIDIIn(dev.first.c_str(),
std::bind(&BooBackendMIDIReader::_MIDIReceive, this,
std::placeholders::_1));
if (m_midiIn)
return;
}
m_midiIn = voxAlloc.m_booEngine.newVirtualMIDIIn(std::bind(&BooBackendMIDIReader::_MIDIReceive, this, m_midiIn = voxAlloc.m_booEngine.newVirtualMIDIIn(std::bind(&BooBackendMIDIReader::_MIDIReceive, this,
std::placeholders::_1)); std::placeholders::_1));
}
else else
m_midiIn = voxAlloc.m_booEngine.newRealMIDIIn(name, m_midiIn = voxAlloc.m_booEngine.newRealMIDIIn(name,
std::bind(&BooBackendMIDIReader::_MIDIReceive, this, std::bind(&BooBackendMIDIReader::_MIDIReceive, this,
std::placeholders::_1)); std::placeholders::_1));
} }
void BooBackendMIDIReader::_MIDIReceive(std::vector<uint8_t>&& bytes) void BooBackendMIDIReader::_MIDIReceive(std::vector<uint8_t>&& bytes)
@ -170,7 +181,7 @@ void BooBackendMIDIReader::noteOn(uint8_t chan, uint8_t key, uint8_t velocity)
seq->keyOn(chan, key, velocity); seq->keyOn(chan, key, velocity);
} }
void BooBackendMIDIReader::notePressure(uint8_t chan, uint8_t key, uint8_t pressure) void BooBackendMIDIReader::notePressure(uint8_t /*chan*/, uint8_t /*key*/, uint8_t /*pressure*/)
{ {
} }
@ -186,7 +197,7 @@ void BooBackendMIDIReader::programChange(uint8_t chan, uint8_t program)
seq->setChanProgram(chan, program); seq->setChanProgram(chan, program);
} }
void BooBackendMIDIReader::channelPressure(uint8_t chan, uint8_t pressure) void BooBackendMIDIReader::channelPressure(uint8_t /*chan*/, uint8_t /*pressure*/)
{ {
} }
@ -203,11 +214,11 @@ void BooBackendMIDIReader::allSoundOff(uint8_t chan)
seq->allOff(chan, true); seq->allOff(chan, true);
} }
void BooBackendMIDIReader::resetAllControllers(uint8_t chan) void BooBackendMIDIReader::resetAllControllers(uint8_t /*chan*/)
{ {
} }
void BooBackendMIDIReader::localControl(uint8_t chan, bool on) void BooBackendMIDIReader::localControl(uint8_t /*chan*/, bool /*on*/)
{ {
} }
@ -217,28 +228,28 @@ void BooBackendMIDIReader::allNotesOff(uint8_t chan)
seq->allOff(chan, false); seq->allOff(chan, false);
} }
void BooBackendMIDIReader::omniMode(uint8_t chan, bool on) void BooBackendMIDIReader::omniMode(uint8_t /*chan*/, bool /*on*/)
{ {
} }
void BooBackendMIDIReader::polyMode(uint8_t chan, bool on) void BooBackendMIDIReader::polyMode(uint8_t /*chan*/, bool /*on*/)
{ {
} }
void BooBackendMIDIReader::sysex(const void* data, size_t len) void BooBackendMIDIReader::sysex(const void* /*data*/, size_t /*len*/)
{ {
} }
void BooBackendMIDIReader::timeCodeQuarterFrame(uint8_t message, uint8_t value) void BooBackendMIDIReader::timeCodeQuarterFrame(uint8_t /*message*/, uint8_t /*value*/)
{ {
} }
void BooBackendMIDIReader::songPositionPointer(uint16_t pointer) void BooBackendMIDIReader::songPositionPointer(uint16_t /*pointer*/)
{ {
} }
void BooBackendMIDIReader::songSelect(uint8_t song) void BooBackendMIDIReader::songSelect(uint8_t /*song*/)
{ {
} }

View File

@ -201,6 +201,13 @@ std::list<std::shared_ptr<Voice>>::iterator Voice::_destroyVoice(Voice* voice)
return m_childVoices.erase(voice->m_engineIt); return m_childVoices.erase(voice->m_engineIt);
} }
static void ApplyVolume(float vol, int16_t& samp)
{
/* -10dB to 0dB mapped to full volume range */
float factor = (std::pow(10.f, vol - 1.f) - 0.1f) * (1.f / 0.9f);
samp *= factor;
}
bool Voice::_advanceSample(int16_t& samp, int32_t& newPitch) bool Voice::_advanceSample(int16_t& samp, int32_t& newPitch)
{ {
double dt = 1.0 / m_sampleRate; double dt = 1.0 / m_sampleRate;
@ -251,8 +258,8 @@ bool Voice::_advanceSample(int16_t& samp, int32_t& newPitch)
} }
} }
/* Multiply sample with total volume */ /* Apple total volume to sample using decibel scale */
samp = ClampFull<int16_t>(samp * totalVol); ApplyVolume(ClampFull<float>(totalVol), samp);
/* Process active pan-sweep */ /* Process active pan-sweep */
if (m_panningTime >= 0.f) if (m_panningTime >= 0.f)