mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-27 00:30:26 +00:00
Attempts to use table-based maths.
This commit is contained in:
parent
4a295cd95e
commit
3948304172
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#include "Channel.hpp"
|
||||
#include "Tables.h"
|
||||
|
||||
using namespace Yamaha::OPL;
|
||||
|
||||
@ -39,19 +40,15 @@ int Channel::update(Operator *modulator, Operator *carrier, OperatorOverrides *m
|
||||
|
||||
// TODO: almost everything. This is a quick test.
|
||||
// Specifically: use lookup tables.
|
||||
const auto modulator_level = level(modulator_state_, 0.0f); // TODO: what's the proper scaling on this?
|
||||
return int(level(carrier_state_, modulator_level) * 20'000.0f);
|
||||
const auto modulator_level = level(modulator_state_, 0);
|
||||
return level(carrier_state_, modulator_level);
|
||||
}
|
||||
|
||||
bool Channel::is_audible(Operator *carrier, OperatorOverrides *carrier_overrides) {
|
||||
return carrier->is_audible(carrier_state_, carrier_overrides);
|
||||
}
|
||||
|
||||
float Channel::level(OperatorState &state, float modulator_level) {
|
||||
const float phase = modulator_level + float(state.phase) / 1024.0f;
|
||||
const float phase_attenuation = logf(1.0f + sinf(float(M_PI) * 2.0f * phase));
|
||||
const float total_attenuation = phase_attenuation + float(state.attenuation) / 1023.0f;
|
||||
const float result = expf(total_attenuation / 2.0f);
|
||||
|
||||
return result;
|
||||
int Channel::level(OperatorState &state, int modulator_level) {
|
||||
const auto log_sin = negative_log_sin(modulator_level + state.phase);
|
||||
return power_two(log_sin.logsin + state.attenuation) * log_sin.sign;
|
||||
}
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
#include "Operator.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace Yamaha {
|
||||
namespace OPL {
|
||||
|
||||
@ -48,7 +46,7 @@ class Channel {
|
||||
bool is_audible(Operator *carrier, OperatorOverrides *carrier_overrides = nullptr);
|
||||
|
||||
private:
|
||||
float level(OperatorState &state, float modulator_level);
|
||||
int level(OperatorState &state, int modulator_level);
|
||||
|
||||
/// 'F-Num' in the spec; this plus the current octave determines channel frequency.
|
||||
int period_ = 0;
|
||||
|
@ -109,7 +109,7 @@ struct OPLL: public OPLBase<OPLL> {
|
||||
for(int c = 0; c < 6; ++ c) { // Don't do anything with channels that might be percussion for now.
|
||||
channels_[c].level = (channels_[c].update() * total_volume_) >> 14;
|
||||
}
|
||||
channels_[2].level = (channels_[2].update() * total_volume_) >> 14;
|
||||
// channels_[2].level = (channels_[2].update() * total_volume_) >> 14;
|
||||
}
|
||||
Channel channels_[9];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user