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);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 AudioSettings::dpcPitch() const
{
return lboundInt(mySettings.getInt(SETTING_DPC_PITCH), 10000);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AudioSettings::setPreset(AudioSettings::Preset preset)
{
@ -262,6 +268,14 @@ void AudioSettings::setStereo(bool 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)
{

View File

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

View File

@ -16,6 +16,7 @@
//============================================================================
#include "System.hxx"
#include "AudioSettings.hxx"
#include "CartDPC.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -60,6 +61,8 @@ void CartridgeDPC::reset()
// Upon reset we switch to the startup bank
initializeStartBank(1);
bank(startBank());
myDpcPitch = mySettings.getInt(AudioSettings::SETTING_DPC_PITCH);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -102,7 +105,7 @@ inline void CartridgeDPC::updateMusicModeDataFetchers()
myAudioCycles = mySystem->cycles();
// 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);
myFractionalClocks = clocks - double(wholeClocks);

View File

@ -125,6 +125,8 @@ class CartridgeDPC : public Cartridge
*/
string name() const override { return "CartridgeDPC"; }
void setDpcPitch(double pitch) { myDpcPitch = pitch; }
#ifdef DEBUGGER_SUPPORT
/**
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)
uInt16 myBankOffset;
// DPC pitch
double myDpcPitch;
private:
// Following constructors and assignment operators not supported
CartridgeDPC() = delete;

View File

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

View File

@ -20,6 +20,8 @@
#include "bspf.hxx"
#include "Console.hxx"
#include "Cart.hxx"
#include "CartDPC.hxx"
#include "Control.hxx"
#include "Dialog.hxx"
#include "Font.hxx"
@ -53,7 +55,7 @@ AudioDialog::AudioDialog(OSystem& osystem, DialogContainer& parent,
// Set real dimensions
_w = 48 * fontWidth + HBORDER * 2;
_h = 11 * (lineHeight + VGAP) + VBORDER + _th;
_h = 12 * (lineHeight + VGAP) + VBORDER + _th;
xpos = HBORDER; ypos = VBORDER + _th;
@ -146,6 +148,14 @@ AudioDialog::AudioDialog(OSystem& osystem, DialogContainer& parent,
myStereoSoundCheckbox = new CheckboxWidget(this, font, xpos, ypos,
"Stereo for all ROMs");
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
addDefaultsOKCancelBGroup(wid, font);
@ -167,6 +177,9 @@ void AudioDialog::loadConfig()
// Stereo
myStereoSoundCheckbox->setState(audioSettings.stereo());
// DPC Pitch
myDpcPitch->setValue(audioSettings.dpcPitch());
// Preset / mode
myModePopup->setSelected(static_cast<int>(audioSettings.preset()));
@ -210,6 +223,15 @@ void AudioDialog::saveConfig()
// Stereo
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.setPreset(preset);
@ -234,6 +256,7 @@ void AudioDialog::setDefaults()
mySoundEnableCheckbox->setState(AudioSettings::DEFAULT_ENABLED);
myVolumeSlider->setValue(AudioSettings::DEFAULT_VOLUME);
myStereoSoundCheckbox->setState(AudioSettings::DEFAULT_STEREO);
myDpcPitch->setValue(AudioSettings::DEFAULT_DPC_PITCH);
myModePopup->setSelected(static_cast<int>(AudioSettings::DEFAULT_PRESET));
if (AudioSettings::DEFAULT_PRESET == AudioSettings::Preset::custom) {
@ -258,6 +281,8 @@ void AudioDialog::updateEnabledState()
myVolumeSlider->setEnabled(active);
myStereoSoundCheckbox->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);
myFreqPopup->setEnabled(active && userMode);
@ -280,7 +305,6 @@ void AudioDialog::updatePreset()
updateSettingsWithPreset(audioSettings);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AudioDialog::handleCommand(CommandSender* sender, int cmd,
int data, int id)

View File

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