You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

125 lines
2.6 KiB

/* Extended Module Player
* Copyright (C) 1996-2012 Claudio Matsuoka and Hipolito Carraro Jr
*
* This file is part of the Extended Module Player and is distributed
* under the terms of the GNU General Public License. See doc/COPYING
* for more information.
*/
/* This should work for OpenBSD */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/param.h>
#include <sys/audioio.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "common.h"
#include "driver.h"
#include "mixer.h"
static int audio_fd;
static int init(struct context_data *);
static int setaudio(struct xmp_options *);
static void bufdump(struct context_data *, void *, int);
static void shutdown(struct context_data *);
static void dummy()
{
}
static char *help[] = {
"gain=val", "Audio output gain (0 to 255)",
"buffer=val", "Audio buffer size (default is 32768)",
NULL
};
struct xmp_drv_info drv_openbsd = {
"openbsd", /* driver ID */
"OpenBSD PCM audio", /* driver description */
help, /* help */
init, /* init */
shutdown, /* shutdown */
dummy, /* starttimer */
dummy, /* flush */
bufdump, /* bufdump */
};
static int setaudio(struct xmp_options *o)
{
audio_info_t ainfo;
int gain = 128;
int bsize = 32 * 1024;
char *token, **parm;
parm_init();
chkparm1("gain", gain = strtoul(token, NULL, 0));
chkparm1("buffer", bsize = strtoul(token, NULL, 0));
parm_end();
if (gain < AUDIO_MIN_GAIN)
gain = AUDIO_MIN_GAIN;
if (gain > AUDIO_MAX_GAIN)
gain = AUDIO_MAX_GAIN;
AUDIO_INITINFO(&ainfo);
ainfo.play.sample_rate = o->freq;
ainfo.play.channels = o->outfmt & XMP_FORMAT_MONO ? 1 : 2;
ainfo.play.precision = o->resol;
ainfo.play.encoding = o->resol > 8 ?
AUDIO_ENCODING_SLINEAR : AUDIO_ENCODING_ULINEAR;
ainfo.play.gain = gain;
ainfo.play.buffer_size = bsize;
if (ioctl(audio_fd, AUDIO_SETINFO, &ainfo) == -1) {
close(audio_fd);
return XMP_ERR_DINIT;
}
drv_openbsd.description = "OpenBSD PCM audio";
return 0;
}
static int init(struct context_data *ctx)
{
if ((audio_fd = open("/dev/sound", O_WRONLY)) == -1)
return XMP_ERR_DINIT;
if (setaudio(&ctx->o) != 0)
return XMP_ERR_DINIT;
return 0;
}
/* Build and write one tick (one PAL frame or 1/50 s in standard vblank
* timed mods) of audio data to the output device.
*/
static void bufdump(struct context_data *ctx, void *b, int i)
{
int j;
while (i) {
if ((j = write(audio_fd, b, i)) > 0) {
i -= j;
b = (char *)b + j;
} else
break;
}
}
static void shutdown(struct context_data *ctx)
{
close(audio_fd);
}