File: ossdelay.c

package info (click to toggle)
alsa-driver 1.0.13-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 20,108 kB
  • ctags: 50,477
  • sloc: ansic: 319,881; sh: 32,930; makefile: 2,015; python: 1,527; perl: 1,316; xml: 896; awk: 66
file content (38 lines) | stat: -rw-r--r-- 977 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>

int main (void)
{
  short buf[256*2*100];
  int hifi, precision=8, stereo=1, rate=8000, odelay, old = 0x7ffffff, x;
  
  hifi = open ("/dev/dsp", O_WRONLY);
  if (hifi < 0 ||
  ioctl(hifi, SNDCTL_DSP_SAMPLESIZE, &precision) == -1 ||
  ioctl(hifi, SNDCTL_DSP_STEREO, &stereo) == -1 ||
  ioctl(hifi, SNDCTL_DSP_SPEED, &rate) == -1) {
    fprintf (stderr, "Unable to open sound device\n");
    return 3;
  }
  memset(buf, 0, sizeof(buf));
  write(hifi, buf, sizeof(buf));
  for (x=0;;x++) {
    //usleep (50000); // Take this out, to experiment
    if (ioctl (hifi, SNDCTL_DSP_GETODELAY, &odelay) < 0) {
    	perror("ioctl");
    	return 4;
    }
    if (old != odelay) {
	    printf ("%c %10d %10d\n", old < odelay ? '*' : ' ', odelay, odelay % 256);
	    old = odelay;
    }
    if (odelay == 0)
      break;
  }
  return 0;
}