diff -urN ScummVM/README ScummVM+test/README
--- ScummVM/README	2004-05-21 18:45:21.371875000 +0200
+++ ScummVM+test/README	2004-05-25 09:30:02.253125000 +0200
@@ -34,6 +34,7 @@
  * 7.3 Native MIDI support
  * 7.4 UNIX native & ALSA sequencer support
  * 7.5 Using compressed audiofiles (MP3, Ogg Vorbis, Flac)
+ * 7.6 Output sample rate
 8.0) Configuration Files
 9.0) Compiling
 X.X) Credits
@@ -330,6 +331,7 @@
                            atari, fmtowns, mac, pc)
   --multi-midi             Enable combination of Adlib and native MIDI
   --native-mt32            True Roland MT-32 (disable GM emulation)
+  --output-rate=RATE       Select output sample rate in Hz (e.g. 22050)
   --aspect-ratio           Enable aspect ratio correction
 
   --alt-intro              Use alternative intro for CD versions of Beneath a
@@ -861,6 +863,35 @@
 Eventually you will have a much smaller *.mp3, *.ogg or *.fla file, copy this
 file to your game dir. You can safely remove the old file.
 
+7.6) Output sample rate:
+---- -------------------
+
+The output sample rate tells ScummVM how many sound samples to play per channel
+per second. There is much that could be said on this subject, but most of it
+would be irrelevant here. The short version is that for most games 22050 Hz is
+fine, but in some cases 44100 Hz is preferable. On extremely low-end systems
+you may want to use 11025 Hz, but it's unlikely that you have to worry about
+that.
+
+To elaborate, most of the sounds ScummVM has to play were sampled at either
+22050 Hz or 11025 Hz. Using a higher sample rate will not magically improve the
+quality of these sounds. Hence, 22050 Hz is fine.
+
+Some games use CD audio. If you use compressed files for this, they are
+probably sampled at 44100 Hz, so for these games that may be a better choice of
+sample rate.
+
+When using the Adlib, FM Towns, PC Speaker or IBM PCjr music drivers, ScummVM
+is responsible for generating the samples. Usually 22050 Hz will be plenty for
+these, but there is at least one piece of Adlib music in Beneath a Steeel Sky
+that will sound a lot better at 44100 Hz.
+
+Using frequencies in between is not recommended. For one thing, your sound card
+may not support it. In theory, ScummVM should fall back on a sensible frequency
+in that case, but don't count on it. More importantly, ScummVM has to resample
+all sounds to its output frequency. This is much easier to do well if the
+output frequency is a multiple of the original frequency.
+
 
 8.0) Configuration file:
 ---- -------------------
@@ -944,6 +975,8 @@
         joystick_num    number   Number of joystick device to use for input
         master_volume   number   The master volume setting (0-255)
         music_driver    string   The music engine to use.
+        output_rate     number   The output sample rate to use, in Hz. Sensible
+                                 values are 11025, 22050 and 44100.
         alsa_port       string   Port to use for output when using the
                                  ALSA music driver.
         music_volume    number   The music volume setting (0-255)
diff -urN ScummVM/backends/sdl/sdl-common.h ScummVM+test/backends/sdl/sdl-common.h
--- ScummVM/backends/sdl/sdl-common.h	2004-05-09 16:59:52.093750000 +0200
+++ ScummVM+test/backends/sdl/sdl-common.h	2004-05-25 09:30:02.268750000 +0200
@@ -133,6 +133,7 @@
 	
 	virtual void setWindowCaption(const char *caption);
 	virtual bool openCD(int drive);
+	virtual void setOutputSampleRate(int rate);
 	virtual int getOutputSampleRate() const;
 
 	virtual bool hasFeature(Feature f);
@@ -169,6 +170,9 @@
 	SDL_Surface *_tmpscreen;
 	bool _overlayVisible;
 
+	// Audio
+	int _samplesPerSec;
+
 	// CD Audio
 	SDL_CD *_cdrom;
 	int cd_track, cd_num_loops, cd_start_frame, cd_duration;
diff -urN ScummVM/backends/sdl/sdl.cpp ScummVM+test/backends/sdl/sdl.cpp
--- ScummVM/backends/sdl/sdl.cpp	2004-05-09 16:59:52.109375000 +0200
+++ ScummVM+test/backends/sdl/sdl.cpp	2004-05-25 09:30:02.300000000 +0200
@@ -95,6 +95,7 @@
 #endif
 	_hwscreen(0), _screen(0), _screenWidth(0), _screenHeight(0),
 	_tmpscreen(0), _overlayVisible(false),
+	_samplesPerSec(SAMPLES_PER_SEC),
 	_cdrom(0), _scaler_proc(0), _modeChanged(false), _dirty_checksums(0),
 	_mouseVisible(false), _mouseDrawn(false), _mouseData(0),
 	_mouseHotspotX(0), _mouseHotspotY(0),
