4 * Author: Jaroslav Kysela <perex@perex.cz>
6 * Author of bandpass filter sweep effect:
7 * Maarten de Boer <mdeboer@iua.upf.es>
9 * This small demo program can be used for measuring latency between
10 * capture and playback. This latency is measured from driver (diff when
11 * playback and capture was started). Scheduler is set to SCHED_RR.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
38 #include "../include/asoundlib.h"
42 #ifndef CLOCK_MONOTONIC_RAW
43 #define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
46 #if defined(__OpenBSD__)
47 #define sched_getparam(pid, parm) (-1)
48 #define sched_setscheduler(pid, policy, parm) (-1)
51 typedef struct timespec timestamp_t;
53 char *sched_policy = "rr";
54 char *pdevice = "hw:0,0";
55 char *cdevice = "hw:0,0";
56 snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE;
59 int buffer_size = 0; /* auto */
60 int period_size = 0; /* auto */
61 int latency_min = 32; /* in frames / 2 */
62 int latency_max = 2048; /* in frames / 2 */
63 int loop_sec = 30; /* seconds */
64 int block = 0; /* block mode */
68 int sys_latency = 0; /* data I/O: use system timings instead driver wakeups */
69 int pos_dump = 0; /* dump positions */
70 int realtime_check = 0;
71 unsigned long loop_limit;
72 snd_pcm_uframes_t playback_buffer_size;
74 snd_output_t *output = NULL;
76 static inline long long frames_to_micro(size_t frames)
78 return (long long)((frames * 1000000LL) + (rate / 2)) / rate;
81 void timestamp_now(timestamp_t *tstamp)
83 if (clock_gettime(CLOCK_MONOTONIC_RAW, tstamp))
84 printf("clock_gettime() failed\n");
87 long long timestamp_diff_micro(timestamp_t *tstamp)
89 timestamp_t now, diff;
91 if (tstamp->tv_nsec > now.tv_nsec) {
92 diff.tv_sec = now.tv_sec - tstamp->tv_sec - 1;
93 diff.tv_nsec = (now.tv_nsec + 1000000000L) - tstamp->tv_nsec;
95 diff.tv_sec = now.tv_sec - tstamp->tv_sec;
96 diff.tv_nsec = now.tv_nsec - tstamp->tv_nsec;
99 return (diff.tv_sec * 1000000) + ((diff.tv_nsec + 500L) / 1000L);
102 int setparams_stream(snd_pcm_t *handle,
103 snd_pcm_hw_params_t *params,
109 err = snd_pcm_hw_params_any(handle, params);
111 printf("Broken configuration for %s PCM: no configurations available: %s\n", snd_strerror(err), id);
114 err = snd_pcm_hw_params_set_rate_resample(handle, params, resample);
116 printf("Resample setup failed for %s (val %i): %s\n", id, resample, snd_strerror(err));
119 err = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
121 printf("Access type not available for %s: %s\n", id, snd_strerror(err));
124 err = snd_pcm_hw_params_set_format(handle, params, format);
126 printf("Sample format not available for %s: %s\n", id, snd_strerror(err));
129 err = snd_pcm_hw_params_set_channels(handle, params, channels);
131 printf("Channels count (%i) not available for %s: %s\n", channels, id, snd_strerror(err));
135 err = snd_pcm_hw_params_set_rate_near(handle, params, &rrate, 0);
137 printf("Rate %iHz not available for %s: %s\n", rate, id, snd_strerror(err));
140 if ((int)rrate != rate) {
141 printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err);
144 /* we do not want driver wakeups */
145 if (sys_latency > 0 && snd_pcm_hw_params_can_disable_period_wakeup(params)) {
146 err = snd_pcm_hw_params_set_period_wakeup(handle, params, 0);
148 printf("Cannot disable period wakeups for %s\n", id);
155 int setparams_bufsize(snd_pcm_t *handle,
156 snd_pcm_hw_params_t *params,
157 snd_pcm_hw_params_t *tparams,
158 snd_pcm_uframes_t bufsize,
162 snd_pcm_uframes_t periodsize;
164 snd_pcm_hw_params_copy(params, tparams);
165 periodsize = bufsize * 2;
166 err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &periodsize);
168 printf("Unable to set buffer size %li for %s: %s\n", bufsize * 2, id, snd_strerror(err));
172 periodsize = period_size;
175 err = snd_pcm_hw_params_set_period_size_near(handle, params, &periodsize, 0);
177 printf("Unable to set period size %li for %s: %s\n", periodsize, id, snd_strerror(err));
183 int setparams_set(snd_pcm_t *handle,
184 snd_pcm_hw_params_t *params,
185 snd_pcm_sw_params_t *swparams,
189 snd_pcm_uframes_t val;
191 err = snd_pcm_hw_params(handle, params);
193 printf("Unable to set hw params for %s: %s\n", id, snd_strerror(err));
196 err = snd_pcm_sw_params_current(handle, swparams);
198 printf("Unable to determine current swparams for %s: %s\n", id, snd_strerror(err));
201 err = snd_pcm_sw_params_set_start_threshold(handle, swparams, 0x7fffffff);
203 printf("Unable to set start threshold mode for %s: %s\n", id, snd_strerror(err));
209 snd_pcm_hw_params_get_period_size(params, &val, NULL);
210 err = snd_pcm_sw_params_set_avail_min(handle, swparams, val);
212 printf("Unable to set avail min for %s: %s\n", id, snd_strerror(err));
215 err = snd_pcm_sw_params(handle, swparams);
217 printf("Unable to set sw params for %s: %s\n", id, snd_strerror(err));
223 int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int *bufsize)
225 int err, last_bufsize = *bufsize;
226 snd_pcm_hw_params_t *pt_params, *ct_params; /* templates with rate, format and channels */
227 snd_pcm_hw_params_t *p_params, *c_params;
228 snd_pcm_sw_params_t *p_swparams, *c_swparams;
229 snd_pcm_uframes_t p_size, c_size, p_psize, c_psize;
230 unsigned int p_time, c_time;
233 snd_pcm_hw_params_alloca(&p_params);
234 snd_pcm_hw_params_alloca(&c_params);
235 snd_pcm_hw_params_alloca(&pt_params);
236 snd_pcm_hw_params_alloca(&ct_params);
237 snd_pcm_sw_params_alloca(&p_swparams);
238 snd_pcm_sw_params_alloca(&c_swparams);
239 if ((err = setparams_stream(phandle, pt_params, "playback")) < 0) {
240 printf("Unable to set parameters for playback stream: %s\n", snd_strerror(err));
243 if ((err = setparams_stream(chandle, ct_params, "capture")) < 0) {
244 printf("Unable to set parameters for playback stream: %s\n", snd_strerror(err));
248 if (buffer_size > 0) {
249 *bufsize = buffer_size;
256 if (last_bufsize == *bufsize)
258 last_bufsize = *bufsize;
259 if (*bufsize > latency_max)
262 if ((err = setparams_bufsize(phandle, p_params, pt_params, *bufsize, "playback")) < 0) {
263 printf("Unable to set hw parameters for playback stream: %s\n", snd_strerror(err));
266 if ((err = setparams_bufsize(chandle, c_params, ct_params, *bufsize, "capture")) < 0) {
267 printf("Unable to set hw parameters for capture stream: %s\n", snd_strerror(err));
271 snd_pcm_hw_params_get_period_size(p_params, &p_psize, NULL);
272 if (p_psize > (unsigned int)*bufsize)
274 snd_pcm_hw_params_get_period_size(c_params, &c_psize, NULL);
275 if (c_psize > (unsigned int)*bufsize)
277 snd_pcm_hw_params_get_period_time(p_params, &p_time, NULL);
278 snd_pcm_hw_params_get_period_time(c_params, &c_time, NULL);
279 if (p_time != c_time)
282 snd_pcm_hw_params_get_buffer_size(p_params, &p_size);
283 playback_buffer_size = p_size;
284 if (p_psize * 2 < p_size) {
285 snd_pcm_hw_params_get_periods_min(p_params, &val, NULL);
287 printf("playback device does not support 2 periods per buffer\n");
292 snd_pcm_hw_params_get_buffer_size(c_params, &c_size);
293 if (c_psize * 2 < c_size) {
294 snd_pcm_hw_params_get_periods_min(c_params, &val, NULL);
296 printf("capture device does not support 2 periods per buffer\n");
301 if ((err = setparams_set(phandle, p_params, p_swparams, "playback")) < 0) {
302 printf("Unable to set sw parameters for playback stream: %s\n", snd_strerror(err));
305 if ((err = setparams_set(chandle, c_params, c_swparams, "capture")) < 0) {
306 printf("Unable to set sw parameters for playback stream: %s\n", snd_strerror(err));
310 if ((err = snd_pcm_prepare(phandle)) < 0) {
311 printf("Prepare error: %s\n", snd_strerror(err));
315 snd_pcm_dump(phandle, output);
316 snd_pcm_dump(chandle, output);
321 void showstat(snd_pcm_t *handle, size_t frames)
324 snd_pcm_status_t *status;
326 snd_pcm_status_alloca(&status);
327 if ((err = snd_pcm_status(handle, status)) < 0) {
328 printf("Stream status error: %s\n", snd_strerror(err));
331 printf("*** frames = %li ***\n", (long)frames);
332 snd_pcm_status_dump(status, output);
335 void showlatency(size_t latency)
339 d = (double)latency / (double)rate;
340 printf("Trying latency %li frames, %.3fus, %.6fms (%.4fHz)\n", (long)latency, d * 1000000, d * 1000, (double)1 / d);
343 void showinmax(size_t in_max)
347 printf("Maximum read: %li frames\n", (long)in_max);
348 d = (double)in_max / (double)rate;
349 printf("Maximum read latency: %.3fus, %.6fms (%.4fHz)\n", d * 1000000, d * 1000, (double)1 / d);
352 void gettimestamp(snd_pcm_t *handle, snd_timestamp_t *timestamp)
355 snd_pcm_status_t *status;
357 snd_pcm_status_alloca(&status);
358 if ((err = snd_pcm_status(handle, status)) < 0) {
359 printf("Stream status error: %s\n", snd_strerror(err));
362 snd_pcm_status_get_trigger_tstamp(status, timestamp);
365 void setscheduler(void)
367 struct sched_param sched_param;
368 int policy = SCHED_RR;
369 const char *spolicy = "Round Robin";
371 if (strcasecmp(sched_policy, "fifo") == 0) {
374 } else if (strcasecmp(sched_policy, "other") == 0) {
375 policy = SCHED_OTHER;
378 if (sched_getparam(0, &sched_param) < 0) {
379 printf("Scheduler getparam failed...\n");
382 sched_param.sched_priority = sched_get_priority_max(policy);
383 if (!sched_setscheduler(0, policy, &sched_param)) {
384 printf("Scheduler set to %s with priority %i...\n", spolicy, sched_param.sched_priority);
388 printf("!!!Scheduler set to %s with priority %i FAILED!!!\n", spolicy, sched_param.sched_priority);
391 long timediff(snd_timestamp_t t1, snd_timestamp_t t2)
395 t1.tv_sec -= t2.tv_sec;
396 l = (signed long) t1.tv_usec - (signed long) t2.tv_usec;
402 return (t1.tv_sec * 1000000) + l;
405 long readbuf(snd_pcm_t *handle, char *buf, long len, size_t *frames, size_t *max)
411 r = snd_pcm_readi(handle, buf, len);
412 } while (r == -EAGAIN);
418 // printf("read = %li\n", r);
420 int frame_bytes = (snd_pcm_format_physical_width(format) / 8) * channels;
422 r = snd_pcm_readi(handle, buf, len);
424 buf += r * frame_bytes;
430 // printf("r = %li, len = %li\n", r, len);
431 } while (r >= 1 && len > 0);
433 // showstat(handle, 0);
437 long writebuf(snd_pcm_t *handle, char *buf, long len, size_t *frames)
440 int frame_bytes = (snd_pcm_format_physical_width(format) / 8) * channels;
443 r = snd_pcm_writei(handle, buf, len);
446 // printf("write = %li\n", r);
449 // showstat(handle, 0);
450 buf += r * frame_bytes;
457 #define FILTERSWEEP_LFO_CENTER 2000.
458 #define FILTERSWEEP_LFO_DEPTH 1800.
459 #define FILTERSWEEP_LFO_FREQ 0.2
460 #define FILTER_BANDWIDTH 50
462 /* filter the sweep variables */
463 float lfo,dlfo,fs,fc,BW,C,D,a0,a1,a2,b1,b2,*x[3],*y[3];
465 void applyeffect(char* buffer,int r)
467 short* samples = (short*) buffer;
473 fc = sin(lfo)*FILTERSWEEP_LFO_DEPTH+FILTERSWEEP_LFO_CENTER;
475 if (lfo>2.*M_PI) lfo -= 2.*M_PI;
476 C = 1./tan(M_PI*BW/fs);
477 D = 2.*cos(2*M_PI*fc/fs);
484 for (chn=0;chn<channels;chn++)
486 x[chn][2] = x[chn][1];
487 x[chn][1] = x[chn][0];
489 y[chn][2] = y[chn][1];
490 y[chn][1] = y[chn][0];
492 x[chn][0] = samples[i*channels+chn];
493 y[chn][0] = a0*x[chn][0] + a1*x[chn][1] + a2*x[chn][2]
494 - b1*y[chn][1] - b2*y[chn][2];
495 samples[i*channels+chn] = y[chn][0];
500 static ssize_t get_avail(snd_pcm_t *pcm)
505 avail = snd_pcm_avail(pcm);
506 if (avail == -EAGAIN)
517 "Usage: latency [OPTION]... [FILE]...\n"
519 "-P,--pdevice playback device\n"
520 "-C,--cdevice capture device\n"
521 "-m,--min minimum latency in frames\n"
522 "-M,--max maximum latency in frames\n"
523 "-U,--updates I/O updates in milliseconds (0 = off)\n"
524 "-F,--frames frames to transfer\n"
525 "-f,--format sample format\n"
526 "-c,--channels channels\n"
528 "-B,--buffer buffer size in frames\n"
529 "-E,--period period size in frames\n"
530 "-s,--seconds duration of test in seconds\n"
531 "-b,--block block mode\n"
532 "-p,--poll use poll (wait for event - reduces CPU usage)\n"
533 "-y,--usleep sleep for the specified amount of microseconds between\n"
534 " stream updates (default 0 - off)\n"
535 "-e,--effect apply an effect (bandpass filter sweep)\n"
536 "-x,--posdump dump buffer positions\n"
537 "-X,--realtime do a realtime check (buffering)\n"
538 "-O,--policy set scheduler policy (RR, FIFO or OTHER)\n"
540 printf("Recognized sample formats are:");
541 for (k = 0; k < SND_PCM_FORMAT_LAST; ++k) {
542 const char *s = snd_pcm_format_name(k);
548 "Tip #1 (usable latency with large periods, non-blocking mode, good CPU usage,\n"
549 " superb xrun prevention):\n"
550 " latency -m 8192 -M 8192 -t 1 -p\n"
551 "Tip #2 (superb latency, non-blocking mode, but heavy CPU usage):\n"
552 " latency -m 128 -M 128\n"
556 int main(int argc, char *argv[])
558 struct option long_option[] =
560 {"help", 0, NULL, 'h'},
561 {"pdevice", 1, NULL, 'P'},
562 {"cdevice", 1, NULL, 'C'},
563 {"min", 1, NULL, 'm'},
564 {"max", 1, NULL, 'M'},
565 {"updates", 1, NULL, 'U'},
566 {"frames", 1, NULL, 'F'},
567 {"format", 1, NULL, 'f'},
568 {"channels", 1, NULL, 'c'},
569 {"rate", 1, NULL, 'r'},
570 {"buffer", 1, NULL, 'B'},
571 {"period", 1, NULL, 'E'},
572 {"seconds", 1, NULL, 's'},
573 {"block", 0, NULL, 'b'},
574 {"poll", 0, NULL, 'p'},
575 {"usleep", 1, NULL, 'y'},
576 {"effect", 0, NULL, 'e'},
577 {"posdump", 0, NULL, 'x'},
578 {"realtime", 0, NULL, 'X'},
579 {"policy", 1, NULL, 'O'},
582 snd_pcm_t *phandle, *chandle;
584 int err, latency, morehelp;
586 snd_timestamp_t p_tstamp, c_tstamp;
587 ssize_t r, cap_avail, cap_avail_max, pbk_fill, pbk_fill_min;
588 size_t frames_in, frames_out, in_max;
589 timestamp_t tstamp_start;
594 if ((c = getopt_long(argc, argv, "hP:C:m:M:U:F:f:c:r:B:E:s:y:O:bpenxX", long_option, NULL)) < 0)
601 pdevice = strdup(optarg);
604 cdevice = strdup(optarg);
607 err = atoi(optarg) / 2;
608 latency_min = err >= 4 ? err : 4;
609 if (latency_max < latency_min)
610 latency_max = latency_min;
613 err = atoi(optarg) / 2;
614 latency_max = latency_min > err ? latency_min : err;
618 sys_latency = err <= 0 ? 0 : err;
621 format = snd_pcm_format_value(optarg);
622 if (format == SND_PCM_FORMAT_UNKNOWN) {
623 printf("Unknown format, setting to default S16_LE\n");
624 format = SND_PCM_FORMAT_S16_LE;
629 channels = err >= 1 && err < 1024 ? err : 1;
633 rate = err >= 4000 && err < 200000 ? err : 44100;
637 buffer_size = err >= 32 && err < 200000 ? err : 0;
641 period_size = err >= 32 && err < 200000 ? err : 0;
645 loop_sec = err >= 1 && err <= 100000 ? err : 30;
654 usleep_val = atoi(optarg);
669 sched_policy = optarg;
678 err = snd_output_stdio_attach(&output, stdout, 0);
680 printf("Output failed: %s\n", snd_strerror(err));
684 loop_limit = loop_sec * rate;
685 latency = latency_min - 4;
686 buffer = malloc((latency_max * 2 * snd_pcm_format_physical_width(format) / 8) * channels);
688 /* I/O updates based on a system timer */
689 if (sys_latency > 0) {
696 printf("Playback device is %s\n", pdevice);
697 printf("Capture device is %s\n", cdevice);
698 printf("Parameters are %iHz, %s, %i channels, %s mode, use poll %s\n",
699 rate, snd_pcm_format_name(format),
700 channels, block ? "blocking" : "non-blocking",
701 use_poll ? "yes" : "no");
702 printf("Loop limit is %lu frames, minimum latency = %i, maximum latency = %i",
703 loop_limit, latency_min * 2, latency_max * 2);
705 printf(", I/O updates %ims", sys_latency);
706 else if (!block && !use_poll)
707 printf(", I/O usleep %ius", usleep_val);
710 if ((err = snd_pcm_open(&phandle, pdevice, SND_PCM_STREAM_PLAYBACK, block ? 0 : SND_PCM_NONBLOCK)) < 0) {
711 printf("Playback open error: %s\n", snd_strerror(err));
714 if ((err = snd_pcm_open(&chandle, cdevice, SND_PCM_STREAM_CAPTURE, block ? 0 : SND_PCM_NONBLOCK)) < 0) {
715 printf("Record open error: %s\n", snd_strerror(err));
719 /* initialize the filter sweep variables */
722 BW = FILTER_BANDWIDTH;
725 dlfo = 2.*M_PI*FILTERSWEEP_LFO_FREQ/fs;
727 x[0] = (float*) malloc(channels*sizeof(float));
728 x[1] = (float*) malloc(channels*sizeof(float));
729 x[2] = (float*) malloc(channels*sizeof(float));
730 y[0] = (float*) malloc(channels*sizeof(float));
731 y[1] = (float*) malloc(channels*sizeof(float));
732 y[2] = (float*) malloc(channels*sizeof(float));
736 pbk_fill_min = latency * 2;
739 frames_in = frames_out = 0;
740 if (setparams(phandle, chandle, &latency) < 0)
742 showlatency(latency);
743 if ((err = snd_pcm_link(chandle, phandle)) < 0) {
744 printf("Streams link error: %s\n", snd_strerror(err));
747 if (snd_pcm_format_set_silence(format, buffer, latency * channels) < 0) {
748 fprintf(stderr, "silence error\n");
751 if (writebuf(phandle, buffer, latency, &frames_out) < 0) {
752 fprintf(stderr, "write error\n");
755 if (writebuf(phandle, buffer, latency, &frames_out) < 0) {
756 fprintf(stderr, "write error\n");
761 timestamp_now(&tstamp_start);
762 if ((err = snd_pcm_start(chandle)) < 0) {
763 printf("Go error: %s\n", snd_strerror(err));
767 printf("[%lldus] Stream start\n", timestamp_diff_micro(&tstamp_start));
768 gettimestamp(phandle, &p_tstamp);
769 gettimestamp(chandle, &c_tstamp);
771 printf("Playback:\n");
772 showstat(phandle, frames_out);
773 printf("Capture:\n");
774 showstat(chandle, frames_in);
779 while (ok && frames_in < loop_limit) {
781 if (sys_latency > 0) {
782 poll(NULL, 0, sys_latency);
783 cap_avail = get_avail(chandle);
785 printf("Avail failed: %s\n", snd_strerror(cap_avail));
789 } else if (use_poll) {
790 /* use poll to wait for next event */
791 snd_pcm_wait(chandle, 1000);
792 } else if (!block && usleep_val > 0) {
795 if (pos_dump || realtime_check) {
796 if (sys_latency <= 0)
797 cap_avail = get_avail(chandle);
798 pbk_fill = get_avail(phandle);
800 pbk_fill = playback_buffer_size - pbk_fill;
801 if (cap_avail > cap_avail_max)
802 cap_avail_max = cap_avail;
803 if (pbk_fill >= 0 && pbk_fill < pbk_fill_min)
804 pbk_fill_min = pbk_fill;
805 if (realtime_check) {
806 long long diff = timestamp_diff_micro(&tstamp_start);
807 long long cap_pos = frames_to_micro(frames_in + cap_avail);
808 long long pbk_pos = frames_to_micro(frames_out - pbk_fill);
809 printf("[%lldus] POS: p=%zd (min=%zd, rt=%lldus) c=%zd (max=%zd, rt=%lldus)\n",
810 diff, pbk_fill, pbk_fill_min, pbk_pos - diff,
811 cap_avail, cap_avail_max, cap_pos - diff);
812 } else if (pos_dump) {
813 printf("POS: p=%zd (min=%zd), c=%zd (max=%zd)\n",
814 pbk_fill, pbk_fill_min, cap_avail, cap_avail_max);
817 if ((r = readbuf(chandle, buffer, cap_avail, &frames_in, &in_max)) < 0)
821 applyeffect(buffer, r);
822 if (writebuf(phandle, buffer, r, &frames_out) < 0)
830 printf("Playback:\n");
831 showstat(phandle, frames_out);
832 printf("Capture:\n");
833 showstat(chandle, frames_in);
835 if (p_tstamp.tv_sec == c_tstamp.tv_sec &&
836 p_tstamp.tv_usec == c_tstamp.tv_usec)
837 printf("Hardware sync\n");
838 if (realtime_check) {
839 long long diff = timestamp_diff_micro(&tstamp_start);
840 long long mtime = frames_to_micro(frames_in);
841 printf("Elapsed real time: %lldus\n", diff);
842 printf("Elapsed device time: %lldus\n", mtime);
843 printf("Test time diff (device - real): %lldus\n", mtime - diff);
845 snd_pcm_drop(chandle);
846 snd_pcm_nonblock(phandle, 0);
847 snd_pcm_drain(phandle);
848 snd_pcm_nonblock(phandle, !block ? 1 : 0);
851 printf("Playback time = %li.%i, Record time = %li.%i, diff = %li\n",
852 (long)p_tstamp.tv_sec,
853 (int)p_tstamp.tv_usec,
854 (long)c_tstamp.tv_sec,
855 (int)c_tstamp.tv_usec,
856 timediff(p_tstamp, c_tstamp));
860 snd_pcm_unlink(chandle);
861 snd_pcm_hw_free(phandle);
862 snd_pcm_hw_free(chandle);
864 snd_pcm_close(phandle);
865 snd_pcm_close(chandle);
866 snd_output_close(output);
867 snd_config_update_free_global();