Mesen2/Core/WS/APU/WsApuCh3.h
Sour c90b8a9ef6 WS: APU - Disabled channels should output 0
+ Ch2 outputs PCM if PCM is enabled, even when channel is disabled
2025-03-10 17:55:22 +09:00

60 lines
1.1 KiB
C++

#pragma once
#include "pch.h"
#include "WS/APU/WsApu.h"
#include "WS/WsTypes.h"
class WsApuCh3
{
private:
WsApu* _apu = nullptr;
WsApuCh3State* _state = nullptr;
public:
WsApuCh3(WsApu* apu, WsApuCh3State& state)
{
_state = &state;
_apu = apu;
}
void Exec()
{
if(!_state->Enabled) {
return;
}
if(_state->SweepEnabled) {
_state->SweepScaler++;
if(_state->UseSweepCpuClock || _state->SweepScaler >= 0x2000) {
_state->SweepScaler = 0;
if(_state->SweepTimer == 0) {
_state->SweepTimer = _state->SweepPeriod;
_state->Frequency = (_state->Frequency + _state->SweepValue) & 0xFFF;
} else {
_state->SweepTimer--;
}
}
}
if(_state->Timer == 0) {
_state->Timer = 2047 - _state->Frequency;
_state->SamplePosition = (_state->SamplePosition + 1) & 0x1F;
} else {
_state->Timer--;
}
}
void UpdateOutput()
{
if(!_state->Enabled) {
_state->LeftOutput = 0;
_state->RightOutput = 0;
return;
}
uint8_t sample = _apu->ReadSample(2, _state->SamplePosition);
_state->LeftOutput = _state->LeftVolume * sample;
_state->RightOutput = _state->RightVolume * sample;
}
};