@@ -289,18 +290,35 @@
 
 bool OSystem_SDL::setSoundCallback(SoundProc proc, void *param) {
 	SDL_AudioSpec desired;
+	SDL_AudioSpec obtained;
 
 	memset(&desired, 0, sizeof(desired));
 
-	desired.freq = SAMPLES_PER_SEC;
+	// Originally, we always used 2048 samples. This loop will produce the
+	// same result at 22050 Hz, and should hopefully produce something
+	// sensible for other frequencies. Note that it must be a power of two.
+
+	uint16 samples = 0x8000;
+
+	for (;;) {
+		if (samples / (_samplesPerSec / 1000) < 100)
+			break;
+		samples >>= 1;
+	}
+
+	desired.freq = _samplesPerSec;
 	desired.format = AUDIO_S16SYS;
 	desired.channels = 2;
-	desired.samples = 2048;
+	desired.samples = samples;
 	desired.callback = proc;
 	desired.userdata = param;
-	if (SDL_OpenAudio(&desired, NULL) != 0) {
+	if (SDL_OpenAudio(&desired, &obtained) != 0) {
 		return false;
 	}
+	// Note: This should be the obtained output rate, but it seems that at
+	// least on some platforms SDL will lie and claim it did get the rate
+	// even if it didn't. Probably only happens for "weird" rates, though.
+	_samplesPerSec = obtained.freq;
 	SDL_PauseAudio(0);
 	return true;
 }
@@ -309,8 +327,14 @@
 	SDL_CloseAudio();
 }
 
+void OSystem_SDL::setOutputSampleRate(int rate) {
+	// The function can't be called after the audio device has been opened
+	if (SDL_GetAudioStatus() == SDL_AUDIO_STOPPED)
+		_samplesPerSec = rate;
+}
+
 int OSystem_SDL::getOutputSampleRate() const {
-	return SAMPLES_PER_SEC;
+	return _samplesPerSec;
 }
 
 #pragma mark -
diff -urN ScummVM/base/gameDetector.cpp ScummVM+test/base/gameDetector.cpp
--- ScummVM/base/gameDetector.cpp	2004-05-05 13:07:08.510000000 +0200
+++ ScummVM+test/base/gameDetector.cpp	2004-05-25 09:30:02.315625000 +0200
@@ -78,6 +78,7 @@
 	"                           atari, fmtowns, mac, pc)\n"
 	"  --multi-midi             Enable combination Adlib and native MIDI\n"
 	"  --native-mt32            True Roland MT-32 (disable GM emulation)\n"
+	"  --output-rate=RATE       Select output sample rate in Hz (e.g. 22050)\n"
 	"  --aspect-ratio           Enable aspect ratio correction\n"
 	"\n"
 #if !defined(DISABLE_SKY) || !defined(DISABLE_QUEEN)
@@ -312,6 +313,10 @@
 				ConfMan.set("music_driver", option, kTransientDomain);
 			END_OPTION
 
+			DO_LONG_OPTION("output-rate")
+				ConfMan.set("output_rate", (int)strtol(option, 0, 10), kTransientDomain);
+			END_OPTION
+
 			DO_OPTION_BOOL('f', "fullscreen")
 				ConfMan.set("fullscreen", cmdValue, kTransientDomain);
 			END_OPTION
