2
* Purpose: A program that demonstrates use of syncronization groups.
3
* Copyright (C) 4Front Technologies, 2002-2004. Released under GPLv2/CDDL.
6
* This program opens three audio devices (hard coded in the program)
7
* and creates a syncronization group using {!nlink SNDCTL_DSP_SYNCGROUP}.
9
* Next it starts all the devices joined in the group simultaneously
10
* by calling {!nlink SNDCTL_DSP_SYNCSTART}. Finally it will keep copying
11
* audio input from the 3rd device to the other two ones.
17
#include <sys/ioctl.h>
18
#include <soundcard.h>
23
main (int argc, char *argv[])
25
int i, id, fd[MAX_DEV], ndevs = 0;
26
char buf[32768] = { 0 };
31
group.mode = PCM_ENABLE_OUTPUT;
34
* Open the devices listed on command line
39
for (i = 1; i < argc; i++)
41
if ((fd[ndevs] = open (argv[i], O_WRONLY, 0)) == -1)
47
if (ioctl (fd[ndevs], SNDCTL_DSP_SYNCGROUP, &group) == -1)
49
perror ("SNDCTL_DSP_SYNCGROUP");
53
* Note! It is very important to write some data to all output devices
54
* between calling SNDCTL_DSP_SYNCGROUP and SNDCTL_DSP_SYNCSTART. Otherwise
55
* playback will not start properly. However do not write more data than
56
* there is room in device's DMA buffer. Recommended amount of prteload data
57
* is one full fragment.
59
* In applications that record audio, process it and then play back it's
60
* necessary to write two fragments of silence to the output device(s) before
61
* starting the group. Otherwise output device(s) will run out of data before
62
* the first read from the input device returns.
65
if (write (fd[ndevs], buf, sizeof (buf)) != sizeof (buf))
74
printf ("Sync group %x created with %d devices\n", group.id, ndevs);
79
if (ioctl (fd[0], SNDCTL_DSP_SYNCSTART, &id) == -1)
81
perror ("SNDCTL_DSP_SYNCSTART");
87
for (i = 0; i < ndevs; i++)
88
if (write (fd[i], buf, sizeof (buf)) != sizeof (buf))