mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-27 05:23:51 +00:00
Add audio volume controls to settings
This commit is contained in:
parent
f5185c08cf
commit
7060c80b81
9 changed files with 79 additions and 5 deletions
|
|
@ -218,6 +218,7 @@ bool ActivitySoundManager::playOneShot(const std::vector<Sample>& clips, float v
|
|||
|
||||
std::uniform_real_distribution<float> pitchDist(pitchLo, pitchHi);
|
||||
float pitch = pitchDist(rng);
|
||||
volume *= volumeScale;
|
||||
if (volume < 0.1f) volume = 0.1f;
|
||||
if (volume > 1.2f) volume = 1.2f;
|
||||
std::string filter = "asetrate=44100*" + std::to_string(pitch) +
|
||||
|
|
@ -241,7 +242,7 @@ void ActivitySoundManager::startSwimLoop() {
|
|||
out.write(reinterpret_cast<const char*>(sample.data.data()), static_cast<std::streamsize>(sample.data.size()));
|
||||
out.close();
|
||||
|
||||
float volume = swimMoving ? 0.85f : 0.65f;
|
||||
float volume = (swimMoving ? 0.85f : 0.65f) * volumeScale;
|
||||
std::string filter = "volume=" + std::to_string(volume);
|
||||
|
||||
swimLoopPid = platform::spawnProcess({
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ bool FootstepManager::playRandomStep(FootstepSurface surface, bool sprinting) {
|
|||
std::uniform_real_distribution<float> pitchDist(0.97f, 1.05f);
|
||||
std::uniform_real_distribution<float> volumeDist(0.92f, 1.00f);
|
||||
float pitch = pitchDist(rng);
|
||||
float volume = volumeDist(rng) * (sprinting ? 1.0f : 0.88f);
|
||||
float volume = volumeDist(rng) * (sprinting ? 1.0f : 0.88f) * volumeScale;
|
||||
if (volume > 1.0f) volume = 1.0f;
|
||||
if (volume < 0.1f) volume = 0.1f;
|
||||
|
||||
|
|
|
|||
|
|
@ -60,13 +60,14 @@ void MusicManager::playMusic(const std::string& mpqPath, bool loop) {
|
|||
args.push_back("0");
|
||||
}
|
||||
args.push_back("-volume");
|
||||
args.push_back("30");
|
||||
args.push_back(std::to_string(volumePercent));
|
||||
args.push_back(tempFilePath);
|
||||
|
||||
playerPid = platform::spawnProcess(args);
|
||||
if (playerPid != INVALID_PROCESS) {
|
||||
playing = true;
|
||||
currentTrack = mpqPath;
|
||||
currentTrackIsFile = false;
|
||||
LOG_INFO("Music: Playing ", mpqPath);
|
||||
} else {
|
||||
LOG_ERROR("Music: Failed to spawn ffplay process");
|
||||
|
|
@ -91,13 +92,14 @@ void MusicManager::playFilePath(const std::string& filePath, bool loop) {
|
|||
args.push_back("0");
|
||||
}
|
||||
args.push_back("-volume");
|
||||
args.push_back("30");
|
||||
args.push_back(std::to_string(volumePercent));
|
||||
args.push_back(filePath);
|
||||
|
||||
playerPid = platform::spawnProcess(args);
|
||||
if (playerPid != INVALID_PROCESS) {
|
||||
playing = true;
|
||||
currentTrack = filePath;
|
||||
currentTrackIsFile = true;
|
||||
LOG_INFO("Music: Playing file ", filePath);
|
||||
} else {
|
||||
LOG_ERROR("Music: Failed to spawn ffplay process");
|
||||
|
|
@ -109,6 +111,27 @@ void MusicManager::stopMusic(float fadeMs) {
|
|||
stopCurrentProcess();
|
||||
playing = false;
|
||||
currentTrack.clear();
|
||||
currentTrackIsFile = false;
|
||||
}
|
||||
|
||||
void MusicManager::setVolume(int volume) {
|
||||
if (volume < 0) volume = 0;
|
||||
if (volume > 100) volume = 100;
|
||||
if (volumePercent == volume) return;
|
||||
volumePercent = volume;
|
||||
if (playing && !currentTrack.empty()) {
|
||||
std::string track = currentTrack;
|
||||
bool isFile = currentTrackIsFile;
|
||||
stopCurrentProcess();
|
||||
playing = false;
|
||||
currentTrack.clear();
|
||||
currentTrackIsFile = false;
|
||||
if (isFile) {
|
||||
playFilePath(track, true);
|
||||
} else {
|
||||
playMusic(track, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MusicManager::crossfadeTo(const std::string& mpqPath, float fadeMs) {
|
||||
|
|
|
|||
|
|
@ -1807,6 +1807,22 @@ void GameScreen::renderSettingsWindow() {
|
|||
pendingFullscreen = window->isFullscreen();
|
||||
pendingVsync = window->isVsyncEnabled();
|
||||
pendingShadows = renderer ? renderer->areShadowsEnabled() : true;
|
||||
if (renderer) {
|
||||
if (auto* music = renderer->getMusicManager()) {
|
||||
pendingMusicVolume = music->getVolume();
|
||||
}
|
||||
if (auto* footstep = renderer->getFootstepManager()) {
|
||||
float scale = footstep->getVolumeScale();
|
||||
pendingSfxVolume = static_cast<int>(scale * 100.0f + 0.5f);
|
||||
if (pendingSfxVolume < 0) pendingSfxVolume = 0;
|
||||
if (pendingSfxVolume > 100) pendingSfxVolume = 100;
|
||||
} else if (auto* activity = renderer->getActivitySoundManager()) {
|
||||
float scale = activity->getVolumeScale();
|
||||
pendingSfxVolume = static_cast<int>(scale * 100.0f + 0.5f);
|
||||
if (pendingSfxVolume < 0) pendingSfxVolume = 0;
|
||||
if (pendingSfxVolume > 100) pendingSfxVolume = 100;
|
||||
}
|
||||
}
|
||||
pendingResIndex = 0;
|
||||
int curW = window->getWidth();
|
||||
int curH = window->getHeight();
|
||||
|
|
@ -1822,7 +1838,7 @@ void GameScreen::renderSettingsWindow() {
|
|||
ImGuiIO& io = ImGui::GetIO();
|
||||
float screenW = io.DisplaySize.x;
|
||||
float screenH = io.DisplaySize.y;
|
||||
ImVec2 size(360.0f, 240.0f);
|
||||
ImVec2 size(380.0f, 320.0f);
|
||||
ImVec2 pos((screenW - size.x) * 0.5f, (screenH - size.y) * 0.5f);
|
||||
|
||||
ImGui::SetNextWindowPos(pos, ImGuiCond_Always);
|
||||
|
|
@ -1848,6 +1864,16 @@ void GameScreen::renderSettingsWindow() {
|
|||
}
|
||||
ImGui::Combo(resLabel, &pendingResIndex, resItems, kResCount);
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
ImGui::Spacing();
|
||||
|
||||
ImGui::Text("Audio");
|
||||
ImGui::SliderInt("Music Volume", &pendingMusicVolume, 0, 100, "%d");
|
||||
ImGui::SliderInt("SFX Volume", &pendingSfxVolume, 0, 100, "%d");
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
ImGui::Spacing();
|
||||
if (ImGui::Button("Apply", ImVec2(-1, 0))) {
|
||||
window->setVsync(pendingVsync);
|
||||
|
|
@ -1855,6 +1881,16 @@ void GameScreen::renderSettingsWindow() {
|
|||
window->applyResolution(kResolutions[pendingResIndex][0], kResolutions[pendingResIndex][1]);
|
||||
if (renderer) {
|
||||
renderer->setShadowsEnabled(pendingShadows);
|
||||
if (auto* music = renderer->getMusicManager()) {
|
||||
music->setVolume(pendingMusicVolume);
|
||||
}
|
||||
float sfxScale = static_cast<float>(pendingSfxVolume) / 100.0f;
|
||||
if (auto* footstep = renderer->getFootstepManager()) {
|
||||
footstep->setVolumeScale(sfxScale);
|
||||
}
|
||||
if (auto* activity = renderer->getActivitySoundManager()) {
|
||||
activity->setVolumeScale(sfxScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::Spacing();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue