
# include <stdio.h>
# include <unistd.h>
# include <fcntl.h>
# include <sys/ioctl.h>
# include <sys/soundcard.h>

# define DEV_MIXER  "/dev/mixer"

/* The following definitions are from include/asm-arm/arch-sa1100/empeg.h
   in the beta10a kernel source */

# define EMPEG_MIXER_MAGIC 'm'

# define EMPEG_MIXER_SET_SAM _IOW(EMPEG_MIXER_MAGIC, 15, int)

int main(int argc, char *argv[])
{
  int fd, opt, sam = -1;

  while ((opt = getopt(argc, argv, "mu")) != -1) {
    switch (opt) {
    case 'm':
      sam = 1;
      break;

    case 'u':
      sam = 0;
      break;

    default:
      return 1;
    }
  }

  if (sam == -1) {
    fprintf(stderr, "Usage: %s {-u|-m}\n", argv[0]);
    return 1;
  }

  fd = open(DEV_MIXER, O_RDONLY);
  if (fd == -1) {
    perror(DEV_MIXER);
    return 2;
  }

  if (ioctl(fd, EMPEG_MIXER_SET_SAM, &sam) == -1) {
    perror("ioctl(EMPEG_MIXER_SET_SAM)");
    return 3;
  }

  printf("Soft Audio Mute %s\n", sam ? "enabled" : "disabled");

  if (close(fd) == -1) {
    perror("close");
    return 5;
  }

  return 0;
}

