From 333f9c8d3e6165bdd4c620843f42ad87a27e720b Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Fri, 30 Mar 2012 07:09:55 -0300 Subject: [PATCH] [xmp] Add Amiga AHI driver Signed-off-by: Claudio Matsuoka --- configure.ac | 4 ++ src/drivers/amiga.c | 90 --------------------------------------------- src/sound.c | 4 ++ src/sound_ahi.c | 88 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 90 deletions(-) delete mode 100644 src/drivers/amiga.c create mode 100644 src/sound_ahi.c diff --git a/configure.ac b/configure.ac index 770ca15..dce9503 100644 --- a/configure.ac +++ b/configure.ac @@ -56,6 +56,10 @@ if test "${ac_cv_header_alsa_asoundlib_h}" = "yes"; then fi case "${host_os}" in +amigaos*|aros) + DRIVERS="${DRIVERS} sound_ahi.o" + AC_DEFINE(DRIVER_AHI) + ;; darwin*) AC_CHECK_HEADER(CoreAudio/CoreAudio.h) if test "${ac_cv_header_CoreAudio_CoreAudio_h}" = "yes"; then diff --git a/src/drivers/amiga.c b/src/drivers/amiga.c deleted file mode 100644 index d5b2d7d..0000000 --- a/src/drivers/amiga.c +++ /dev/null @@ -1,90 +0,0 @@ -/* Amiga AHI driver for Extended Module Player - * Copyright (C) 2007 Lorence Lombardo - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#include "common.h" -#include "driver.h" -#include "mixer.h" -#include "convert.h" - -static int fd; - -static int init(struct context_data *); -static void bufdump(struct context_data *, void *, int); -static void shutdown(struct context_data *); - -static void dummy() -{ -} - -static char *help[] = { - "buffer=val", "Audio buffer size", - NULL -}; - -struct xmp_drv_info drv_amiga = { - "ahi", /* driver ID */ - "Amiga AHI audio", /* driver description */ - help, /* help */ - init, /* init */ - shutdown, /* shutdown */ - dummy, /* starttimer */ - dummy, /* stoptimer */ - dummy, /* resetvoices */ - bufdump, /* bufdump */ - NULL -}; - -static int init(struct context_data *ctx) -{ - struct xmp_options *o = &ctx->o; - char outfile[256]; - int nch = o->outfmt & XMP_FORMAT_MONO ? 1 : 2; - int bsize = o->freq * nch * o->resol / 4; - char *token, **parm; - - parm_init(); - chkparm1("buffer", bsize = strtoul(token, NULL, 0)); - parm_end(); - - sprintf(outfile, "AUDIO:B/%d/F/%d/C/%d/BUFFER/%d", - o->resol, o->freq, nch, bsize); - - fd = open(outfile, O_WRONLY); - - return 0; -} - -static void bufdump(struct context_data *ctx, void *b, int i) -{ - int j; - - while (i) { - if ((j = write(fd, b, i)) > 0) { - i -= j; - b = (char *)b + j; - } else - break; - } -} - -static void shutdown(struct context_data *ctx) -{ - if (fd) - close(fd); -} diff --git a/src/sound.c b/src/sound.c index 079f149..565bc5f 100644 --- a/src/sound.c +++ b/src/sound.c @@ -11,6 +11,7 @@ extern struct sound_driver sound_sndio; extern struct sound_driver sound_solaris; extern struct sound_driver sound_bsd; extern struct sound_driver sound_beos; +extern struct sound_driver sound_amiga; LIST_HEAD(sound_driver_list); @@ -21,6 +22,9 @@ static void register_sound_driver(struct sound_driver *sd) void init_sound_drivers() { +#ifdef SOUND_AHI + register_sound_driver(&sound_ahi); +#endif #ifdef SOUND_BEOS register_sound_driver(&sound_beos); #endif diff --git a/src/sound_ahi.c b/src/sound_ahi.c new file mode 100644 index 0000000..013bd53 --- /dev/null +++ b/src/sound_ahi.c @@ -0,0 +1,88 @@ +/* Amiga AHI driver for Extended Module Player + * Copyright (C) 2007 Lorence Lombardo + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include "sound.h" + +static int fd; + +static int init(struct options *options) +{ + char **parm = options->driver_parm; + char outfile[256]; + int nch = options->format & XMP_FORMAT_MONO ? 1 : 2; + int res = options->format & XMP_FORMAT_8BIT ? 8 : 16; + int bsize = options->rate * nch * res / 4; + + parm_init(parm); + chkparm1("buffer", bsize = strtoul(token, NULL, 0)); + parm_end(); + + sprintf(outfile, "AUDIO:B/%d/F/%d/C/%d/BUFFER/%d", + res, options->rate, nch, bsize); + + fd = open(outfile, O_WRONLY); + if (fd < 0) + return -1; + + return 0; +} + +static void play(void *b, int i) +{ + int j; + + while (i) { + if ((j = write(fd, b, i)) > 0) { + i -= j; + b = (char *)b + j; + } else + break; + } +} + +static void deinit() +{ + close(fd); +} + +static void flush() +{ +} + +static void onpause() +{ +} + +static void onresume() +{ +} + + +static char *help[] = { + "buffer=val", "Audio buffer size", + NULL +}; + +struct sound_driver sound_ahi = { + "ahi", + "Amiga AHI audio", + help, + init, + deinit, + play, + flush, + onpause, + onresume +}; +