diff --git a/configure.ac b/configure.ac index 19ca3151..97a9d8bf 100644 --- a/configure.ac +++ b/configure.ac @@ -158,12 +158,29 @@ AC_CHECK_LIB( [audio], [AuOpenServer], ) # Check for PortAudio -AC_CHECK_LIB( [portaudio], [Pa_Initialize], - [ AC_CHECK_HEADER( [portaudio.h], - [ HAVE_PORTAUDIO="yes" ], - [ AC_MSG_WARN([Found PortAudio library but NOT header files on your system]) ] ) - ] -) +case $target in + *-*-mingw32) + # We tested portaudio with MME + if test "x$HAVE_PORTAUDIO" != "xyes"; then + AC_CHECK_LIB( [portaudio], [Pa_Initialize], + [ AC_CHECK_HEADER( [portaudio.h], + [ HAVE_PORTAUDIO_WINMM="yes" && HAVE_PORTAUDIO="yes" ], + [ AC_MSG_WARN([Found PortAudio library but NOT header files on your system]) ] ) + ], + [ HAVE_PORTAUDIO="no" ], + [ -lwinmm ] + ) + fi + ;; + *) + AC_CHECK_LIB( [portaudio], [Pa_Initialize], + [ AC_CHECK_HEADER( [portaudio.h], + [ HAVE_PORTAUDIO="yes" ], + [ AC_MSG_WARN([Found PortAudio library but NOT header files on your system]) ] ) + ] + ) + ;; +esac # Check for ALSA AC_CHECK_LIB( [asound], [snd_pcm_open], @@ -182,10 +199,10 @@ AC_CHECK_HEADERS([stdlib.h string.h unistd.h sched.h sys/ioctl.h stdint.h limits # OSS Header files -AC_CHECK_HEADERS([sys/soundcard.h linux/soundcard.h machine/soundcard.h]) +AC_CHECK_HEADERS([sys/soundcard.h linux/soundcard.h machine/soundcard.h], HAVE_OSS=yes, HAVE_OSS=no) # Sun Audio headers -AC_CHECK_HEADERS([sun/audioio.h sys/audioio.h asm/audioio.h sys/audio.h]) +AC_CHECK_HEADERS([sun/audioio.h sys/audioio.h asm/audioio.h sys/audio.h], HAVE_SUNAUDIO=yes, HAVE_SUNAUDIO=no) # Mac OS X AC_CHECK_HEADERS([AudioUnit/AudioUnit.h CoreServices/CoreServices.h AudioToolbox/AudioToolbox.h], @@ -205,7 +222,8 @@ if test "$debugging" = "enabled"; then CFLAGS="$CFLAGS -g" # gcc specific... if test "$GCC" = "yes"; then - CFLAGS="$CFLAGS -Wall -Werror -pedantic -fno-strict-aliasing" + # no -Werror until I fixed that SSE long-long stuff... + CFLAGS="$CFLAGS -Wall -pedantic -fno-strict-aliasing" fi fi @@ -268,10 +286,30 @@ case $target in *-pc-cygwin*) cpu_type="generic_fpu" ;; + *-*-mingw32) + LIBS="-lwsock32 $LIBS" + CPPFLAGS="-DNOXFERMEM $CPPFLAGS" + cpu_type="x86" + ;; + i386-*) + AC_MSG_WARN([Unknown target operating system]) + cpu_type="i386" + CFLAGS="-DGENERIC $CFLAGS" + ;; + i486-*) + AC_MSG_WARN([Unknown target operating system]) + cpu_type="i486" + CFLAGS="-DGENERIC $CFLAGS" + ;; + i586-*) + AC_MSG_WARN([Unknown target operating system]) + cpu_type="i586" + CFLAGS="-DGENERIC $CFLAGS" + ;; *) AC_MSG_WARN([Unknown target operating system]) cpu_type="generic_fpu" - CFLAGS="$CFLAGS -DGENERIC" + CFLAGS="-DGENERIC $CFLAGS" ;; esac @@ -393,36 +431,28 @@ AC_DEFINE_UNQUOTED(INDEX_SIZE, $seektable, [size of the frame index seek table]) dnl ############## Audio Sub-system Settings -# Choose audio subsystem based on Operating System -case $target in - *-*-linux*) - if test "x$HAVE_ALSA" = "xyes" ; then - audio_system="alsa" - else - audio_system="oss" - fi - ;; - *-*-freebsd*) - audio_system="oss" - ;; - *-*-kfreebsd*) - audio_system="oss" - ;; - *-apple-darwin*) - audio_system="macosx" - ;; - *-*-solaris*) - audio_system="sun" - ;; - # esd has been assumed to be the one for cygwin, but plain OSS does it - # can even make mpg123 run "natively" with a cygwin.dll - *-*-cygwin*) - audio_system="oss" - ;; - *) - audio_system="dummy" - ;; -esac +# Choose audio subsystem based on what we have. + +if test "x$HAVE_ALSA" = "xyes"; then + audio_system="alsa" +elif test "x$HAVE_OSS" = "xyes"; then + audio_system="oss" +elif test "x$HAVE_MACOSXAUDIO" = "xyes"; then + audio_system="macosx" +elif test "x$HAVE_SUNAUDIO" = "xyes"; then + audio_system="sun" +elif test "x$HAVE_JACK" = "xyes"; then + audio_system="jack" +elif test "x$HAVE_PORTAUDIO" = "xyes"; then + audio_system="portaudio" +elif test "x$HAVE_NAS" = "xyes"; then + audio_system="nas" +elif test "x$HAVE_SDL" = "xyes"; then + audio_system="sdl" +elif test "x$HAVE_ESOUND" = "xyes"; then + audio_system="esd" +fi + # Did user choose other audio type ? if test "x$with_audio" != "x"; then @@ -430,7 +460,6 @@ if test "x$with_audio" != "x"; then fi - AUDIO_OBJ="audio_$audio_system.\$(OBJEXT)" AUDIO_CFLAGS="" AUDIO_LIBS="" @@ -455,7 +484,7 @@ case $audio_system in ;; esd) if test "x$HAVE_ESOUND" != "xyes" ; then - AC_MSG_ERROR( ESounD is not available for audio output subsystem. ) + AC_MSG_WARN( ESounD is not available for audio output subsystem. ) fi AUDIO_CFLAGS=$ESOUND_CFLAGS AUDIO_LIBS=$ESOUND_LIBS @@ -508,10 +537,13 @@ case $audio_system in fi AUDIO_CFLAGS="" AUDIO_LIBS="-lportaudio" + if test "x$HAVE_PORTAUDIO_WINMM" = "xyes"; then + AUDIO_LIBS="$AUDIO_LIBS -lwinmm" + fi ;; sdl) if test "x$HAVE_SDL" != "xyes" ; then - AC_MSG_ERROR( SDL is not available for audio output subsystem. ) + AC_MSG_WARN( SDL not found via pkgconfig. ) fi AUDIO_CFLAGS=$SDL_CFLAGS AUDIO_LIBS=$SDL_LIBS diff --git a/src/Makefile.am b/src/Makefile.am index 3721e174..b9e463ce 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,8 +5,8 @@ ## initially written by Nicholas J. Humfrey AM_CFLAGS = @AUDIO_CFLAGS@ -AM_LDFLAGS = @AUDIO_LIBS@ -mpg123_LDADD = @AUDIO_OBJ@ @CPU_TYPE_LIB@ +#AM_LDFLAGS = +mpg123_LDADD = @AUDIO_OBJ@ @CPU_TYPE_LIB@ @AUDIO_LIBS@ mpg123_DEPENDENCIES = @AUDIO_OBJ@ @CPU_TYPE_LIB@ EXTRA_DIST = Makefile.legacy config.h.legacy @@ -200,3 +200,8 @@ libcpu_x86_a_SOURCES = \ tabinit_mmx.S \ equalizer_3dnow.S \ getcpuflags.S + +# explicit preprocessing since mingw32 does not honor the big .S +.S.o: + $(CPP) $(CPPFLAGS) $< > $<.s + $(CCAS) -c -o $@ $<.s && rm $<.s diff --git a/src/audio_portaudio.c b/src/audio_portaudio.c index 498843af..67b8dbae 100644 --- a/src/audio_portaudio.c +++ b/src/audio_portaudio.c @@ -18,6 +18,9 @@ #include "mpg123.h" #include "debug.h" +#ifdef WIN32 +#include +#endif #define SAMPLE_SIZE (2) #define FRAMES_PER_BUFFER (256) @@ -107,7 +110,11 @@ int audio_play_samples(struct audio_info_struct *ai, unsigned char *buf, int len /* Sleep for half the length of the FIFO */ while (sfifo_space( &fifo ) < len ) { +#ifdef WIN32 + Sleep( (FIFO_DURATION/2) * 1000); +#else usleep( (FIFO_DURATION/2) * 1000000 ); +#endif } /* Write the audio to the ring buffer */ diff --git a/src/buffer.c b/src/buffer.c index 51326afc..99fe5451 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -10,6 +10,8 @@ - dammed night coders;-) */ +#ifndef NOXFERMEM + #include #include @@ -35,41 +37,42 @@ static void catch_usr1 (void) extern void buffer_sig(int signal, int block); -void buffer_ignore_lowmem(void) +void real_buffer_ignore_lowmem(void) { -#ifndef NOXFERMEM if (!buffermem) return; if(buffermem->wakeme[XF_READER]) xfermem_putcmd(buffermem->fd[XF_WRITER], XF_CMD_WAKEUP); -#endif } -void buffer_end(void) +void real_buffer_end(void) { -#ifndef NOXFERMEM if (!buffermem) return; xfermem_putcmd(buffermem->fd[XF_WRITER], XF_CMD_TERMINATE); -#endif } -void buffer_resync(void) +void real_buffer_resync(void) { buffer_sig(SIGINT, TRUE); } -void buffer_reset(void) +void real_plain_buffer_resync(void) +{ + buffer_sig(SIGINT, FALSE); +} + +void real_buffer_reset(void) { buffer_sig(SIGUSR1, TRUE); } -void buffer_start(void) +void real_buffer_start(void) { buffer_sig(SIGCONT, FALSE); } -void buffer_stop(void) +void real_buffer_stop(void) { buffer_sig(SIGSTOP, FALSE); } @@ -78,8 +81,6 @@ extern int buffer_pid; void buffer_sig(int signal, int block) { - -#ifndef NOXFERMEM if (!buffermem) return; @@ -90,13 +91,9 @@ void buffer_sig(int signal, int block) if(xfermem_block(XF_WRITER, buffermem) != XF_CMD_WAKEUP) perror("Could not resync/reset buffers"); -#endif - return; } -#ifndef NOXFERMEM - void buffer_loop(struct audio_info_struct *ai, sigset_t *oldsigset) { int bytes; diff --git a/src/buffer.h b/src/buffer.h index 4e4b5847..ff362bed 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -16,11 +16,30 @@ #ifndef _MPG123_BUFFER_H_ #define _MPG123_BUFFER_H_ -void buffer_ignore_lowmem(void); -void buffer_end(void); -void buffer_resync(void); -void buffer_reset(void); -void buffer_start(void); -void buffer_stop(void); +#ifndef NOXFERMEM +void real_buffer_ignore_lowmem(void); +void real_buffer_end(void); +void real_buffer_resync(void); +void real_plain_buffer_resync(void); +void real_buffer_reset(void); +void real_buffer_start(void); +void real_buffer_stop(void); +/* Hm, that's funny preprocessor weirdness. */ +#define buffer_start() (param.usebuffer ? real_buffer_start(),0 : 0) +#define buffer_stop() (param.usebuffer ? real_buffer_stop(),0 : 0) +#define buffer_reset() (param.usebuffer ? real_buffer_reset(),0 : 0) +#define buffer_resync() (param.usebuffer ? real_buffer_resync(),0 : 0) +#define plain_buffer_resync() (param.usebuffer ? real_plain_buffer_resync(),0 : 0) +#define buffer_end() (param.usebuffer ? real_buffer_end(),0 : 0) +#define buffer_ignore_lowmem() (param.usebuffer ? real_buffer_ignore_lowmem(),0 : 0) +#else +#define buffer_start() +#define buffer_stop() +#define buffer_reset() +#define buffer_resync() +#define plain_buffer_resync() +#define buffer_end() +#define buffer_ignore_lowmem() +#endif #endif diff --git a/src/common.c b/src/common.c index 8b81c529..10726d3e 100644 --- a/src/common.c +++ b/src/common.c @@ -27,6 +27,10 @@ #include "common.h" #include "debug.h" +#ifdef WIN32 +#include +#endif + /* bitrates for [mpeg1/2][layer] */ int tabsel_123[2][3][16] = { { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,}, diff --git a/src/control_generic.c b/src/control_generic.c index 94eaa16d..2437c82f 100644 --- a/src/control_generic.c +++ b/src/control_generic.c @@ -12,16 +12,21 @@ #include #include #include +#ifndef WIN32 #include +#include +#else +#include +#endif #include #include #include -#include #include "config.h" #include "mpg123.h" #include "common.h" +#include "buffer.h" #include "icy.h" #include "debug.h" #ifdef GAPLESS @@ -102,7 +107,11 @@ int control_generic (struct frame *fr) else outstream = stdout; +#ifndef WIN32 setlinebuf(outstream); +#else /* perhaps just use setvbuf as it's C89 */ + setvbuf(outstream, (char*)NULL, _IOLBF, 0); +#endif /* the command behaviour is different, so is the ID */ /* now also with version for command availability */ fprintf(outstream, "@R MPG123 (ThOr) v2\n"); @@ -221,17 +230,11 @@ int control_generic (struct frame *fr) if (mode == MODE_PLAYING) { mode = MODE_PAUSED; audio_flush(param.outmode, &ai); -#ifndef NOXFERMEM - if (param.usebuffer) - kill(buffer_pid, SIGSTOP); -#endif + buffer_stop(); generic_sendmsg("P 1"); } else { mode = MODE_PLAYING; -#ifndef NOXFERMEM - if (param.usebuffer) - kill(buffer_pid, SIGCONT); -#endif + buffer_start(); generic_sendmsg("P 2"); } } diff --git a/src/decode_3dnow.S b/src/decode_3dnow.S index 7e003e27..89c7b610 100644 --- a/src/decode_3dnow.S +++ b/src/decode_3dnow.S @@ -33,12 +33,12 @@ #include "mangle.h" - #ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MINGW32__) .comm buffs.40,4352 - #else +#else .local buffs.40 .comm buffs.40,4352,32 - #endif +#endif .data .align 4 /* .type bo.42,@object */ diff --git a/src/decode_i586.S b/src/decode_i586.S index 4868fc61..990c0b99 100644 --- a/src/decode_i586.S +++ b/src/decode_i586.S @@ -33,11 +33,11 @@ #include "mangle.h" .bss - #ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MINGW32__) .comm buffs,4352 - #else +#else .comm buffs,4352,4 - #endif +#endif .data .align 4 bo: diff --git a/src/decode_i586_dither.S b/src/decode_i586_dither.S index 5a15aa03..47e7b5a0 100644 --- a/src/decode_i586_dither.S +++ b/src/decode_i586_dither.S @@ -30,14 +30,14 @@ #include "mangle.h" .bss - #ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MINGW32__) .comm buffs,4352 .comm ditherindex.1,4 - #else +#else .comm buffs,4352,4 .local ditherindex.1 .comm ditherindex.1,4,4 - #endif +#endif .data .align 4 bo: diff --git a/src/mangle.h b/src/mangle.h index 61333b0e..4dabaadd 100644 --- a/src/mangle.h +++ b/src/mangle.h @@ -14,9 +14,11 @@ (defined(__OpenBSD__) && !defined(__ELF__)) || defined(__APPLE__) #define MANGLE(a) "_" #a #define ASM_NAME(a) _##a +#define ASM_VALUE(a) $_##a #else #define MANGLE(a) #a #define ASM_NAME(a) a +#define ASM_VALUE(a) "$" #a #endif #endif /* !__MANGLE_H */ diff --git a/src/tabinit_mmx.S b/src/tabinit_mmx.S index 89bc4d3c..d6cc48da 100644 --- a/src/tabinit_mmx.S +++ b/src/tabinit_mmx.S @@ -10,17 +10,17 @@ .bss .align 32 - #ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MINGW32__) .comm ASM_NAME(decwin_mmx),2176 - #else +#else .comm ASM_NAME(decwin_mmx),2176,32 - #endif +#endif .align 32 - #ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MINGW32__) .comm ASM_NAME(decwins),2176 - #else +#else .comm ASM_NAME(decwins),2176,32 - #endif +#endif .data .align 32 diff --git a/src/term.c b/src/term.c index c2ebdfe2..5c1fb374 100644 --- a/src/term.c +++ b/src/term.c @@ -158,8 +158,7 @@ static long term_handle_input(struct frame *fr, int do_delay) break; case NEXT_KEY: if(!param.usebuffer) audio_queueflush(&ai); - if (buffer_pid) - kill(buffer_pid, SIGINT); + plain_buffer_resync(); next_track(); break; case QUIT_KEY: @@ -175,8 +174,7 @@ static long term_handle_input(struct frame *fr, int do_delay) } if(stopped) { stopped=0; - if(param.usebuffer) - buffer_start(); + buffer_start(); } fprintf(stderr, "%s", (paused) ? PAUSED_STRING : EMPTY_STRING); break; @@ -189,8 +187,7 @@ static long term_handle_input(struct frame *fr, int do_delay) paused=0; offset -= pause_cycle; } - if(param.usebuffer) - (stopped) ? buffer_stop() : buffer_start(); + if(stopped) buffer_stop(); else buffer_start(); fprintf(stderr, "%s", (stopped) ? STOPPED_STRING : EMPTY_STRING); break; case FINE_REWIND_KEY: diff --git a/src/wav.c b/src/wav.c index 595c4693..ca5555d5 100644 --- a/src/wav.c +++ b/src/wav.c @@ -112,7 +112,7 @@ static int testEndian(void) static int open_file(char *filename) { -#ifndef GENERIC +#if !defined(GENERIC) && !defined(__WIN32__) setuid(getuid()); /* dunno whether this helps. I'm not a security expert */ #endif if(!strcmp("-",filename)) {