user selectable audio buffer size & better default
authorJavier S. Pedro <javier@javispedro.com>
Mon, 24 Aug 2009 15:35:24 +0000 (17:35 +0200)
committerJavier S. Pedro <javier@javispedro.com>
Mon, 24 Aug 2009 15:35:24 +0000 (17:35 +0200)
platform/config.cpp
platform/sdla.cpp

index e925a1d..41fac3e 100644 (file)
@@ -53,6 +53,8 @@ static struct poptOption commonOptionsTable[] = {
        "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
 };
 
@@ -168,7 +170,7 @@ static void loadDefaults()
        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;
@@ -343,6 +345,9 @@ static void parseArgs(poptContext optCon)
                        case 14:
                                Settings.SoundPlaybackRate = atoi(poptGetOptArg(optCon));
                                break;
+                       case 15:
+                               Settings.SoundBufferSize = atoi(poptGetOptArg(optCon));
+                               break;
                        case 100:
                                scancode = atoi(poptGetOptArg(optCon));
                                break;
index 6653695..dd78587 100644 (file)
@@ -15,7 +15,7 @@ static SDL_AudioSpec spec;
 
 static void audioCallback(void *userdata, Uint8 *stream, int len)
 {
-       int samplecount = len / 2;
+       int samplecount = len / 2; // 16 bit audio
        S9xMixSamples((short*)stream, samplecount);
 }
 
@@ -25,36 +25,39 @@ void S9xInitAudioOutput()
 
        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:
@@ -64,7 +67,7 @@ no_audio:
        Config.enableAudio = false;
        Settings.APUEnabled = FALSE;
        printf("Audio: no audio\n");
-       
+
        return;
 }