implement variable DPC pitch

This commit is contained in:
Thomas Jentzsch 2019-07-25 11:09:02 +02:00
parent 39feee8c0a
commit 61d9f26bc6
7 changed files with 136 additions and 82 deletions

View File

@ -160,6 +160,12 @@ bool AudioSettings::enabled() const
return mySettings.getBool(SETTING_ENABLED); return mySettings.getBool(SETTING_ENABLED);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 AudioSettings::dpcPitch() const
{
return lboundInt(mySettings.getInt(SETTING_DPC_PITCH), 10000);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AudioSettings::setPreset(AudioSettings::Preset preset) void AudioSettings::setPreset(AudioSettings::Preset preset)
{ {
@ -262,6 +268,14 @@ void AudioSettings::setStereo(bool allROMs)
mySettings.setValue(SETTING_STEREO, allROMs); mySettings.setValue(SETTING_STEREO, allROMs);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AudioSettings::setDpcPitch(uInt32 pitch)
{
if (!myIsPersistent) return;
mySettings.setValue(SETTING_DPC_PITCH, pitch);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AudioSettings::setVolume(uInt32 volume) void AudioSettings::setVolume(uInt32 volume)
{ {

View File

@ -49,6 +49,7 @@ class AudioSettings
static constexpr const char* SETTING_STEREO = "audio.stereo"; static constexpr const char* SETTING_STEREO = "audio.stereo";
static constexpr const char* SETTING_VOLUME = "audio.volume"; static constexpr const char* SETTING_VOLUME = "audio.volume";
static constexpr const char* SETTING_ENABLED = "audio.enabled"; static constexpr const char* SETTING_ENABLED = "audio.enabled";
static constexpr const char* SETTING_DPC_PITCH = "audio.dpc_pitch";
static constexpr Preset DEFAULT_PRESET = Preset::highQualityMediumLag; static constexpr Preset DEFAULT_PRESET = Preset::highQualityMediumLag;
static constexpr uInt32 DEFAULT_SAMPLE_RATE = 44100; static constexpr uInt32 DEFAULT_SAMPLE_RATE = 44100;
@ -59,6 +60,7 @@ class AudioSettings
static constexpr bool DEFAULT_STEREO = false; static constexpr bool DEFAULT_STEREO = false;
static constexpr uInt32 DEFAULT_VOLUME = 80; static constexpr uInt32 DEFAULT_VOLUME = 80;
static constexpr bool DEFAULT_ENABLED = true; static constexpr bool DEFAULT_ENABLED = true;
static constexpr uInt32 DEFAULT_DPC_PITCH = 20000;
static constexpr int MAX_BUFFER_SIZE = 10; static constexpr int MAX_BUFFER_SIZE = 10;
static constexpr int MAX_HEADROOM = 10; static constexpr int MAX_HEADROOM = 10;
@ -87,6 +89,8 @@ class AudioSettings
bool enabled() const; bool enabled() const;
uInt32 dpcPitch() const;
void setPreset(Preset preset); void setPreset(Preset preset);
void setSampleRate(uInt32 sampleRate); void setSampleRate(uInt32 sampleRate);
@ -101,6 +105,8 @@ class AudioSettings
void setStereo(bool allROMs); void setStereo(bool allROMs);
void setDpcPitch(uInt32 pitch);
void setVolume(uInt32 volume); void setVolume(uInt32 volume);
void setEnabled(bool isEnabled); void setEnabled(bool isEnabled);

View File

@ -16,6 +16,7 @@
//============================================================================ //============================================================================
#include "System.hxx" #include "System.hxx"
#include "AudioSettings.hxx"
#include "CartDPC.hxx" #include "CartDPC.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -60,6 +61,8 @@ void CartridgeDPC::reset()
// Upon reset we switch to the startup bank // Upon reset we switch to the startup bank
initializeStartBank(1); initializeStartBank(1);
bank(startBank()); bank(startBank());
myDpcPitch = mySettings.getInt(AudioSettings::SETTING_DPC_PITCH);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -102,7 +105,7 @@ inline void CartridgeDPC::updateMusicModeDataFetchers()
myAudioCycles = mySystem->cycles(); myAudioCycles = mySystem->cycles();
// Calculate the number of DPC OSC clocks since the last update // Calculate the number of DPC OSC clocks since the last update
double clocks = ((20000.0 * cycles) / 1193191.66666667) + myFractionalClocks; double clocks = ((myDpcPitch * cycles) / 1193191.66666667) + myFractionalClocks;
uInt32 wholeClocks = uInt32(clocks); uInt32 wholeClocks = uInt32(clocks);
myFractionalClocks = clocks - double(wholeClocks); myFractionalClocks = clocks - double(wholeClocks);

View File

@ -125,6 +125,8 @@ class CartridgeDPC : public Cartridge
*/ */
string name() const override { return "CartridgeDPC"; } string name() const override { return "CartridgeDPC"; }
void setDpcPitch(double pitch) { myDpcPitch = pitch; }
#ifdef DEBUGGER_SUPPORT #ifdef DEBUGGER_SUPPORT
/** /**
Get debugger widget responsible for accessing the inner workings Get debugger widget responsible for accessing the inner workings
@ -206,6 +208,9 @@ class CartridgeDPC : public Cartridge
// Indicates the offset into the ROM image (aligns to current bank) // Indicates the offset into the ROM image (aligns to current bank)
uInt16 myBankOffset; uInt16 myBankOffset;
// DPC pitch
double myDpcPitch;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported
CartridgeDPC() = delete; CartridgeDPC() = delete;

View File

@ -80,6 +80,7 @@ Settings::Settings()
setPermanent(AudioSettings::SETTING_HEADROOM, AudioSettings::DEFAULT_HEADROOM); setPermanent(AudioSettings::SETTING_HEADROOM, AudioSettings::DEFAULT_HEADROOM);
setPermanent(AudioSettings::SETTING_BUFFER_SIZE, AudioSettings::DEFAULT_BUFFER_SIZE); setPermanent(AudioSettings::SETTING_BUFFER_SIZE, AudioSettings::DEFAULT_BUFFER_SIZE);
setPermanent(AudioSettings::SETTING_STEREO, AudioSettings::DEFAULT_STEREO); setPermanent(AudioSettings::SETTING_STEREO, AudioSettings::DEFAULT_STEREO);
setPermanent(AudioSettings::SETTING_DPC_PITCH, AudioSettings::DEFAULT_DPC_PITCH);
// Input event options // Input event options
setPermanent("event_ver", "1"); setPermanent("event_ver", "1");

View File

@ -20,6 +20,8 @@
#include "bspf.hxx" #include "bspf.hxx"
#include "Console.hxx" #include "Console.hxx"
#include "Cart.hxx"
#include "CartDPC.hxx"
#include "Control.hxx" #include "Control.hxx"
#include "Dialog.hxx" #include "Dialog.hxx"
#include "Font.hxx" #include "Font.hxx"
@ -53,7 +55,7 @@ AudioDialog::AudioDialog(OSystem& osystem, DialogContainer& parent,
// Set real dimensions // Set real dimensions
_w = 48 * fontWidth + HBORDER * 2; _w = 48 * fontWidth + HBORDER * 2;
_h = 11 * (lineHeight + VGAP) + VBORDER + _th; _h = 12 * (lineHeight + VGAP) + VBORDER + _th;
xpos = HBORDER; ypos = VBORDER + _th; xpos = HBORDER; ypos = VBORDER + _th;
@ -146,6 +148,14 @@ AudioDialog::AudioDialog(OSystem& osystem, DialogContainer& parent,
myStereoSoundCheckbox = new CheckboxWidget(this, font, xpos, ypos, myStereoSoundCheckbox = new CheckboxWidget(this, font, xpos, ypos,
"Stereo for all ROMs"); "Stereo for all ROMs");
wid.push_back(myStereoSoundCheckbox); wid.push_back(myStereoSoundCheckbox);
ypos += lineHeight + VGAP;
myDpcPitch = new SliderWidget(this, font, xpos, ypos,
"DPC Pitch ", 0, 0, 5 * fontWidth);
myDpcPitch->setMinValue(10000); myDpcPitch->setMaxValue(30000);
myDpcPitch->setStepValue(100);
myDpcPitch->setTickmarkIntervals(2);
wid.push_back(myDpcPitch);
// Add Defaults, OK and Cancel buttons // Add Defaults, OK and Cancel buttons
addDefaultsOKCancelBGroup(wid, font); addDefaultsOKCancelBGroup(wid, font);
@ -167,6 +177,9 @@ void AudioDialog::loadConfig()
// Stereo // Stereo
myStereoSoundCheckbox->setState(audioSettings.stereo()); myStereoSoundCheckbox->setState(audioSettings.stereo());
// DPC Pitch
myDpcPitch->setValue(audioSettings.dpcPitch());
// Preset / mode // Preset / mode
myModePopup->setSelected(static_cast<int>(audioSettings.preset())); myModePopup->setSelected(static_cast<int>(audioSettings.preset()));
@ -210,6 +223,15 @@ void AudioDialog::saveConfig()
// Stereo // Stereo
audioSettings.setStereo(myStereoSoundCheckbox->getState()); audioSettings.setStereo(myStereoSoundCheckbox->getState());
// DPC Pitch
audioSettings.setDpcPitch(myDpcPitch->getValue());
// update if current cart is Pitfall II
if (instance().hasConsole() && instance().console().cartridge().name() == "CartridgeDPC")
{
CartridgeDPC& cart = (CartridgeDPC&)instance().console().cartridge();
cart.setDpcPitch(myDpcPitch->getValue());
}
AudioSettings::Preset preset = static_cast<AudioSettings::Preset>(myModePopup->getSelectedTag().toInt()); AudioSettings::Preset preset = static_cast<AudioSettings::Preset>(myModePopup->getSelectedTag().toInt());
audioSettings.setPreset(preset); audioSettings.setPreset(preset);
@ -234,6 +256,7 @@ void AudioDialog::setDefaults()
mySoundEnableCheckbox->setState(AudioSettings::DEFAULT_ENABLED); mySoundEnableCheckbox->setState(AudioSettings::DEFAULT_ENABLED);
myVolumeSlider->setValue(AudioSettings::DEFAULT_VOLUME); myVolumeSlider->setValue(AudioSettings::DEFAULT_VOLUME);
myStereoSoundCheckbox->setState(AudioSettings::DEFAULT_STEREO); myStereoSoundCheckbox->setState(AudioSettings::DEFAULT_STEREO);
myDpcPitch->setValue(AudioSettings::DEFAULT_DPC_PITCH);
myModePopup->setSelected(static_cast<int>(AudioSettings::DEFAULT_PRESET)); myModePopup->setSelected(static_cast<int>(AudioSettings::DEFAULT_PRESET));
if (AudioSettings::DEFAULT_PRESET == AudioSettings::Preset::custom) { if (AudioSettings::DEFAULT_PRESET == AudioSettings::Preset::custom) {
@ -258,6 +281,8 @@ void AudioDialog::updateEnabledState()
myVolumeSlider->setEnabled(active); myVolumeSlider->setEnabled(active);
myStereoSoundCheckbox->setEnabled(active); myStereoSoundCheckbox->setEnabled(active);
myModePopup->setEnabled(active); myModePopup->setEnabled(active);
// enable only for Pitfall II cart
myDpcPitch->setEnabled(active && instance().hasConsole() && instance().console().cartridge().name() == "CartridgeDPC");
myFragsizePopup->setEnabled(active && userMode); myFragsizePopup->setEnabled(active && userMode);
myFreqPopup->setEnabled(active && userMode); myFreqPopup->setEnabled(active && userMode);
@ -280,7 +305,6 @@ void AudioDialog::updatePreset()
updateSettingsWithPreset(audioSettings); updateSettingsWithPreset(audioSettings);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AudioDialog::handleCommand(CommandSender* sender, int cmd, void AudioDialog::handleCommand(CommandSender* sender, int cmd,
int data, int id) int data, int id)

View File

@ -63,6 +63,7 @@ class AudioDialog : public Dialog
PopUpWidget* myResamplingPopup; PopUpWidget* myResamplingPopup;
SliderWidget* myHeadroomSlider; SliderWidget* myHeadroomSlider;
SliderWidget* myBufferSizeSlider; SliderWidget* myBufferSizeSlider;
SliderWidget* myDpcPitch;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported