2
0
Fork 0

Add Envelope parameters and IntFloatParameter wrapper.

This commit is contained in:
bruce 2013-09-12 20:17:31 +08:00
parent ad1167f562
commit f1d35c42ac
6 changed files with 88 additions and 15 deletions

View file

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "c:\code\game\fm\juceoplvsti\source\floatparameter.h" #include "FloatParameter.h"
class EnumFloatParameter : class EnumFloatParameter :
public FloatParameter public FloatParameter
{ {

View file

@ -0,0 +1,27 @@
#include "IntFloatParameter.h"
IntFloatParameter::IntFloatParameter(String name, int min, int max)
:FloatParameter(name)
{
this->min = min;
this->max = max;
}
IntFloatParameter::~IntFloatParameter(void)
{
}
int IntFloatParameter::getParameterValue(void)
{
int range = max - min;
int i = (int)(this->value * range);
if (i > range)
i = range;
return i;
}
String IntFloatParameter::getParameterText(void)
{
return String(this->getParameterValue());
}

View file

@ -0,0 +1,15 @@
#pragma once
#include "FloatParameter.h"
class IntFloatParameter :
public FloatParameter
{
public:
IntFloatParameter(String name, int min, int max);
~IntFloatParameter(void);
String getParameterText(void);
int getParameterValue(void);
private:
int min;
int max;
};

View file

@ -1,6 +1,7 @@
#include "PluginProcessor.h" #include "PluginProcessor.h"
#include "PluginEditor.h" #include "PluginEditor.h"
#include "EnumFloatParameter.h" #include "EnumFloatParameter.h"
#include "IntFloatParameter.h"
//============================================================================== //==============================================================================
JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor() JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor()
@ -29,6 +30,14 @@ JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor()
params.push_back(new EnumFloatParameter("Modulator Frequency Multiplier", params.push_back(new EnumFloatParameter("Modulator Frequency Multiplier",
StringArray(frq_multipliers, sizeof(frq_multipliers)/sizeof(String))) StringArray(frq_multipliers, sizeof(frq_multipliers)/sizeof(String)))
); );
params.push_back(new IntFloatParameter("Carrier Attack", 0, 15));
params.push_back(new IntFloatParameter("Carrier Sustain", 0, 15));
params.push_back(new IntFloatParameter("Carrier Decay", 0, 15));
params.push_back(new IntFloatParameter("Carrier Release", 0, 15));
params.push_back(new IntFloatParameter("Modulator Attack", 0, 15));
params.push_back(new IntFloatParameter("Modulator Sustain", 0, 15));
params.push_back(new IntFloatParameter("Modulator Decay", 0, 15));
params.push_back(new IntFloatParameter("Modulator Release", 0, 15));
} }
JuceOplvstiAudioProcessor::~JuceOplvstiAudioProcessor() JuceOplvstiAudioProcessor::~JuceOplvstiAudioProcessor()
@ -56,18 +65,18 @@ void JuceOplvstiAudioProcessor::setParameter (int index, float newValue)
FloatParameter* p = params[index]; FloatParameter* p = params[index];
p->setParameter(newValue); p->setParameter(newValue);
String name = p->getName(); String name = p->getName();
if (name == "Carrier Wave") { int osc = 1; // Carrier
Opl->SetWaveform(1, 1, (Waveform)((EnumFloatParameter*)p)->getParameterIndex()); if (name.startsWith("Modulator")) {
} else if (name == "Modulator Wave") { osc = 2;
Opl->SetWaveform(1, 2, (Waveform)((EnumFloatParameter*)p)->getParameterIndex()); }
} else if (name == "Modulator Attenuation") { if (name.endsWith("Wave")) {
Opl->SetAttenuation(1, 1, 0x1<<((EnumFloatParameter*)p)->getParameterIndex()); Opl->SetWaveform(1, osc, (Waveform)((EnumFloatParameter*)p)->getParameterIndex());
} else if (name == "Carrier Attenuation") { } else if (name.endsWith("Attenuation")) {
Opl->SetAttenuation(1, 2, 0x1<<((EnumFloatParameter*)p)->getParameterIndex()); Opl->SetAttenuation(1, osc, 0x1<<((EnumFloatParameter*)p)->getParameterIndex());
} else if (name == "Carrier Frequency Multiplier") { } else if (name.endsWith("Frequency Multiplier")) {
Opl->SetFrequencyMultiple(1, 1, (FreqMultiple)((EnumFloatParameter*)p)->getParameterIndex()); Opl->SetFrequencyMultiple(1, osc, (FreqMultiple)((EnumFloatParameter*)p)->getParameterIndex());
} else if (name == "Modulator Frequency Multiplier") { } else if (name.endsWith("Attack")) {
Opl->SetFrequencyMultiple(1, 2, (FreqMultiple)((EnumFloatParameter*)p)->getParameterIndex()); Opl->SetEnvelopeAttack(1, osc, ((IntFloatParameter*)p)->getParameterValue());
} }
} }

