Browse Source

ps2audio: SDL3ified the style

Ryan C. Gordon 1 year ago
parent
commit
6f12f68ec9
1 changed files with 8 additions and 14 deletions
  1. 8 14
      src/audio/ps2/SDL_ps2audio.c

+ 8 - 14
src/audio/ps2/SDL_ps2audio.c

@@ -29,16 +29,12 @@
 
 static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device)
 {
-    int i, mixlen;
-    struct audsrv_fmt_t format;
-
-    device->hidden = (struct SDL_PrivateAudioData *)
-        SDL_calloc(1, sizeof(*device->hidden));
+    device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
     if (device->hidden == NULL) {
         return SDL_OutOfMemory();
     }
 
-    /* These are the native supported audio PS2 configs  */
+    // These are the native supported audio PS2 configs
     switch (device->spec.freq) {
     case 11025:
     case 12000:
@@ -57,6 +53,7 @@ static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device)
     device->spec.channels = device->spec.channels == 1 ? 1 : 2;
     device->spec.format = device->spec.format == SDL_AUDIO_S8 ? SDL_AUDIO_S8 : SDL_AUDIO_S16;
 
+    struct audsrv_fmt_t format;
     format.bits = device->spec.format == SDL_AUDIO_S8 ? 8 : 16;
     format.freq = device->spec.freq;
     format.channels = device->spec.channels;
@@ -70,24 +67,23 @@ static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device)
         return SDL_SetError("Couldn't reserve hardware channel");
     }
 
-    /* Update the fragment size as size in bytes. */
+    // Update the fragment size as size in bytes.
     SDL_UpdatedAudioDeviceFormat(device);
 
     /* Allocate the mixing buffer.  Its size and starting address must
        be a multiple of 64 bytes.  Our sample count is already a multiple of
        64, so spec->size should be a multiple of 64 as well. */
-    mixlen = device->buffer_size * NUM_BUFFERS;
+    const int mixlen = device->buffer_size * NUM_BUFFERS;
     device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen);
     if (device->hidden->rawbuf == NULL) {
         return SDL_SetError("Couldn't allocate mixing buffer");
     }
 
-    SDL_memset(device->hidden->rawbuf, 0, mixlen);
-    for (i = 0; i < NUM_BUFFERS; i++) {
+    SDL_memset(device->hidden->rawbuf, device->silence_value, mixlen);
+    for (int i = 0; i < NUM_BUFFERS; i++) {
         device->hidden->mixbufs[i] = &device->hidden->rawbuf[i * device->buffer_size];
     }
 
-    device->hidden->next_buffer = 0;
     return 0;
 }
 
@@ -96,7 +92,6 @@ static void PS2AUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, in
     audsrv_play_audio((char *)buffer, buflen);
 }
 
-/* This function waits until it is possible to write a full sound buffer */
 static void PS2AUDIO_WaitDevice(SDL_AudioDevice *device)
 {
     audsrv_wait_audio(device->buffer_size);
@@ -148,7 +143,6 @@ static SDL_bool PS2AUDIO_Init(SDL_AudioDriverImpl *impl)
         return SDL_FALSE;
     }
 
-    /* Set the function pointers */
     impl->OpenDevice = PS2AUDIO_OpenDevice;
     impl->PlayDevice = PS2AUDIO_PlayDevice;
     impl->WaitDevice = PS2AUDIO_WaitDevice;
@@ -157,7 +151,7 @@ static SDL_bool PS2AUDIO_Init(SDL_AudioDriverImpl *impl)
     impl->ThreadInit = PS2AUDIO_ThreadInit;
     impl->Deinitialize = PS2AUDIO_Deinitialize;
     impl->OnlyHasDefaultOutputDevice = SDL_TRUE;
-    return SDL_TRUE; /* this audio target is available. */
+    return SDL_TRUE; // this audio target is available.
 }
 
 AudioBootStrap PS2AUDIO_bootstrap = {