1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-05 10:28:58 +00:00

Rename Table.h; LogSin -> LogSign and make it a bit more typer.

This commit is contained in:
Thomas Harte 2020-04-19 13:33:17 -04:00
parent 92d0c466c2
commit c54bbc5a04
6 changed files with 18 additions and 22 deletions

View File

@ -7,7 +7,6 @@
//
#include "Channel.hpp"
#include "Tables.h"
using namespace Yamaha::OPL;

View File

@ -9,12 +9,11 @@
#include "Operator.hpp"
#include <algorithm>
#include "Tables.h"
using namespace Yamaha::OPL;
int OperatorState::level() {
return power_two(attenuation.logsin) * attenuation.sign;
return power_two(attenuation);
}
void Operator::set_attack_decay(uint8_t value) {
@ -179,10 +178,10 @@ void Operator::update(OperatorState &state, bool key_on, int channel_period, int
// Overrides here represent per-channel volume on an OPLL. The bits are defined to represent
// attenuations of 24db to 3db; the main envelope generator is stated to have a resolution of
// 0.325db (which I've assumed is supposed to say 0.375db).
state.attenuation.logsin += state.adsr_attenuation_ + (overrides->attenuation << 4);
state.attenuation.log += state.adsr_attenuation_ + (overrides->attenuation << 4);
} else {
// Overrides here represent per-channel volume on an OPLL. The bits are defined to represent
// attenuations of 24db to 0.75db.
state.attenuation.logsin += (state.adsr_attenuation_ << 3) + (attenuation_ << 5);
state.attenuation.log += (state.adsr_attenuation_ << 3) + (attenuation_ << 5);
}
}

View File

@ -10,7 +10,7 @@
#define Operator_hpp
#include <cstdint>
#include "Tables.h"
#include "Tables.hpp"
namespace Yamaha {
namespace OPL {
@ -24,7 +24,7 @@ struct OperatorState {
int level();
private:
LogSin attenuation;
LogSign attenuation;
int raw_phase_ = 0;
enum class ADSRPhase {

View File

@ -1,13 +1,13 @@
//
// Tables.h
// Tables.hpp
// Clock Signal
//
// Created by Thomas Harte on 15/04/2020.
// Copyright © 2020 Thomas Harte. All rights reserved.
//
#ifndef Tables_h
#define Tables_h
#ifndef Tables_hpp
#define Tables_hpp
namespace Yamaha {
namespace OPL {
@ -21,14 +21,14 @@ namespace OPL {
*/
struct LogSin {
int logsin;
struct LogSign {
int log;
int sign;
};
/*!
@returns Negative log sin of x, assuming a 1024-unit circle.
*/
constexpr LogSin negative_log_sin(int x) {
constexpr LogSign negative_log_sin(int x) {
/// Defines the first quadrant of 1024-unit negative log to the base two of sine (that conveniently misses sin(0)).
///
/// Expected branchless usage for a full 1024 unit output:
@ -77,7 +77,7 @@ constexpr LogSin negative_log_sin(int x) {
constexpr int16_t mask[] = { 0, 255 };
return {
.logsin = log_sin[x & 255] ^ mask[(x >> 8) & 1],
.log = log_sin[x & 255] ^ mask[(x >> 8) & 1],
.sign = sign[(x >> 9) & 1]
};
}
@ -85,7 +85,7 @@ constexpr LogSin negative_log_sin(int x) {
/*!
@returns 2 ^ -x/256 in 0.10 fixed-point form.
*/
constexpr int power_two(int x) {
constexpr int power_two(LogSign ls) {
/// A derivative of the exponent table in a real OPL2; mapped_exp[x] = (source[c ^ 0xff] << 1) | 0x800.
///
/// The ahead-of-time transformation represents fixed work the OPL2 does when reading its table
@ -102,7 +102,7 @@ constexpr int power_two(int x) {
/// be achieved more easily. Specifically, to convert a logarithmic attenuation to a linear one, just perform:
///
/// result = mapped_exp[x & 0xff] >> (x >> 8)
constexpr int mapped_exp[] = {
constexpr int16_t mapped_exp[] = {
4084, 4074, 4062, 4052, 4040, 4030, 4020, 4008,
3998, 3986, 3976, 3966, 3954, 3944, 3932, 3922,
3912, 3902, 3890, 3880, 3870, 3860, 3848, 3838,
@ -137,7 +137,7 @@ constexpr int power_two(int x) {
2088, 2082, 2076, 2070, 2064, 2060, 2054, 2048,
};
return mapped_exp[x & 0xff] >> (x >> 8);
return (mapped_exp[ls.log & 0xff] >> (ls.log >> 8)) * ls.sign;
}
/*
@ -195,4 +195,4 @@ constexpr uint8_t percussion_patch_set[] = {
}
}
#endif /* Tables_h */
#endif /* Tables_hpp */

View File

@ -11,8 +11,6 @@
#include <cassert>
#include <cmath>
#include "Implementation/Tables.h"
using namespace Yamaha::OPL;
template <typename Child>

View File

@ -1660,7 +1660,7 @@
4BC0CB312447EC7C00A79DBB /* Operator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Operator.hpp; sourceTree = "<group>"; };
4BC0CB352447EC9A00A79DBB /* Channel.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Channel.cpp; sourceTree = "<group>"; };
4BC0CB362447EC9A00A79DBB /* Channel.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Channel.hpp; sourceTree = "<group>"; };
4BC0CB3A2447ECAE00A79DBB /* Tables.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Tables.h; sourceTree = "<group>"; };
4BC0CB3A2447ECAE00A79DBB /* Tables.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Tables.hpp; sourceTree = "<group>"; };
4BC1316D2346DE5000E4FF3D /* StaticAnalyser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = StaticAnalyser.hpp; sourceTree = "<group>"; };
4BC1316E2346DE5000E4FF3D /* Target.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Target.hpp; sourceTree = "<group>"; };
4BC1316F2346DE5000E4FF3D /* StaticAnalyser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StaticAnalyser.cpp; sourceTree = "<group>"; };
@ -3514,7 +3514,7 @@
4BC0CB312447EC7C00A79DBB /* Operator.hpp */,
4BC0CB352447EC9A00A79DBB /* Channel.cpp */,
4BC0CB362447EC9A00A79DBB /* Channel.hpp */,
4BC0CB3A2447ECAE00A79DBB /* Tables.h */,
4BC0CB3A2447ECAE00A79DBB /* Tables.hpp */,
);
path = Implementation;
sourceTree = "<group>";