--- a/sc2src/alsadirect.cpp
+++ b/sc2src/alsadirect.cpp
@@ -47,6 +47,9 @@
#ifndef MIN
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#endif
+
+// Max absolute variation of the adjusted samplerate
+static const double max_delta{0.01};
// The queue for audio blocks ready for alsa. This is the maximum size
// before the upstream task blocks
@@ -450,10 +453,11 @@
samplerate_ratio = 1.0 + adj;
// Limit extension
- if (samplerate_ratio < 0.9)
- samplerate_ratio = 0.9;
- if (samplerate_ratio > 1.1)
- samplerate_ratio = 1.1;
+ if (samplerate_ratio < 1.0 - max_delta) {
+ samplerate_ratio = 1.0 - max_delta;
+ } else if (samplerate_ratio > 1.0 + max_delta) {
+ samplerate_ratio = 1.0 + max_delta;
+ }
} else {
// Starting up, wait for more info
@@ -623,8 +627,7 @@
{
// Number of frames per buffer. This is mostly constant for a
// given stream (depends on fe and buffer time, Windows Songcast
- // buffers are 10mS, so 441 frames at cd q). Recomputed on first
- // buf, the init is to avoid warnings
+ // buffers are 10mS, so 441 frames at cd q).
int bufframes = tsk->frames();
double samplerate_ratio = 1.0;
@@ -766,6 +769,16 @@
goto done;
}
} else {
+ static int cnt;
+ if (cnt++ == 103) {
+ int bufframes = tsk->frames()?tsk->frames():441;
+ int qs = alsaqueue.qsize() * bufframes + alsa_delay;
+ LOGDEB("audioEater:alsa: "
+ " qstarg " << qstarg <<
+ " iqsz " << alsaqueue.qsize() <<
+ " qsize " << int(qs/bufframes) << endl);
+ cnt = 0;
+ }
convert_to16le(tsk);
}