From 2d642f015cdcdc32330b7dc790318d5b7024803a Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Fri, 23 Mar 2012 20:57:49 -0300 Subject: [PATCH] [xmp] Fixes for mingw32 build Signed-off-by: Claudio Matsuoka --- Makefile.in | 2 +- configure.ac | 22 ++++--- src/Makefile | 2 +- src/commands.c | 5 +- src/main.c | 22 +++++-- src/{drivers/win32.c => sound_win32.c} | 80 ++++++++++++++------------ src/terminal.c | 9 ++- 7 files changed, 90 insertions(+), 52 deletions(-) rename src/{drivers/win32.c => sound_win32.c} (75%) diff --git a/Makefile.in b/Makefile.in index 5799af0..ec52b68 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,7 +1,7 @@ VERSION = 3.9.0 CC = @CC@ -CFLAGS = -c -Wall @CFLAGS@ @DEFS@ @CPPFLAGS@ +CFLAGS = -c -Wall @CFLAGS@ @DEFS@ @CPPFLAGS@ -DSOUND_DRIVER=$(DRIVER) LD = @CC@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ diff --git a/configure.ac b/configure.ac index 9d80bb8..83c6c89 100644 --- a/configure.ac +++ b/configure.ac @@ -12,7 +12,12 @@ if test "$libxmp_path" != ""; then LIBS="${LIBS} -L${libxmp_path}/lib" fi -AC_CHECK_HEADERS(xmp.h getopt.h signal.h termios.h alsa/asoundlib.h CoreAudio/CoreAudio.h) +AC_CHECK_HEADERS(xmp.h getopt.h signal.h termios.h) +AC_CHECK_HEADER(windows.h,,[ + AC_CHECK_HEADER(CoreAudio/CoreAudio.h,,[ + AC_CHECK_HEADER(alsa/asoundlib.h) + ]) +]) if test "${ac_cv_header_xmp_h}" = "yes"; then AC_CHECK_LIB(xmp,xmp_player_start,, @@ -21,18 +26,19 @@ else AC_MSG_ERROR(Can't find libxmp header files) fi -if test "${ac_cv_header_alsa_asoundlib_h}" = "yes"; then +if test "${ac_cv_header_windows_h}" = "yes"; then + AC_SUBST(SOUND_DRIVER,sound_win32) + LIBS="${LIBS} -lwinmm" +elif test "${ac_cv_header_CoreAudio_CoreAudio_h}" = "yes"; then + AC_SUBST(SOUND_DRIVER,sound_coreaudio) + LIBS="${LIBS} -framework AudioToolbox -framework AudioUnit -framework CoreServices" +elif test "${ac_cv_header_alsa_asoundlib_h}" = "yes"; then AC_SUBST(SOUND_DRIVER,sound_alsa) AC_CHECK_LIB(asound,snd_pcm_open,, AC_MSG_ERROR(Can't find libasound)) fi -if test "${ac_cv_header_CoreAudio_CoreAudio_h}" = "yes"; then - AC_SUBST(SOUND_DRIVER,sound_coreaudio) - LIBS="${LIBS} -framework AudioToolbox -framework AudioUnit -framework CoreServices" -fi - -AC_CHECK_FUNCS(getopt_long) +AC_CHECK_FUNCS(kill getopt_long) AC_PROG_INSTALL AC_CONFIG_FILES([Makefile]) diff --git a/src/Makefile b/src/Makefile index de99e07..c7105ad 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,7 +12,7 @@ dist-src: cp -RPp $(addprefix $(SRC_PATH)/,$(SRC_DFILES)) $(DIST)/$(SRC_PATH) $(SRC_PATH)/xmp: $(OBJS) $(SRC_PATH)/$(DRIVER).o - @CMD='$(LD) -o $@ $(LDFLAGS) $(OBJS) $(SRC_PATH)/$(DRIVER).o $(LIBS) -lasound'; \ + @CMD='$(LD) -o $@ $(LDFLAGS) $(OBJS) $(SRC_PATH)/$(DRIVER).o $(LIBS)'; \ if [ "$(V)" -gt 0 ]; then echo $$CMD; else echo LD $@ ; fi; \ eval $$CMD diff --git a/src/commands.c b/src/commands.c index 6d667dd..7aee0f4 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1,4 +1,7 @@ #include +#ifdef WIN32 +#include +#endif #include #include "common.h" @@ -56,7 +59,7 @@ static int read_key() ret = read(0, &key, 1); #elif defined WIN32 if (kbhit()) { - cmd = getch(); + key = getch(); ret = 1; } #elif defined __AMIGA__ diff --git a/src/main.c b/src/main.c index d8b751b..257e209 100644 --- a/src/main.c +++ b/src/main.c @@ -11,11 +11,15 @@ #include "sound.h" #include "common.h" +#ifdef WIN32 +#include +#endif + extern int optind; -extern struct sound_driver sound_alsa; +extern struct sound_driver SOUND_DRIVER; extern struct sound_driver sound_null; -struct sound_driver *sound = &sound_alsa; +struct sound_driver *sound = &SOUND_DRIVER; static int background = 0; static int refresh_status; @@ -25,7 +29,9 @@ static void cleanup(int sig) { signal(SIGTERM, SIG_DFL); signal(SIGINT, SIG_DFL); +#ifdef SIGQUIT signal(SIGQUIT, SIG_DFL); +#endif signal(SIGFPE, SIG_DFL); signal(SIGSEGV, SIG_DFL); @@ -33,7 +39,9 @@ static void cleanup(int sig) reset_tty(); signal(sig, SIG_DFL); +#ifdef HAVE_KILL kill(getpid(), sig); +#endif } #endif @@ -42,18 +50,20 @@ static void sigtstp_handler(int n) { fprintf(stderr, "\n"); signal(SIGTSTP, SIG_DFL); +#ifdef HAVE_KILL kill(getpid(), SIGTSTP); +#endif } static void sigcont_handler(int sig) { -#ifndef __AMIGA__ +#ifdef HAVE_TERMIOS_H background = (tcgetpgrp(0) == getppid()); -#endif if (!background) { set_tty(); } +#endif refresh_status = 1; @@ -179,18 +189,22 @@ int main(int argc, char **argv) signal(SIGINT, cleanup); signal(SIGFPE, cleanup); signal(SIGSEGV, cleanup); +#ifdef SIGQUIT signal(SIGQUIT, cleanup); +#endif #ifdef SIGTSTP signal(SIGCONT, sigcont_handler); signal(SIGTSTP, sigtstp_handler); #endif #endif +#ifdef HAVE_TERMIOS_H background = (tcgetpgrp (0) == getppid ()); if (!background) { set_tty(); } +#endif handle = xmp_create_context(); diff --git a/src/drivers/win32.c b/src/sound_win32.c similarity index 75% rename from src/drivers/win32.c rename to src/sound_win32.c index 2d5bb11..a9a3aba 100644 --- a/src/drivers/win32.c +++ b/src/sound_win32.c @@ -14,13 +14,16 @@ #endif #include -#include "common.h" -#include "driver.h" -#include "mixer.h" +#include +#include "sound.h" #define MAXBUFFERS 32 /* max number of buffers */ #define BUFFERSIZE 120 /* buffer size in ms */ +/* frame rate = (50 * bpm / 125) Hz */ +/* frame size = (sampling rate * channels * size) / frame rate */ +#define OUT_MAXLEN 0x8000 + static HWAVEOUT hwaveout; static WAVEHDR header[MAXBUFFERS]; static LPSTR buffer[MAXBUFFERS]; /* pointers to buffers */ @@ -28,30 +31,11 @@ static WORD freebuffer; /* */ static WORD nextbuffer; /* next buffer to be mixed */ static int num_buffers; -static int init(struct context_data *); -static void bufdump(struct context_data *, void *, int); -static void deinit(struct context_data *); - -static void dummy() -{ -} - static char *help[] = { "buffers=val", "Number of buffers (default 10)", NULL }; -struct xmp_drv_info drv_win32 = { - "win32", /* driver ID */ - "Windows WinMM driver", /* driver description */ - help, /* help */ - init, /* init */ - deinit, /* shutdown */ - dummy, /* starttimer */ - dummy, /* flush */ - bufdump, /* bufdump */ -}; - static void show_error(int res) { char *msg; @@ -91,30 +75,29 @@ static void CALLBACK wave_callback(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance, } } -static int init(struct context_data *ctx) +static int init(int *sampling_rate, int *format) { - struct xmp_options *o = &ctx->o; MMRESULT res; WAVEFORMATEX wfe; int i; - char *token, **parm; + //char *token, **parm; num_buffers = 10; - parm_init(); - chkparm1("buffers", num_buffers = strtoul(token, NULL, 0)); - parm_end(); + //parm_init(); + //chkparm1("buffers", num_buffers = strtoul(token, NULL, 0)); + //parm_end(); if (num_buffers > MAXBUFFERS) num_buffers = MAXBUFFERS; if (!waveOutGetNumDevs()) - return XMP_ERR_DINIT; + return -1; wfe.wFormatTag = WAVE_FORMAT_PCM; - wfe.wBitsPerSample = o->resol; - wfe.nChannels = o->flags & XMP_FORMAT_MONO ? 1 : 2; - wfe.nSamplesPerSec = o->freq; + wfe.wBitsPerSample = *format & XMP_FORMAT_8BIT ? 8 : 16; + wfe.nChannels = *format & XMP_FORMAT_MONO ? 1 : 2; + wfe.nSamplesPerSec = *sampling_rate; wfe.nAvgBytesPerSec = wfe.nSamplesPerSec * wfe.nChannels * wfe.wBitsPerSample / 8; wfe.nBlockAlign = wfe.nChannels * wfe.wBitsPerSample / 8; @@ -124,7 +107,7 @@ static int init(struct context_data *ctx) if (res != MMSYSERR_NOERROR) { show_error(res); - return XMP_ERR_DINIT; + return -1; } waveOutReset(hwaveout); @@ -135,7 +118,7 @@ static int init(struct context_data *ctx) if (!buffer[i] || res != MMSYSERR_NOERROR) { show_error(res); - return XMP_ERR_DINIT; + return -1; } } @@ -144,7 +127,7 @@ static int init(struct context_data *ctx) return 0; } -static void bufdump(struct context_data *ctx, void *b, int len) +static void play(void *b, int len) { memcpy(buffer[nextbuffer], b, len); @@ -159,7 +142,7 @@ static void bufdump(struct context_data *ctx, void *b, int len) nextbuffer %= num_buffers; } -static void deinit(struct context_data *ctx) +static void deinit() { int i; @@ -175,3 +158,28 @@ static void deinit(struct context_data *ctx) hwaveout = NULL; } } + +static void flush() +{ +} + +static void onpause() +{ +} + +static void onresume() +{ +} + +struct sound_driver sound_win32 = { + "win32", + "Windows WinMM", + help, + init, + deinit, + play, + flush, + onpause, + onresume +}; + diff --git a/src/terminal.c b/src/terminal.c index 687c2fa..a22aea5 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -1,12 +1,16 @@ #include -#include #include #include "common.h" +#ifdef HAVE_TERMIOS_H +#include + static struct termios term; +#endif int set_tty() { +#ifdef HAVE_TERMIOS_H struct termios t; if (tcgetattr(0, &term) < 0) @@ -18,16 +22,19 @@ int set_tty() if (tcsetattr(0, TCSAFLUSH, &t) < 0) return -1; +#endif return 0; } int reset_tty() { +#ifdef HAVE_TERMIOS_H if (tcsetattr(0, TCSAFLUSH, &term) < 0) { fprintf(stderr, "can't reset terminal!\n"); return -1; } +#endif return 0; }