Added a GetPendingBytes method to the audio backend.
authorRyan C. Gordon
Wed, 30 Jul 2014 11:08:31 -0400
changeset 9031e963a13a720c
parent 9030 3ac4c7b7c769
child 9032 36c472422d64
Added a GetPendingBytes method to the audio backend.

This will (eventually) make SDL_GetQueuedAudioSize() more accurate, and thus
reduce latency. Right now this isn't implemented anywhere, so we assume data
fed to the audio callback is consumed by the hardware and immediately played
to completion.
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
     1.1 --- a/src/audio/SDL_audio.c	Wed Jul 30 09:54:01 2014 -0400
     1.2 +++ b/src/audio/SDL_audio.c	Wed Jul 30 11:08:31 2014 -0400
     1.3 @@ -178,6 +178,12 @@
     1.4  {                               /* no-op. */
     1.5  }
     1.6  
     1.7 +static int
     1.8 +SDL_AudioGetPendingBytes_Default(_THIS)
     1.9 +{
    1.10 +    return 0;
    1.11 +}
    1.12 +
    1.13  static Uint8 *
    1.14  SDL_AudioGetDeviceBuf_Default(_THIS)
    1.15  {
    1.16 @@ -253,6 +259,7 @@
    1.17      FILL_STUB(ThreadInit);
    1.18      FILL_STUB(WaitDevice);
    1.19      FILL_STUB(PlayDevice);
    1.20 +    FILL_STUB(GetPendingBytes);
    1.21      FILL_STUB(GetDeviceBuf);
    1.22      FILL_STUB(WaitDone);
    1.23      FILL_STUB(CloseDevice);
    1.24 @@ -471,7 +478,7 @@
    1.25      SDL_AudioDevice *device = get_audio_device(devid);
    1.26      if (device) {
    1.27          current_audio.impl.LockDevice(device);
    1.28 -        retval = device->queued_bytes;
    1.29 +        retval = device->queued_bytes + current_audio.impl.GetPendingBytes(device);
    1.30          current_audio.impl.UnlockDevice(device);
    1.31      }
    1.32  
     2.1 --- a/src/audio/SDL_sysaudio.h	Wed Jul 30 09:54:01 2014 -0400
     2.2 +++ b/src/audio/SDL_sysaudio.h	Wed Jul 30 11:08:31 2014 -0400
     2.3 @@ -60,6 +60,7 @@
     2.4      void (*ThreadInit) (_THIS); /* Called by audio thread at start */
     2.5      void (*WaitDevice) (_THIS);
     2.6      void (*PlayDevice) (_THIS);
     2.7 +    int (*GetPendingBytes) (_THIS);
     2.8      Uint8 *(*GetDeviceBuf) (_THIS);
     2.9      void (*WaitDone) (_THIS);
    2.10      void (*CloseDevice) (_THIS);