From: cloudwalk Date: Wed, 15 Jul 2020 13:55:21 +0000 (+0000) Subject: libxmp: Misc improvements (nico) X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=b419e8685167f1515291e282282854fd8d9aeb0d libxmp: Misc improvements (nico) * Don't use global CFLAGS for libxmp in makefile * Add S_GetSoundWidth() function, currently not used (yet) * Clamp samplerate to engine min/max * Lower the excessive stereo separation https://gitlab.com/xonotic/darkplaces/-/merge_requests/94 git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12816 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/makefile.inc b/makefile.inc index 0297c489..251c061f 100644 --- a/makefile.inc +++ b/makefile.inc @@ -45,7 +45,7 @@ STRIP?=strip ###### Sound ##### -OBJ_SND_COMMON=snd_main.o snd_mem.o snd_mix.o snd_ogg.o snd_wav.o +OBJ_SND_COMMON=snd_main.o snd_mem.o snd_mix.o snd_ogg.o snd_wav.o $(OBJ_SND_XMP) # No sound OBJ_SND_NULL=snd_null.o @@ -53,23 +53,23 @@ LIB_SND_NULL= # Open Sound System (Linux, FreeBSD and Solaris) OBJ_SND_OSS=$(OBJ_SND_COMMON) snd_oss.o -LIB_SND_OSS=$(LIB_SND_XMP) +LIB_SND_OSS= # Advanced Linux Sound Architecture (Linux) OBJ_SND_ALSA=$(OBJ_SND_COMMON) snd_alsa.o -LIB_SND_ALSA=-lasound $(LIB_SND_XMP) +LIB_SND_ALSA=-lasound # Core Audio (Mac OS X) OBJ_SND_COREAUDIO=$(OBJ_SND_COMMON) snd_coreaudio.o -LIB_SND_COREAUDIO=-framework CoreAudio $(LIB_SND_XMP) +LIB_SND_COREAUDIO=-framework CoreAudio # BSD / Sun audio API (NetBSD and OpenBSD) OBJ_SND_BSD=$(OBJ_SND_COMMON) snd_bsd.o -LIB_SND_BSD=$(LIB_SND_XMP) +LIB_SND_BSD= # DirectX and Win32 WAVE output (Win32) OBJ_SND_WIN=$(OBJ_SND_COMMON) snd_win.o -LIB_SND_WIN=$(LIB_SND_XMP) +LIB_SND_WIN= ###### Common objects and flags ##### @@ -470,6 +470,20 @@ mod_skeletal_animatevertices_sse.o: mod_skeletal_animatevertices_sse.c $(CHECKLEVEL2) $(DO_CC) $(CFLAGS_SSE) +snd_xmp.o: snd_xmp.c + $(CHECKLEVEL2) + $(DO_CC) $(CFLAGS_SND_XMP) + +#this checks USEXMP when compiling so it needs the XMP flags as well +snd_main.o: snd_main.c + $(CHECKLEVEL2) + $(DO_CC) $(CFLAGS_SND_XMP) + +#this checks USEXMP when compiling so it needs the XMP flags as well +snd_mem.o: snd_mem.c + $(CHECKLEVEL2) + $(DO_CC) $(CFLAGS_SND_XMP) + darkplaces.o: %.o : %.rc $(CHECKLEVEL2) $(WINDRES) -o $@ $< diff --git a/snd_main.c b/snd_main.c index 1509d97b..3b995e73 100644 --- a/snd_main.c +++ b/snd_main.c @@ -375,6 +375,11 @@ int S_GetSoundChannels(void) return snd_renderbuffer ? snd_renderbuffer->format.channels : 0; } +int S_GetSoundWidth(void) +{ + return snd_renderbuffer ? snd_renderbuffer->format.width : 0; +} + #define SWAP_LISTENERS(l1, l2, tmpl) { tmpl = (l1); (l1) = (l2); (l2) = tmpl; } @@ -572,7 +577,7 @@ void S_Startup (void) { chosen_fmt.width = SND_MIN_WIDTH; } - else if (chosen_fmt.width == 3) + else if (chosen_fmt.width == 3) { chosen_fmt.width = 4; } diff --git a/snd_xmp.c b/snd_xmp.c index 5b4e3945..e963e18e 100644 --- a/snd_xmp.c +++ b/snd_xmp.c @@ -121,8 +121,8 @@ void XMP_CloseLibrary (void) {} //#define XMP_MAX_ENV_POINTS 32 /* Max number of envelope points */ #define XMP_MAX_MOD_LENGTH 256 /* Max number of patterns in module */ //#define XMP_MAX_CHANNELS 64 /* Max number of channels in module */ -//#define XMP_MAX_SRATE 49170 /* max sampling rate (Hz) */ -//#define XMP_MIN_SRATE 4000 /* min sampling rate (Hz) */ +#define XMP_MAX_SRATE 49170 /* max sampling rate (Hz) */ +#define XMP_MIN_SRATE 4000 /* min sampling rate (Hz) */ //#define XMP_MIN_BPM 20 /* min BPM */ #define XMP_MAX_FRAMESIZE (5 * XMP_MAX_SRATE * 2 / XMP_MIN_BPM) @@ -464,9 +464,22 @@ static void XMP_GetSamplesFloat(channel_t *ch, sfx_t *sfx, int firstsampleframe, } // start playing the loaded file - if (sfx->format.width == 1) { format |= XMP_FORMAT_8BIT; } // else 16bit + if (sfx->format.width == 1) { format |= XMP_FORMAT_8BIT | XMP_FORMAT_UNSIGNED; } // else 16bit if (sfx->format.channels == 1) { format |= XMP_FORMAT_MONO; } // else stereo - if (qxmp_start_player(per_ch->playercontext, sfx->format.speed, format) < 0) // FIXME: only if speed is in XMP acceptable range, else default to 48khz and let DP mix + + if (qxmp_start_player(per_ch->playercontext, sfx->format.speed, format) < 0) + { + Mem_Free(per_ch); + return; + } + /* percentual left/right channel separation, default is 70. */ + if (sfx->format.channels == 2 && (qxmp_set_player(per_ch->playercontext, XMP_PLAYER_MIX, 50) != 0)) + { + Mem_Free(per_ch); + return; + } + /* interpolation type, default is XMP_INTERP_LINEAR */ + if (qxmp_set_player(per_ch->playercontext, XMP_PLAYER_INTERP, XMP_INTERP_SPLINE) != 0) { Mem_Free(per_ch); return; @@ -634,20 +647,20 @@ qboolean XMP_LoadModFile(const char *filename, sfx_t *sfx) // set dp sfx sfx->memsize += sizeof(*per_sfx); sfx->memsize += filesize; // total memory used (including sfx_t and fetcher data) -// sfx->format // format describing the audio data that fetcher->getsamplesfloat shall return - sfx->format.speed = 48000; // default to this sample rate - sfx->format.width = 2; // default to 16 bit samples -// sfx->format.width = 1; // 8-bit - sfx->format.channels = 2; // default to stereo -// sfx->format.channels = 1; // mono + if (S_GetSoundRate() > XMP_MAX_SRATE) + sfx->format.speed = 48000; + else if (S_GetSoundRate() < XMP_MIN_SRATE) + sfx->format.speed = 8000; + else + sfx->format.speed = S_GetSoundRate(); + sfx->format.width = S_GetSoundWidth(); // 2 = 16 bit samples + sfx->format.channels = S_GetSoundChannels(); sfx->flags |= SFXFLAG_STREAMED; // cf SFXFLAG_* defines -// sfx->total_length // in (pcm) sample frames - sfx->total_length = 1<<30; // 2147384647; // they always loop (FIXME this breaks after 6 hours, we need support for a real "infinite" value!) + sfx->total_length = 1<<30; // 2147384647; // in (pcm) sample frames - they always loop (FIXME this breaks after 6 hours, we need support for a real "infinite" value!) sfx->loopstart = sfx->total_length; // (modplug does it) in sample frames. equals total_length if not looped sfx->fetcher_data = per_sfx; sfx->fetcher = &xmp_fetcher; -// sfx->volume_mult // for replay gain (multiplier to apply) -// sfx->volume_peak // for replay gain (highest peak); if set to 0, ReplayGain isn't supported + sfx->volume_peak = 0; qxmp_get_module_info(xc, &mi); if (developer_loading.integer >= 2) diff --git a/sound.h b/sound.h index 4da72a1e..288b475c 100644 --- a/sound.h +++ b/sound.h @@ -117,5 +117,6 @@ void S_UnblockSound (void); int S_GetSoundRate (void); int S_GetSoundChannels (void); +int S_GetSoundWidth (void); #endif