Skip to content

Commit

Permalink
add setting to disable DC offset correction
Browse files Browse the repository at this point in the history
  • Loading branch information
tildearrow committed Oct 29, 2023
1 parent 38103d9 commit 717e75f
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/engine/blip_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct blip_t
int avail;
int size;
int integrator;
unsigned char hipass;
};

typedef int buf_t;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/engine/blip_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );
Expand Down
5 changes: 5 additions & 0 deletions src/engine/blip_buf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Author : Shay Green <[email protected]>
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
--------
Expand Down
9 changes: 8 additions & 1 deletion src/engine/dispatchContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<DIV_MAX_OUTPUTS; i++) {
if (bb[i]==NULL) continue;
blip_set_dc(bb[i],dcHiPass);
}
}

void DivDispatchContainer::grow(size_t size) {
Expand All @@ -123,6 +128,7 @@ void DivDispatchContainer::grow(size_t size) {
logE("not enough memory!"); \
return; \
} \
blip_set_dc(bb[i],hiPass); \
blip_set_rates(bb[i],dispatch->rate,rateMemory); \
\
if (bbIn[i]==NULL) bbIn[i]=new short[bbInLen]; \
Expand Down Expand Up @@ -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);
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3353,7 +3353,7 @@ bool DivEngine::switchMaster(bool full) {
if (initAudioBackend()) {
for (int i=0; i<song.systemLen; i++) {
disCont[i].setRates(got.rate);
disCont[i].setQuality(lowQuality);
disCont[i].setQuality(lowQuality,dcHiPass);
}
if (!output->setRun(true)) {
logE("error while activating audio!");
Expand Down Expand Up @@ -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; i<song.systemLen; i++) {
disCont[i].init(song.system[i],this,getChannelCount(song.system[i]),got.rate,song.systemFlags[i],isRender);
disCont[i].setRates(got.rate);
disCont[i].setQuality(lowQuality);
disCont[i].setQuality(lowQuality,dcHiPass);
}
if (song.patchbayAuto) {
saveLock.lock();
Expand Down Expand Up @@ -3534,7 +3538,6 @@ bool DivEngine::initAudioBackend() {
}
#endif

lowQuality=getConfInt("audioQuality",0);
forceMono=getConfInt("forceMono",0);
clampSamples=getConfInt("clampSamples",0);
lowLatency=getConfInt("lowLatency",0);
Expand Down Expand Up @@ -3782,6 +3785,7 @@ bool DivEngine::init() {
logE("not enough memory!");
return false;
}
blip_set_dc(samp_bb,0);

samp_bbOut=new short[32768];

Expand Down
7 changes: 5 additions & 2 deletions src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ struct DivDispatchContainer {
short* bbInMapped[DIV_MAX_OUTPUTS];
short* bbIn[DIV_MAX_OUTPUTS];
short* bbOut[DIV_MAX_OUTPUTS];
bool lowQuality, dcOffCompensation;
bool lowQuality, dcOffCompensation, hiPass;
double rateMemory;

// used in multi-thread
int cycles;
unsigned int size;

void setRates(double gotRate);
void setQuality(bool lowQual);
void setQuality(bool lowQual, bool dcHiPass);
void grow(size_t size);
void acquire(size_t offset, size_t count);
void flush(size_t count);
Expand All @@ -230,6 +230,7 @@ struct DivDispatchContainer {
lastAvail(0),
lowQuality(false),
dcOffCompensation(false),
hiPass(true),
rateMemory(0.0),
cycles(0),
size(0) {
Expand Down Expand Up @@ -389,6 +390,7 @@ class DivEngine {
int chans;
bool active;
bool lowQuality;
bool dcHiPass;
bool playing;
bool freelance;
bool shallStop, shallStopSched;
Expand Down Expand Up @@ -1224,6 +1226,7 @@ class DivEngine {
chans(0),
active(false),
lowQuality(false),
dcHiPass(true),
playing(false),
freelance(false),
shallStop(false),
Expand Down
6 changes: 3 additions & 3 deletions src/engine/wavOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void DivEngine::runExportThread() {
if (initAudioBackend()) {
for (int i=0; i<song.systemLen; i++) {
disCont[i].setRates(got.rate);
disCont[i].setQuality(lowQuality);
disCont[i].setQuality(lowQuality,dcHiPass);
}
if (!output->setRun(true)) {
logE("error while activating audio!");
Expand Down Expand Up @@ -223,7 +223,7 @@ void DivEngine::runExportThread() {
if (initAudioBackend()) {
for (int i=0; i<song.systemLen; i++) {
disCont[i].setRates(got.rate);
disCont[i].setQuality(lowQuality);
disCont[i].setQuality(lowQuality,dcHiPass);
}
if (!output->setRun(true)) {
logE("error while activating audio!");
Expand Down Expand Up @@ -349,7 +349,7 @@ void DivEngine::runExportThread() {
if (initAudioBackend()) {
for (int i=0; i<song.systemLen; i++) {
disCont[i].setRates(got.rate);
disCont[i].setQuality(lowQuality);
disCont[i].setQuality(lowQuality,dcHiPass);
}
if (!output->setRun(true)) {
logE("error while activating audio!");
Expand Down
2 changes: 2 additions & 0 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ class FurnaceGUI {
int mainFontSize, patFontSize, headFontSize, iconSize;
int audioEngine;
int audioQuality;
int audioHiPass;
int audioChans;
int arcadeCore;
int ym2612Core;
Expand Down Expand Up @@ -1656,6 +1657,7 @@ class FurnaceGUI {
iconSize(16),
audioEngine(DIV_AUDIO_SDL),
audioQuality(0),
audioHiPass(1),
audioChans(2),
arcadeCore(0),
ym2612Core(0),
Expand Down
13 changes: 12 additions & 1 deletion src/gui/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 717e75f

Please sign in to comment.