Ticket #8341: output-freq-alt.diff

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

Alternative patch, without setOuputSampleRate()

  • README

    diff -urN ScummVM/README ScummVM+test/README
    old new  
    3434 * 7.3 Native MIDI support
    3535 * 7.4 UNIX native & ALSA sequencer support
    3636 * 7.5 Using compressed audiofiles (MP3, Ogg Vorbis, Flac)
     37 * 7.6 Output sample rate
    37388.0) Configuration Files
    38399.0) Compiling
    3940X.X) Credits
     
    330331                           atari, fmtowns, mac, pc)
    331332  --multi-midi             Enable combination of Adlib and native MIDI
    332333  --native-mt32            True Roland MT-32 (disable GM emulation)
     334  --output-rate=RATE       Select output sample rate in Hz (e.g. 22050)
    333335  --aspect-ratio           Enable aspect ratio correction
    334336
    335337  --alt-intro              Use alternative intro for CD versions of Beneath a
     
    861863Eventually you will have a much smaller *.mp3, *.ogg or *.fla file, copy this
    862864file to your game dir. You can safely remove the old file.
    863865
     8667.6) Output sample rate:
     867---- -------------------
     868
     869The output sample rate tells ScummVM how many sound samples to play per channel
     870per second. There is much that could be said on this subject, but most of it
     871would be irrelevant here. The short version is that for most games 22050 Hz is
     872fine, but in some cases 44100 Hz is preferable. On extremely low-end systems
     873you may want to use 11025 Hz, but it's unlikely that you have to worry about
     874that.
     875
     876To elaborate, most of the sounds ScummVM has to play were sampled at either
     87722050 Hz or 11025 Hz. Using a higher sample rate will not magically improve the
     878quality of these sounds. Hence, 22050 Hz is fine.
     879
     880Some games use CD audio. If you use compressed files for this, they are
     881probably sampled at 44100 Hz, so for these games that may be a better choice of
     882sample rate.
     883
     884When using the Adlib, FM Towns, PC Speaker or IBM PCjr music drivers, ScummVM
     885is responsible for generating the samples. Usually 22050 Hz will be plenty for
     886these, but there is at least one piece of Adlib music in Beneath a Steeel Sky
     887that will sound a lot better at 44100 Hz.
     888
     889Using frequencies in between is not recommended. For one thing, your sound card
     890may not support it. In theory, ScummVM should fall back on a sensible frequency
     891in that case, but don't count on it. More importantly, ScummVM has to resample
     892all sounds to its output frequency. This is much easier to do well if the
     893output frequency is a multiple of the original frequency.
     894
    864895
    8658968.0) Configuration file:
    866897---- -------------------
     
    944975        joystick_num    number   Number of joystick device to use for input
    945976        master_volume   number   The master volume setting (0-255)
    946977        music_driver    string   The music engine to use.
     978        output_rate     number   The output sample rate to use, in Hz. Sensible
     979                                 values are 11025, 22050 and 44100.
    947980        alsa_port       string   Port to use for output when using the
    948981                                 ALSA music driver.
    949982        music_volume    number   The music volume setting (0-255)
  • backends/sdl/sdl-common.h

    diff -urN ScummVM/backends/sdl/sdl-common.h ScummVM+test/backends/sdl/sdl-common.h
    old new  
    169169        SDL_Surface *_tmpscreen;
    170170        bool _overlayVisible;
    171171
     172        // Audio
     173        int _samplesPerSec;
     174
    172175        // CD Audio
    173176        SDL_CD *_cdrom;
    174177        int cd_track, cd_num_loops, cd_start_frame, cd_duration;
  • backends/sdl/sdl.cpp

    diff -urN ScummVM/backends/sdl/sdl.cpp ScummVM+test/backends/sdl/sdl.cpp
    old new  
    9595#endif
    9696        _hwscreen(0), _screen(0), _screenWidth(0), _screenHeight(0),
    9797        _tmpscreen(0), _overlayVisible(false),
     98        _samplesPerSec(0),
    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        if (ConfMan.hasKey("output_rate"))
     298                _samplesPerSec = ConfMan.getInt("output_rate");
     299        else
     300                _samplesPerSec = SAMPLES_PER_SEC;
     301
     302        // Originally, we always used 2048 samples. This loop will produce the
     303        // same result at 22050 Hz, and should hopefully produce something
     304        // sensible for other frequencies. Note that it must be a power of two.
     305
     306        uint16 samples = 0x8000;
     307
     308        for (;;) {
     309                if (samples / (_samplesPerSec / 1000) < 100)
     310                        break;
     311                samples >>= 1;
     312        }
     313
     314        desired.freq = _samplesPerSec;
    296315        desired.format = AUDIO_S16SYS;
    297316        desired.channels = 2;
    298         desired.samples = 2048;
     317        desired.samples = samples;
    299318        desired.callback = proc;
    300319        desired.userdata = param;
    301         if (SDL_OpenAudio(&desired, NULL) != 0) {
     320        if (SDL_OpenAudio(&desired, &obtained) != 0) {
    302321                return false;
    303322        }
     323        // Note: This should be the obtained output rate, but it seems that at
     324        // least on some platforms SDL will lie and claim it did get the rate
     325        // even if it didn't. Probably only happens for "weird" rates, though.
     326        _samplesPerSec = obtained.freq;
    304327        SDL_PauseAudio(0);
    305328        return true;
    306329}
     
    310333}
    311334
    312335int OSystem_SDL::getOutputSampleRate() const {
    313         return SAMPLES_PER_SEC;
     336        return _samplesPerSec;
    314337}
    315338
    316339#pragma mark -
  • base/gameDetector.cpp

    diff -urN ScummVM/base/gameDetector.cpp ScummVM+test/base/gameDetector.cpp
    old new  
    7878        "                           atari, fmtowns, mac, pc)\n"
    7979        "  --multi-midi             Enable combination Adlib and native MIDI\n"
    8080        "  --native-mt32            True Roland MT-32 (disable GM emulation)\n"
     81        "  --output-rate=RATE       Select output sample rate in Hz (e.g. 22050)\n"
    8182        "  --aspect-ratio           Enable aspect ratio correction\n"
    8283        "\n"
    8384#if !defined(DISABLE_SKY) || !defined(DISABLE_QUEEN)
     
    312313                                ConfMan.set("music_driver", option, kTransientDomain);
    313314                        END_OPTION
    314315
     316                        DO_LONG_OPTION("output-rate")
     317                                ConfMan.set("output_rate", (int)strtol(option, 0, 10), kTransientDomain);
     318                        END_OPTION
     319
    315320                        DO_OPTION_BOOL('f', "fullscreen")
    316321                                ConfMan.set("fullscreen", cmdValue, kTransientDomain);
    317322                        END_OPTION
  • doc/05_01.tex

    diff -urN ScummVM/doc/05_01.tex ScummVM+test/doc/05_01.tex
    old new  
    3737                          &atari, fmtowns, mac, pc)\\
    3838  --multi-midi            &Enable combination of Adlib and native MIDI\\
    3939  --native-mt32           &True Roland MT-32 (disable GM emulation)\\
     40  --output-rate=RATE      &Select output sample rate in Hz (e.g. 22050)\\
    4041  --aspect-ratio          &Enable aspect ratio correction\\
    4142\\
    4243  --alt-intro             &Use alternative intro for CD versions of Beneath a\\
  • doc/07.tex

    diff -urN ScummVM/doc/07.tex ScummVM+test/doc/07.tex
    old new  
    3434\input {07_02.tex}
    3535\input {07_03.tex}
    3636\input {07_04.tex}
    37 \input {07_05.tex}
    38  No newline at end of file
     37\input {07_05.tex}
     38\input {07_06.tex}
  • doc/07_06.tex

    diff -urN ScummVM/doc/07_06.tex ScummVM+test/doc/07_06.tex
    old new  
     1
     2%%% Local Variables:
     3%%% mode: latex
     4%%% TeX-master: "readme"
     5%%% End:
     6
     7\subsection{Output sample rate}
     8
     9The output sample rate tells ScummVM how many sound samples to play per channel
     10per second. There is much that could be said on this subject, but most of it
     11would be irrelevant here. The short version is that for most games 22050 Hz is
     12fine, but in some cases 44100 Hz is preferable. On extremely low-end systems
     13you may want to use 11025 Hz, but it's unlikely that you have to worry about
     14that.
     15
     16To elaborate, most of the sounds ScummVM has to play were sampled at either
     1722050 Hz or 11025 Hz. Using a higher sample rate will not magically improve the
     18quality of these sounds. Hence, 22050 Hz is fine.
     19
     20Some games use CD audio. If you use compressed files for this, they are
     21probably sampled at 44100 Hz, so for these games that may be a better choice of
     22sample rate.
     23
     24When using the Adlib, FM Towns, PC Speaker or IBM PCjr music drivers, ScummVM
     25is responsible for generating the samples. Usually 22050 Hz will be plenty for
     26these, but there is at least one piece of Adlib music in Beneath a Steeel Sky
     27that will sound a lot better at 44100 Hz.
     28
     29Using frequencies in between is not recommended. For one thing, your sound card
     30may not support it. In theory, ScummVM should fall back on a sensible frequency
     31in that case, but don't count on it. More importantly, ScummVM has to resample
     32all sounds to its output frequency. This is much easier to do well if the
     33output frequency is a multiple of the original frequency.
  • doc/08.tex

    diff -urN ScummVM/doc/08.tex ScummVM+test/doc/08.tex
    old new  
    9292        joystick\_num   &number   Number of joystick device to use for input\\
    9393        master\_volume  &number   The master volume setting (0-255)\\
    9494        music\_driver   &string   The music engine to use.\\
     95        output\_rate    &number   The output sample rate to use, in Hz. Sensible\\
     96                        &         values are 11025, 22050 and 44100.\\
    9597        alsa\_port      &string   Port to use for output when using the\\
    9698                        &         ALSA music driver.\\
    9799        music\_volume   &number   The music volume setting (0-255)\\
  • sound/mixer.cpp

    diff -urN ScummVM/sound/mixer.cpp ScummVM+test/sound/mixer.cpp
    old new  
    111111        _premixProc = 0;
    112112        int i = 0;
    113113
    114         _outputRate = (uint) _syst->getOutputSampleRate();
    115 
    116         if (_outputRate == 0)
    117                 error("OSystem returned invalid sample rate");
    118 
    119114        _globalVolume = 0;
    120115        _musicVolume = 0;
    121116
     
    125120                _channels[i] = 0;
    126121
    127122        _mixerReady = _syst->setSoundCallback(mixCallback, this);
     123        _outputRate = (uint) _syst->getOutputSampleRate();
     124
     125        if (_outputRate == 0)
     126                error("OSystem returned invalid sample rate");
     127
     128        debug(1, "Output sample rate: %d Hz", _outputRate);
    128129}
    129130
    130131SoundMixer::~SoundMixer() {