From b53255598dde08b8dd80499352914f3deff98bb0 Mon Sep 17 00:00:00 2001 From: bsutherland Date: Sun, 7 Feb 2016 19:47:22 +0900 Subject: [PATCH] Finally allow sample rates other than 44100 Hz. --- Source/PluginGui.cpp | 1 - Source/PluginProcessor.cpp | 39 ++------------------------------------ Source/PluginProcessor.h | 7 ------- Source/hiopl.cpp | 4 ++++ Source/hiopl.h | 4 +++- 5 files changed, 9 insertions(+), 46 deletions(-) diff --git a/Source/PluginGui.cpp b/Source/PluginGui.cpp index 79e9a1c..c01497f 100644 --- a/Source/PluginGui.cpp +++ b/Source/PluginGui.cpp @@ -27,7 +27,6 @@ void PluginGui::updateFromParameters() { emulatorSlider->setValue(processor->getEnumParameter("Emulator"), juce::NotificationType::dontSendNotification); - setRecordButtonState(processor->isThisInstanceRecording()); /// setToggleState(bool, bool) is deprecated. /// Jeff-Russ replaced the second arg of "false" with dontSendNotification: diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 689770c..684f428 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -15,9 +15,6 @@ AdlibBlasterAudioProcessor::AdlibBlasterAudioProcessor() Opl = new Hiopl(); Opl->SetSampleRate(44100); Opl->EnableWaveformControl(); - dro = new DROMultiplexer(); - - recordingFile = NULL; // Initialize parameters @@ -142,26 +139,6 @@ AdlibBlasterAudioProcessor::AdlibBlasterAudioProcessor() available_channels.push_back(i); } -bool AdlibBlasterAudioProcessor::isThisInstanceRecording() { - return NULL != recordingFile; -} - -bool AdlibBlasterAudioProcessor::isAnyInstanceRecording() { - return dro->IsAnInstanceRecording(); -} - -void AdlibBlasterAudioProcessor::startRecording(File *outputFile) { - recordingFile = outputFile; - if (!dro->StartCapture(outputFile->getFullPathName().toUTF8(), Opl)) { - juce::AlertWindow::showMessageBoxAsync(juce::AlertWindow::InfoIcon, "Could not open specified file for writing!", "OK"); - } -} - -void AdlibBlasterAudioProcessor::stopRecording() { - dro->StopCapture(); - recordingFile = NULL; -} - void AdlibBlasterAudioProcessor::initPrograms() { // these ones from the Syndicate in-game music @@ -450,7 +427,6 @@ AdlibBlasterAudioProcessor::~AdlibBlasterAudioProcessor() for (unsigned int i=0; i < params.size(); ++i) delete params[i]; delete Opl; - delete dro; } //============================================================================== @@ -717,7 +693,8 @@ void AdlibBlasterAudioProcessor::changeProgramName (int index, const String& new //============================================================================== void AdlibBlasterAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock) { - //Opl->SetSampleRate((int)sampleRate); + Opl->SetSampleRate((int)sampleRate); + Opl->EnableWaveformControl(); // Use this method as the place to do any pre-playback // initialisation that you need.. } @@ -751,9 +728,6 @@ void AdlibBlasterAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBu Opl->SetFrequency(i, noteHz, false); } Opl->HitPercussion(DRUM_INDEX[perc - 1]); - if (isAnyInstanceRecording()) { - dro->GetMaster()->PercussionChange(Opl, perc - 1); - } } else { if (!available_channels.empty()) { @@ -794,17 +768,11 @@ void AdlibBlasterAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBu Opl->KeyOn(ch, noteHz); active_notes[ch] = n; applyPitchBend(); - if (isAnyInstanceRecording()) { - dro->GetMaster()->TwoOpMelodicNoteOn(Opl, ch); - } } } else if (midi_message.isNoteOff()) { if (perc > 0) { Opl->ReleasePercussion(); - if (isAnyInstanceRecording()) { - dro->GetMaster()->PercussionChange(Opl, perc - 1); - } } else { int n = midi_message.getNoteNumber(); @@ -828,9 +796,6 @@ void AdlibBlasterAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBu Opl->KeyOff(ch); active_notes[ch] = NO_NOTE; } - if (isAnyInstanceRecording()) { - dro->GetMaster()->TwoOpMelodicNoteOff(Opl, ch); - } } } else if (midi_message.isPitchWheel()) { diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 3ea6c95..6a69e89 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -27,11 +27,6 @@ public: void applyPitchBend(); ~AdlibBlasterAudioProcessor(); - bool isThisInstanceRecording(); - bool isAnyInstanceRecording(); - void startRecording(File *outputFile); - void stopRecording(); - //============================================================================== void prepareToPlay (double sampleRate, int samplesPerBlock); void releaseResources(); @@ -90,7 +85,6 @@ public: private: Hiopl *Opl; - DROMultiplexer *dro; std::vector params; std::map paramIdxByName; std::map> programs; @@ -103,7 +97,6 @@ private: std::deque available_channels; // most recently freed at end std::deque used_channels; // most recently used at end float currentScaledBend; - File *recordingFile; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AdlibBlasterAudioProcessor) diff --git a/Source/hiopl.cpp b/Source/hiopl.cpp index 0951381..f992ef7 100644 --- a/Source/hiopl.cpp +++ b/Source/hiopl.cpp @@ -67,6 +67,10 @@ void Hiopl::Generate(int length, float* buffer) { void Hiopl::SetSampleRate(int hz) { adlib->Init(hz); + EnableWaveformControl(); + for (int i = 0; i < OPL_N_REG; i++) { + adlib->WriteReg(i, regCache[i]); + } } void Hiopl::_WriteReg(Bit32u reg, Bit8u value, Bit8u mask) { diff --git a/Source/hiopl.h b/Source/hiopl.h index e06c720..7e30e2c 100644 --- a/Source/hiopl.h +++ b/Source/hiopl.h @@ -12,6 +12,8 @@ // Number of static buffers to use. Again probably excessive, but let's be safe. #define INTERMEDIATE_BUF_N 4 +#define OPL_N_REG 256 + enum Waveform { SIN = 0, HALF_SIN = 1, ABS_SIN = 2, QUART_SIN = 3 @@ -88,7 +90,7 @@ class Hiopl { Emulator emulator; DBOPL::Handler *adlib; OPLEmul *zdoom; - Bit8u regCache[256]; + Bit8u regCache[OPL_N_REG]; int intermediateBufIdx; Bit32s intermediateBuf[INTERMEDIATE_BUF_N][INTERMEDIATE_BUF_SAMPLES]; bool _CheckParams(int ch, int osc);