Skip to content

Commit

Permalink
Add filter curve switch plus recommended 6581 filter setting (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
drfiemost committed Nov 10, 2023
1 parent 036ae68 commit 2e2c394
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 17 deletions.
7 changes: 7 additions & 0 deletions doc/en/sidplayfp.pod
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ Simulate c64 power on delay as number of cpu cycles.
If greater than 8191 the delay will be random.
This is the default.

=item B<--fcurve=>I<< <num>|auto >>

Controls the filter curve in the ReSIDfp mulation.
Ranges from 0.0 (light) to 1.0 (dark), the default
value is 0.5. If set to auto it will choose a
predefined value for 6581 depending on the tune author.

=item B<--noaudio>

Run without an audio output device.
Expand Down
13 changes: 12 additions & 1 deletion src/args.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of sidplayfp, a console SID player.
*
* Copyright 2011-2021 Leandro Nini
* Copyright 2011-2023 Leandro Nini
* Copyright 2000-2001 Simon White
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -379,6 +379,17 @@ int ConsolePlayer::args(int argc, const char *argv[])
{
m_engCfg.powerOnDelay = (uint_least16_t) atoi(&argv[i][8]);
}
else if (strncmp (&argv[i][1], "-fcurve=", 8) == 0)
{
if (strncmp (&argv[i][9], "auto", 4) == 0)
{
m_autofilter = true;
}
else
{
m_fcurve = atof(&argv[i][9]);
}
}
// File format conversions
else if (argv[i][1] == 'w')
{
Expand Down
6 changes: 1 addition & 5 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,8 @@ void ConsolePlayer::menu ()

consoleTable (tableStart);
consoleTable (tableMiddle);
consoleColour (red, true);
cerr << " SID";
consoleColour (blue, true);
cerr << "PLAYFP";
consoleColour (white, true);
cerr << " - Music Player and C64 SID Chip Emulator" << endl;
cerr << " SIDPLAYFP - Music Player and C64 SID Chip Emulator" << endl;
consoleTable (tableMiddle);
consoleColour (white, false);
{
Expand Down
83 changes: 74 additions & 9 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ using std::endl;
#include <sidplayfp/SidInfo.h>
#include <sidplayfp/SidTuneInfo.h>

#ifdef HAVE_CXX11
# include <unordered_map>
typedef std::unordered_map<std::string, double> filter_map_t;
typedef std::unordered_map<std::string, double>::const_iterator filter_map_iter_t;
#else
# include <map>
typedef std::map<std::string, double> filter_map_t;
typedef std::map<std::string, double>::const_iterator filter_map_iter_t;
#endif

// Previous song select timeout (4 secs)
#define SID2_PREV_SONG_TIMEOUT 4000

Expand Down Expand Up @@ -103,6 +113,26 @@ uint16_t freqTableNtsc[]
};
#endif

static const filter_map_t filterCurveMap =
{
{ "David Dunn", 1.1 },
{ "David Dunn & Aidan Bell", 1.1 },
// { "Martin Galway", 0.6 }, // Any other setting higher than 0.5 makes "Wizball" misbehave
{ "Chris H\xFClsbeck", 0.6 },
{ "Georg Feil", 0.6 },
{ "Jeroen Tel", 0.6 },
{ "Rob Hubbard", 0.6 },
{ "Rob Hubbard & Ben Daglish", 0.6 },
{ "Fred Gray", 1.1 }, // He only used the filter in "Frankie Goes to Hollywood"
{ "Geir Tjelta", 0.6 },
};

double getRecommendedFilterCurve(const std::string& author)
{
filter_map_iter_t it = filterCurveMap.find(author);
return (it != filterCurveMap.end()) ? it->second : 0.5;
}

uint8_t* loadRom(const SID_STRING &romPath, const int size)
{
SID_IFSTREAM is(romPath.c_str(), std::ios::binary);
Expand Down Expand Up @@ -178,9 +208,11 @@ ConsolePlayer::ConsolePlayer (const char * const name) :
m_state(playerStopped),
m_outfile(NULL),
m_filename(""),
m_fcurve(-1.0),
m_quietLevel(0),
m_cpudebug(false),
newSonglengthDB(false)
newSonglengthDB(false),
m_autofilter(false)
{
#ifdef FEAT_REGS_DUMP_SID
memset(m_registers, 0, 32*3);
Expand Down Expand Up @@ -263,7 +295,7 @@ ConsolePlayer::ConsolePlayer (const char * const name) :
m_verboseLevel = (m_iniCfg.sidplay2()).verboseLevel;

createOutput (OUT_NULL, nullptr);
createSidEmu (EMU_NONE);
createSidEmu (EMU_NONE, nullptr);

uint8_t *kernalRom = loadRom((m_iniCfg.sidplay2()).kernalRom, 8192, TEXT("kernal"));
uint8_t *basicRom = loadRom((m_iniCfg.sidplay2()).basicRom, 8192, TEXT("basic"));
Expand Down Expand Up @@ -422,7 +454,7 @@ bool ConsolePlayer::createOutput (OUTPUTS driver, const SidTuneInfo *tuneInfo)


// Create the sid emulation
bool ConsolePlayer::createSidEmu (SIDEMUS emu)
bool ConsolePlayer::createSidEmu (SIDEMUS emu, const SidTuneInfo *tuneInfo)
{
// Remove old driver and emulation
if (m_engCfg.sidEmulation)
Expand All @@ -448,10 +480,43 @@ bool ConsolePlayer::createSidEmu (SIDEMUS emu)
rs->create ((m_engine.info ()).maxsids());
if (!rs->getStatus()) goto createSidEmu_error;

if (m_filter.filterCurve6581)
rs->filter6581Curve(m_filter.filterCurve6581);
if (m_filter.filterCurve8580)
rs->filter8580Curve((double)m_filter.filterCurve8580);
double fcurve;
if (m_autofilter && (tuneInfo->numberOfInfoStrings() == 3))
{
fcurve = getRecommendedFilterCurve(tuneInfo->infoString(1));
}
else if (m_fcurve >= 0.0)
{
fcurve = m_fcurve;
}
else if (m_filter.filterCurve6581 >= 0.0)
{
fcurve = m_filter.filterCurve6581;
}

if (fcurve >= 0.0)
{
if (m_verboseLevel > 1)
cerr << "6581 filter curve: " << fcurve << endl;
rs->filter6581Curve(fcurve);
}

fcurve = -1.0;
if (m_fcurve >= 0.0)
{
fcurve = m_fcurve;
}
if (m_filter.filterCurve8580 >= 0.0)
{
fcurve = m_filter.filterCurve8580;
}

if (fcurve >= 0.0)
{
if (m_verboseLevel > 1)
cerr << "8580 filter curve: " << fcurve << endl;
rs->filter8580Curve(fcurve);
}
}
catch (std::bad_alloc const &ba) {}
break;
Expand Down Expand Up @@ -567,7 +632,7 @@ bool ConsolePlayer::open (void)
m_track.songs = tuneInfo->songs();
if (!createOutput(m_driver.output, tuneInfo))
return false;
if (!createSidEmu(m_driver.sid))
if (!createSidEmu(m_driver.sid, tuneInfo))
return false;

// Configure engine with settings
Expand Down Expand Up @@ -649,7 +714,7 @@ void ConsolePlayer::close ()

// Shutdown drivers, etc
createOutput (OUT_NULL, nullptr);
createSidEmu (EMU_NONE);
createSidEmu (EMU_NONE, nullptr);
m_engine.load (nullptr);
m_engine.config (m_engCfg);

Expand Down
8 changes: 6 additions & 2 deletions src/player.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of sidplayfp, a console SID player.
*
* Copyright 2011-2022 Leandro Nini
* Copyright 2011-2023 Leandro Nini
* Copyright 2000-2001 Simon White
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -126,6 +126,8 @@ class ConsolePlayer
IniConfig m_iniCfg;
SidDatabase m_database;

double m_fcurve;

uint8_t m_registers[3][32];
uint16_t* m_freqTable;

Expand All @@ -137,6 +139,8 @@ class ConsolePlayer

bool newSonglengthDB;

bool m_autofilter;

bool vMute[9];

int m_channels;
Expand Down Expand Up @@ -200,7 +204,7 @@ class ConsolePlayer
void displayArgs (const char *arg = NULL);

bool createOutput (OUTPUTS driver, const SidTuneInfo *tuneInfo);
bool createSidEmu (SIDEMUS emu);
bool createSidEmu (SIDEMUS emu, const SidTuneInfo *tuneInfo);
void displayError (const char *error);
void displayError (unsigned int num) { ::displayError (m_name, num); }
void decodeKeys (void);
Expand Down

0 comments on commit 2e2c394

Please sign in to comment.