Prepare MainVolume

This commit is contained in:
2022-08-31 17:05:22 +02:00
parent ba095f2064
commit 41c8c32db8
5 changed files with 116 additions and 25 deletions

View File

@@ -1,14 +1,20 @@
#ifndef __JABYENGINE_SPU_PORTS_HPP__
#define __JABYENGINE_SPU_PORTS_HPP__
#include "../Auxiliary/io_class_helper.hpp"
#include "../../limits.h"
namespace SPU {
//SampleRate is defined as 4096 == 44100Hz
enum Mode {
Linear = 0,
Exponential = 1,
};
struct __no_align SampleRate {
uint16_t raw_value = 0;
static constexpr SampleRate from_HZ(long double freq)
{
//SampleRate is defined as 4096 == 44100Hz
constexpr long double Base = (4096.0 / 44100.0);
return static_cast<SampleRate>(((freq*4096.0)/44100.0));
@@ -16,10 +22,8 @@ namespace SPU {
};
struct __no_align SweepVolume {
enum Type {
Linear = 0,
Exponential = 1,
};
static constexpr int16_t VolumeLevelStep100 = (I16_MAX/100);
static constexpr int16_t VolumeLevelStep1000 = (I16_MAX/1000);
enum Direction {
Increase = 0,
@@ -31,12 +35,17 @@ namespace SPU {
Negative = 1,
};
uint16_t raw_value = 0;
int16_t raw_value = 0;
constexpr SweepVolume() = default;
constexpr void set_volume(int16_t volume) {
this->raw_value = bit::value::set_normalized(this->raw_value, bit::cast<uint16_t>(volume >> 1), __start_end_bit2_start_length(0, 14));
static constexpr int16_t VolumeLevelPercent(double percent) {
return static_cast<int16_t>((I16_MAX/100.0)*percent);
}
constexpr auto& set_volume(int16_t volume) {
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<int16_t>(volume >> 1), __start_end_bit2_start_length(0, 14));
return *this;
}
constexpr int16_t get_volume() const {
@@ -44,14 +53,15 @@ namespace SPU {
}
io_class__2option_map(volume_mode, sweep_mode, 15);
io_class__2option_map_getter(Type, linear_sweep_mode, exponential_sweep_mode, sweep_mode_type, 14);
io_class__2option_map_getter(Mode, linear_sweep_mode, exponential_sweep_mode, sweep_mode_type, 14);
io_class__2option_map_getter(Direction, increase_sweep_mode, decrease_sweep_mode, sweep_mode_direction, 13);
io_class__2option_map_getter(Phase, positive_sweep_phase, negative_sweep_phase, sweep_phase, 12);
//Uses only 5bit of shift (0..1F (slow..fast))
constexpr void set_sweep_shift(uint8_5b shift) {
const uint16_t crop_value = static_cast<uint16_t>(shift); //(bit::value::crop_value(shift, 5));
constexpr auto& set_sweep_shift(uint8_5b shift) {
const int16_t crop_value = static_cast<int16_t>(shift); //(bit::value::crop_value(shift, 5));
this->raw_value = bit::value::set_normalized(this->raw_value, crop_value, __start_end_bit2_start_length(2, 6));
return *this;
}
constexpr uint8_5b get_sweep_shift() const {
@@ -59,8 +69,9 @@ namespace SPU {
}
//0..3 maps to => +7, +6, +5, +4 or -8, -7, -6, -5
constexpr void set_sweep_step(uint8_2b step) {
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<uint16_t>(step), __start_end_bit2_start_length(0, 1));
constexpr auto& set_sweep_step(uint8_2b step) {
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<int16_t>(step), __start_end_bit2_start_length(0, 1));
return *this;
}
constexpr uint8_2b get_sweep_step() const {
@@ -68,15 +79,26 @@ namespace SPU {
}
};
struct __no_align ADSR {
uint32_t raw_value = 0;
};
struct __no_align Voice {
static constexpr size_t Count = 24;
static inline __always_inline auto& Channel = reinterpret_cast<Voice(&)[Count]>(*reinterpret_cast<Voice*>(0x1f801c00));
SweepVolume volumeLeft;
SweepVolume volumeRight;
/*VolatileValue<SampleRate> sampleRate;
VolatileValue<uint16_t> adr;
VolatileValue<uint16_t> ad; //0x...08: 15 - 0
VolatileValue<uint16_t> sr; //0x...0A: 31 - 16
VolatileValue<uint16_t> currentVolume; //Not used
VolatileValue<uint16_t> repeatAdr;*/
SampleRate sampleRate;
uint16_t adr;
ADSR adsr;
SweepVolume currentVolume; //Not used
uint16_t repeatAdr;
};
struct MainVolume {
static inline __always_inline auto& Left = *reinterpret_cast<SweepVolume*>(0x1F801D80);
static inline __always_inline auto& Right = *reinterpret_cast<SweepVolume*>(0x1F801D82);
};
}