Ticket #9102: 0001-Implement-sound-volume-changing.patch

File 0001-Implement-sound-volume-changing.patch, 5.1 KB (added by SF/lwalkera, 15 years ago)

The patch

  • engines/sci/engine/ksound.cpp

    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) {  
    474474                int vol = (argc > 1) ? argv[1].toSint16() : -1;
    475475
    476476                if (vol != -1)
    477                         s->_sound.sfx_set_volume(vol << 0xf);
     477                        s->_sound.sfx_set_volume(vol);
    478478                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());
    480480                break;
    481481        }
    482482        case _K_SCI01_SOUND_MUTE_SOUND : {
    static reg_t kDoSoundSci1Late(EngineState *s, int argc, reg_t *argv) {  
    781781
    782782        switch (command) {
    783783        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};
    785786
    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;
    791795        }
    792796        case _K_SCI1_SOUND_MUTE_SOUND : {
    793797                /* if there's a parameter, we're setting it.  Otherwise,
  • engines/sci/sfx/core.cpp

    diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp
    index fe044e9..0880144 100644
    a b public:  
    133133         * @param argv  the buffer itself
    134134         */
    135135        void tell_synth(int buf_nr, byte *buf);
     136
     137        void set_volume(int vol);
     138
     139        int get_volume(void);
    136140};
    137141
    138142SfxPlayer::SfxPlayer() {
    Common::Error SfxPlayer::resume() {  
    316320        return Common::kNoError;
    317321}
    318322
     323void SfxPlayer::set_volume(int vol) {
     324        _mididrv->setVolume(vol);
     325}
     326
     327int SfxPlayer::get_volume(void) {
     328        return _mididrv->getVolume();
     329}
    319330
    320331#pragma mark -
    321332
    Common::Error SfxState::sfx_send_midi(SongHandle handle, int channel,  
    986997}
    987998
    988999int SfxState::sfx_get_volume() {
    989         warning("FIXME: Implement volume");
    990         return 0;
     1000        return _player->get_volume();
    9911001}
    9921002
    9931003void SfxState::sfx_set_volume(int volume) {
    994         warning("FIXME: Implement volume");
     1004        _player->set_volume(volume);
    9951005}
    9961006
    9971007void SfxState::sfx_all_stop() {
  • engines/sci/sfx/sci_midi.h

    diff --git a/engines/sci/sfx/sci_midi.h b/engines/sci/sfx/sci_midi.h
    index 9facca2..b8227db 100644
    a b namespace Sci {  
    3535class ResourceManager;
    3636
    3737enum {
    38         MIDI_CHANNELS = 16
     38        MIDI_CHANNELS = 16,
     39        MIDI_PROP_MASTER_VOLUME = 0
    3940};
    4041
    4142
    public:  
    8081        virtual int getPolyphony() const = 0;
    8182
    8283        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;
    8791        }
    8892
    8993        virtual void playSwitch(bool play) {
  • engines/sci/sfx/softseq/adlib.cpp

    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) {  
    629629        return true;
    630630}
    631631
     632uint32 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
    632646int MidiPlayer_Adlib::open(ResourceManager *resMan) {
    633647        assert(resMan != NULL);
    634648
  • engines/sci/sfx/softseq/adlib.h

    diff --git a/engines/sci/sfx/softseq/adlib.h b/engines/sci/sfx/softseq/adlib.h
    index 771bdc3..8daa73f 100644
    a b public:  
    3636        };
    3737
    3838        MidiDriver_Adlib(Audio::Mixer *mixer) : MidiDriver_Emulated(mixer), _playSwitch(true), _masterVolume(15), _rhythmKeyMap(0), _opl(0) { }
    39         ~MidiDriver_Adlib() { }
     39        virtual ~MidiDriver_Adlib() { }
    4040
    4141        // MidiDriver
    4242        int open(bool isSCI0);
    public:  
    5656        void playSwitch(bool play);
    5757        bool loadResource(const byte *data, uint size);
    5858
     59        virtual uint32 property(int prop, uint32 param);
     60
    5961private:
    6062        enum ChannelID {
    6163                kLeftChannel = 1,