~ubuntu-branches/ubuntu/oneiric/oss4/oneiric-proposed

« back to all changes in this revision

Viewing changes to tutorials/sndkit/samples/playtgt.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2011-06-16 20:37:48 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110616203748-jbrxik6ql33z54co
Tags: 4.2-build2004-1ubuntu1
* Merge from Debian unstable.
  - Supports our current kernel (LP: #746048)
  Remaining changes:
  - debian/oss4-dkms.dkms.in: s/source/build/ in Kernel headers paths.
* ld-as-needed.patch: Re-order CC arguments to enable building with ld
  --as-needed (LP: #770972)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Purpose: A sample program for play target selection
 
3
 * Copyright (C) 4Front Technologies, 2002-2007. Released under GPLv2/CDDL.
 
4
 *
 
5
 * Description:
 
6
 * This program demonstrates the new ioctl call interface used to
 
7
 * control the play target selection.
 
8
 *
 
9
 * The first command line argument is the audio device (/dev/dsp#). If there 
 
10
 * are no other arguments then the available choices will be printed. If the 
 
11
 * second argument is "-" then the current setting will be printed.
 
12
 * Finally the source can be changed by giving it's name as the
 
13
 * second argument.
 
14
 *
 
15
 * {!notice Please not that the change may stay in effect even after closing
 
16
 * the device. However equally well it's possible that the device returns back
 
17
 * to some default source. There is no way to predict how the device will
 
18
 * behave and the application must not expect any particular behaviour.}
 
19
 */
 
20
#include <stdio.h>
 
21
#include <unistd.h>
 
22
#include <stdlib.h>
 
23
#include <string.h>
 
24
#include <fcntl.h>
 
25
#include <soundcard.h>
 
26
#include <time.h>
 
27
 
 
28
int
 
29
main (int argc, char *argv[])
 
30
{
 
31
  int fd, i, src;
 
32
  oss_mixer_enuminfo ei;
 
33
 
 
34
  if (argc < 2)
 
35
    {
 
36
      fprintf (stderr, "Usage: %s dspdev\n", argv[0]);
 
37
      exit (-1);
 
38
    }
 
39
 
 
40
  if ((fd = open (argv[1], O_WRONLY, 0)) == -1)
 
41
    {
 
42
      perror (argv[1]);
 
43
      exit (-1);
 
44
    }
 
45
 
 
46
  if (ioctl (fd, SNDCTL_DSP_GET_PLAYTGT_NAMES, &ei) == -1)
 
47
    {
 
48
      perror ("SNDCTL_DSP_GET_PLAYTGT_NAMES");
 
49
      exit (-1);
 
50
    }
 
51
 
 
52
  if (argc == 2)
 
53
    {
 
54
      for (i = 0; i < ei.nvalues; i++)
 
55
        printf ("Play target #%d = '%s'\n", i, ei.strings + ei.strindex[i]);
 
56
      exit (0);
 
57
    }
 
58
 
 
59
  if (strcmp (argv[2], "?") == 0 || strcmp (argv[2], "-") == 0)
 
60
    {
 
61
      if (ioctl (fd, SNDCTL_DSP_GET_PLAYTGT, &src) == -1)
 
62
        {
 
63
          perror ("SNDCTL_DSP_GET_PLAYTGT");
 
64
          exit (-1);
 
65
        }
 
66
 
 
67
      printf ("Current play target is #%d\n", src);
 
68
      printf ("Current play target is #%d (%s)\n",
 
69
              src, ei.strings + ei.strindex[src]);
 
70
      exit (0);
 
71
    }
 
72
 
 
73
  src = 0;
 
74
 
 
75
  for (i = 0; i < ei.nvalues; i++)
 
76
    {
 
77
      if (strcmp (argv[2], ei.strings + ei.strindex[i]) == 0)
 
78
        {
 
79
          if (ioctl (fd, SNDCTL_DSP_SET_PLAYTGT, &src) == -1)
 
80
            {
 
81
              perror ("SNDCTL_DSP_SET_PLAYTGT");
 
82
              exit (-1);
 
83
            }
 
84
 
 
85
          exit (0);
 
86
        }
 
87
 
 
88
      src++;
 
89
    }
 
90
 
 
91
  fprintf (stderr, "What?\n");
 
92
  exit (-1);
 
93
}