Ticket #8341: output-freq.diff

File output-freq.diff, 3.9 KB (added by eriktorbjorn, 20 years ago)

Patch against a May 20 CVS snapshot

  • backends/sdl/sdl-common.h

    diff -ur --exclude=CVS ScummVM/backends/sdl/sdl-common.h ScummVM+hack/backends/sdl/sdl-common.h
    old new  
    133133       
    134134        virtual void setWindowCaption(const char *caption);
    135135        virtual bool openCD(int drive);
     136        virtual void setOutputSampleRate(int rate);
    136137        virtual int getOutputSampleRate() const;
    137138
    138139        virtual bool hasFeature(Feature f);
     
    169170        SDL_Surface *_tmpscreen;
    170171        bool _overlayVisible;
    171172
     173        // Audio
     174        int _samplesPerSec;
     175
    172176        // CD Audio
    173177        SDL_CD *_cdrom;
    174178        int cd_track, cd_num_loops, cd_start_frame, cd_duration;
  • backends/sdl/sdl.cpp

    diff -ur --exclude=CVS ScummVM/backends/sdl/sdl.cpp ScummVM+hack/backends/sdl/sdl.cpp
    old new  
    9595#endif
    9696        _hwscreen(0), _screen(0), _screenWidth(0), _screenHeight(0),
    9797        _tmpscreen(0), _overlayVisible(false),
     98        _samplesPerSec(SAMPLES_PER_SEC),
    9899        _cdrom(0), _scaler_proc(0), _modeChanged(false), _dirty_checksums(0),
    99100        _mouseVisible(false), _mouseDrawn(false), _mouseData(0),
    100101        _mouseHotspotX(0), _mouseHotspotY(0),
     
    289290
    290291bool OSystem_SDL::setSoundCallback(SoundProc proc, void *param) {
    291292        SDL_AudioSpec desired;
     293        SDL_AudioSpec obtained;
    292294
    293295        memset(&desired, 0, sizeof(desired));
    294296
    295         desired.freq = SAMPLES_PER_SEC;
     297        desired.freq = _samplesPerSec;
    296298        desired.format = AUDIO_S16SYS;
    297299        desired.channels = 2;
    298300        desired.samples = 2048;
    299301        desired.callback = proc;
    300302        desired.userdata = param;
    301         if (SDL_OpenAudio(&desired, NULL) != 0) {
     303        if (SDL_OpenAudio(&desired, &obtained) != 0) {
    302304                return false;
    303305        }
     306        // Note: This should be the obtained output rate, but it seems that at
     307        // least on some platforms SDL will lie and claim it did get the rate
     308        // even if it didn't. Probably only happens for "weird" rates, though.
     309        _samplesPerSec = obtained.freq;
    304310        SDL_PauseAudio(0);
    305311        return true;
    306312}
     
    309315        SDL_CloseAudio();
    310316}
    311317
     318void OSystem_SDL::setOutputSampleRate(int rate) {
     319        _samplesPerSec = rate;
     320}
     321
    312322int OSystem_SDL::getOutputSampleRate() const {
    313         return SAMPLES_PER_SEC;
     323        return _samplesPerSec;
    314324}
    315325
    316326#pragma mark -
  • common/system.h

    diff -ur --exclude=CVS ScummVM/common/system.h ScummVM+hack/common/system.h
    old new  
    546546        virtual void clearSoundCallback() = 0;
    547547
    548548        /**
     549         * Set the desired output sample rate. It has to be called before
     550         * setSoundCallback(), and it's not certain that we actually get it.
     551         * Use getOutputSampleRate() to find out.
     552         */
     553        virtual void setOutputSampleRate(int rate) = 0;
     554
     555        /**
    549556         * Determine the output sample rate. Audio data provided by the sound
    550557         * callback will be played using this rate.
    551558         * @return the output sample rate
  • sound/mixer.cpp

    diff -ur --exclude=CVS ScummVM/sound/mixer.cpp ScummVM+hack/sound/mixer.cpp
    old new  
    2121 */
    2222
    2323#include "stdafx.h"
     24#include "common/config-manager.h"
    2425#include "common/file.h"
    2526#include "common/util.h"
    2627
     
    111112        _premixProc = 0;
    112113        int i = 0;
    113114
    114         _outputRate = (uint) _syst->getOutputSampleRate();
    115 
    116         if (_outputRate == 0)
    117                 error("OSystem returned invalid sample rate");
     115        if (ConfMan.hasKey("output_rate"))
     116                _syst->setOutputSampleRate(ConfMan.getInt("output_rate"));
    118117
    119118        _globalVolume = 0;
    120119        _musicVolume = 0;
     
    125124                _channels[i] = 0;
    126125
    127126        _mixerReady = _syst->setSoundCallback(mixCallback, this);
     127        _outputRate = (uint) _syst->getOutputSampleRate();
     128
     129        if (_outputRate == 0)
     130                error("OSystem returned invalid sample rate");
     131
     132        debug(1, "Output sample rate: %d Hz", _outputRate);
    128133}
    129134
    130135SoundMixer::~SoundMixer() {