diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-07-19 23:16:59 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-07-19 23:16:59 +1000 |
commit | 1f038540a59ff96aed3cda901449a298b6f1c11c (patch) | |
tree | e0768bc861938423c74d6e2abb9ef74357574238 /source/frontend | |
parent | d682b164aa87435183a5ad3196b25b5ff8a5ad18 (diff) |
Port in the voice settings menu
Diffstat (limited to 'source/frontend')
-rw-r--r-- | source/frontend/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/frontend/StarMainMixer.cpp | 3 | ||||
-rw-r--r-- | source/frontend/StarOptionsMenu.cpp | 14 | ||||
-rw-r--r-- | source/frontend/StarOptionsMenu.hpp | 3 | ||||
-rw-r--r-- | source/frontend/StarVoice.cpp | 52 | ||||
-rw-r--r-- | source/frontend/StarVoice.hpp | 2 | ||||
-rw-r--r-- | source/frontend/StarVoiceLuaBindings.cpp | 12 | ||||
-rw-r--r-- | source/frontend/StarVoiceLuaBindings.hpp | 2 | ||||
-rw-r--r-- | source/frontend/StarVoiceSettingsMenu.cpp | 23 | ||||
-rw-r--r-- | source/frontend/StarVoiceSettingsMenu.hpp | 24 |
10 files changed, 108 insertions, 29 deletions
diff --git a/source/frontend/CMakeLists.txt b/source/frontend/CMakeLists.txt index 4c6b9c8..b002155 100644 --- a/source/frontend/CMakeLists.txt +++ b/source/frontend/CMakeLists.txt @@ -58,6 +58,7 @@ SET (star_frontend_HEADERS StarWireInterface.hpp StarVoice.hpp StarVoiceLuaBindings.hpp + StarVoiceSettingsMenu.hpp ) SET (star_frontend_SOURCES @@ -108,6 +109,7 @@ SET (star_frontend_SOURCES StarWireInterface.cpp StarVoice.cpp StarVoiceLuaBindings.cpp + StarVoiceSettingsMenu.cpp ) ADD_LIBRARY (star_frontend OBJECT ${star_frontend_SOURCES} ${star_frontend_HEADERS}) diff --git a/source/frontend/StarMainMixer.cpp b/source/frontend/StarMainMixer.cpp index 6d68ea2..d4a2e73 100644 --- a/source/frontend/StarMainMixer.cpp +++ b/source/frontend/StarMainMixer.cpp @@ -121,6 +121,9 @@ void MainMixer::update(bool muteSfx, bool muteMusic) { if (m_mixer->hasEffect("echo")) m_mixer->removeEffect("echo", 0); + if (Voice* voice = Voice::singletonPtr()) + voice->update(); + m_mixer->update(); } } diff --git a/source/frontend/StarOptionsMenu.cpp b/source/frontend/StarOptionsMenu.cpp index cef2e7d..caa1b21 100644 --- a/source/frontend/StarOptionsMenu.cpp +++ b/source/frontend/StarOptionsMenu.cpp @@ -7,6 +7,7 @@ #include "StarLabelWidget.hpp" #include "StarAssets.hpp" #include "StarKeybindingsMenu.hpp" +#include "StarVoiceSettingsMenu.hpp" #include "StarBindingsMenu.hpp" #include "StarGraphicsMenu.hpp" @@ -49,8 +50,14 @@ OptionsMenu::OptionsMenu(PaneManager* manager) reader.registerCallback("showKeybindings", [=](Widget*) { displayControls(); }); + reader.registerCallback("showVoiceSettings", [=](Widget*) { + displayVoiceSettings(); + }); + reader.registerCallback("showVoicePlayers", [=](Widget*) { + + }); reader.registerCallback("showModBindings", [=](Widget*) { - displayModBindings(); + displayModBindings(); }); reader.registerCallback("showGraphics", [=](Widget*) { displayGraphics(); @@ -74,6 +81,7 @@ OptionsMenu::OptionsMenu(PaneManager* manager) m_sfxSlider->setRange(m_sfxRange, assets->json("/interface/optionsmenu/optionsmenu.config:sfxDelta").toInt()); m_musicSlider->setRange(m_musicRange, assets->json("/interface/optionsmenu/optionsmenu.config:musicDelta").toInt()); + m_voiceSettingsMenu = make_shared<VoiceSettingsMenu>(assets->json(config.getString("voiceSettingsPanePath", "/interface/opensb/voicechat/voicechat.config"))); m_modBindingsMenu = make_shared<BindingsMenu>(assets->json(config.getString("bindingsPanePath", "/interface/opensb/bindings/bindings.config"))); m_keybindingsMenu = make_shared<KeybindingsMenu>(); m_graphicsMenu = make_shared<GraphicsMenu>(); @@ -169,6 +177,10 @@ void OptionsMenu::displayControls() { m_paneManager->displayPane(PaneLayer::ModalWindow, m_keybindingsMenu); } +void OptionsMenu::displayVoiceSettings() { + m_paneManager->displayPane(PaneLayer::ModalWindow, m_voiceSettingsMenu); +} + void OptionsMenu::displayModBindings() { m_paneManager->displayPane(PaneLayer::ModalWindow, m_modBindingsMenu); } diff --git a/source/frontend/StarOptionsMenu.hpp b/source/frontend/StarOptionsMenu.hpp index bd8c4ba..b984f02 100644 --- a/source/frontend/StarOptionsMenu.hpp +++ b/source/frontend/StarOptionsMenu.hpp @@ -10,6 +10,7 @@ namespace Star { STAR_CLASS(SliderBarWidget); STAR_CLASS(ButtonWidget); STAR_CLASS(LabelWidget); +STAR_CLASS(VoiceSettingsMenu); STAR_CLASS(KeybindingsMenu); STAR_CLASS(GraphicsMenu); STAR_CLASS(BindingsMenu); @@ -38,6 +39,7 @@ private: void syncGuiToConf(); void displayControls(); + void displayVoiceSettings(); void displayModBindings(); void displayGraphics(); @@ -59,6 +61,7 @@ private: JsonObject m_origConfig; JsonObject m_localChanges; + VoiceSettingsMenuPtr m_voiceSettingsMenu; BindingsMenuPtr m_modBindingsMenu; KeybindingsMenuPtr m_keybindingsMenu; GraphicsMenuPtr m_graphicsMenu; diff --git a/source/frontend/StarVoice.cpp b/source/frontend/StarVoice.cpp index b7f8a6c..843203f 100644 --- a/source/frontend/StarVoice.cpp +++ b/source/frontend/StarVoice.cpp @@ -312,15 +312,19 @@ void Voice::readAudioData(uint8_t* stream, int len) { size_t sampleCount = len / 2; if (active) { - float volume = m_inputVolume; float decibels = getAudioLoudness((int16_t*)stream, sampleCount); + if (!m_loopback) + m_clientSpeaker->decibelLevel = getAudioLoudness((int16_t*)stream, sampleCount, m_inputVolume); + if (m_inputMode == VoiceInputMode::VoiceActivity) { if (decibels > m_threshold) m_lastThresholdTime = now; active = now - m_lastThresholdTime < 50; } } + else if (!m_loopback) + m_clientSpeaker->decibelLevel = -96.0f; if (!m_loopback) { if (active && !m_clientSpeaker->playing) @@ -405,6 +409,7 @@ void Voice::mix(int16_t* buffer, size_t frameCount, unsigned channels) { } else { speaker->playing = false; + speaker->decibelLevel = -96.0f; it = m_activeSpeakers.erase(it); } } @@ -423,23 +428,25 @@ void Voice::mix(int16_t* buffer, size_t frameCount, unsigned channels) { } void Voice::update(PositionalAttenuationFunction positionalAttenuationFunction) { - if (positionalAttenuationFunction) { - for (auto& entry : m_speakers) { - if (SpeakerPtr& speaker = entry.second) { - speaker->channelVolumes = { - 1.0f - positionalAttenuationFunction(0, speaker->position, 1.0f), + for (auto& entry : m_speakers) { + if (SpeakerPtr& speaker = entry.second) { + if (positionalAttenuationFunction) { + speaker->channelVolumes = { + 1.0f - positionalAttenuationFunction(0, speaker->position, 1.0f), 1.0f - positionalAttenuationFunction(1, speaker->position, 1.0f) - }; + }; + } + else + speaker->channelVolumes = Vec2F::filled(1.0f); - auto& dbHistory = speaker->dbHistory; - memcpy(&dbHistory[1], &dbHistory[0], (dbHistory.size() - 1) * sizeof(float)); - dbHistory[0] = speaker->decibelLevel; - float smoothDb = 0.0f; - for (float dB : dbHistory) - smoothDb += dB; - - speaker->smoothDb = smoothDb / dbHistory.size(); - } + auto& dbHistory = speaker->dbHistory; + memcpy(&dbHistory[1], &dbHistory[0], (dbHistory.size() - 1) * sizeof(float)); + dbHistory[0] = speaker->decibelLevel; + float smoothDb = 0.0f; + for (float dB : dbHistory) + smoothDb += dB; + + speaker->smoothDb = smoothDb / dbHistory.size(); } } @@ -467,6 +474,7 @@ StringList Voice::availableDevices() { for (size_t i = 0; i != devices; ++i) deviceList.emplace_back(SDL_GetAudioDeviceName(i, 1)); } + deviceList.sort(); return deviceList; } @@ -488,7 +496,7 @@ int Voice::send(DataStreamBuffer& out, size_t budget) { for (auto& chunk : encodedChunks) { out.write<uint32_t>(chunk.size()); out.writeBytes(chunk); - if ((budget -= min<size_t>(budget, chunk.size())) == 0) + if (budget && (budget -= min<size_t>(budget, chunk.size())) == 0) break; } @@ -499,7 +507,7 @@ int Voice::send(DataStreamBuffer& out, size_t budget) { } bool Voice::receive(SpeakerPtr speaker, std::string_view view) { - if (!speaker || view.empty()) + if (!m_enabled || !speaker || view.empty()) return false; try { @@ -635,9 +643,8 @@ void Voice::closeDevice() { return; m_applicationController->closeAudioInputDevice(); - if (!m_loopback) - m_clientSpeaker->playing = false; - + m_clientSpeaker->playing = false; + m_clientSpeaker->decibelLevel = -96.0f; m_deviceOpen = false; } @@ -684,9 +691,6 @@ void Voice::thread() { samples[i] *= m_inputVolume; } - if (!m_loopback) - m_clientSpeaker->decibelLevel = getAudioLoudness(samples.data(), samples.size()); - if (int encodedSize = opus_encode(m_encoder.get(), samples.data(), VOICE_FRAME_SIZE, (unsigned char*)encoded.ptr(), encoded.size())) { if (encodedSize == 1) continue; diff --git a/source/frontend/StarVoice.hpp b/source/frontend/StarVoice.hpp index 4500aa6..95046af 100644 --- a/source/frontend/StarVoice.hpp +++ b/source/frontend/StarVoice.hpp @@ -141,7 +141,7 @@ public: void setDeviceName(Maybe<String> device); StringList availableDevices(); - int send(DataStreamBuffer& out, size_t budget); + int send(DataStreamBuffer& out, size_t budget = 0); bool receive(SpeakerPtr speaker, std::string_view view); // Must be called every frame with input state, expires after 1s. diff --git a/source/frontend/StarVoiceLuaBindings.cpp b/source/frontend/StarVoiceLuaBindings.cpp index 1b62aef..934b294 100644 --- a/source/frontend/StarVoiceLuaBindings.cpp +++ b/source/frontend/StarVoiceLuaBindings.cpp @@ -6,9 +6,11 @@ namespace Star { typedef Voice::SpeakerId SpeakerId; -LuaCallbacks LuaBindings::makeVoiceCallbacks(Voice* voice) { +LuaCallbacks LuaBindings::makeVoiceCallbacks() { LuaCallbacks callbacks; + auto voice = Voice::singletonPtr(); + callbacks.registerCallbackWithSignature<StringList>("devices", bind(&Voice::availableDevices, voice)); callbacks.registerCallback( "getSettings", [voice]() -> Json { return voice->saveJson(); }); callbacks.registerCallback("mergeSettings", [voice](Json const& settings) { voice->loadJson(settings); }); @@ -21,7 +23,13 @@ LuaCallbacks LuaBindings::makeVoiceCallbacks(Voice* voice) { callbacks.registerCallback("speakerPosition", [voice](SpeakerId speakerId) { return voice->speaker(speakerId)->position; }); - callbacks.registerCallback("speaker", [voice](SpeakerId speakerId) { return voice->speaker(speakerId)->toJson(); }); + callbacks.registerCallback("speaker", [voice](Maybe<SpeakerId> speakerId) { + if (speakerId) + return voice->speaker(*speakerId)->toJson(); + else + return voice->localSpeaker()->toJson(); + }); + callbacks.registerCallback("speakers", [voice](Maybe<bool> onlyPlaying) -> List<Json> { List<Json> list; diff --git a/source/frontend/StarVoiceLuaBindings.hpp b/source/frontend/StarVoiceLuaBindings.hpp index 8c83e54..5d670f3 100644 --- a/source/frontend/StarVoiceLuaBindings.hpp +++ b/source/frontend/StarVoiceLuaBindings.hpp @@ -8,7 +8,7 @@ namespace Star { STAR_CLASS(Voice); namespace LuaBindings { - LuaCallbacks makeVoiceCallbacks(Voice* voice); + LuaCallbacks makeVoiceCallbacks(); } } diff --git a/source/frontend/StarVoiceSettingsMenu.cpp b/source/frontend/StarVoiceSettingsMenu.cpp new file mode 100644 index 0000000..c815dee --- /dev/null +++ b/source/frontend/StarVoiceSettingsMenu.cpp @@ -0,0 +1,23 @@ +#include "StarVoiceSettingsMenu.hpp" +#include "StarVoiceLuaBindings.hpp" + +namespace Star { + +VoiceSettingsMenu::VoiceSettingsMenu(Json const& config) : BaseScriptPane(config) { + m_script.setLuaRoot(make_shared<LuaRoot>()); + m_script.addCallbacks("voice", LuaBindings::makeVoiceCallbacks()); +} + +void VoiceSettingsMenu::show() { + BaseScriptPane::show(); +} + +void VoiceSettingsMenu::displayed() { + BaseScriptPane::displayed(); +} + +void VoiceSettingsMenu::dismissed() { + BaseScriptPane::dismissed(); +} + +}
\ No newline at end of file diff --git a/source/frontend/StarVoiceSettingsMenu.hpp b/source/frontend/StarVoiceSettingsMenu.hpp new file mode 100644 index 0000000..1f9e58d --- /dev/null +++ b/source/frontend/StarVoiceSettingsMenu.hpp @@ -0,0 +1,24 @@ +#ifndef STAR_VOICE_SETTINGS_MENU_HPP +#define STAR_VOICE_SETTINGS_MENU_HPP + +#include "StarBaseScriptPane.hpp" + +namespace Star { + +STAR_CLASS(VoiceSettingsMenu); + +class VoiceSettingsMenu : public BaseScriptPane { +public: + VoiceSettingsMenu(Json const& config); + + virtual void show() override; + void displayed() override; + void dismissed() override; + +private: + +}; + +} + +#endif |