From e2ee8c550fac27d0d688fa42a158422734d30f5a Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 20 May 2016 15:15:31 -1000 Subject: [PATCH] Integrate -10dB volume curve --- driver/main.cpp | 24 ++++++++++-------------- lib/BooBackend.cpp | 37 ++++++++++++++++++++++++------------- lib/Voice.cpp | 11 +++++++++-- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/driver/main.cpp b/driver/main.cpp index e7c1b34..446aa1f 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -10,8 +10,6 @@ #include #include -#define VOL_FACTOR 0.25 - static logvisor::Module Log("amuseplay"); static amuse::IntrusiveAudioGroupData LoadFromArgs(int argc, const boo::SystemChar** argv, @@ -210,7 +208,7 @@ struct AppCallback : boo::IApplicationCallback m_seq->kill(); } m_seq = m_engine->seqPlay(m_groupId, setupId, nullptr); - m_seq->setVolume(m_volume * VOL_FACTOR); + m_seq->setVolume(m_volume); if (m_arrData) m_seq->playSong(m_arrData.get(), false); @@ -218,8 +216,7 @@ struct AppCallback : boo::IApplicationCallback UpdateSongDisplay(); } - void SongLoop(const amuse::AudioGroup& group, - const amuse::SongGroupIndex& index) + void SongLoop(const amuse::SongGroupIndex& index) { printf("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" "░░░ ████ ████ ┃ ████ ████ ████ ┃ ████ ████ ░░░\n" @@ -344,8 +341,7 @@ struct AppCallback : boo::IApplicationCallback UpdateSFXDisplay(); } - void SFXLoop(const amuse::AudioGroup& group, - const amuse::SFXGroupIndex& index) + void SFXLoop(const amuse::SFXGroupIndex& index) { printf(": keyon/keyoff, : cycle SFX, : volume, : quit\n"); @@ -775,9 +771,9 @@ struct AppCallback : boo::IApplicationCallback /* Enter playback loop */ if (m_sfxGroup) - SFXLoop(*group, *proj.getSFXGroupIndex(m_groupId)); + SFXLoop(*proj.getSFXGroupIndex(m_groupId)); else - SongLoop(*group, *proj.getSongGroupIndex(m_groupId)); + SongLoop(*proj.getSongGroupIndex(m_groupId)); return 0; } @@ -818,18 +814,18 @@ void EventCallback::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, 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 * VOL_FACTOR); + m_app.m_vox->setVolume(m_app.m_volume); 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; 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 * VOL_FACTOR); + m_app.m_vox->setVolume(m_app.m_volume); 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; break; default: break; @@ -887,7 +883,7 @@ int main(int argc, const boo::SystemChar** argv) logvisor::RegisterConsoleLogger(); AppCallback app(argc, argv); 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"); return ret; } diff --git a/lib/BooBackend.cpp b/lib/BooBackend.cpp index 82f8b78..8f19160 100644 --- a/lib/BooBackend.cpp +++ b/lib/BooBackend.cpp @@ -114,12 +114,23 @@ BooBackendMIDIReader::BooBackendMIDIReader(Engine& engine, const char* name) { BooBackendVoiceAllocator& voxAlloc = static_cast(engine.getBackend()); 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, - std::placeholders::_1)); + std::placeholders::_1)); + } else m_midiIn = voxAlloc.m_booEngine.newRealMIDIIn(name, - std::bind(&BooBackendMIDIReader::_MIDIReceive, this, - std::placeholders::_1)); + std::bind(&BooBackendMIDIReader::_MIDIReceive, this, + std::placeholders::_1)); } void BooBackendMIDIReader::_MIDIReceive(std::vector&& bytes) @@ -170,7 +181,7 @@ void BooBackendMIDIReader::noteOn(uint8_t chan, uint8_t key, uint8_t 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); } -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); } -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); } -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*/) { } diff --git a/lib/Voice.cpp b/lib/Voice.cpp index 873558d..7254712 100644 --- a/lib/Voice.cpp +++ b/lib/Voice.cpp @@ -201,6 +201,13 @@ std::list>::iterator Voice::_destroyVoice(Voice* voice) 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) { double dt = 1.0 / m_sampleRate; @@ -251,8 +258,8 @@ bool Voice::_advanceSample(int16_t& samp, int32_t& newPitch) } } - /* Multiply sample with total volume */ - samp = ClampFull(samp * totalVol); + /* Apple total volume to sample using decibel scale */ + ApplyVolume(ClampFull(totalVol), samp); /* Process active pan-sweep */ if (m_panningTime >= 0.f)