"Unfreeze previous game on start and freeze game on exit", 0 },
{ "audio-rate", 'u', POPT_ARG_INT, 0, 14,
"Audio output rate", "HZ" },
+ { "audio-buffer-size", 'b', POPT_ARG_INT, 0, 15,
+ "Audio output buffer size", "SAMPLES" },
POPT_TABLEEND
};
Settings.JoystickEnabled = FALSE;
Settings.SoundPlaybackRate = 22050;
Settings.Stereo = TRUE;
- Settings.SoundBufferSize = 0;
+ Settings.SoundBufferSize = 512; // in samples
Settings.CyclesPercentage = 100;
Settings.DisableSoundEcho = FALSE;
Settings.APUEnabled = FALSE;
case 14:
Settings.SoundPlaybackRate = atoi(poptGetOptArg(optCon));
break;
+ case 15:
+ Settings.SoundBufferSize = atoi(poptGetOptArg(optCon));
+ break;
case 100:
scancode = atoi(poptGetOptArg(optCon));
break;
static void audioCallback(void *userdata, Uint8 *stream, int len)
{
- int samplecount = len / 2;
+ int samplecount = len / 2; // 16 bit audio
S9xMixSamples((short*)stream, samplecount);
}
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
DIE("SDL_InitSubSystem(AUDIO): %s", SDL_GetError());
-
+
SDL_AudioSpec desired;
desired.freq = Settings.SoundPlaybackRate;
desired.format = AUDIO_S16LSB;
desired.channels = Settings.Stereo ? 2 : 1;
- desired.samples = MAX_BUFFER_SIZE;
+ desired.samples = Settings.SoundBufferSize;
desired.callback = audioCallback;
desired.userdata = 0;
-
+
if (SDL_OpenAudio(&desired, &spec) < 0) {
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
goto no_audio_free;
}
-
+
Settings.APUEnabled = TRUE;
Settings.SoundPlaybackRate = spec.freq;
- if (spec.format == AUDIO_S16LSB)
+ if (spec.format == AUDIO_S16LSB) {
Settings.SixteenBitSound = TRUE;
- else if (spec.format == AUDIO_S8)
+ } else if (spec.format == AUDIO_S8) {
Settings.SixteenBitSound = FALSE;
- else {
+ fprintf(stderr, "Cannot output 8 bit sound\n");
+ goto no_audio_free;
+ } else {
fprintf(stderr, "Invalid audio format\n");
goto no_audio_free;
}
Settings.Stereo = spec.channels == 2 ? TRUE : FALSE;
-
- printf("Audio: %d Hz, %d %s, %s\n", spec.freq,
+
+ printf("Audio: %d Hz, %d %s, %s, %u samples in buffer\n", spec.freq,
spec.channels, Settings.Stereo ? "channels" : "channel",
- Settings.SixteenBitSound ? "16 bits" : "8 bits");
-
+ Settings.SixteenBitSound ? "16 bits" : "8 bits",
+ spec.samples);
+
return;
no_audio_free:
Config.enableAudio = false;
Settings.APUEnabled = FALSE;
printf("Audio: no audio\n");
-
+
return;
}