aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/kyra/sound_intern.h2
-rw-r--r--engines/kyra/sound_towns.cpp15
-rw-r--r--sound/softsynth/fmtowns_pc98/towns_audio.cpp25
-rw-r--r--sound/softsynth/fmtowns_pc98/towns_audio.h10
-rw-r--r--sound/softsynth/fmtowns_pc98/towns_euphony.cpp21
-rw-r--r--sound/softsynth/fmtowns_pc98/towns_euphony.h5
-rw-r--r--sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp8
7 files changed, 78 insertions, 8 deletions
diff --git a/engines/kyra/sound_intern.h b/engines/kyra/sound_intern.h
index 186162a700..f8738bc791 100644
--- a/engines/kyra/sound_intern.h
+++ b/engines/kyra/sound_intern.h
@@ -122,6 +122,8 @@ public:
void beginFadeOut();
+ void updateVolumeSettings();
+
private:
bool loadInstruments();
void playEuphonyTrack(uint32 offset, int loop);
diff --git a/engines/kyra/sound_towns.cpp b/engines/kyra/sound_towns.cpp
index 1209c6b69a..5f877f7d8a 100644
--- a/engines/kyra/sound_towns.cpp
+++ b/engines/kyra/sound_towns.cpp
@@ -203,6 +203,19 @@ void SoundTowns::playSoundEffect(uint8 track) {
_driver->playSoundEffect(_sfxChannel, note, 127, sfxPlaybackBuffer);
}
+void SoundTowns::updateVolumeSettings() {
+ if (!_driver)
+ return;
+
+ bool mute = false;
+ _driver->setSoundEffectVolume(ConfMan.getInt("sfx_volume"));
+ if (ConfMan.hasKey("mute"))
+ mute = ConfMan.getBool("mute");
+
+ _driver->setMusicVolume((mute ? 0 : ConfMan.getInt("music_volume")));
+ _driver->setSoundEffectVolume((mute ? 0 : ConfMan.getInt("sfx_volume")));
+}
+
void SoundTowns::stopAllSoundEffects() {
_driver->chanVolume(0x46, 0);
_driver->chanVolume(0x47, 0);
@@ -298,7 +311,7 @@ bool SoundTowns::loadInstruments() {
src = src + READ_LE_UINT16(&src[12]) + 32;
}
- _driver->reserveSfxChannels(2);
+ _driver->reserveSoundEffectChannels(2);
delete[] twm;
diff --git a/sound/softsynth/fmtowns_pc98/towns_audio.cpp b/sound/softsynth/fmtowns_pc98/towns_audio.cpp
index 3d3427fcfb..683f574f65 100644
--- a/sound/softsynth/fmtowns_pc98/towns_audio.cpp
+++ b/sound/softsynth/fmtowns_pc98/towns_audio.cpp
@@ -101,7 +101,8 @@ private:
TownsAudioInterface::TownsAudioInterface(Audio::Mixer *mixer, TownsAudioInterfacePluginDriver *driver) : TownsPC98_FmSynth(mixer, kTypeTowns),
_fmInstruments(0), _pcmInstruments(0), _pcmChan(0), _waveTables(0), _waveTablesTotalDataSize(0),
- _baserate(55125.0f / (float)mixer->getOutputRate()), _tickLength(0), _timer(0), _drv(driver), _ready(false) {
+ _baserate(55125.0f / (float)mixer->getOutputRate()), _tickLength(0), _timer(0), _drv(driver),
+ _musicVolume(256), _sfxVolume(256), _pcmSfxChanMask(0), _ready(false) {
#define INTCB(x) &TownsAudioInterface::intf_##x
static const TownsAudioIntfCallback intfCb[] = {
@@ -247,6 +248,8 @@ bool TownsAudioInterface::init() {
_timer = 0;
+ setVolumeChannelMasks(-1, 0);
+
callback(0);
_ready = true;
@@ -269,6 +272,22 @@ int TownsAudioInterface::callback(int command, ...) {
return res;
}
+void TownsAudioInterface::setMusicVolume(int volume) {
+ _musicVolume = CLIP<uint16>(volume, 0, Audio::Mixer::kMaxMixerVolume);
+ setVolumeIntern(_musicVolume, _sfxVolume);
+}
+
+void TownsAudioInterface::setSoundEffectVolume(int volume) {
+ _sfxVolume = CLIP<uint16>(volume, 0, Audio::Mixer::kMaxMixerVolume);
+ setVolumeIntern(_musicVolume, _sfxVolume);
+}
+
+void TownsAudioInterface::setSoundEffectChanMask(uint32 mask) {
+ _pcmSfxChanMask = mask >> 6;
+ mask &= 0x3f;
+ setVolumeChannelMasks(~mask, mask);
+}
+
void TownsAudioInterface::nextTickEx(int32 *buffer, uint32 bufferSize) {
if (!_ready)
return;
@@ -302,6 +321,10 @@ void TownsAudioInterface::nextTickEx(int32 *buffer, uint32 bufferSize) {
for (int ii = 0; ii < 8; ii++) {
if (_pcmChanOut & _chanFlags[ii]) {
int32 o = _pcmChan[ii].data[_pcmChan[ii].pos >> 11] * _pcmChan[ii].velo;
+ if ((1 << ii) & (~_pcmSfxChanMask))
+ o = (o * _musicVolume) / Audio::Mixer::kMaxMixerVolume;
+ if ((1 << ii) & _pcmSfxChanMask)
+ o = (o * _sfxVolume) / Audio::Mixer::kMaxMixerVolume;
if (_pcmChan[ii].panLeft)
finOutL += ((o * _pcmChan[ii].panLeft) >> 3);
if (_pcmChan[ii].panRight)
diff --git a/sound/softsynth/fmtowns_pc98/towns_audio.h b/sound/softsynth/fmtowns_pc98/towns_audio.h
index 93a9198fe4..707c9e6bd4 100644
--- a/sound/softsynth/fmtowns_pc98/towns_audio.h
+++ b/sound/softsynth/fmtowns_pc98/towns_audio.h
@@ -46,6 +46,12 @@ public:
int callback(int command, ...);
+ void setMusicVolume(int volume);
+ void setSoundEffectVolume(int volume);
+ // Defines the channels used as sound effect channels for the purpose of ScummVM GUI volume control.
+ // The first 6 bits are the 6 fm channels. The next 8 bits are pcm channels.
+ void setSoundEffectChanMask(uint32 mask);
+
private:
void nextTickEx(int32 *buffer, uint32 bufferSize);
@@ -148,6 +154,10 @@ private:
uint32 _tickLength;
uint32 _timer;
+ uint16 _musicVolume;
+ uint16 _sfxVolume;
+ uint32 _pcmSfxChanMask;
+
TownsAudioInterfacePluginDriver *_drv;
bool _ready;
diff --git a/sound/softsynth/fmtowns_pc98/towns_euphony.cpp b/sound/softsynth/fmtowns_pc98/towns_euphony.cpp
index 4fe645e2fc..13120df17a 100644
--- a/sound/softsynth/fmtowns_pc98/towns_euphony.cpp
+++ b/sound/softsynth/fmtowns_pc98/towns_euphony.cpp
@@ -130,8 +130,19 @@ void TownsEuphonyDriver::unloadWaveTable(int id) {
_intf->callback(35, id);
}
-void TownsEuphonyDriver::reserveSfxChannels(int num) {
+void TownsEuphonyDriver::reserveSoundEffectChannels(int num) {
_intf->callback(33, num);
+ uint32 volMask = 0;
+
+ if (num > 8)
+ return;
+
+ for (uint32 v = 1 << 13; num; num--) {
+ volMask |= v;
+ v >>= 1;
+ }
+
+ _intf->setSoundEffectChanMask(volMask);
}
int TownsEuphonyDriver::setMusicTempo(int tempo) {
@@ -289,6 +300,14 @@ void TownsEuphonyDriver::timerCallback(int timerId) {
}
}
+void TownsEuphonyDriver::setMusicVolume(int volume) {
+ _intf->setMusicVolume(volume);
+}
+
+void TownsEuphonyDriver::setSoundEffectVolume(int volume) {
+ _intf->setSoundEffectVolume(volume);
+}
+
void TownsEuphonyDriver::resetTables() {
memset(_tEnable, 0xff, 32);
memset(_tMode, 0xff, 16);
diff --git a/sound/softsynth/fmtowns_pc98/towns_euphony.h b/sound/softsynth/fmtowns_pc98/towns_euphony.h
index c869b612a3..47cfdcb2b9 100644
--- a/sound/softsynth/fmtowns_pc98/towns_euphony.h
+++ b/sound/softsynth/fmtowns_pc98/towns_euphony.h
@@ -39,7 +39,7 @@ public:
void loadInstrument(int chanType, int id, const uint8 *data);
void loadWaveTable(const uint8 *data);
void unloadWaveTable(int id);
- void reserveSfxChannels(int num);
+ void reserveSoundEffectChannels(int num);
int setMusicTempo(int tempo);
int startMusicTrack(const uint8 *data, int trackSize, int startTick);
@@ -66,6 +66,9 @@ public:
void timerCallback(int timerId);
+ void setMusicVolume(int volume);
+ void setSoundEffectVolume(int volume);
+
TownsAudioInterface *intf() {
return _intf;
}
diff --git a/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp b/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp
index 7a91cb81b9..507c8e159a 100644
--- a/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp
+++ b/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp
@@ -1157,12 +1157,12 @@ uint8 TownsPC98_FmSynth::readSSGStatus() {
void TownsPC98_FmSynth::setVolumeIntern(int volA, int volB) {
Common::StackLock lock(_mutex);
- _volumeA = volA;
- _volumeB = volB;
+ _volumeA = CLIP<uint16>(volA, 0, Audio::Mixer::kMaxMixerVolume);
+ _volumeB = CLIP<uint16>(volB, 0, Audio::Mixer::kMaxMixerVolume);
if (_ssg)
- _ssg->setVolumeIntern(volA, volB);
+ _ssg->setVolumeIntern(_volumeA, _volumeB);
if (_prc)
- _prc->setVolumeIntern(volA, volB);
+ _prc->setVolumeIntern(_volumeA, _volumeB);
}
void TownsPC98_FmSynth::setVolumeChannelMasks(int channelMaskA, int channelMaskB) {