mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-21 11:41:25 +00:00
KYRA/TOWNS: implement music/sfx volume control via GUI/GMM
svn-id: r51695
This commit is contained in:
parent
221934ea93
commit
5962b0bbe2
@ -122,6 +122,8 @@ public:
|
||||
|
||||
void beginFadeOut();
|
||||
|
||||
void updateVolumeSettings();
|
||||
|
||||
private:
|
||||
bool loadInstruments();
|
||||
void playEuphonyTrack(uint32 offset, int loop);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user