comparison ym2612.c @ 1002:8d032a368dd5

Made low pass filter frequency configurable
author Michael Pavone <pavone@retrodev.com>
date Sun, 01 May 2016 13:36:14 -0700
parents 5257e85364ed
children c15896605bf2
comparison
equal deleted inserted replaced
1001:1dc749c9c0d9 1002:8d032a368dd5
126 126
127 #ifdef __ANDROID__ 127 #ifdef __ANDROID__
128 #define log2(x) (log(x)/log(2)) 128 #define log2(x) (log(x)/log(2))
129 #endif 129 #endif
130 130
131 #define LOWPASS_CUTOFF 3390 131 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)
132
133 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)
134 { 132 {
135 static uint8_t registered_finalize; 133 static uint8_t registered_finalize;
136 dfopen(debug_file, "ym_debug.txt", "w"); 134 dfopen(debug_file, "ym_debug.txt", "w");
137 memset(context, 0, sizeof(*context)); 135 memset(context, 0, sizeof(*context));
138 context->audio_buffer = malloc(sizeof(*context->audio_buffer) * sample_limit*2); 136 context->audio_buffer = malloc(sizeof(*context->audio_buffer) * sample_limit*2);
139 context->back_buffer = malloc(sizeof(*context->audio_buffer) * sample_limit*2); 137 context->back_buffer = malloc(sizeof(*context->audio_buffer) * sample_limit*2);
140 context->sample_rate = sample_rate; 138 context->sample_rate = sample_rate;
141 context->clock_inc = clock_div * 6; 139 context->clock_inc = clock_div * 6;
142 ym_adjust_master_clock(context, master_clock); 140 ym_adjust_master_clock(context, master_clock);
143 141
144 double rc = (1.0 / (double)LOWPASS_CUTOFF) / (2.0 * M_PI); 142 double rc = (1.0 / (double)lowpass_cutoff) / (2.0 * M_PI);
145 double dt = 1.0 / ((double)master_clock / (double)(context->clock_inc * NUM_OPERATORS)); 143 double dt = 1.0 / ((double)master_clock / (double)(context->clock_inc * NUM_OPERATORS));
146 double alpha = dt / (dt + rc); 144 double alpha = dt / (dt + rc);
147 context->lowpass_alpha = (int32_t)(((double)0x10000) * alpha); 145 context->lowpass_alpha = (int32_t)(((double)0x10000) * alpha);
148 146
149 context->sample_limit = sample_limit*2; 147 context->sample_limit = sample_limit*2;