static int buffer_pos = 0;
static size_t bits_per_sample, bits_per_frame;
static size_t chunk_bytes;
+static int test_position = 0;
static snd_output_t *log;
static int fd = -1;
" --disable-resample disable automatic rate resample\n"
" --disable-channels disable automatic channel conversions\n"
" --disable-format disable automatic format conversions\n"
-" --disable-softvol disable software volume control (softvol)\n")
+" --disable-softvol disable software volume control (softvol)\n"
+" --test-position test ring buffer position\n")
, command);
printf(_("Recognized sample formats are:"));
for (k = 0; k < SND_PCM_FORMAT_LAST; ++k) {
OPT_DISABLE_RESAMPLE,
OPT_DISABLE_CHANNELS,
OPT_DISABLE_FORMAT,
- OPT_DISABLE_SOFTVOL
+ OPT_DISABLE_SOFTVOL,
+ OPT_TEST_POSITION
};
int main(int argc, char *argv[])
{"disable-channels", 0, 0, OPT_DISABLE_CHANNELS},
{"disable-format", 0, 0, OPT_DISABLE_FORMAT},
{"disable-softvol", 0, 0, OPT_DISABLE_SOFTVOL},
+ {"test-position", 0, 0, OPT_TEST_POSITION},
{0, 0, 0, 0}
};
char *pcm_name = "default";
case OPT_DISABLE_SOFTVOL:
open_mode |= SND_PCM_NO_SOFTVOL;
break;
+ case OPT_TEST_POSITION:
+ test_position = 1;
+ break;
default:
fprintf(stderr, _("Try `%s --help' for more information.\n"), command);
return 1;
/* not required, but for sure */
snd_pcm_mmap_commit(handle, offset, 0);
}
+
+ buffer_frames = buffer_size; /* for position test */
}
#ifndef timersub
}
}
+static void do_test_position(void)
+{
+ static int counter = 0;
+ snd_pcm_sframes_t avail, delay;
+ int err;
+
+ err = snd_pcm_avail_delay(handle, &avail, &delay);
+ if (err < 0)
+ return;
+ if (avail > 4 * (snd_pcm_sframes_t)buffer_frames ||
+ avail < -4 * (snd_pcm_sframes_t)buffer_frames ||
+ delay > 4 * (snd_pcm_sframes_t)buffer_frames ||
+ delay < -4 * (snd_pcm_sframes_t)buffer_frames) {
+ fprintf(stderr, "Suspicious buffer position (%i total): avail = %li, delay = %li, buffer = %li\n", ++counter, (long)avail, (long)delay, (long)buffer_frames);
+ } else if (verbose) {
+ fprintf(stderr, "Buffer position: %li/%li (%li)\n", (long)avail, (long)delay, (long)buffer_frames);
+ }
+}
+
/*
* write function
*/
count = chunk_size;
}
while (count > 0) {
+ if (test_position)
+ do_test_position();
r = writei_func(handle, data, count);
+ if (test_position)
+ do_test_position();
if (r == -EAGAIN || (r >= 0 && (size_t)r < count)) {
snd_pcm_wait(handle, 1000);
} else if (r == -EPIPE) {
size_t offset = result;
for (channel = 0; channel < channels; channel++)
bufs[channel] = data[channel] + offset * bits_per_sample / 8;
+ if (test_position)
+ do_test_position();
r = writen_func(handle, bufs, count);
+ if (test_position)
+ do_test_position();
if (r == -EAGAIN || (r >= 0 && (size_t)r < count)) {
snd_pcm_wait(handle, 1000);
} else if (r == -EPIPE) {
}
while (count > 0) {
+ if (test_position)
+ do_test_position();
r = readi_func(handle, data, count);
+ if (test_position)
+ do_test_position();
if (r == -EAGAIN || (r >= 0 && (size_t)r < count)) {
snd_pcm_wait(handle, 1000);
} else if (r == -EPIPE) {
size_t offset = result;
for (channel = 0; channel < channels; channel++)
bufs[channel] = data[channel] + offset * bits_per_sample / 8;
+ if (test_position)
+ do_test_position();
r = readn_func(handle, bufs, count);
+ if (test_position)
+ do_test_position();
if (r == -EAGAIN || (r >= 0 && (size_t)r < count)) {
snd_pcm_wait(handle, 1000);
} else if (r == -EPIPE) {