Added LP filter

This commit is contained in:
2025-05-22 17:50:58 -06:00
parent 55ec5e658b
commit 237b68892e

View File

@ -5,11 +5,13 @@
#include <portaudio.h>
#include <pa_ringbuffer.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string.h>
#define SAMPLE_RATE 192000.0
#define FRAMES_PER_BUFFER 64
#define SAMPLE_RATE 44100.0
#define CPU_RATE 4194304.0
#define FRAMES_PER_BUFFER 16
#define SAMPLES_PER_AUDIO_TICK SAMPLE_RATE / 4194304.0
#define HISTORY_INTERVAL 5
@ -66,6 +68,8 @@ const u8 *square_sample[4] = {
static audio_context ctx;
static PaStream *stream;
static float previous_left;
static float previous_right;
audio_context *audio_get_context() {
return &ctx;
@ -281,10 +285,20 @@ void audio_sample_tick() {
u8 right_vol = ctx.volume_right == 0 ? 1 : ctx.volume_right;
left *= (float)left_vol/7.0f;
right *= (float)right_vol/7.0f;
double rc = 1.0 / (2.0 * M_PI * (SAMPLE_RATE/2));
double dt = 1.0 / CPU_RATE;
double alpha = dt / (rc+dt);
left = alpha * left + (1.0 - alpha) * previous_left;
previous_left = left;
right = alpha * right + (1.0 - alpha) * previous_right;
previous_right = right;
ctx.cycles_needed += emu_get_context()->fast_forward ? SAMPLES_PER_AUDIO_TICK/FAST_FORWARD_SPEED : SAMPLES_PER_AUDIO_TICK;
if(ctx.cycles_needed > 1){
ctx.cycles_needed -= 1;
//if(Pa_GetStreamWriteAvailable(stream) < 1)
// return;
bool dacs = ctx.ch1_dac || ctx.ch2_dac || ctx.ch3_dac || ctx.ch4_dac;
float left_out = 0;