diff -urN ScummVM/common/system.h ScummVM+test/common/system.h
--- ScummVM/common/system.h	2004-05-05 08:43:04.322500000 +0200
+++ ScummVM+test/common/system.h	2004-05-25 09:30:02.331250000 +0200
@@ -546,6 +546,13 @@
 	virtual void clearSoundCallback() = 0;
 
 	/**
+	 * Set the desired output sample rate. It has to be called before
+	 * setSoundCallback(), and it's not certain that we actually get it.
+	 * Use getOutputSampleRate() to find out.
+	 */
+	virtual void setOutputSampleRate(int rate) = 0;
+
+	/**
 	 * Determine the output sample rate. Audio data provided by the sound
 	 * callback will be played using this rate.
 	 * @return the output sample rate
diff -urN ScummVM/doc/05_01.tex ScummVM+test/doc/05_01.tex
--- ScummVM/doc/05_01.tex	2004-05-05 13:07:10.885000000 +0200
+++ ScummVM+test/doc/05_01.tex	2004-05-25 09:30:07.378125000 +0200
@@ -37,6 +37,7 @@
                           &atari, fmtowns, mac, pc)\\
   --multi-midi            &Enable combination of Adlib and native MIDI\\
   --native-mt32           &True Roland MT-32 (disable GM emulation)\\
+  --output-rate=RATE      &Select output sample rate in Hz (e.g. 22050)\\
   --aspect-ratio          &Enable aspect ratio correction\\
 \\
   --alt-intro             &Use alternative intro for CD versions of Beneath a\\
diff -urN ScummVM/doc/07.tex ScummVM+test/doc/07.tex
--- ScummVM/doc/07.tex	2004-02-09 11:54:58.111250000 +0100
+++ ScummVM+test/doc/07.tex	2004-05-25 09:30:07.393750000 +0200
@@ -34,4 +34,5 @@
 \input {07_02.tex}
 \input {07_03.tex}
 \input {07_04.tex}
-\input {07_05.tex}
\ No newline at end of file
+\input {07_05.tex}
+\input {07_06.tex}
diff -urN ScummVM/doc/07_06.tex ScummVM+test/doc/07_06.tex
--- ScummVM/doc/07_06.tex	1970-01-01 01:00:00.000000000 +0100
+++ ScummVM+test/doc/07_06.tex	2004-05-25 09:32:03.409375000 +0200
@@ -0,0 +1,33 @@
+
+%%% Local Variables: 
+%%% mode: latex
+%%% TeX-master: "readme"
+%%% End: 
+
+\subsection{Output sample rate}
+
+The output sample rate tells ScummVM how many sound samples to play per channel
+per second. There is much that could be said on this subject, but most of it
+would be irrelevant here. The short version is that for most games 22050 Hz is
+fine, but in some cases 44100 Hz is preferable. On extremely low-end systems
+you may want to use 11025 Hz, but it's unlikely that you have to worry about
+that.
+
+To elaborate, most of the sounds ScummVM has to play were sampled at either
+22050 Hz or 11025 Hz. Using a higher sample rate will not magically improve the
+quality of these sounds. Hence, 22050 Hz is fine.
+
+Some games use CD audio. If you use compressed files for this, they are
+probably sampled at 44100 Hz, so for these games that may be a better choice of
+sample rate.
+
+When using the Adlib, FM Towns, PC Speaker or IBM PCjr music drivers, ScummVM
+is responsible for generating the samples. Usually 22050 Hz will be plenty for
+these, but there is at least one piece of Adlib music in Beneath a Steeel Sky
+that will sound a lot better at 44100 Hz.
+
+Using frequencies in between is not recommended. For one thing, your sound card
+may not support it. In theory, ScummVM should fall back on a sensible frequency
+in that case, but don't count on it. More importantly, ScummVM has to resample
+all sounds to its output frequency. This is much easier to do well if the
+output frequency is a multiple of the original frequency.
diff -urN ScummVM/doc/08.tex ScummVM+test/doc/08.tex
--- ScummVM/doc/08.tex	2004-04-06 14:06:10.735625000 +0200
+++ ScummVM+test/doc/08.tex	2004-05-25 09:30:07.456250000 +0200
@@ -92,6 +92,8 @@
         joystick\_num   &number   Number of joystick device to use for input\\
         master\_volume  &number   The master volume setting (0-255)\\
         music\_driver   &string   The music engine to use.\\
+        output\_rate    &number   The output sample rate to use, in Hz. Sensible\\
+                        &         values are 11025, 22050 and 44100.\\
         alsa\_port      &string   Port to use for output when using the\\
                         &         ALSA music driver.\\
         music\_volume   &number   The music volume setting (0-255)\\
diff -urN ScummVM/sound/mixer.cpp ScummVM+test/sound/mixer.cpp
--- ScummVM/sound/mixer.cpp	2004-02-28 14:30:58.811250000 +0100
+++ ScummVM+test/sound/mixer.cpp	2004-05-25 09:30:02.346875000 +0200
@@ -21,6 +21,7 @@
  */
 
 #include "stdafx.h"
+#include "common/config-manager.h"
 #include "common/file.h"
 #include "common/util.h"
 
@@ -111,10 +112,8 @@
 	_premixProc = 0;
 	int i = 0;
 
-	_outputRate = (uint) _syst->getOutputSampleRate();
-
-	if (_outputRate == 0)
-		error("OSystem returned invalid sample rate");
+	if (ConfMan.hasKey("output_rate"))
+		_syst->setOutputSampleRate(ConfMan.getInt("output_rate"));
 
 	_globalVolume = 0;
 	_musicVolume = 0;
@@ -125,6 +124,12 @@
 		_channels[i] = 0;
 
 	_mixerReady = _syst->setSoundCallback(mixCallback, this);
+	_outputRate = (uint) _syst->getOutputSampleRate();
+
+	if (_outputRate == 0)
+		error("OSystem returned invalid sample rate");
+
+	debug(1, "Output sample rate: %d Hz", _outputRate);
 }
 
 SoundMixer::~SoundMixer() {
