From 384350b919a1040e402b1f83c8ece1a5a19c1611 Mon Sep 17 00:00:00 2001
From: Laine Walker-Avina <lwalkera@ieee.org>
Date: Sun, 18 Oct 2009 20:33:02 +0000
Subject: [PATCH] Implement sound volume changing:
add accessor for masterVolume
make get and setVolume calls use virtual propery method of the MidiDriver
Implement calls to get/setVolume in ksound.cpp
remove accidental changes to kgraphics
fix formatting
---
engines/sci/engine/ksound.cpp | 22 +++++++++++++---------
engines/sci/sfx/core.cpp | 16 +++++++++++++---
engines/sci/sfx/sci_midi.h | 14 +++++++++-----
engines/sci/sfx/softseq/adlib.cpp | 14 ++++++++++++++
engines/sci/sfx/softseq/adlib.h | 4 +++-
5 files changed, 52 insertions(+), 18 deletions(-)
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index 74a08fd..daef17c 100644
a
|
b
|
static reg_t kDoSoundSci1Early(EngineState *s, int argc, reg_t *argv) {
|
474 | 474 | int vol = (argc > 1) ? argv[1].toSint16() : -1; |
475 | 475 | |
476 | 476 | if (vol != -1) |
477 | | s->_sound.sfx_set_volume(vol << 0xf); |
| 477 | s->_sound.sfx_set_volume(vol); |
478 | 478 | else |
479 | | s->r_acc = make_reg(0, s->_sound.sfx_get_volume() >> 0xf); |
| 479 | s->r_acc = make_reg(0, s->_sound.sfx_get_volume()); |
480 | 480 | break; |
481 | 481 | } |
482 | 482 | case _K_SCI01_SOUND_MUTE_SOUND : { |
… |
… |
static reg_t kDoSoundSci1Late(EngineState *s, int argc, reg_t *argv) {
|
781 | 781 | |
782 | 782 | switch (command) { |
783 | 783 | case _K_SCI1_SOUND_MASTER_VOLME : { |
784 | | /*int vol = UPARAM_OR_ALT (1, -1); |
| 784 | int vol = (argc > 1 ? argv[1].offset : -1); |
| 785 | reg_t reg = {0,0}; |
785 | 786 | |
786 | | if (vol != -1) |
787 | | s->acc = s->sound_server->command(s, SOUND_COMMAND_SET_VOLUME, 0, vol); |
788 | | else |
789 | | s->acc = s->sound_server->command(s, SOUND_COMMAND_GET_VOLUME, 0, 0); |
790 | | break;*/ |
| 787 | if (vol != -1) { |
| 788 | s->_sound.sfx_set_volume(vol); |
| 789 | reg.offset = s->_sound.sfx_get_volume(); |
| 790 | } else { |
| 791 | reg.offset = s->_sound.sfx_get_volume(); |
| 792 | } |
| 793 | s->r_acc = reg; |
| 794 | break; |
791 | 795 | } |
792 | 796 | case _K_SCI1_SOUND_MUTE_SOUND : { |
793 | 797 | /* if there's a parameter, we're setting it. Otherwise, |
diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp
index fe044e9..0880144 100644
a
|
b
|
public:
|
133 | 133 | * @param argv the buffer itself |
134 | 134 | */ |
135 | 135 | void tell_synth(int buf_nr, byte *buf); |
| 136 | |
| 137 | void set_volume(int vol); |
| 138 | |
| 139 | int get_volume(void); |
136 | 140 | }; |
137 | 141 | |
138 | 142 | SfxPlayer::SfxPlayer() { |
… |
… |
Common::Error SfxPlayer::resume() {
|
316 | 320 | return Common::kNoError; |
317 | 321 | } |
318 | 322 | |
| 323 | void SfxPlayer::set_volume(int vol) { |
| 324 | _mididrv->setVolume(vol); |
| 325 | } |
| 326 | |
| 327 | int SfxPlayer::get_volume(void) { |
| 328 | return _mididrv->getVolume(); |
| 329 | } |
319 | 330 | |
320 | 331 | #pragma mark - |
321 | 332 | |
… |
… |
Common::Error SfxState::sfx_send_midi(SongHandle handle, int channel,
|
986 | 997 | } |
987 | 998 | |
988 | 999 | int SfxState::sfx_get_volume() { |
989 | | warning("FIXME: Implement volume"); |
990 | | return 0; |
| 1000 | return _player->get_volume(); |
991 | 1001 | } |
992 | 1002 | |
993 | 1003 | void SfxState::sfx_set_volume(int volume) { |
994 | | warning("FIXME: Implement volume"); |
| 1004 | _player->set_volume(volume); |
995 | 1005 | } |
996 | 1006 | |
997 | 1007 | void SfxState::sfx_all_stop() { |
diff --git a/engines/sci/sfx/sci_midi.h b/engines/sci/sfx/sci_midi.h
index 9facca2..b8227db 100644
a
|
b
|
namespace Sci {
|
35 | 35 | class ResourceManager; |
36 | 36 | |
37 | 37 | enum { |
38 | | MIDI_CHANNELS = 16 |
| 38 | MIDI_CHANNELS = 16, |
| 39 | MIDI_PROP_MASTER_VOLUME = 0 |
39 | 40 | }; |
40 | 41 | |
41 | 42 | |
… |
… |
public:
|
80 | 81 | virtual int getPolyphony() const = 0; |
81 | 82 | |
82 | 83 | virtual void setVolume(byte volume) { |
83 | | // Master Volume SysEx message |
84 | | const byte message[] = {0x7f, 0x7f, 0x04, 0x01, (volume * 127 / 15) & 0x7f, (volume * 127 / 15) & 0x7f}; |
85 | | |
86 | | _driver->sysEx(message, 6); |
| 84 | if(_driver) |
| 85 | _driver->property(MIDI_PROP_MASTER_VOLUME, volume); |
| 86 | } |
| 87 | virtual int getVolume() { |
| 88 | if(_driver) |
| 89 | return _driver->property(MIDI_PROP_MASTER_VOLUME, -1); |
| 90 | return 0; |
87 | 91 | } |
88 | 92 | |
89 | 93 | virtual void playSwitch(bool play) { |
diff --git a/engines/sci/sfx/softseq/adlib.cpp b/engines/sci/sfx/softseq/adlib.cpp
index 15e1ed9..71f6d74 100644
a
|
b
|
bool MidiDriver_Adlib::loadResource(const byte *data, uint size) {
|
629 | 629 | return true; |
630 | 630 | } |
631 | 631 | |
| 632 | uint32 MidiDriver_Adlib::property(int prop, uint32 param) { |
| 633 | switch(prop) { |
| 634 | case MIDI_PROP_MASTER_VOLUME: { |
| 635 | if((int32)param != -1) |
| 636 | _masterVolume = param; |
| 637 | return _masterVolume; |
| 638 | break; |
| 639 | } |
| 640 | default: |
| 641 | break; |
| 642 | } |
| 643 | return -1; |
| 644 | } |
| 645 | |
632 | 646 | int MidiPlayer_Adlib::open(ResourceManager *resMan) { |
633 | 647 | assert(resMan != NULL); |
634 | 648 | |
diff --git a/engines/sci/sfx/softseq/adlib.h b/engines/sci/sfx/softseq/adlib.h
index 771bdc3..8daa73f 100644
a
|
b
|
public:
|
36 | 36 | }; |
37 | 37 | |
38 | 38 | MidiDriver_Adlib(Audio::Mixer *mixer) : MidiDriver_Emulated(mixer), _playSwitch(true), _masterVolume(15), _rhythmKeyMap(0), _opl(0) { } |
39 | | ~MidiDriver_Adlib() { } |
| 39 | virtual ~MidiDriver_Adlib() { } |
40 | 40 | |
41 | 41 | // MidiDriver |
42 | 42 | int open(bool isSCI0); |
… |
… |
public:
|
56 | 56 | void playSwitch(bool play); |
57 | 57 | bool loadResource(const byte *data, uint size); |
58 | 58 | |
| 59 | virtual uint32 property(int prop, uint32 param); |
| 60 | |
59 | 61 | private: |
60 | 62 | enum ChannelID { |
61 | 63 | kLeftChannel = 1, |