[mupen64plus-audio-sdl] 108/163: Imported Upstream version 1.99.5+7+d483528be393
Sven Eckelmann
ecsv-guest at moszumanska.debian.org
Thu Nov 26 05:53:26 UTC 2015
This is an automated email from the git hooks/post-receive script.
ecsv-guest pushed a commit to branch armhf_test
in repository mupen64plus-audio-sdl.
commit 18cbf6874d280596a337e8fc371544728736cf45
Author: Sven Eckelmann <sven at narfation.org>
Date: Mon Oct 29 22:40:33 2012 +0100
Imported Upstream version 1.99.5+7+d483528be393
---
projects/unix/Makefile | 19 ++++++--
src/main.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 138 insertions(+), 10 deletions(-)
diff --git a/projects/unix/Makefile b/projects/unix/Makefile
index 7f270da..05645ca 100644
--- a/projects/unix/Makefile
+++ b/projects/unix/Makefile
@@ -166,16 +166,28 @@ ifeq ($(OS),LINUX)
LDLIBS += $(shell sdl-config --libs)
endif
+# test for presence of speexdsp
+ifneq ($(strip $(shell pkg-config speexdsp --modversion 2> /dev/null)),)
+ ifneq ($(NO_SPEEX), 1)
+ # set speexdsp flags and libraries
+ CFLAGS += $(shell pkg-config speexdsp --cflags) -DUSE_SPEEX
+ LDLIBS += $(shell pkg-config speexdsp --libs)
+ endif
+else
+ # warn user
+ $(warning No libspeexdsp development libraries found. Mupen64plus-sdl-audio will be built without speex-* resampler.)
+endif
+
# test for presence of libsamplerate
ifneq ($(strip $(shell pkg-config samplerate --modversion 2> /dev/null)),)
- ifneq ($(NO_RESAMP), 1)
+ ifneq ($(NO_SRC), 1)
# set libsamplerate flags and libraries
CFLAGS += $(shell pkg-config samplerate --cflags) -DUSE_SRC
LDLIBS += $(shell pkg-config samplerate --libs)
endif
else
# warn user
- $(warning No libsamplerate development libraries found. Mupen64plus-sdl-audio will be built without Best Quality SINC resampler.)
+ $(warning No libsamplerate development libraries found. Mupen64plus-sdl-audio will be built without src-* resampler.)
endif
# test for the presence of OSS
@@ -274,7 +286,8 @@ targets:
@echo " APIDIR=path == path to find Mupen64Plus Core headers"
@echo " OPTFLAGS=flag == compiler optimization (default: -O3)"
@echo " PIC=(1|0) == Force enable/disable of position independent code"
- @echo " NO_RESAMP=1 == build without libsamplerate; disables high-quality audio resampling"
+ @echo " NO_SRC=1 == build without libsamplerate; disables src-* high-quality audio resampling"
+ @echo " NO_SPEEX=1 == build without libspeexdsp; disables speex-* high-quality audio resampling"
@echo " Install Options:"
@echo " PREFIX=path == install/uninstall prefix (default: /usr/local)"
@echo " LIBDIR=path == library prefix (default: PREFIX/lib)"
diff --git a/src/main.c b/src/main.c
index 0f8bce5..c23c660 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,6 +32,9 @@
#ifdef USE_SRC
#include <samplerate.h>
#endif
+#ifdef USE_SPEEX
+#include <speex/speex_resampler.h>
+#endif
#define M64P_PLUGIN_PROTOTYPES 1
#include "m64p_types.h"
@@ -82,6 +85,16 @@ static int l_PluginInit = 0;
static int l_PausedForSync = 1; /* Audio is started in paused state after SDL initialization */
static m64p_handle l_ConfigAudio;
+enum resampler_type {
+ RESAMPLER_TRIVIAL,
+#ifdef USE_SRC
+ RESAMPLER_SRC,
+#endif
+#ifdef USE_SPEEX
+ RESAMPLER_SPEEX,
+#endif
+};
+
/* Read header for type definition */
static AUDIO_INFO AudioInfo;
/* The hardware specifications we are using */
@@ -107,8 +120,10 @@ static unsigned int PrimaryBufferSize = PRIMARY_BUFFER_SIZE;
static unsigned int PrimaryBufferTarget = PRIMARY_BUFFER_TARGET;
// Size of Secondary audio buffer in output samples
static unsigned int SecondaryBufferSize = SECONDARY_BUFFER_SIZE;
-// Resample or not
-static unsigned char Resample = 1;
+// Resample type
+static enum resampler_type Resample = RESAMPLER_TRIVIAL;
+// Resampler specific quality
+static int ResampleQuality = 3;
// volume to scale the audio by, range of 0..100
// if muted, this holds the volume when not muted
static int VolPercent = 80;
@@ -259,7 +274,7 @@ EXPORT m64p_error CALL PluginStartup(m64p_dynlib_handle CoreLibHandle, void *Con
ConfigSetDefaultInt(l_ConfigAudio, "PRIMARY_BUFFER_SIZE", PRIMARY_BUFFER_SIZE, "Size of primary buffer in output samples. This is where audio is loaded after it's extracted from n64's memory.");
ConfigSetDefaultInt(l_ConfigAudio, "PRIMARY_BUFFER_TARGET", PRIMARY_BUFFER_TARGET, "Fullness level target for Primary audio buffer, in equivalent output samples");
ConfigSetDefaultInt(l_ConfigAudio, "SECONDARY_BUFFER_SIZE", SECONDARY_BUFFER_SIZE, "Size of secondary buffer in output samples. This is SDL's hardware buffer.");
- ConfigSetDefaultInt(l_ConfigAudio, "RESAMPLE", 1, "Audio resampling algorithm. 1 = unfiltered, 2 = SINC resampling (Best Quality, requires libsamplerate)");
+ ConfigSetDefaultString(l_ConfigAudio, "RESAMPLE", "trivial", "Audio resampling algorithm. src-sinc-best-quality, src-sinc-medium-quality, src-sinc-fastest, src-zero-order-hold, src-linear, speex-fixed-{10-0}, trivial");
ConfigSetDefaultInt(l_ConfigAudio, "VOLUME_CONTROL_TYPE", VOLUME_TYPE_SDL, "Volume control type: 1 = SDL (only affects Mupen64Plus output) 2 = OSS mixer (adjusts master PC volume)");
ConfigSetDefaultInt(l_ConfigAudio, "VOLUME_ADJUST", 5, "Percentage change each time the volume is increased or decreased");
ConfigSetDefaultInt(l_ConfigAudio, "VOLUME_DEFAULT", 80, "Default volume when a game is started. Only used if VOLUME_CONTROL_TYPE is 1");
@@ -448,14 +463,44 @@ static int error;
static SRC_STATE *src_state;
static SRC_DATA src_data;
#endif
+#ifdef USE_SPEEX
+SpeexResamplerState* spx_state = NULL;
+static int error;
+#endif
static int resample(unsigned char *input, int input_avail, int oldsamplerate, unsigned char *output, int output_needed, int newsamplerate)
{
int *psrc = (int*)input;
int *pdest = (int*)output;
int i = 0, j = 0;
+
+#ifdef USE_SPEEX
+ spx_uint32_t in_len, out_len;
+ if(Resample == RESAMPLER_SPEEX)
+ {
+ if(spx_state == NULL)
+ {
+ spx_state = speex_resampler_init(2, oldsamplerate, newsamplerate, ResampleQuality, &error);
+ if(spx_state == NULL)
+ {
+ memset(output, 0, output_needed);
+ return 0;
+ }
+ }
+ speex_resampler_set_rate(spx_state, oldsamplerate, newsamplerate);
+ in_len = input_avail / 4;
+ out_len = output_needed / 4;
+
+ if ((error = speex_resampler_process_interleaved_int(spx_state, (const spx_int16_t *)input, &in_len, (spx_int16_t *)output, &out_len)))
+ {
+ memset(output, 0, output_needed);
+ return input_avail; // number of bytes consumed
+ }
+ return in_len * 4;
+ }
+#endif
#ifdef USE_SRC
- if(Resample == 2)
+ if(Resample == RESAMPLER_SRC)
{
// the high quality resampler needs more input than the samplerate ratio would indicate to work properly
if (input_avail > output_needed * 3 / 2)
@@ -476,7 +521,7 @@ static int resample(unsigned char *input, int input_avail, int oldsamplerate, un
memset(_dest,0,_dest_len);
if(src_state == NULL)
{
- src_state = src_new (SRC_SINC_BEST_QUALITY, 2, &error);
+ src_state = src_new (ResampleQuality, 2, &error);
if(src_state == NULL)
{
memset(output, 0, output_needed);
@@ -499,7 +544,7 @@ static int resample(unsigned char *input, int input_avail, int oldsamplerate, un
return src_data.input_frames_used * 4;
}
#endif
- // RESAMPLE == 1
+ // RESAMPLE == TRIVIAL
if (newsamplerate >= oldsamplerate)
{
int sldf = oldsamplerate;
@@ -776,16 +821,86 @@ EXPORT void CALL SetSpeedFactor(int percentage)
static void ReadConfig(void)
{
+ const char *resampler_id;
+
/* read the configuration values into our static variables */
GameFreq = ConfigGetParamInt(l_ConfigAudio, "DEFAULT_FREQUENCY");
SwapChannels = ConfigGetParamBool(l_ConfigAudio, "SWAP_CHANNELS");
PrimaryBufferSize = ConfigGetParamInt(l_ConfigAudio, "PRIMARY_BUFFER_SIZE");
PrimaryBufferTarget = ConfigGetParamInt(l_ConfigAudio, "PRIMARY_BUFFER_TARGET");
SecondaryBufferSize = ConfigGetParamInt(l_ConfigAudio, "SECONDARY_BUFFER_SIZE");
- Resample = ConfigGetParamInt(l_ConfigAudio, "RESAMPLE");
+ resampler_id = ConfigGetParamString(l_ConfigAudio, "RESAMPLE");
VolumeControlType = ConfigGetParamInt(l_ConfigAudio, "VOLUME_CONTROL_TYPE");
VolDelta = ConfigGetParamInt(l_ConfigAudio, "VOLUME_ADJUST");
VolPercent = ConfigGetParamInt(l_ConfigAudio, "VOLUME_DEFAULT");
+
+ if (!resampler_id) {
+ Resample = RESAMPLER_TRIVIAL;
+ DebugMessage(M64MSG_WARNING, "Could not find RESAMPLE configuration; use trivial resampler");
+ return;
+ }
+ if (strcmp(resampler_id, "trivial") == 0) {
+ Resample = RESAMPLER_TRIVIAL;
+ return;
+ }
+#ifdef USE_SPEEX
+ if (strncmp(resampler_id, "speex-fixed-", strlen("speex-fixed-")) == 0) {
+ int i;
+ static const char *speex_quality[] = {
+ "speex-fixed-0",
+ "speex-fixed-1",
+ "speex-fixed-2",
+ "speex-fixed-3",
+ "speex-fixed-4",
+ "speex-fixed-5",
+ "speex-fixed-6",
+ "speex-fixed-7",
+ "speex-fixed-8",
+ "speex-fixed-9",
+ "speex-fixed-10",
+ };
+ Resample = RESAMPLER_SPEEX;
+ for (i = 0; i < sizeof(speex_quality) / sizeof(*speex_quality); i++) {
+ if (strcmp(speex_quality[i], resampler_id) == 0) {
+ ResampleQuality = i;
+ return;
+ }
+ }
+ DebugMessage(M64MSG_WARNING, "Unknown RESAMPLE configuration %s; use speex-fixed-4 resampler", resampler_id);
+ ResampleQuality = 4;
+ return;
+ }
+#endif
+#ifdef USE_SRC
+ if (strncmp(resampler_id, "src-", strlen("src-")) == 0) {
+ Resample = RESAMPLER_SRC;
+ if (strcmp(resampler_id, "src-sinc-best-quality") == 0) {
+ ResampleQuality = SRC_SINC_BEST_QUALITY;
+ return;
+ }
+ if (strcmp(resampler_id, "src-sinc-medium-quality") == 0) {
+ ResampleQuality = SRC_SINC_MEDIUM_QUALITY;
+ return;
+ }
+ if (strcmp(resampler_id, "src-sinc-fastest") == 0) {
+ ResampleQuality = SRC_SINC_FASTEST;
+ return;
+ }
+ if (strcmp(resampler_id, "src-zero-order-hold") == 0) {
+ ResampleQuality = SRC_ZERO_ORDER_HOLD;
+ return;
+ }
+ if (strcmp(resampler_id, "src-linear") == 0) {
+ ResampleQuality = SRC_LINEAR;
+ return;
+ }
+ DebugMessage(M64MSG_WARNING, "Unknown RESAMPLE configuration %s; use src-sinc-medium-quality resampler", resampler_id);
+ ResampleQuality = SRC_SINC_MEDIUM_QUALITY;
+ return;
+ }
+#endif
+ DebugMessage(M64MSG_WARNING, "Unknown RESAMPLE configuration %s; use trivial resampler", resampler_id);
+ Resample = RESAMPLER_TRIVIAL;
}
// Returns the most recent ummuted volume level.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/mupen64plus-audio-sdl.git
More information about the Pkg-games-commits
mailing list