Skip to content

Instantly share code, notes, and snippets.

@alfredh
Created August 3, 2019 15:57
Show Gist options
  • Save alfredh/473a4ea2db44733786dd4d564846933c to your computer and use it in GitHub Desktop.
Save alfredh/473a4ea2db44733786dd4d564846933c to your computer and use it in GitHub Desktop.
auloop.diff
diff --git a/modules/auloop/auloop.c b/modules/auloop/auloop.c
index 8028d69..5ec5dce 100644
--- a/modules/auloop/auloop.c
+++ b/modules/auloop/auloop.c
@@ -42,7 +42,14 @@ struct audio_loop {
bool started;
uint64_t n_read;
+ uint64_t n_read_count;
uint64_t n_write;
+
+ uint64_t us_last;
+ double ptime_acc; /* accumulated */
+ double ptime_min;
+ double ptime_max;
+ bool ptime_set;
};
@@ -62,16 +69,28 @@ static int print_summary(struct re_printf *pf, const struct audio_loop *al)
if (al->ausrc) {
struct ausrc *as = ausrc_get(al->ausrc);
+ double avg_sampc;
+ double avg_ptime;
+
+ avg_sampc = (double)al->n_read / (double)al->n_read_count;
+ avg_ptime = al->ptime_acc / (double)al->n_read_count;
+
err |= re_hprintf(pf,
"* Source\n"
" module %s\n"
" samples %llu\n"
" duration %.3f sec\n"
+ " real ptime %.2f / %.2f / %.2f ms"
+ " (min/avg/max)\n"
+ " avg.sampc %.3f ms\n"
"\n"
,
as->name,
al->n_read,
- (double)al->n_read / scale);
+ (double)al->n_read / scale,
+ al->ptime_min, avg_ptime, al->ptime_max,
+ 1000.0 * avg_sampc / scale
+ );
}
/* Player */
@@ -148,11 +167,41 @@ static void read_handler(const void *sampv, size_t sampc, void *arg)
int err;
al->n_read += sampc;
+ al->n_read_count += 1;
+
+ uint64_t us, delta;
+ double ptime;
+
+ us = tmr_jiffies_usec();
+
+ if (al->us_last) {
+
+ delta = us - al->us_last;
+
+ ptime = .001 * delta;
+
+ al->ptime_acc += ptime;
+
+ if (al->ptime_set) {
+ if (ptime < al->ptime_min)
+ al->ptime_min = ptime;
+ if (ptime > al->ptime_max)
+ al->ptime_max = ptime;
+ }
+ else {
+ al->ptime_min = ptime;
+ al->ptime_max = ptime;
+
+ al->ptime_set = true;
+ }
+ }
err = aubuf_write(al->aubuf, sampv, num_bytes);
if (err) {
warning("auloop: aubuf_write: %m\n", err);
}
+
+ al->us_last = us;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment