aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/uhd.c
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-03-04 06:35:38 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2017-03-04 06:35:38 +0100
commit4201717f36f1236fd0de1597679f5e9411c8a7eb (patch)
tree27a6346bec0e919792af440dc92e6091d7147049 /src/common/uhd.c
parent9d0e6b82b7cc289fb76e580946c8fefcb2b9cb18 (diff)
Rework on audio buffer management
Use function to get samples to be sent to fill audio buffers to a level. This replaces the function that only shows how much data is in the buffer. This way the function itself can control how much data will be sent.
Diffstat (limited to 'src/common/uhd.c')
-rw-r--r--src/common/uhd.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/common/uhd.c b/src/common/uhd.c
index 15c13b9..1423703 100644
--- a/src/common/uhd.c
+++ b/src/common/uhd.c
@@ -379,19 +379,24 @@ int uhd_receive(float *buff, int max)
return got;
}
-/* estimate current unsent number of samples */
-int uhd_get_inbuffer(void)
+/* estimate number of samples that can be sent */
+int uhd_get_tosend(int latspl)
{
double advance;
+ int tosend;
/* we need the rx time stamp to determine how much data is already sent in advance */
if (rx_time_secs == 0 && rx_time_fract_sec == 0.0)
- return -EAGAIN;
+ return 0;
/* if we have not yet sent any data, we set initial tx time stamp */
if (tx_time_secs == 0 && tx_time_fract_sec == 0.0) {
tx_time_secs = rx_time_secs;
- tx_time_fract_sec = rx_time_fract_sec;
+ tx_time_fract_sec = rx_time_fract_sec + (double)latspl / samplerate;
+ if (tx_time_fract_sec >= 1.0) {
+ tx_time_fract_sec -= 1.0;
+ tx_time_secs++;
+ }
}
/* we check how advance our transmitted time stamp is */
@@ -399,7 +404,10 @@ int uhd_get_inbuffer(void)
/* in case of underrun: */
if (advance < 0)
advance = 0;
+ tosend = latspl - (int)(advance * samplerate);
+ if (tosend < 0)
+ tosend = 0;
- return (int)(advance * samplerate);
+ return tosend;
}