summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2016-05-01 13:36:14 -0700
committerMichael Pavone <pavone@retrodev.com>2016-05-01 13:36:14 -0700
commitdfb5ea9cf695c24d24e451da24d384dd69634d43 (patch)
tree695a8cc1883a6fa919b2bbc0d22009f03fe96772
parent5be1df76921a1f7ad103dca3e7f731fa4a53d254 (diff)
Made low pass filter frequency configurable
-rw-r--r--blastem.c8
-rw-r--r--default.cfg1
-rw-r--r--psg.c6
-rw-r--r--psg.h2
-rw-r--r--vgmplay.c7
-rw-r--r--ym2612.c6
-rw-r--r--ym2612.h2
7 files changed, 18 insertions, 14 deletions
diff --git a/blastem.c b/blastem.c
index c065b96..faa7d78 100644
--- a/blastem.c
+++ b/blastem.c
@@ -32,6 +32,7 @@ uint32_t MCLKS_PER_68K;
#define MCLKS_PER_Z80 15
#define MCLKS_PER_PSG (MCLKS_PER_Z80*16)
#define DEFAULT_SYNC_INTERVAL MCLKS_LINE
+#define DEFAULT_LOWPASS_CUTOFF 3390
//TODO: Figure out the exact value for this
#define LINES_NTSC 262
@@ -898,11 +899,14 @@ genesis_context *alloc_init_genesis(rom_info *rom, int fps, uint32_t ym_opts)
char * config_cycles = tern_find_path(config, "clocks\0max_cycles\0").ptrval;
gen->max_cycles = config_cycles ? atoi(config_cycles) : DEFAULT_SYNC_INTERVAL;
+ char * lowpass_cutoff_str = tern_find_path(config, "audio\0lowpass_cutoff\0").ptrval;
+ uint32_t lowpass_cutoff = lowpass_cutoff_str ? atoi(lowpass_cutoff_str) : DEFAULT_LOWPASS_CUTOFF;
+
gen->ym = malloc(sizeof(ym2612_context));
- ym_init(gen->ym, render_sample_rate(), gen->master_clock, MCLKS_PER_YM, render_audio_buffer(), ym_opts);
+ ym_init(gen->ym, render_sample_rate(), gen->master_clock, MCLKS_PER_YM, render_audio_buffer(), ym_opts, lowpass_cutoff);
gen->psg = malloc(sizeof(psg_context));
- psg_init(gen->psg, render_sample_rate(), gen->master_clock, MCLKS_PER_PSG, render_audio_buffer());
+ psg_init(gen->psg, render_sample_rate(), gen->master_clock, MCLKS_PER_PSG, render_audio_buffer(), lowpass_cutoff);
gen->z80 = calloc(1, sizeof(z80_context));
#ifndef NO_Z80
diff --git a/default.cfg b/default.cfg
index ab02353..84376c6 100644
--- a/default.cfg
+++ b/default.cfg
@@ -113,6 +113,7 @@ video {
audio {
rate 48000
buffer 512
+ lowpass_cutoff 3390
}
clocks {
diff --git a/psg.c b/psg.c
index ae5fb2c..fe6912d 100644
--- a/psg.c
+++ b/psg.c
@@ -10,9 +10,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
-#define LOWPASS_CUTOFF 3390
-
-void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t samples_frame)
+void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t samples_frame, uint32_t lowpass_cutoff)
{
memset(context, 0, sizeof(*context));
context->audio_buffer = malloc(sizeof(*context->audio_buffer) * samples_frame);
@@ -20,7 +18,7 @@ void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock
context->clock_inc = clock_div;
context->sample_rate = sample_rate;
context->samples_frame = samples_frame;
- double rc = (1.0 / (double)LOWPASS_CUTOFF) / (2.0 * M_PI);
+ double rc = (1.0 / (double)lowpass_cutoff) / (2.0 * M_PI);
double dt = 1.0 / ((double)master_clock / (double)clock_div);
double alpha = dt / (dt + rc);
context->lowpass_alpha = (int32_t)(((double)0x10000) * alpha);
diff --git a/psg.h b/psg.h
index 5a97e18..d1b8541 100644
--- a/psg.h
+++ b/psg.h
@@ -33,7 +33,7 @@ typedef struct {
} psg_context;
-void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t samples_frame);
+void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t samples_frame, uint32_t lowpass_cutoff);
void psg_free(psg_context *context);
void psg_adjust_master_clock(psg_context * context, uint32_t master_clock);
void psg_write(psg_context * context, uint8_t value);
diff --git a/vgmplay.c b/vgmplay.c
index e889f1e..f1b401e 100644
--- a/vgmplay.c
+++ b/vgmplay.c
@@ -95,12 +95,15 @@ int main(int argc, char ** argv)
if (argc >= 3 && !strcmp(argv[2], "-y")) {
opts |= YM_OPT_WAVE_LOG;
}
+
+ char * lowpass_cutoff_str = tern_find_path(config, "audio\0lowpass_cutoff\0").ptrval;
+ uint32_t lowpass_cutoff = lowpass_cutoff_str ? atoi(lowpass_cutoff_str) : 3390;
ym2612_context y_context;
- ym_init(&y_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_YM, render_audio_buffer(), opts);
+ ym_init(&y_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_YM, render_audio_buffer(), opts, lowpass_cutoff);
psg_context p_context;
- psg_init(&p_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_PSG, render_audio_buffer());
+ psg_init(&p_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_PSG, render_audio_buffer(), lowpass_cutoff);
FILE * f = fopen(argv[1], "rb");
vgm_header header;
diff --git a/ym2612.c b/ym2612.c
index cfb6719..52568dc 100644
--- a/ym2612.c
+++ b/ym2612.c
@@ -128,9 +128,7 @@ void ym_adjust_master_clock(ym2612_context * context, uint32_t master_clock)
#define log2(x) (log(x)/log(2))
#endif
-#define LOWPASS_CUTOFF 3390
-
-void ym_init(ym2612_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t sample_limit, uint32_t options)
+void ym_init(ym2612_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t sample_limit, uint32_t options, uint32_t lowpass_cutoff)
{
static uint8_t registered_finalize;
dfopen(debug_file, "ym_debug.txt", "w");
@@ -141,7 +139,7 @@ void ym_init(ym2612_context * context, uint32_t sample_rate, uint32_t master_clo
context->clock_inc = clock_div * 6;
ym_adjust_master_clock(context, master_clock);
- double rc = (1.0 / (double)LOWPASS_CUTOFF) / (2.0 * M_PI);
+ double rc = (1.0 / (double)lowpass_cutoff) / (2.0 * M_PI);
double dt = 1.0 / ((double)master_clock / (double)(context->clock_inc * NUM_OPERATORS));
double alpha = dt / (dt + rc);
context->lowpass_alpha = (int32_t)(((double)0x10000) * alpha);
diff --git a/ym2612.h b/ym2612.h
index 566626e..84f1517 100644
--- a/ym2612.h
+++ b/ym2612.h
@@ -125,7 +125,7 @@ enum {
REG_LR_AMS_PMS = 0xB4
};
-void ym_init(ym2612_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t sample_limit, uint32_t options);
+void ym_init(ym2612_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t sample_limit, uint32_t options, uint32_t lowpass_cutoff);
void ym_free(ym2612_context *context);
void ym_adjust_master_clock(ym2612_context * context, uint32_t master_clock);
void ym_run(ym2612_context * context, uint32_t to_cycle);