From 717e75f82d1b1f63b6698dd06bcc7c9a0673aefc Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 29 Oct 2023 15:25:23 -0500 Subject: [PATCH] add setting to disable DC offset correction --- src/engine/blip_buf.c | 10 +++++++++- src/engine/blip_buf.h | 6 ++++++ src/engine/blip_buf.txt | 5 +++++ src/engine/dispatchContainer.cpp | 9 ++++++++- src/engine/engine.cpp | 10 +++++++--- src/engine/engine.h | 7 +++++-- src/engine/wavOps.cpp | 6 +++--- src/gui/gui.h | 2 ++ src/gui/settings.cpp | 13 ++++++++++++- 9 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/engine/blip_buf.c b/src/engine/blip_buf.c index 929b8fc669..63f14a049c 100644 --- a/src/engine/blip_buf.c +++ b/src/engine/blip_buf.c @@ -67,6 +67,7 @@ struct blip_t int avail; int size; int integrator; + unsigned char hipass; }; typedef int buf_t; @@ -119,6 +120,7 @@ blip_t* blip_new( int size ) { m->factor = time_unit / blip_max_ratio; m->size = size; + m->hipass = 1; blip_clear( m ); check_assumptions(); } @@ -135,6 +137,10 @@ void blip_delete( blip_t* m ) } } +void blip_set_dc( blip_t* m, unsigned char enable ) { + m->hipass=enable; +} + void blip_set_rates( blip_t* m, double clock_rate, double sample_rate ) { double factor = time_unit * sample_rate / clock_rate; @@ -231,7 +237,9 @@ int blip_read_samples( blip_t* m, short out [], int count, int stereo ) out += step; /* High-pass filter */ - sum -= s << (delta_bits - bass_shift); + if (m->hipass) { + sum -= s << (delta_bits - bass_shift); + } } while ( in != end ); m->integrator = sum; diff --git a/src/engine/blip_buf.h b/src/engine/blip_buf.h index 0853595efe..524d102650 100644 --- a/src/engine/blip_buf.h +++ b/src/engine/blip_buf.h @@ -5,6 +5,9 @@ Sample buffer that resamples from input clock rate to output sample rate */ #ifndef BLIP_BUF_H #define BLIP_BUF_H +// MODIFIED by tildearrow: +// - add option to disable high-pass filter + #ifdef __cplusplus extern "C" { #endif @@ -18,6 +21,9 @@ so that there are blip_max_ratio clocks per sample. Returns pointer to new buffer, or NULL if insufficient memory. */ blip_t* blip_new( int sample_count ); +/** (tildearrow) sets whether to enable high-pass filter. */ +void blip_set_dc( blip_t*, unsigned char enable ); + /** Sets approximate input clock rate and output sample rate. For every clock_rate input clocks, approximately sample_rate samples are generated. */ void blip_set_rates( blip_t*, double clock_rate, double sample_rate ); diff --git a/src/engine/blip_buf.txt b/src/engine/blip_buf.txt index 5bf7a3d09a..94d49db27b 100644 --- a/src/engine/blip_buf.txt +++ b/src/engine/blip_buf.txt @@ -4,6 +4,11 @@ Author : Shay Green Website : http://www.slack.net/~ant/ License : GNU Lesser General Public License (LGPL) +MODIFICATION DISCLAIMER +----------------------- +I have modified this library in order to add a function that disables the DC offset correction high-pass filter. + - tildearrow + Contents -------- diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index 8ff1a33c7a..393a8ba9ac 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -96,8 +96,13 @@ void DivDispatchContainer::setRates(double gotRate) { rateMemory=gotRate; } -void DivDispatchContainer::setQuality(bool lowQual) { +void DivDispatchContainer::setQuality(bool lowQual, bool dcHiPass) { lowQuality=lowQual; + hiPass=dcHiPass; + for (int i=0; irate,rateMemory); \ \ if (bbIn[i]==NULL) bbIn[i]=new short[bbInLen]; \ @@ -621,6 +627,7 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do bbOut[i]=new short[bbInLen]; memset(bbIn[i],0,bbInLen*sizeof(short)); memset(bbOut[i],0,bbInLen*sizeof(short)); + blip_set_dc(bb[i],hiPass); } } diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index ae1f639301..00f9407406 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -3353,7 +3353,7 @@ bool DivEngine::switchMaster(bool full) { if (initAudioBackend()) { for (int i=0; isetRun(true)) { logE("error while activating audio!"); @@ -3452,10 +3452,14 @@ void DivEngine::initDispatch(bool isRender) { BUSY_BEGIN; logV("initializing dispatch..."); if (isRender) logI("render cores set"); + + lowQuality=getConfInt("audioQuality",0); + dcHiPass=getConfInt("audioHiPass",1); + for (int i=0; isetRun(true)) { logE("error while activating audio!"); @@ -223,7 +223,7 @@ void DivEngine::runExportThread() { if (initAudioBackend()) { for (int i=0; isetRun(true)) { logE("error while activating audio!"); @@ -349,7 +349,7 @@ void DivEngine::runExportThread() { if (initAudioBackend()) { for (int i=0; isetRun(true)) { logE("error while activating audio!"); diff --git a/src/gui/gui.h b/src/gui/gui.h index 7a17624dbe..5d98548f73 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1464,6 +1464,7 @@ class FurnaceGUI { int mainFontSize, patFontSize, headFontSize, iconSize; int audioEngine; int audioQuality; + int audioHiPass; int audioChans; int arcadeCore; int ym2612Core; @@ -1656,6 +1657,7 @@ class FurnaceGUI { iconSize(16), audioEngine(DIV_AUDIO_SDL), audioQuality(0), + audioHiPass(1), audioChans(2), arcadeCore(0), ym2612Core(0), diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index d325b4821d..de5fc62e16 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -1060,6 +1060,12 @@ void FurnaceGUI::drawSettings() { settingsChanged=true; } + bool audioHiPassB=settings.audioHiPass; + if (ImGui::Checkbox("DC offset correction",&audioHiPassB)) { + settings.audioHiPass=audioHiPassB; + settingsChanged=true; + } + // SUBSECTION METRONOME CONFIG_SUBSECTION("Metronome"); ImGui::AlignTextToFramePadding(); @@ -3574,6 +3580,7 @@ void FurnaceGUI::syncSettings() { settings.renderDriver=e->getConfString("renderDriver",""); settings.sdlAudioDriver=e->getConfString("sdlAudioDriver",""); settings.audioQuality=e->getConfInt("audioQuality",0); + settings.audioHiPass=e->getConfInt("audioHiPass",1); settings.audioBufSize=e->getConfInt("audioBufSize",1024); settings.audioRate=e->getConfInt("audioRate",44100); settings.arcadeCore=e->getConfInt("arcadeCore",0); @@ -3756,6 +3763,7 @@ void FurnaceGUI::syncSettings() { clampSetting(settings.iconSize,2,48); clampSetting(settings.audioEngine,0,2); clampSetting(settings.audioQuality,0,1); + clampSetting(settings.audioHiPass,0,1); clampSetting(settings.audioBufSize,32,4096); clampSetting(settings.audioRate,8000,384000); clampSetting(settings.audioChans,1,16); @@ -3987,7 +3995,9 @@ void FurnaceGUI::commitSettings() { settings.fdsCoreRender!=e->getConfInt("fdsCoreRender",0) || settings.c64CoreRender!=e->getConfInt("c64CoreRender",0) || settings.pokeyCoreRender!=e->getConfInt("pokeyCoreRender",1) || - settings.opnCoreRender!=e->getConfInt("opnCoreRender",1) + settings.opnCoreRender!=e->getConfInt("opnCoreRender",1) || + settings.audioQuality!=e->getConfInt("audioQuality",0) || + settings.audioHiPass!=e->getConfInt("audioHiPass",1) ); e->setConf("mainFontSize",settings.mainFontSize); @@ -4001,6 +4011,7 @@ void FurnaceGUI::commitSettings() { e->setConf("renderDriver",settings.renderDriver); e->setConf("sdlAudioDriver",settings.sdlAudioDriver); e->setConf("audioQuality",settings.audioQuality); + e->setConf("audioHiPass",settings.audioHiPass); e->setConf("audioBufSize",settings.audioBufSize); e->setConf("audioRate",settings.audioRate); e->setConf("audioChans",settings.audioChans);