Ticket #8430: gob-beeper.diff

File gob-beeper.diff, 4.5 KB (added by eriktorbjorn, 19 years ago)

Patch against a May 5 CVS snapshot

  • gob/goblin.cpp

    diff -ur ScummVM-cvs20050505/gob/goblin.cpp ScummVM-cvs20050505+hack/gob/goblin.cpp
    old new  
    15621562        if (gobDesc->state >= 0 && gobDesc->state < 10 &&
    15631563            gobDesc->stateMach == gobDesc->realStateMach &&
    15641564            (gobDesc->curFrame == 3 || gobDesc->curFrame == 6)) {
    1565                 snd_speakerOn(10 * util_getRandom(3) + 50);
    1566                 util_delay(5);
    1567                 snd_speakerOff();
     1565                snd_speakerOn(10 * util_getRandom(3) + 50, 5);
    15681566        }
    15691567
    15701568        if (gob_currentGoblin == 0
  • gob/inter.cpp

    diff -ur ScummVM-cvs20050505/gob/inter.cpp ScummVM-cvs20050505+hack/gob/inter.cpp
    old new  
    13141314                                break;
    13151315
    13161316                        case 2:
    1317                                 snd_speakerOn(parse_parseValExpr());
     1317                                snd_speakerOn(parse_parseValExpr(), -1);
    13181318                                break;
    13191319
    13201320                        case 3:
  • gob/sound.cpp

    diff -ur ScummVM-cvs20050505/gob/sound.cpp ScummVM-cvs20050505+hack/gob/sound.cpp
    old new  
    1919 * $Header: /cvsroot/scummvm/scummvm/gob/sound.cpp,v 1.9 2005/05/01 10:15:30 eriktorbjorn Exp $
    2020 *
    2121 */
     22
     23#include "sound/audiostream.h"
     24
    2225#include "gob/gob.h"
    2326#include "gob/global.h"
    2427#include "gob/sound.h"
     28
    2529namespace Gob {
    2630
     31// TODO: This is a very primitive square wave generator. The only thing is
     32//       has in common with the PC speaker is that it sounds terrible.
     33
     34class SquareWaveStream : public AudioStream {
     35private:
     36        uint _rate;
     37        bool _beepForever;
     38        uint32 _periodLength;
     39        uint32 _periodSamples;
     40        uint32 _remainingSamples;
     41        int16 _sampleValue;
     42
     43public:
     44        SquareWaveStream() {}
     45        ~SquareWaveStream() {}
     46
     47        void playNote(int freq, int32 ms);
     48
     49        int readBuffer(int16 *buffer, const int numSamples);
     50
     51        bool endOfData() const  { return _remainingSamples == 0; }
     52        bool isStereo() const   { return false; }
     53        int getRate() const     { return _rate; }
     54};
     55
     56void SquareWaveStream::playNote(int freq, int32 ms) {
     57        _rate = _vm->_mixer->getOutputRate();
     58        _periodLength = _rate / (2 * freq);
     59        _periodSamples = 0;
     60        _sampleValue = 25000;
     61        if (ms == -1) {
     62                _remainingSamples = 1;
     63                _beepForever = true;
     64        } else {
     65                _remainingSamples = (_rate * ms) / 1000;
     66                _beepForever = false;
     67        }
     68}
     69
     70int SquareWaveStream::readBuffer(int16 *buffer, const int numSamples) {
     71        int samples = 0;
     72
     73        while (samples < numSamples && _remainingSamples > 0) {
     74                *buffer++ = _sampleValue;
     75                if (_periodSamples++ > _periodLength) {
     76                        _periodSamples = 0;
     77                        _sampleValue = -_sampleValue;
     78                }
     79                samples++;
     80                if (!_beepForever)
     81                        _remainingSamples--;
     82        }
     83
     84        return samples;
     85}
     86
     87SquareWaveStream speakerStream;
     88SoundHandle speakerHandle;
    2789Snd_SoundDesc *snd_loopingSounds[5]; // Should be enough
    2890
    2991void snd_initSound(void) {
     
    48110int16 snd_checkAdlib(void) {return 0;}
    49111int16 snd_checkBlaster(void) {return 0;}
    50112void snd_setBlasterPort(int16 port) {return;}
    51 void snd_speakerOn(int16 frequency) {return;}
    52 void snd_speakerOff(void) {return;}
     113
     114void snd_speakerOn(int16 frequency, int32 length) {
     115        speakerStream.playNote(frequency, length);
     116        if (!_vm->_mixer->isSoundHandleActive(speakerHandle)) {
     117                _vm->_mixer->playInputStream(SoundMixer::kSFXSoundType, &speakerHandle, &speakerStream, -1, 255, 0, false);
     118        }
     119}
     120
     121void snd_speakerOff(void) {
     122        _vm->_mixer->stopHandle(speakerHandle);
     123}
     124
    53125void snd_stopSound(int16 arg){return;}
    54126void snd_setResetTimerFlag(char flag){return;}
    55127
  • gob/sound.h

    diff -ur ScummVM-cvs20050505/gob/sound.h ScummVM-cvs20050505+hack/gob/sound.h
    old new  
    3030int16 snd_checkAdlib(void);
    3131int16 snd_checkBlaster(void);
    3232void snd_setBlasterPort(int16 port);
    33 void snd_speakerOn(int16 frequency);
     33void snd_speakerOn(int16 frequency, int32 length);
    3434void snd_speakerOff(void);
    3535void snd_stopSound(int16 arg);
    3636void snd_setResetTimerFlag(char flag);
  • gob/util.cpp

    diff -ur ScummVM-cvs20050505/gob/util.cpp ScummVM-cvs20050505+hack/gob/util.cpp
    old new  
    192192        if (soundFlags == 0)
    193193                return;
    194194
    195         //sound(freq);
    196         util_delay(50);
    197         //nosound();
     195        snd_speakerOn(freq, 50);
    198196}
    199197
    200198uint32 util_getTimeKey(void) {