Audio

 view release on metacpan or  search on metacpan

Play/config/sun.xs  view on Meta::CPAN

/*
  Copyright (c) 1995,1996,1997 Nick Ing-Simmons. All rights reserved.
  This program is free software; you can redistribute it and/or
  modify it under the same terms as Perl itself.
*/

#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/filio.h>
#include <signal.h>

#include "../../Data/Audio.m"

AudioVtab     *AudioVptr;

#include <sys/ioctl.h>

#ifdef HAVE_SYS_IOCCOM_H
#include <sys/ioccom.h>
#endif
#ifdef HAVE_SYS_AUDIOIO_H
#include <sys/audioio.h>
#endif
#ifdef HAVE_SUN_AUDIOIO_H
#include <sun/audioio.h>
#endif

#define SAMP_RATE 8000

typedef struct
{
 audio_info_t info;
 int fd;
 int kind;
} play_audio_t;

static char *dev_file = "/dev/audio";

audio_open(play_audio_t *dev, int Wait)
{
 /* Try it quickly, first */
 Zero(dev, 1, play_audio_t);
 dev->fd = open(dev_file, O_WRONLY | O_NDELAY);
 if ((dev->fd < 0) && (errno == EBUSY))
  {
   if (!Wait)
    {
     croak("%s is busy\n", dev_file);
    }
   /* Now hang until it's open */
   dev->fd = open(dev_file, O_WRONLY);
  }
 else if (dev->fd >= 0)
  {
   int flags = fcntl(dev->fd, F_GETFL, NULL);
   if (flags >= 0)
    fcntl(dev->fd, F_SETFL, flags & ~O_NDELAY);
   else
    perror("fcntl - F_GETFL");
  }
 if (dev->fd < 0)
  {
   return 0;
  }
 else
  {
#ifdef AUDIO_DEV_AMD
   /* Get the device output encoding configuration */
   if (ioctl(dev->fd, AUDIO_GETDEV, &dev->kind))
    {
     /* Old releases of SunOs don't support the ioctl,
        but can only be run on old machines which have AMD device...
      */
     dev->kind = AUDIO_DEV_AMD;
    }
#endif
   if (ioctl(dev->fd, AUDIO_GETINFO, &dev->info) != 0)
    {
     return 0;
    }
  }
 return 1;
}

static int
audio_setinfo(play_audio_t *dev)
{
 return (ioctl(dev->fd, AUDIO_SETINFO, &dev->info) != 0);
}

IV
audio_rate(play_audio_t *dev,IV rate)
{
 IV prev_rate = dev->info.play.sample_rate;
 if (rate)
  {
   dev->info.play.sample_rate = rate;
#ifdef AUDIO_ENCODING_LINEAR
   if (rate > 8000)
    {
     dev->info.play.encoding = AUDIO_ENCODING_LINEAR;
     dev->info.play.precision = 16;
    }
   else
    {
     dev->info.play.encoding = AUDIO_ENCODING_ULAW;
     dev->info.play.precision = 8;
    }



( run in 3.367 seconds using v1.01-cache-2.11-cpan-302cb4679cc )