aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends/alsa.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2012-08-17 13:38:52 -0700
committerChris Robinson <[email protected]>2012-08-17 13:38:52 -0700
commitac4fc4026c3b1b0b9487216399bef04d419b04b8 (patch)
tree730148652e49723e644f7df8107c0c3be3c19821 /Alc/backends/alsa.c
parent9737f683150180a5531d276959030ffa0bd35492 (diff)
Add a device method to retrieve the active latency
This is effectively the time until the next update will be heard by the user, or the closest approximation thereof, in nanoseconds.
Diffstat (limited to 'Alc/backends/alsa.c')
-rw-r--r--Alc/backends/alsa.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c
index 49fec523..880f7ac9 100644
--- a/Alc/backends/alsa.c
+++ b/Alc/backends/alsa.c
@@ -79,6 +79,7 @@ MAKE_FUNC(snd_pcm_start);
MAKE_FUNC(snd_pcm_resume);
MAKE_FUNC(snd_pcm_reset);
MAKE_FUNC(snd_pcm_wait);
+MAKE_FUNC(snd_pcm_delay);
MAKE_FUNC(snd_pcm_state);
MAKE_FUNC(snd_pcm_avail_update);
MAKE_FUNC(snd_pcm_areas_silence);
@@ -151,6 +152,7 @@ MAKE_FUNC(snd_card_next);
#define snd_pcm_resume psnd_pcm_resume
#define snd_pcm_reset psnd_pcm_reset
#define snd_pcm_wait psnd_pcm_wait
+#define snd_pcm_delay psnd_pcm_delay
#define snd_pcm_state psnd_pcm_state
#define snd_pcm_avail_update psnd_pcm_avail_update
#define snd_pcm_areas_silence psnd_pcm_areas_silence
@@ -241,6 +243,7 @@ static ALCboolean alsa_load(void)
LOAD_FUNC(snd_pcm_resume);
LOAD_FUNC(snd_pcm_reset);
LOAD_FUNC(snd_pcm_wait);
+ LOAD_FUNC(snd_pcm_delay);
LOAD_FUNC(snd_pcm_state);
LOAD_FUNC(snd_pcm_avail_update);
LOAD_FUNC(snd_pcm_areas_silence);
@@ -1224,6 +1227,21 @@ static void alsa_stop_capture(ALCdevice *Device)
}
+static ALint64 alsa_get_latency(ALCdevice *device)
+{
+ alsa_data *data = (alsa_data*)device->ExtraData;
+ snd_pcm_sframes_t delay = 0;
+ int err;
+
+ if((err=snd_pcm_delay(data->pcmHandle, &delay)) < 0)
+ {
+ ERR("Failed to get latency!\n");
+ return 0;
+ }
+ return maxi64((ALint64)delay*1000000000/device->Frequency, 0);
+}
+
+
static const BackendFuncs alsa_funcs = {
alsa_open_playback,
alsa_close_playback,
@@ -1235,7 +1253,8 @@ static const BackendFuncs alsa_funcs = {
alsa_start_capture,
alsa_stop_capture,
alsa_capture_samples,
- alsa_available_samples
+ alsa_available_samples,
+ alsa_get_latency
};
ALCboolean alc_alsa_init(BackendFuncs *func_list)