TYPE_INTEGER,
&setup.volume_music, "volume_music"
},
+ {
+ TYPE_SWITCH,
+ &setup.audio_sample_rate_44100, "audio_sample_rate_44100"
+ },
{
TYPE_SWITCH,
&setup.network_mode, "network_mode"
si->volume_simple = 100; // percent
si->volume_loops = 100; // percent
si->volume_music = 100; // percent
+ si->audio_sample_rate_44100 = FALSE;
si->network_mode = FALSE;
si->network_player_nr = 0; // first player
return;
}
- if (Mix_OpenAudio(DEFAULT_AUDIO_SAMPLE_RATE, MIX_DEFAULT_FORMAT,
- AUDIO_NUM_CHANNELS_STEREO,
+ // set audio sample rate for mixer
+ audio.sample_rate = (setup.audio_sample_rate_44100 ? 44100 : 22050);
+
+ if (Mix_OpenAudio(audio.sample_rate, MIX_DEFAULT_FORMAT, AUDIO_NUM_CHANNELS_STEREO,
setup.system.audio_fragment_size) < 0)
{
Warn("Mix_OpenAudio() failed: %s", SDL_GetError());
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
+void SDLReopenAudio(void)
+{
+ SDLCloseAudio();
+ SDLOpenAudio();
+}
+
// ============================================================================
// event functions
void SDLOpenAudio(void);
void SDLCloseAudio(void);
+void SDLReopenAudio(void);
void SDLWaitEvent(Event *);
void SDLCorrectRawMousePosition(int *, int *);
audio.device_name = NULL;
audio.device_fd = -1;
+ audio.sample_rate = DEFAULT_AUDIO_SAMPLE_RATE;
+
audio.num_channels = 0;
audio.music_channel = 0;
audio.first_sound_channel = 0;
char *device_name;
int device_fd;
+ int sample_rate;
+
int num_channels;
int music_channel;
int first_sound_channel;
int volume_simple;
int volume_loops;
int volume_music;
+ boolean audio_sample_rate_44100;
boolean network_mode;
int network_player_nr;
{ TYPE_ENTER_LIST, execSetupChooseVolumeMusic, "Music Volume:" },
{ TYPE_STRING, &volume_music_text, "" },
{ TYPE_EMPTY, NULL, "" },
+ { TYPE_SWITCH, &setup.audio_sample_rate_44100, "44100 Hz audio mixing:" },
+ { TYPE_EMPTY, NULL, "" },
{ TYPE_LEAVE_MENU, execSetupMain, "Back" },
{ 0, NULL, NULL }
if (si->value == &setup.fullscreen)
ToggleFullscreenIfNeeded();
+ // audio sample rate may have changed at this point
+ if (si->value == &setup.audio_sample_rate_44100)
+ ToggleAudioSampleRateIfNeeded();
+
// network mode may have changed at this point
if (si->value == &setup.network_mode)
ToggleNetworkModeIfNeeded();
#endif
}
+void ToggleAudioSampleRateIfNeeded(void)
+{
+ int setup_audio_sample_rate = (setup.audio_sample_rate_44100 ? 44100 : 22050);
+
+ // if setup and audio sample rate are already matching, nothing do do
+ if ((setup_audio_sample_rate == audio.sample_rate) ||
+ !audio.sound_available)
+ return;
+
+#if 1
+ // apparently changing the audio output sample rate does not work at runtime,
+ // so currently the program has to be restarted to apply the new sample rate
+ Request("Please restart the program to change audio sample rate!", REQ_CONFIRM);
+#else
+ SDLReopenAudio();
+
+ // set setup value according to successfully changed audio sample rate
+ setup.audio_sample_rate_44100 = (audio.sample_rate == 44100);
+#endif
+}
+
void ToggleFullscreenIfNeeded(void)
{
// if setup and video fullscreen state are already matching, nothing do do
void SetLevelSetInfo(char *, int);
+void ToggleAudioSampleRateIfNeeded(void);
void ToggleFullscreenIfNeeded(void);
void ChangeWindowScalingIfNeeded(void);
void ChangeVsyncModeIfNeeded(void);