view pwplib/snd-oss.c @ 71:a87eb778f225

Improvements to the MinGW crossbuild. Should now build with default tools from Debian mingw packages, though you need Win32 version of libSDL with the necessary headers and so on in addition. 64-bit builds not tested and probably won't work. Tested on Debian 7.0, earlier won't work. binutils-mingw-w64-i686 gcc-mingw-w64-i686 mingw-w64-i686-dev
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 14 Aug 2012 03:08:10 +0300
parents 85671798fdb3
children
line wrap: on
line source

#include "config.h"

#ifdef DRIVE_OSS

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

#include <linux/soundcard.h>
#include "sound.h"

struct {
   int fd;
   char buf[4096];
   int buflgt;
   int freq;
} pwp_oss;

static void oss_loopflush()
{
  for(;;)
  {
    audio_buf_info bi;
    ioctl(pwp_oss.fd, SNDCTL_DSP_GETOSPACE, &bi);
    if (bi.fragments == 1) break;
    pwplib.player();
    gb_genwave(pwp_oss.buf, pwp_oss.buflgt);
    write(pwp_oss.fd, pwp_oss.buf, pwp_oss.buflgt);
    if (bi.fragments < 3) break;
  }
}

static void oss_restore()
{
  close(pwp_oss.fd);
}

int oss_init(void)
{
  pwp_oss.fd = open("/dev/dsp", O_WRONLY);
  if (pwp_oss.fd < 0)
    return 0;

  pwpwrite("* OSS sound\n");

  pwp_oss.freq = 8000;
  pwp_oss.buflgt = pwp_oss.freq/TIMERHZ;

  pwplib.sound = gb_sound;
  pwplib.loopflush = oss_loopflush;
  gb_init(pwp_oss.freq);

  pwplib_regdestr(oss_restore);

  return 1;
}

#endif