2
0
Fork 0

Finally allow sample rates other than 44100 Hz.

This commit is contained in:
bsutherland 2016-02-07 19:47:22 +09:00
parent 0309b92e97
commit b53255598d
5 changed files with 9 additions and 46 deletions

View file

@ -27,7 +27,6 @@
void PluginGui::updateFromParameters() void PluginGui::updateFromParameters()
{ {
emulatorSlider->setValue(processor->getEnumParameter("Emulator"), juce::NotificationType::dontSendNotification); emulatorSlider->setValue(processor->getEnumParameter("Emulator"), juce::NotificationType::dontSendNotification);
setRecordButtonState(processor->isThisInstanceRecording());
/// setToggleState(bool, bool) is deprecated. /// setToggleState(bool, bool) is deprecated.
/// Jeff-Russ replaced the second arg of "false" with dontSendNotification: /// Jeff-Russ replaced the second arg of "false" with dontSendNotification:

View file

@ -15,9 +15,6 @@ AdlibBlasterAudioProcessor::AdlibBlasterAudioProcessor()
Opl = new Hiopl(); Opl = new Hiopl();
Opl->SetSampleRate(44100); Opl->SetSampleRate(44100);
Opl->EnableWaveformControl(); Opl->EnableWaveformControl();
dro = new DROMultiplexer();
recordingFile = NULL;
// Initialize parameters // Initialize parameters
@ -142,26 +139,6 @@ AdlibBlasterAudioProcessor::AdlibBlasterAudioProcessor()
available_channels.push_back(i); 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() void AdlibBlasterAudioProcessor::initPrograms()
{ {
// these ones from the Syndicate in-game music // these ones from the Syndicate in-game music
@ -450,7 +427,6 @@ AdlibBlasterAudioProcessor::~AdlibBlasterAudioProcessor()
for (unsigned int i=0; i < params.size(); ++i) for (unsigned int i=0; i < params.size(); ++i)
delete params[i]; delete params[i];
delete Opl; delete Opl;
delete dro;
} }
//============================================================================== //==============================================================================
@ -717,7 +693,8 @@ void AdlibBlasterAudioProcessor::changeProgramName (int index, const String& new
//============================================================================== //==============================================================================
void AdlibBlasterAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock) 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 // Use this method as the place to do any pre-playback
// initialisation that you need.. // initialisation that you need..
} }
@ -751,9 +728,6 @@ void AdlibBlasterAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBu
Opl->SetFrequency(i, noteHz, false); Opl->SetFrequency(i, noteHz, false);
} }
Opl->HitPercussion(DRUM_INDEX[perc - 1]); Opl->HitPercussion(DRUM_INDEX[perc - 1]);
if (isAnyInstanceRecording()) {
dro->GetMaster()->PercussionChange(Opl, perc - 1);
}
} else { } else {
if (!available_channels.empty()) if (!available_channels.empty())
{ {
@ -794,17 +768,11 @@ void AdlibBlasterAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBu
Opl->KeyOn(ch, noteHz); Opl->KeyOn(ch, noteHz);
active_notes[ch] = n; active_notes[ch] = n;
applyPitchBend(); applyPitchBend();
if (isAnyInstanceRecording()) {
dro->GetMaster()->TwoOpMelodicNoteOn(Opl, ch);
}
} }
} }
else if (midi_message.isNoteOff()) { else if (midi_message.isNoteOff()) {
if (perc > 0) { if (perc > 0) {
Opl->ReleasePercussion(); Opl->ReleasePercussion();
if (isAnyInstanceRecording()) {
dro->GetMaster()->PercussionChange(Opl, perc - 1);
}
} }
else { else {
int n = midi_message.getNoteNumber(); int n = midi_message.getNoteNumber();
@ -828,9 +796,6 @@ void AdlibBlasterAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBu
Opl->KeyOff(ch); Opl->KeyOff(ch);
active_notes[ch] = NO_NOTE; active_notes[ch] = NO_NOTE;
} }
if (isAnyInstanceRecording()) {
dro->GetMaster()->TwoOpMelodicNoteOff(Opl, ch);
}
} }
} }
else if (midi_message.isPitchWheel()) { else if (midi_message.isPitchWheel()) {

View file

@ -27,11 +27,6 @@ public:
void applyPitchBend(); void applyPitchBend();
~AdlibBlasterAudioProcessor(); ~AdlibBlasterAudioProcessor();
bool isThisInstanceRecording();
bool isAnyInstanceRecording();
void startRecording(File *outputFile);
void stopRecording();
//============================================================================== //==============================================================================
void prepareToPlay (double sampleRate, int samplesPerBlock); void prepareToPlay (double sampleRate, int samplesPerBlock);
void releaseResources(); void releaseResources();
@ -90,7 +85,6 @@ public:
private: private:
Hiopl *Opl; Hiopl *Opl;
DROMultiplexer *dro;
std::vector<FloatParameter*> params; std::vector<FloatParameter*> params;
std::map<String, int> paramIdxByName; std::map<String, int> paramIdxByName;
std::map<String, std::vector<float>> programs; std::map<String, std::vector<float>> programs;
@ -103,7 +97,6 @@ private:
std::deque<int> available_channels; // most recently freed at end std::deque<int> available_channels; // most recently freed at end
std::deque<int> used_channels; // most recently used at end std::deque<int> used_channels; // most recently used at end
float currentScaledBend; float currentScaledBend;
File *recordingFile;
//============================================================================== //==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AdlibBlasterAudioProcessor) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AdlibBlasterAudioProcessor)

View file

@ -67,6 +67,10 @@ void Hiopl::Generate(int length, float* buffer) {
void Hiopl::SetSampleRate(int hz) { void Hiopl::SetSampleRate(int hz) {
adlib->Init(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) { void Hiopl::_WriteReg(Bit32u reg, Bit8u value, Bit8u mask) {

View file

@ -12,6 +12,8 @@
// Number of static buffers to use. Again probably excessive, but let's be safe. // Number of static buffers to use. Again probably excessive, but let's be safe.
#define INTERMEDIATE_BUF_N 4 #define INTERMEDIATE_BUF_N 4
#define OPL_N_REG 256
enum Waveform enum Waveform
{ {
SIN = 0, HALF_SIN = 1, ABS_SIN = 2, QUART_SIN = 3 SIN = 0, HALF_SIN = 1, ABS_SIN = 2, QUART_SIN = 3
@ -88,7 +90,7 @@ class Hiopl {
Emulator emulator; Emulator emulator;
DBOPL::Handler *adlib; DBOPL::Handler *adlib;
OPLEmul *zdoom; OPLEmul *zdoom;
Bit8u regCache[256]; Bit8u regCache[OPL_N_REG];
int intermediateBufIdx; int intermediateBufIdx;
Bit32s intermediateBuf[INTERMEDIATE_BUF_N][INTERMEDIATE_BUF_SAMPLES]; Bit32s intermediateBuf[INTERMEDIATE_BUF_N][INTERMEDIATE_BUF_SAMPLES];
bool _CheckParams(int ch, int osc); bool _CheckParams(int ch, int osc);