diff --git a/src/common/AudioSettings.cxx b/src/common/AudioSettings.cxx index 63e8e5ea2..b919e46ca 100644 --- a/src/common/AudioSettings.cxx +++ b/src/common/AudioSettings.cxx @@ -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) { diff --git a/src/common/AudioSettings.hxx b/src/common/AudioSettings.hxx index 9c6a2bea6..2d603deb3 100644 --- a/src/common/AudioSettings.hxx +++ b/src/common/AudioSettings.hxx @@ -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); diff --git a/src/emucore/CartDPC.cxx b/src/emucore/CartDPC.cxx index c7c92740e..616f16d87 100644 --- a/src/emucore/CartDPC.cxx +++ b/src/emucore/CartDPC.cxx @@ -16,6 +16,7 @@ //============================================================================ #include "System.hxx" +#include "AudioSettings.hxx" #include "CartDPC.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -48,7 +49,7 @@ CartridgeDPC::CartridgeDPC(const ByteBuffer& image, uInt32 size, myMusicMode[0] = myMusicMode[1] = myMusicMode[2] = false; // Initialize the DPC's random number generator register (must be non-zero) - myRandomNumber = 1; + myRandomNumber = 1; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -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); diff --git a/src/emucore/CartDPC.hxx b/src/emucore/CartDPC.hxx index 45fe0ecca..711319d7d 100644 --- a/src/emucore/CartDPC.hxx +++ b/src/emucore/CartDPC.hxx @@ -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; diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index ba16d183f..284429c0c 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -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"); diff --git a/src/gui/AudioDialog.cxx b/src/gui/AudioDialog.cxx index 0012b8ebf..877bdd106 100644 --- a/src/gui/AudioDialog.cxx +++ b/src/gui/AudioDialog.cxx @@ -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(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(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(AudioSettings::DEFAULT_PRESET)); if (AudioSettings::DEFAULT_PRESET == AudioSettings::Preset::custom) { @@ -256,8 +279,10 @@ void AudioDialog::updateEnabledState() bool userMode = preset == AudioSettings::Preset::custom; myVolumeSlider->setEnabled(active); - myStereoSoundCheckbox->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); @@ -279,8 +304,7 @@ void AudioDialog::updatePreset() updateSettingsWithPreset(audioSettings); } - - + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AudioDialog::handleCommand(CommandSender* sender, int cmd, int data, int id) diff --git a/src/gui/AudioDialog.hxx b/src/gui/AudioDialog.hxx index a65723c15..b520a9aab 100644 --- a/src/gui/AudioDialog.hxx +++ b/src/gui/AudioDialog.hxx @@ -1,76 +1,77 @@ -//============================================================================ -// -// SSSS tt lll lll -// SS SS tt ll ll -// SS tttttt eeee ll ll aaaa -// SSSS tt ee ee ll ll aa -// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" -// SS SS tt ee ll ll aa aa -// SSSS ttt eeeee llll llll aaaaa -// -// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony -// and the Stella Team -// -// See the file "License.txt" for information on usage and redistribution of -// this file, and for a DISCLAIMER OF ALL WARRANTIES. -//============================================================================ - -#ifndef AUDIO_DIALOG_HXX -#define AUDIO_DIALOG_HXX - -class CommandSender; -class Dialog; -class DialogContainer; -class PopUpWidget; -class SliderWidget; -class StaticTextWidget; -class CheckboxWidget; -class OSystem; -class AudioSettings; - -#include "bspf.hxx" - -class AudioDialog : public Dialog -{ - public: - AudioDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font); - virtual ~AudioDialog() = default; - - private: - void loadConfig() override; - void saveConfig() override; - void setDefaults() override; - - void updatePreset(); - void updateEnabledState(); - void updateSettingsWithPreset(AudioSettings&); - void handleCommand(CommandSender* sender, int cmd, int data, int id) override; - - private: - enum { - kSoundEnableChanged = 'ADse', - kModeChanged = 'ADmc', - kHeadroomChanged = 'ADhc', - kBufferSizeChanged = 'ADbc' - }; - - CheckboxWidget* mySoundEnableCheckbox; - SliderWidget* myVolumeSlider; - CheckboxWidget* myStereoSoundCheckbox; - PopUpWidget* myModePopup; - PopUpWidget* myFragsizePopup; - PopUpWidget* myFreqPopup; - PopUpWidget* myResamplingPopup; - SliderWidget* myHeadroomSlider; - SliderWidget* myBufferSizeSlider; - - private: - // Following constructors and assignment operators not supported - AudioDialog() = delete; - AudioDialog(const AudioDialog&) = delete; - AudioDialog(AudioDialog&&) = delete; - AudioDialog& operator=(const AudioDialog&) = delete; - AudioDialog& operator=(AudioDialog&&) = delete; -}; - -#endif +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef AUDIO_DIALOG_HXX +#define AUDIO_DIALOG_HXX + +class CommandSender; +class Dialog; +class DialogContainer; +class PopUpWidget; +class SliderWidget; +class StaticTextWidget; +class CheckboxWidget; +class OSystem; +class AudioSettings; + +#include "bspf.hxx" + +class AudioDialog : public Dialog +{ + public: + AudioDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font); + virtual ~AudioDialog() = default; + + private: + void loadConfig() override; + void saveConfig() override; + void setDefaults() override; + + void updatePreset(); + void updateEnabledState(); + void updateSettingsWithPreset(AudioSettings&); + void handleCommand(CommandSender* sender, int cmd, int data, int id) override; + + private: + enum { + kSoundEnableChanged = 'ADse', + kModeChanged = 'ADmc', + kHeadroomChanged = 'ADhc', + kBufferSizeChanged = 'ADbc' + }; + + CheckboxWidget* mySoundEnableCheckbox; + SliderWidget* myVolumeSlider; + CheckboxWidget* myStereoSoundCheckbox; + PopUpWidget* myModePopup; + PopUpWidget* myFragsizePopup; + PopUpWidget* myFreqPopup; + PopUpWidget* myResamplingPopup; + SliderWidget* myHeadroomSlider; + SliderWidget* myBufferSizeSlider; + SliderWidget* myDpcPitch; + + private: + // Following constructors and assignment operators not supported + AudioDialog() = delete; + AudioDialog(const AudioDialog&) = delete; + AudioDialog(AudioDialog&&) = delete; + AudioDialog& operator=(const AudioDialog&) = delete; + AudioDialog& operator=(AudioDialog&&) = delete; +}; + +#endif