2
* Multi channel audio test.
4
* This program is intended to test playback of 16 bit samples using 4 or more
5
* channels at 48000 Hz. The program plays sine wave pulses sequentially on
10
* 1: Number of channelts (default is 8).
11
* 2: Audio device (/dev/dsp by default).
13
* -b Bypass virtual mixer
14
* -r Raw mode (disables automatic sample rate/format conversions)
20
#include <sys/ioctl.h>
21
#include <soundcard.h>
23
static int sinedata[48] = {
25
0, 4276, 8480, 12539, 16383, 19947, 23169, 25995,
26
28377, 30272, 31650, 32486, 32767, 32486, 31650, 30272,
27
28377, 25995, 23169, 19947, 16383, 12539, 8480, 4276,
28
0, -4276, -8480, -12539, -16383, -19947, -23169, -25995,
29
-28377, -30272, -31650, -32486, -32767, -32486, -31650, -30272,
30
-28377, -25995, -23169, -19947, -16383, -12539, -8480, -4276
34
main (int argc, char *argv[])
36
char *dev = "/dev/dsp";
37
int fd, l, i, n = 0, ch, p = 0, phase = 0, arg, channels, srate, thisch = 0;
41
int disable_format_conversions=0;
46
if (sscanf (argv[1], "%d", &nch) != 1)
56
case 'b': /* Bypass virtual mixer */
60
case 'r': /* Use raw mode (disable automatic format conversions) */
61
disable_format_conversions=1;
65
if ((fd = open (dev, O_WRONLY|bypass_vmix, 0)) == -1)
71
if (disable_format_conversions)
74
ioctl(fd, SNDCTL_DSP_COOKEDMODE, &arg);
78
if (ioctl (fd, SNDCTL_DSP_CHANNELS, &arg) == -1)
79
perror ("SNDCTL_DSP_CHANNELS");
81
fprintf (stderr, "Channels %d\n", arg);
84
if (ioctl (fd, SNDCTL_DSP_SETFMT, &arg) == -1)
85
perror ("SNDCTL_DSP_SETFMT");
86
fprintf (stderr, "Format %x\n", arg);
89
if (ioctl (fd, SNDCTL_DSP_SPEED, &arg) == -1)
90
perror ("SNDCTL_DSP_SPEED");
91
printf ("Using sampling rate %d\n", arg);
96
for (ch = 0; ch < channels; ch++)
100
buf[p] = sinedata[phase];
101
phase = (phase + 1 + (ch / 2)) % 48;
102
if (phase == 0 && tick > 10 * channels)
104
thisch = (thisch + 1) % channels;
113
if (p >= sizeof (buf) / 2)
115
if (write (fd, buf, p * 2) != p * 2)