diff options
-rw-r--r-- | blastem.c | 8 | ||||
-rw-r--r-- | default.cfg | 1 | ||||
-rw-r--r-- | psg.c | 6 | ||||
-rw-r--r-- | psg.h | 2 | ||||
-rw-r--r-- | vgmplay.c | 7 | ||||
-rw-r--r-- | ym2612.c | 6 | ||||
-rw-r--r-- | ym2612.h | 2 |
7 files changed, 18 insertions, 14 deletions
@@ -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 { @@ -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); @@ -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); @@ -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; @@ -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); @@ -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); |