View file

@ -109,13 +109,31 @@ void Hiopl::SetFrequencyMultiple(int ch, int osc, FreqMultiple mult) {
_WriteReg(0x20+offset, (Bit8u)mult);//, 0xf); _WriteReg(0x20+offset, (Bit8u)mult);//, 0xf);
} }
void Hiopl::SetEnvelopeAttack(int ch, int osc, int t) {
int offset = this->_GetOffset(ch, osc);
_WriteReg(0x60+offset, (Bit8u)t<<4, 0xf0);
}
void Hiopl::SetEnvelopeDecay(int ch, int osc, int t) {
int offset = this->_GetOffset(ch, osc);
_WriteReg(0x60+offset, (Bit8u)t, 0x0f);
}
void Hiopl::SetEnvelopeSustain(int ch, int osc, int level) {
int offset = this->_GetOffset(ch, osc);
_WriteReg(0x80+offset, (Bit8u)level<<4, 0xf0);
}
void Hiopl::SetEnvelopeRelease(int ch, int osc, int t) {
int offset = this->_GetOffset(ch, osc);
_WriteReg(0x80+offset, (Bit8u)t, 0x0f);
}
void Hiopl::KeyOn(int ch, float frqHz) { void Hiopl::KeyOn(int ch, float frqHz) {
unsigned int fnum, block; unsigned int fnum, block;
_milliHertzToFnum((unsigned int)(frqHz * 1000.0), &fnum, &block); _milliHertzToFnum((unsigned int)(frqHz * 1000.0), &fnum, &block);
_WriteReg(0xa0, fnum % 0x100); _WriteReg(0xa0, fnum % 0x100);
_WriteReg(0xb0, 0x20|((block&0x7)<<2)|(0x3&(fnum/0x100))); _WriteReg(0xb0, 0x20|((block&0x7)<<2)|(0x3&(fnum/0x100)));
//_WriteReg(0xa0, 0x8b);
//_WriteReg(0xb0, 0x26);
} }
void Hiopl::KeyOff(int ch) { void Hiopl::KeyOff(int ch) {

View file

@ -27,6 +27,10 @@ class Hiopl {
Waveform GetWaveform(int ch, int osc); Waveform GetWaveform(int ch, int osc);
void SetAttenuation(int ch, int osc, int level); void SetAttenuation(int ch, int osc, int level);
void SetFrequencyMultiple(int ch, int osc, FreqMultiple mult); void SetFrequencyMultiple(int ch, int osc, FreqMultiple mult);
void SetEnvelopeAttack(int ch, int osc, int t);
void SetEnvelopeDecay(int ch, int osc, int t);
void SetEnvelopeSustain(int ch, int osc, int level);
void SetEnvelopeRelease(int ch, int osc, int t);
void KeyOn(int ch, float frqHz); void KeyOn(int ch, float frqHz);
void KeyOff(int ch); void KeyOff(int ch);
void _WriteReg(Bit32u reg, Bit8u value, Bit8u mask=0x0); void _WriteReg(Bit32u reg, Bit8u value, Bit8u mask=0x0);