mirror of
https://github.com/TomHarte/CLK.git
synced 2025-08-09 05:25:01 +00:00
Rename Table.h; LogSin -> LogSign and make it a bit more typer.
This commit is contained in:
@@ -7,7 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "Channel.hpp"
|
#include "Channel.hpp"
|
||||||
#include "Tables.h"
|
|
||||||
|
|
||||||
using namespace Yamaha::OPL;
|
using namespace Yamaha::OPL;
|
||||||
|
|
||||||
|
@@ -9,12 +9,11 @@
|
|||||||
#include "Operator.hpp"
|
#include "Operator.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "Tables.h"
|
|
||||||
|
|
||||||
using namespace Yamaha::OPL;
|
using namespace Yamaha::OPL;
|
||||||
|
|
||||||
int OperatorState::level() {
|
int OperatorState::level() {
|
||||||
return power_two(attenuation.logsin) * attenuation.sign;
|
return power_two(attenuation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Operator::set_attack_decay(uint8_t value) {
|
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
|
// 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
|
// 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).
|
// 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 {
|
} else {
|
||||||
// Overrides here represent per-channel volume on an OPLL. The bits are defined to represent
|
// Overrides here represent per-channel volume on an OPLL. The bits are defined to represent
|
||||||
// attenuations of 24db to 0.75db.
|
// attenuations of 24db to 0.75db.
|
||||||
state.attenuation.logsin += (state.adsr_attenuation_ << 3) + (attenuation_ << 5);
|
state.attenuation.log += (state.adsr_attenuation_ << 3) + (attenuation_ << 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
#define Operator_hpp
|
#define Operator_hpp
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "Tables.h"
|
#include "Tables.hpp"
|
||||||
|
|
||||||
namespace Yamaha {
|
namespace Yamaha {
|
||||||
namespace OPL {
|
namespace OPL {
|
||||||
@@ -24,7 +24,7 @@ struct OperatorState {
|
|||||||
int level();
|
int level();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LogSin attenuation;
|
LogSign attenuation;
|
||||||
int raw_phase_ = 0;
|
int raw_phase_ = 0;
|
||||||
|
|
||||||
enum class ADSRPhase {
|
enum class ADSRPhase {
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
//
|
//
|
||||||
// Tables.h
|
// Tables.hpp
|
||||||
// Clock Signal
|
// Clock Signal
|
||||||
//
|
//
|
||||||
// Created by Thomas Harte on 15/04/2020.
|
// Created by Thomas Harte on 15/04/2020.
|
||||||
// Copyright © 2020 Thomas Harte. All rights reserved.
|
// Copyright © 2020 Thomas Harte. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef Tables_h
|
#ifndef Tables_hpp
|
||||||
#define Tables_h
|
#define Tables_hpp
|
||||||
|
|
||||||
namespace Yamaha {
|
namespace Yamaha {
|
||||||
namespace OPL {
|
namespace OPL {
|
||||||
@@ -21,14 +21,14 @@ namespace OPL {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
struct LogSin {
|
struct LogSign {
|
||||||
int logsin;
|
int log;
|
||||||
int sign;
|
int sign;
|
||||||
};
|
};
|
||||||
/*!
|
/*!
|
||||||
@returns Negative log sin of x, assuming a 1024-unit circle.
|
@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)).
|
/// 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:
|
/// 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 };
|
constexpr int16_t mask[] = { 0, 255 };
|
||||||
|
|
||||||
return {
|
return {
|
||||||
.logsin = log_sin[x & 255] ^ mask[(x >> 8) & 1],
|
.log = log_sin[x & 255] ^ mask[(x >> 8) & 1],
|
||||||
.sign = sign[(x >> 9) & 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.
|
@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.
|
/// 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
|
/// 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:
|
/// be achieved more easily. Specifically, to convert a logarithmic attenuation to a linear one, just perform:
|
||||||
///
|
///
|
||||||
/// result = mapped_exp[x & 0xff] >> (x >> 8)
|
/// result = mapped_exp[x & 0xff] >> (x >> 8)
|
||||||
constexpr int mapped_exp[] = {
|
constexpr int16_t mapped_exp[] = {
|
||||||
4084, 4074, 4062, 4052, 4040, 4030, 4020, 4008,
|
4084, 4074, 4062, 4052, 4040, 4030, 4020, 4008,
|
||||||
3998, 3986, 3976, 3966, 3954, 3944, 3932, 3922,
|
3998, 3986, 3976, 3966, 3954, 3944, 3932, 3922,
|
||||||
3912, 3902, 3890, 3880, 3870, 3860, 3848, 3838,
|
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,
|
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 */
|
@@ -11,8 +11,6 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "Implementation/Tables.h"
|
|
||||||
|
|
||||||
using namespace Yamaha::OPL;
|
using namespace Yamaha::OPL;
|
||||||
|
|
||||||
template <typename Child>
|
template <typename Child>
|
||||||
|
@@ -1660,7 +1660,7 @@
|
|||||||
4BC0CB312447EC7C00A79DBB /* Operator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Operator.hpp; sourceTree = "<group>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
4BC1316F2346DE5000E4FF3D /* StaticAnalyser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StaticAnalyser.cpp; sourceTree = "<group>"; };
|
||||||
@@ -3514,7 +3514,7 @@
|
|||||||
4BC0CB312447EC7C00A79DBB /* Operator.hpp */,
|
4BC0CB312447EC7C00A79DBB /* Operator.hpp */,
|
||||||
4BC0CB352447EC9A00A79DBB /* Channel.cpp */,
|
4BC0CB352447EC9A00A79DBB /* Channel.cpp */,
|
||||||
4BC0CB362447EC9A00A79DBB /* Channel.hpp */,
|
4BC0CB362447EC9A00A79DBB /* Channel.hpp */,
|
||||||
4BC0CB3A2447ECAE00A79DBB /* Tables.h */,
|
4BC0CB3A2447ECAE00A79DBB /* Tables.hpp */,
|
||||||
);
|
);
|
||||||
path = Implementation;
|
path = Implementation;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
Reference in New Issue
Block a user