comparison psg.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 e6dc30231b83
children c15896605bf2
comparison
equal deleted inserted replaced
1001:1dc749c9c0d9 1002:8d032a368dd5
8 #include "blastem.h" 8 #include "blastem.h"
9 #include <string.h> 9 #include <string.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <math.h> 12 #include <math.h>
13 #define LOWPASS_CUTOFF 3390 13 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)
14
15 void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t samples_frame)
16 { 14 {
17 memset(context, 0, sizeof(*context)); 15 memset(context, 0, sizeof(*context));
18 context->audio_buffer = malloc(sizeof(*context->audio_buffer) * samples_frame); 16 context->audio_buffer = malloc(sizeof(*context->audio_buffer) * samples_frame);
19 context->back_buffer = malloc(sizeof(*context->audio_buffer) * samples_frame); 17 context->back_buffer = malloc(sizeof(*context->audio_buffer) * samples_frame);
20 context->clock_inc = clock_div; 18 context->clock_inc = clock_div;
21 context->sample_rate = sample_rate; 19 context->sample_rate = sample_rate;
22 context->samples_frame = samples_frame; 20 context->samples_frame = samples_frame;
23 double rc = (1.0 / (double)LOWPASS_CUTOFF) / (2.0 * M_PI); 21 double rc = (1.0 / (double)lowpass_cutoff) / (2.0 * M_PI);
24 double dt = 1.0 / ((double)master_clock / (double)clock_div); 22 double dt = 1.0 / ((double)master_clock / (double)clock_div);
25 double alpha = dt / (dt + rc); 23 double alpha = dt / (dt + rc);
26 context->lowpass_alpha = (int32_t)(((double)0x10000) * alpha); 24 context->lowpass_alpha = (int32_t)(((double)0x10000) * alpha);
27 psg_adjust_master_clock(context, master_clock); 25 psg_adjust_master_clock(context, master_clock);
28 for (int i = 0; i < 4; i++) { 26 for (int i = 0; i < 4; i++) {