Reorganize emu folder, update S-SMP system infra
This commit is contained in:
125
src/app/emu/audio/apu.cc
Normal file
125
src/app/emu/audio/apu.cc
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "app/emu/audio/apu.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "app/emu/audio/dsp.h"
|
||||
#include "app/emu/audio/spc700.h"
|
||||
#include "app/emu/clock.h"
|
||||
#include "app/emu/mem.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace emu {
|
||||
|
||||
void APU::Init() {
|
||||
// Set the clock frequency
|
||||
clock_.SetFrequency(kApuClockSpeed);
|
||||
|
||||
// Initialize Digital Signal Processor Callbacks
|
||||
dsp_.SetSampleFetcher([this](uint16_t address) -> uint8_t {
|
||||
return this->FetchSampleFromRam(address);
|
||||
});
|
||||
|
||||
dsp_.SetSamplePusher(
|
||||
[this](int16_t sample) { this->PushToAudioBuffer(sample); });
|
||||
|
||||
// Initialize registers
|
||||
// ...
|
||||
}
|
||||
|
||||
void APU::Reset() {
|
||||
// Reset the clock
|
||||
clock_.ResetAccumulatedTime();
|
||||
|
||||
// Reset the SPC700
|
||||
// ...
|
||||
}
|
||||
|
||||
void APU::Update() {
|
||||
auto cycles_to_run = clock_.GetCycleCount();
|
||||
|
||||
for (auto i = 0; i < cycles_to_run; ++i) {
|
||||
// Update the APU
|
||||
// ...
|
||||
|
||||
// Update the SPC700
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
void APU::ProcessSamples() {
|
||||
// Fetch sample data from AudioRam
|
||||
// Iterate over all voices
|
||||
for (uint8_t voice_num = 0; voice_num < 8; voice_num++) {
|
||||
// Fetch the sample data for the current voice from AudioRam
|
||||
uint8_t sample = FetchSampleForVoice(voice_num);
|
||||
|
||||
// Process the sample through DSP
|
||||
int16_t processed_sample = dsp_.ProcessSample(voice_num, sample);
|
||||
|
||||
// Add the processed sample to the audio buffer
|
||||
audioSamples_.push_back(processed_sample);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t APU::FetchSampleForVoice(uint8_t voice_num) {
|
||||
// Define how you determine the address based on the voice_num
|
||||
uint16_t address = CalculateAddressForVoice(voice_num);
|
||||
return aram_.read(address);
|
||||
}
|
||||
|
||||
uint16_t APU::CalculateAddressForVoice(uint8_t voice_num) {
|
||||
// Placeholder logic to calculate the address in the AudioRam
|
||||
// based on the voice number.
|
||||
return voice_num; // Assuming each voice has a fixed size
|
||||
}
|
||||
|
||||
int16_t APU::GetNextSample() {
|
||||
// This method fetches the next sample. If there's no sample available, it can
|
||||
// return 0 or the last sample.
|
||||
if (!audioSamples_.empty()) {
|
||||
int16_t sample = audioSamples_.front();
|
||||
audioSamples_.erase(audioSamples_.begin());
|
||||
return sample;
|
||||
}
|
||||
return 0; // or return the last sample
|
||||
}
|
||||
|
||||
uint8_t APU::ReadRegister(uint16_t address) {
|
||||
// ...
|
||||
}
|
||||
|
||||
void APU::WriteRegister(uint16_t address, uint8_t value) {
|
||||
// ...
|
||||
}
|
||||
|
||||
const std::vector<int16_t>& APU::GetAudioSamples() const {
|
||||
// ...
|
||||
}
|
||||
|
||||
void APU::UpdateChannelSettings() {
|
||||
// ...
|
||||
}
|
||||
|
||||
int16_t APU::GenerateSample(int channel) {
|
||||
// ...
|
||||
}
|
||||
|
||||
void APU::ApplyEnvelope(int channel) {
|
||||
// ...
|
||||
}
|
||||
|
||||
uint8_t APU::ReadDSPMemory(uint16_t address) {
|
||||
// ...
|
||||
}
|
||||
|
||||
void APU::WriteDSPMemory(uint16_t address, uint8_t value) {
|
||||
// ...
|
||||
}
|
||||
|
||||
} // namespace emu
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
Reference in New Issue
Block a user