2
0
Fork 0

Initialise parameters as floating point values.

This commit is contained in:
bruce 2013-09-12 21:10:19 +08:00
parent f1d35c42ac
commit 2dc2879064
3 changed files with 39 additions and 22 deletions

View file

@ -7,37 +7,52 @@
JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor() JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor()
{ {
Opl = new Hiopl(44100); // 1 second at 44100 Opl = new Hiopl(44100); // 1 second at 44100
Opl->SetSampleRate(44100);
Opl->EnableSustain(1, 1);
Opl->EnableSustain(1, 2);
const String waveforms[] = {"Sine", "Half Sine", "Abs Sine", "Quarter Sine"}; const String waveforms[] = {"Sine", "Half Sine", "Abs Sine", "Quarter Sine"};
params.push_back(new EnumFloatParameter("Carrier Wave", params.push_back(new EnumFloatParameter("Carrier Wave",
StringArray(waveforms, sizeof(waveforms)/sizeof(String))) StringArray(waveforms, sizeof(waveforms)/sizeof(String)))
); ); setParameter(params.size()-1, 0.0f);
params.push_back(new EnumFloatParameter("Modulator Wave", params.push_back(new EnumFloatParameter("Modulator Wave",
StringArray(waveforms, sizeof(waveforms)/sizeof(String))) StringArray(waveforms, sizeof(waveforms)/sizeof(String)))
); ); setParameter(params.size()-1,0.0f);
const String levels[] = {"-0.75 dB", "-1.5 dB", "-3 dB", "-6 dB", "-12 dB", "-24 dB"}; const String levels[] = {"-0.75 dB", "-1.5 dB", "-3 dB", "-6 dB", "-12 dB", "-24 dB"};
params.push_back(new EnumFloatParameter("Carrier Attenuation", params.push_back(new EnumFloatParameter("Carrier Attenuation",
StringArray(levels, sizeof(levels)/sizeof(String))) StringArray(levels, sizeof(levels)/sizeof(String)))
); ); setParameter(params.size()-1,0.0f);
params.push_back(new EnumFloatParameter("Modulator Attenuation", params.push_back(new EnumFloatParameter("Modulator Attenuation",
StringArray(levels, sizeof(levels)/sizeof(String))) StringArray(levels, sizeof(levels)/sizeof(String)))
); ); setParameter(params.size()-1,0.75f);
const String frq_multipliers[] = { const String frq_multipliers[] = {
"x0.5", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x10", "x12", "x12", "x15", "x15" "x0.5", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x10", "x12", "x12", "x15", "x15"
}; };
params.push_back(new EnumFloatParameter("Carrier Frequency Multiplier", params.push_back(new EnumFloatParameter("Carrier Frequency Multiplier",
StringArray(frq_multipliers, sizeof(frq_multipliers)/sizeof(String))) StringArray(frq_multipliers, sizeof(frq_multipliers)/sizeof(String)))
); ); setParameter(params.size()-1, 0.08f);
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)))
); ); setParameter(params.size()-1, 0.15f);
params.push_back(new IntFloatParameter("Carrier Attack", 0, 15)); params.push_back(new IntFloatParameter("Carrier Attack", 0, 15));
params.push_back(new IntFloatParameter("Carrier Sustain", 0, 15)); setParameter(params.size()-1,0.5f);
params.push_back(new IntFloatParameter("Carrier Decay", 0, 15)); params.push_back(new IntFloatParameter("Carrier Decay", 0, 15));
setParameter(params.size()-1,0.25f);
params.push_back(new IntFloatParameter("Carrier Sustain", 0, 15));
setParameter(params.size()-1,0.125f);
params.push_back(new IntFloatParameter("Carrier Release", 0, 15)); params.push_back(new IntFloatParameter("Carrier Release", 0, 15));
setParameter(params.size()-1,0.5f);
params.push_back(new IntFloatParameter("Modulator Attack", 0, 15)); params.push_back(new IntFloatParameter("Modulator Attack", 0, 15));
params.push_back(new IntFloatParameter("Modulator Sustain", 0, 15)); setParameter(params.size()-1,0.5f);
params.push_back(new IntFloatParameter("Modulator Decay", 0, 15)); params.push_back(new IntFloatParameter("Modulator Decay", 0, 15));
setParameter(params.size()-1,0.25f);
params.push_back(new IntFloatParameter("Modulator Sustain", 0, 15));
setParameter(params.size()-1,0.25f);
params.push_back(new IntFloatParameter("Modulator Release", 0, 15)); params.push_back(new IntFloatParameter("Modulator Release", 0, 15));
setParameter(params.size()-1,0.25f);
} }
JuceOplvstiAudioProcessor::~JuceOplvstiAudioProcessor() JuceOplvstiAudioProcessor::~JuceOplvstiAudioProcessor()
@ -65,9 +80,9 @@ 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();
int osc = 1; // Carrier int osc = 2; // Carrier
if (name.startsWith("Modulator")) { if (name.startsWith("Modulator")) {
osc = 2; osc = 1;
} }
if (name.endsWith("Wave")) { if (name.endsWith("Wave")) {
Opl->SetWaveform(1, osc, (Waveform)((EnumFloatParameter*)p)->getParameterIndex()); Opl->SetWaveform(1, osc, (Waveform)((EnumFloatParameter*)p)->getParameterIndex());
@ -77,7 +92,14 @@ void JuceOplvstiAudioProcessor::setParameter (int index, float newValue)
Opl->SetFrequencyMultiple(1, osc, (FreqMultiple)((EnumFloatParameter*)p)->getParameterIndex()); Opl->SetFrequencyMultiple(1, osc, (FreqMultiple)((EnumFloatParameter*)p)->getParameterIndex());
} else if (name.endsWith("Attack")) { } else if (name.endsWith("Attack")) {
Opl->SetEnvelopeAttack(1, osc, ((IntFloatParameter*)p)->getParameterValue()); Opl->SetEnvelopeAttack(1, osc, ((IntFloatParameter*)p)->getParameterValue());
} else if (name.endsWith("Decay")) {
Opl->SetEnvelopeDecay(1, osc, ((IntFloatParameter*)p)->getParameterValue());
} else if (name.endsWith("Sustain")) {
Opl->SetEnvelopeSustain(1, osc, ((IntFloatParameter*)p)->getParameterValue());
} else if (name.endsWith("Release")) {
Opl->SetEnvelopeRelease(1, osc, ((IntFloatParameter*)p)->getParameterValue());
} }
} }
const String JuceOplvstiAudioProcessor::getParameterName (int index) const String JuceOplvstiAudioProcessor::getParameterName (int index)
@ -164,7 +186,7 @@ void JuceOplvstiAudioProcessor::changeProgramName (int index, const String& newN
//============================================================================== //==============================================================================
void JuceOplvstiAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock) void JuceOplvstiAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{ {
Opl->SetSampleRate((int)sampleRate); //Opl->SetSampleRate((int)sampleRate);
// 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..
} }

View file

@ -64,17 +64,6 @@ void Hiopl::Generate(int length, float* buffer) {
void Hiopl::SetSampleRate(int hz) { void Hiopl::SetSampleRate(int hz) {
adlib->Init(hz); adlib->Init(hz);
_WriteReg(0x20,0x32); // modulator multiplier 2
_WriteReg(0x23,0x21); // carrier multiplier 1
_WriteReg(0x40,0x1a); // modulator attenuation
_WriteReg(0x43,0x09); // carrier attenuation
_WriteReg(0x60,0x84); // AD
_WriteReg(0x63,0x84); // AD
_WriteReg(0x80,0x29); // SR
_WriteReg(0x83,0x44); // SR
//_WriteReg(0xe3,0x00); // wave select
//_WriteReg(0xe0,0x02); // wave select
//_WriteReg(0xc0,0x06); // carrier self-feedback level
} }
void Hiopl::_WriteReg(Bit32u reg, Bit8u value, Bit8u mask) { void Hiopl::_WriteReg(Bit32u reg, Bit8u value, Bit8u mask) {
@ -129,6 +118,11 @@ void Hiopl::SetEnvelopeRelease(int ch, int osc, int t) {
_WriteReg(0x80+offset, (Bit8u)t, 0x0f); _WriteReg(0x80+offset, (Bit8u)t, 0x0f);
} }
void Hiopl::EnableSustain(int ch, int osc) {
int offset = this->_GetOffset(ch, osc);
_WriteReg(0x20+offset, (Bit8u)0x20, 0x20);
}
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);

View file

@ -31,6 +31,7 @@ class Hiopl {
void SetEnvelopeDecay(int ch, int osc, int t); void SetEnvelopeDecay(int ch, int osc, int t);
void SetEnvelopeSustain(int ch, int osc, int level); void SetEnvelopeSustain(int ch, int osc, int level);
void SetEnvelopeRelease(int ch, int osc, int t); void SetEnvelopeRelease(int ch, int osc, int t);
void EnableSustain(int ch, int osc);
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);