Permalink
Browse files

BLADERUNNER: Use ScummVM functionality for audio volume management

  • Loading branch information...
peterkohaut committed Feb 10, 2019
1 parent f104cf5 commit 1384afd0f6151e5c39e8f4234fd3a3730ef46f49
@@ -37,7 +37,8 @@ AmbientSounds::AmbientSounds(BladeRunnerEngine *vm) {
_vm = vm;
_nonLoopingSounds = new NonLoopingSound[kNonLoopingSounds];
_loopingSounds = new LoopingSound[kLoopingSounds];
_ambientVolume = 65;

_ambientVolume = BLADERUNNER_ORIGINAL_SETTINGS ? 65 : 100;

for (int i = 0; i != kNonLoopingSounds; ++i) {
NonLoopingSound &track = _nonLoopingSounds[i];
@@ -119,7 +120,7 @@ void AmbientSounds::playSound(int sfxId, int volume, int panStart, int panEnd, i

void AmbientSounds::playSpeech(int actorId, int sentenceId, int volume, int panStart, int panEnd, int priority) {
Common::String name = Common::String::format( "%02d-%04d%s.AUD", actorId, sentenceId, _vm->_languageCode.c_str());
_vm->_audioPlayer->playAud(name, volume * _ambientVolume / 100, panStart, panEnd, priority, kAudioPlayerOverrideVolume);
_vm->_audioPlayer->playAud(name, volume * _ambientVolume / 100, panStart, panEnd, priority, kAudioPlayerOverrideVolume, Audio::Mixer::kSpeechSoundType);
}

void AmbientSounds::addLoopingSound(int sfxId, int volume, int pan, int delay) {
@@ -136,7 +136,7 @@ AudioPlayer::AudioPlayer(BladeRunnerEngine *vm) {
_tracks[i].stream = nullptr;
}

_sfxVolume = 65;
_sfxVolume =BLADERUNNER_ORIGINAL_SETTINGS ? 65 : 100;
}

AudioPlayer::~AudioPlayer() {
@@ -221,7 +221,7 @@ void AudioPlayer::mixerChannelEnded(int channel, void *data) {
audioPlayer->remove(channel);
}

int AudioPlayer::playAud(const Common::String &name, int volume, int panFrom, int panTo, int priority, byte flags) {
int AudioPlayer::playAud(const Common::String &name, int volume, int panFrom, int panTo, int priority, byte flags, Audio::Mixer::SoundType type) {
/* Find first available track or, alternatively, the lowest priority playing track */
int track = -1;
int lowestPriority = 1000000;
@@ -279,7 +279,7 @@ int AudioPlayer::playAud(const Common::String &name, int volume, int panFrom, in
}

int channel = _vm->_audioMixer->play(
Audio::Mixer::kPlainSoundType,
type,
audioStream,
priority,
flags & kAudioPlayerLoop,
@@ -28,6 +28,7 @@
#include "common/str.h"

#include "audio/audiostream.h"
#include "audio/mixer.h"

namespace BladeRunner {

@@ -100,7 +101,7 @@ class AudioPlayer {
AudioPlayer(BladeRunnerEngine *vm);
~AudioPlayer();

int playAud(const Common::String &name, int volume, int panStart, int panEnd, int priority, byte flags = 0);
int playAud(const Common::String &name, int volume, int panStart, int panEnd, int priority, byte flags = 0, Audio::Mixer::SoundType type = Audio::Mixer::kSFXSoundType);
bool isActive(int track) const;
void stop(int track, bool immediately);
void stopAll();
@@ -48,7 +48,7 @@ void AudioSpeech::mixerChannelEnded(int channel, void *data) {

AudioSpeech::AudioSpeech(BladeRunnerEngine *vm) {
_vm = vm;
_speechVolume = 50;
_speechVolume = BLADERUNNER_ORIGINAL_SETTINGS ? 50 : 100;
_isActive = false;
_data = new byte[kBufferSize];
_channel = -1;
@@ -118,7 +118,7 @@ bool AudioSpeech::isPlaying() const {
bool AudioSpeech::playSpeechLine(int actorId, int sentenceId, int volume, int a4, int priority) {
int balance = _vm->_actors[actorId]->soundBalance();
Common::String name = Common::String::format("%02d-%04d%s.AUD", actorId, sentenceId, _vm->_languageCode.c_str());
return _vm->_audioPlayer->playAud(name, _speechVolume * volume / 100, balance, balance, priority, kAudioPlayerOverrideVolume);
return _vm->_audioPlayer->playAud(name, _speechVolume * volume / 100, balance, balance, priority, kAudioPlayerOverrideVolume, Audio::Mixer::kSpeechSoundType);
}

void AudioSpeech::setVolume(int volume) {
@@ -37,6 +37,7 @@

//TODO: change this to debugflag
#define BLADERUNNER_DEBUG_CONSOLE 0
#define BLADERUNNER_ORIGINAL_SETTINGS 0

namespace Common {
struct Event;
@@ -35,7 +35,7 @@ namespace BladeRunner {
Music::Music(BladeRunnerEngine *vm) {
_vm = vm;
_channel = -1;
_musicVolume = 65;
_musicVolume = BLADERUNNER_ORIGINAL_SETTINGS ? 65 : 100;
_isPlaying = false;
_isPaused = false;
_current.loop = false;
@@ -40,6 +40,7 @@
#include "bladerunner/ui/ui_image_picker.h"
#include "bladerunner/ui/ui_slider.h"

#include "audio/mixer.h"
#include "common/keyboard.h"

namespace BladeRunner {
@@ -50,20 +51,30 @@ KIASectionSettings::KIASectionSettings(BladeRunnerEngine *vm)
: KIASectionBase(vm) {

_uiContainer = new UIContainer(_vm);

#if BLADERUNNER_ORIGINAL_SETTINGS
_musicVolume = new UISlider(_vm, sliderCallback, this, Common::Rect(180, 160, 460, 170), 101, 0);
_soundEffectVolume = new UISlider(_vm, sliderCallback, this, Common::Rect( 180, 185, 460, 195), 101, 0);
_soundEffectVolume = new UISlider(_vm, sliderCallback, this, Common::Rect(180, 185, 460, 195), 101, 0);
_ambientSoundVolume = new UISlider(_vm, sliderCallback, this, Common::Rect(180, 210, 460, 220), 101, 0);
_speechVolume = new UISlider(_vm, sliderCallback, this, Common::Rect(180, 235, 460, 245), 101, 0);
_gammaCorrection = new UISlider(_vm, sliderCallback, this, Common::Rect(180, 260, 460, 270), 101, 0);
#else
_musicVolume = new UISlider(_vm, sliderCallback, this, Common::Rect(180, 160, 460, 170), _vm->_mixer->kMaxMixerVolume, 0);
_soundEffectVolume = new UISlider(_vm, sliderCallback, this, Common::Rect(180, 185, 460, 195), _vm->_mixer->kMaxMixerVolume, 0);
_speechVolume = new UISlider(_vm, sliderCallback, this, Common::Rect(180, 210, 460, 220), _vm->_mixer->kMaxMixerVolume, 0);
#endif

_directorsCut = new UICheckBox(_vm, checkBoxCallback, this, Common::Rect(180, 364, 270, 374), 0, false);
_subtitlesEnable = new UICheckBox(_vm, checkBoxCallback, this, Common::Rect(311, 364, 380, 374), 0, false); // moved further to the right to avoid overlap with 'Designer's Cut' in some language versions (ESP)
_playerAgendaSelector = new UIImagePicker(_vm, 5);

_uiContainer->add(_musicVolume);
_uiContainer->add(_soundEffectVolume);
_uiContainer->add(_ambientSoundVolume);
_uiContainer->add(_speechVolume);
#if BLADERUNNER_ORIGINAL_SETTINGS
_uiContainer->add(_ambientSoundVolume);
_uiContainer->add(_gammaCorrection);
#endif
_uiContainer->add(_directorsCut);
_uiContainer->add(_subtitlesEnable);

@@ -74,9 +85,11 @@ KIASectionSettings::~KIASectionSettings() {
delete _uiContainer;
delete _musicVolume;
delete _soundEffectVolume;
delete _ambientSoundVolume;
delete _speechVolume;
#if BLADERUNNER_ORIGINAL_SETTINGS
delete _ambientSoundVolume;
delete _gammaCorrection;
#endif
delete _directorsCut;
delete _subtitlesEnable;
delete _playerAgendaSelector;
@@ -102,26 +115,35 @@ void KIASectionSettings::close() {
}

void KIASectionSettings::draw(Graphics::Surface &surface) {
#if BLADERUNNER_ORIGINAL_SETTINGS
_musicVolume->setValue(_vm->_music->getVolume());
_soundEffectVolume->setValue(_vm->_audioPlayer->getVolume());
_ambientSoundVolume->setValue(_vm->_ambientSounds->getVolume());
_speechVolume->setValue(_vm->_audioSpeech->getVolume());
_gammaCorrection->setValue(100.0f);
#else
_musicVolume->setValue(_vm->_mixer->getVolumeForSoundType(_vm->_mixer->kMusicSoundType));
_soundEffectVolume->setValue(_vm->_mixer->getVolumeForSoundType(_vm->_mixer->kSFXSoundType));
_speechVolume->setValue(_vm->_mixer->getVolumeForSoundType(_vm->_mixer->kSpeechSoundType));
#endif

_directorsCut->setChecked(_vm->_gameFlags->query(kFlagDirectorsCut));

_subtitlesEnable->setChecked(_vm->isSubtitlesEnabled());

const char *textConversationChoices = _vm->_textOptions->getText(0);
const char *textMusic = _vm->_textOptions->getText(2);
const char *textSoundEffects = _vm->_textOptions->getText(3);
const char *textAmbientSound = _vm->_textOptions->getText(4);
const char *textSpeech = _vm->_textOptions->getText(5);
const char *textGammaCorrection = _vm->_textOptions->getText(7);
const char *textSoft = _vm->_textOptions->getText(10);
const char *textLoud = _vm->_textOptions->getText(11);
const char *textDesignersCut = _vm->_textOptions->getText(18);
#if BLADERUNNER_ORIGINAL_SETTINGS
const char *textAmbientSound = _vm->_textOptions->getText(4);
const char *textGammaCorrection = _vm->_textOptions->getText(7);
const char *textDark = _vm->_textOptions->getText(14);
const char *textLight = _vm->_textOptions->getText(15);
const char *textDesignersCut = _vm->_textOptions->getText(18);
#endif

// Allow this to be loading as an extra text item in the resource for text options
const char *subtitlesTranslation = "Subtitles";
@@ -149,11 +171,13 @@ void KIASectionSettings::draw(Graphics::Surface &surface) {
int posConversationChoices = 320 - _vm->_mainFont->getTextWidth(textConversationChoices) / 2;
int posMusic = 320 - _vm->_mainFont->getTextWidth(textMusic) / 2;
int posSoundEffects = 320 - _vm->_mainFont->getTextWidth(textSoundEffects) / 2;
int posAmbientSound = 320 - _vm->_mainFont->getTextWidth(textAmbientSound) / 2;
int posSpeech = 320 - _vm->_mainFont->getTextWidth(textSpeech) / 2;
int posGammaCorrection = 320 - _vm->_mainFont->getTextWidth(textGammaCorrection) / 2;
int posSoft = 178 - _vm->_mainFont->getTextWidth(textSoft);
#if BLADERUNNER_ORIGINAL_SETTINGS
int posAmbientSound = 320 - _vm->_mainFont->getTextWidth(textAmbientSound) / 2;
int posGammaCorrection = 320 - _vm->_mainFont->getTextWidth(textGammaCorrection) / 2;
int posDark = 178 - _vm->_mainFont->getTextWidth(textDark);
#endif

_uiContainer->draw(surface);
_playerAgendaSelector->draw(surface);
@@ -168,6 +192,7 @@ void KIASectionSettings::draw(Graphics::Surface &surface) {
_vm->_mainFont->drawColor(textSoft, surface, posSoft, 186, 0x6EEE);
_vm->_mainFont->drawColor(textLoud, surface, 462, 186, 0x6EEE);

#if BLADERUNNER_ORIGINAL_SETTINGS
_vm->_mainFont->drawColor(textAmbientSound, surface, posAmbientSound, 200, 0x7751);
_vm->_mainFont->drawColor(textSoft, surface, posSoft, 211, 0x6EEE);
_vm->_mainFont->drawColor(textLoud, surface, 462, 211, 0x6EEE);
@@ -179,6 +204,11 @@ void KIASectionSettings::draw(Graphics::Surface &surface) {
_vm->_mainFont->drawColor(textGammaCorrection, surface, posGammaCorrection, 250, 0x7751);
_vm->_mainFont->drawColor(textDark, surface, posDark, 261, 0x6EEE);
_vm->_mainFont->drawColor(textLight, surface, 462, 261, 0x6EEE);
#else
_vm->_mainFont->drawColor(textSpeech, surface, posSpeech, 200, 0x7751);
_vm->_mainFont->drawColor(textSoft, surface, posSoft, 211, 0x6EEE);
_vm->_mainFont->drawColor(textLoud, surface, 462, 211, 0x6EEE);
#endif

_vm->_mainFont->drawColor(textDesignersCut, surface, 192, 365, 0x7751);
_vm->_mainFont->drawColor(textSubtitles, surface, 323, 365, 0x7751); // moved further to the right to avoid overlap with 'Designer's Cut' in some language versions (ESP)
@@ -225,6 +255,7 @@ void KIASectionSettings::handleMouseUp(bool mainButton) {
void KIASectionSettings::sliderCallback(void *callbackData, void *source) {
KIASectionSettings *self = (KIASectionSettings *)callbackData;

#if BLADERUNNER_ORIGINAL_SETTINGS
if (source == self->_musicVolume) {
self->_vm->_music->setVolume(self->_musicVolume->_value);
self->_vm->_music->playSample();
@@ -246,6 +277,21 @@ void KIASectionSettings::sliderCallback(void *callbackData, void *source) {
// Palette_copy(Palette);
// kia::resume(KIA);
}
#else
if (source == self->_musicVolume) {
self->_vm->_mixer->setVolumeForSoundType(self->_vm->_mixer->kMusicSoundType, self->_musicVolume->_value);
self->_vm->_music->playSample();
ConfMan.setInt("music_volume", self->_musicVolume->_value);
} else if (source == self->_soundEffectVolume) {
self->_vm->_mixer->setVolumeForSoundType(self->_vm->_mixer->kSFXSoundType, self->_soundEffectVolume->_value);
self->_vm->_audioPlayer->playSample();
ConfMan.setInt("sfx_volume", self->_soundEffectVolume->_value);
} else if (source == self->_speechVolume) {
self->_vm->_mixer->setVolumeForSoundType(self->_vm->_mixer->kSpeechSoundType, self->_speechVolume->_value);
self->_vm->_audioSpeech->playSample();
ConfMan.setInt("speech_volume", self->_speechVolume->_value);
}
#endif
}

void KIASectionSettings::checkBoxCallback(void *callbackData, void *source) {
@@ -25,6 +25,8 @@

#include "bladerunner/ui/kia_section_base.h"

#include "common/config-manager.h"

namespace BladeRunner {

class BladeRunnerEngine;
@@ -39,9 +41,11 @@ class KIASectionSettings : public KIASectionBase {
UIContainer *_uiContainer;
UISlider *_musicVolume;
UISlider *_soundEffectVolume;
UISlider *_ambientSoundVolume;
UISlider *_speechVolume;
#if BLADERUNNER_ORIGINAL_SETTINGS
UISlider *_ambientSoundVolume;
UISlider *_gammaCorrection;
#endif
UICheckBox *_directorsCut;
UICheckBox *_subtitlesEnable;
UIImagePicker *_playerAgendaSelector;
@@ -1235,7 +1235,7 @@ void OptionsDialog::addMT32Controls(GuiObject *boss, const Common::String &prefi
if (!_domain.equals(Common::ConfigManager::kApplicationDomain)) {
_mt32DevicePopUpDesc->setEnabled(false);
_mt32DevicePopUp->setEnabled(false);
}
}

This comment has been minimized.

@sev-

This comment has been minimized.

@peterkohaut

peterkohaut Feb 10, 2019

Author Contributor

how did that happened? sorry, i will revert this

This comment has been minimized.

@peterkohaut

peterkohaut Feb 10, 2019

Author Contributor

I was prototyping something, but I deleted that in the end, this was just leftover. I just pushed a revert for this.


_enableMT32Settings = true;
}

0 comments on commit 1384afd

Please sign in to comment.