SDL: Allow selecting the audio channel count from the command line

This commit is contained in:
Cameron Cawley 2022-11-13 19:55:29 +00:00 committed by Eugene Sandulenko
parent 9f4f22b3bf
commit 749fd8b490
5 changed files with 25 additions and 6 deletions

View file

@ -73,7 +73,7 @@ void SdlMixerManager::init() {
warning("Could not open audio device: %s", SDL_GetError());
// The mixer is not marked as ready
_mixer = new Audio::MixerImpl(desired.freq, true, desired.samples);
_mixer = new Audio::MixerImpl(desired.freq, desired.channels >= 2, desired.samples);
return;
}
@ -88,7 +88,7 @@ void SdlMixerManager::init() {
warning("Could not open audio device: %s", SDL_GetError());
// The mixer is not marked as ready
_mixer = new Audio::MixerImpl(desired.freq, true, desired.samples);
_mixer = new Audio::MixerImpl(desired.freq, desired.channels >= 2, desired.samples);
return;
}
@ -103,10 +103,11 @@ void SdlMixerManager::init() {
if (_obtained.samples != desired.samples)
warning("SDL mixer output buffer size: %d differs from desired: %d", _obtained.samples, desired.samples);
if (_obtained.channels != 2)
error("SDL mixer output requires stereo output device");
debug(1, "Output channels: %d", _obtained.channels);
if (_obtained.channels != 1 && _obtained.channels != 2)
error("SDL mixer output requires mono or stereo output device");
_mixer = new Audio::MixerImpl(_obtained.freq, true, desired.samples);
_mixer = new Audio::MixerImpl(_obtained.freq, _obtained.channels >= 2, desired.samples);
assert(_mixer);
_mixer->setReady(true);
@ -143,6 +144,12 @@ SDL_AudioSpec SdlMixerManager::getAudioSpec(uint32 outputRate) {
if (freq <= 0)
freq = outputRate;
uint32 channels = 2;
if (ConfMan.hasKey("output_channels"))
channels = ConfMan.getInt("output_channels");
if (channels > 2 || channels <= 0)
channels = 2;
// One SDL "sample" is a complete audio frame (i.e. all channels = 1 sample)
uint32 samples = 0;
@ -166,7 +173,7 @@ SDL_AudioSpec SdlMixerManager::getAudioSpec(uint32 outputRate) {
memset(&desired, 0, sizeof(desired));
desired.freq = freq;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
desired.channels = channels;
desired.samples = roundDownPowerOfTwo(samples);
desired.callback = sdlCallback;
desired.userdata = this;

View file

@ -160,6 +160,7 @@ static const char HELP_STRING4[] =
" --dump-midi Dumps MIDI events to 'dump.mid', until quitting from game\n"
" (if file already exists, it will be overwritten)\n"
" --enable-gs Enable Roland GS mode for MIDI playback\n"
" --output-channels=CHANNELS Select output channel count (e.g. 2 for stereo)\n"
" --output-rate=RATE Select output sample rate in Hz (e.g. 22050)\n"
" --opl-driver=DRIVER Select AdLib (OPL) emulator (db, mame"
#ifndef DISABLE_NUKED_OPL
@ -663,6 +664,9 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
DO_LONG_COMMAND("list-audio-devices")
END_COMMAND
DO_LONG_OPTION_INT("output-channels")
END_OPTION
DO_LONG_OPTION_INT("output-rate")
END_OPTION

View file

@ -326,6 +326,8 @@ Select AdLib (OPL) emulator
.Ar nuked ,
.Ar opl2lpt
.Pc .
.It Fl -output-channels= Ns Ar RATE
Set output channel count (e.g. 2 for stereo).
.It Fl -output-rate= Ns Ar RATE
Set output sample rate in Hz (e.g. 22050).
.It Fl -platform= Ns Ar PLATFORM

View file

@ -200,6 +200,7 @@ Short options are listed where they are available.
``--no-filtering``,,"Forces unfiltered graphics mode"
``--no-fullscreen``,``-F``,"Forces windowed mode"
``--opl-driver=DRIVER``,,":ref:`Selects AdLib (OPL) emulator <opl>`"
``--output-channels=CHANNELS``,,"Select output channel count"
``--output-rate=RATE``,,"Selects output sample rate in Hz"
``--path=PATH``,``-p``,"Sets path to where the game is installed"
``--platform=STRING``,,":ref:`Specifes platform of game <platform>`. Allowed values: 2gs, 3do, acorn, amiga, atari, c64, fmtowns, nes, mac, pc pc98, pce, segacd, wii, windows."

View file

@ -339,6 +339,11 @@ There are many recognized configuration keys. In the table below, each key is ei
- op3lpt
- rwopl3 "
":ref:`originalsaveload <osl>`",boolean,false,
":ref:`output_channels <outputchannels>`",integer,,"
Supported values are:
- 1
- 2"
":ref:`output_rate <outputrate>`",integer,,"
Sensible values are: