Added a GetPendingBytes method to the audio backend.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 30 Jul 2014 11:08:31 -0400
changeset 9031 e963a13a720c
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
--- a/src/audio/SDL_audio.c	Wed Jul 30 09:54:01 2014 -0400
+++ b/src/audio/SDL_audio.c	Wed Jul 30 11:08:31 2014 -0400
@@ -178,6 +178,12 @@
 {                               /* no-op. */
 }
 
+static int
+SDL_AudioGetPendingBytes_Default(_THIS)
+{
+    return 0;
+}
+
 static Uint8 *
 SDL_AudioGetDeviceBuf_Default(_THIS)
 {
@@ -253,6 +259,7 @@
     FILL_STUB(ThreadInit);
     FILL_STUB(WaitDevice);
     FILL_STUB(PlayDevice);
+    FILL_STUB(GetPendingBytes);
     FILL_STUB(GetDeviceBuf);
     FILL_STUB(WaitDone);
     FILL_STUB(CloseDevice);
@@ -471,7 +478,7 @@
     SDL_AudioDevice *device = get_audio_device(devid);
     if (device) {
         current_audio.impl.LockDevice(device);
-        retval = device->queued_bytes;
+        retval = device->queued_bytes + current_audio.impl.GetPendingBytes(device);
         current_audio.impl.UnlockDevice(device);
     }
 
--- a/src/audio/SDL_sysaudio.h	Wed Jul 30 09:54:01 2014 -0400
+++ b/src/audio/SDL_sysaudio.h	Wed Jul 30 11:08:31 2014 -0400
@@ -60,6 +60,7 @@
     void (*ThreadInit) (_THIS); /* Called by audio thread at start */
     void (*WaitDevice) (_THIS);
     void (*PlayDevice) (_THIS);
+    int (*GetPendingBytes) (_THIS);
     Uint8 *(*GetDeviceBuf) (_THIS);
     void (*WaitDone) (_THIS);
     void (*CloseDevice) (_THIS);