mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-26 21:13: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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue