Mute current IIgs audio; work towards push.
This commit is contained in:
1 parent
fb712ca3df
commit
250ecf6d7f
3 files changed
+210
-258
No files matched your search
@@ -100,14 +100,15 @@ public:
|
||||
drives525_{
|
||||
{CLOCK_RATE / 2},
|
||||
{CLOCK_RATE / 2}
|
||||
},
|
||||
sound_glu_(audio_queue_),
|
||||
audio_toggle_(audio_queue_),
|
||||
mixer_(sound_glu_, audio_toggle_),
|
||||
speaker_(mixer_) {
|
||||
}
|
||||
// sound_glu_(audio_queue_),
|
||||
// audio_toggle_(audio_queue_),
|
||||
// mixer_(sound_glu_, audio_toggle_),
|
||||
// speaker_(mixer_)
|
||||
{
|
||||
|
||||
set_clock_rate(double(CLOCK_RATE));
|
||||
speaker_.set_input_rate(float(CLOCK_RATE) / float(audio_divider));
|
||||
// speaker_.set_input_rate(float(CLOCK_RATE) / float(audio_divider));
|
||||
clock_.ClockStorage::set_data(std::begin(default_bram), std::end(default_bram));
|
||||
|
||||
using Target = Analyser::Static::AppleIIgs::Target;
|
||||
@@ -209,10 +210,6 @@ public:
|
||||
insert_media(target.media);
|
||||
}
|
||||
|
||||
~ConcreteMachine() {
|
||||
audio_queue_.lock_flush();
|
||||
}
|
||||
|
||||
void run_for(const Cycles cycles) override {
|
||||
m65816_.run_for(cycles);
|
||||
}
|
||||
@@ -226,7 +223,6 @@ public:
|
||||
}
|
||||
if(outputs & Output::Audio) {
|
||||
AudioUpdater updater(this);
|
||||
audio_queue_.perform();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +243,8 @@ public:
|
||||
}
|
||||
|
||||
Outputs::Speaker::Speaker *get_speaker() final {
|
||||
return &speaker_;
|
||||
return nullptr;
|
||||
// return &speaker_;
|
||||
}
|
||||
|
||||
// MARK: MediaTarget.
|
||||
@@ -504,38 +501,14 @@ public:
|
||||
break;
|
||||
|
||||
// The audio GLU.
|
||||
case Read(0xc03c): {
|
||||
AudioUpdater updater(this);
|
||||
*value = sound_glu_.get_control();
|
||||
} break;
|
||||
case Write(0xc03c): {
|
||||
AudioUpdater updater(this);
|
||||
sound_glu_.set_control(*value);
|
||||
} break;
|
||||
case Read(0xc03d): {
|
||||
AudioUpdater updater(this);
|
||||
*value = sound_glu_.get_data();
|
||||
} break;
|
||||
case Write(0xc03d): {
|
||||
AudioUpdater updater(this);
|
||||
sound_glu_.set_data(*value);
|
||||
} break;
|
||||
case Read(0xc03e): {
|
||||
AudioUpdater updater(this);
|
||||
*value = sound_glu_.get_address_low();
|
||||
} break;
|
||||
case Write(0xc03e): {
|
||||
AudioUpdater updater(this);
|
||||
sound_glu_.set_address_low(*value);
|
||||
} break;
|
||||
case Read(0xc03f): {
|
||||
AudioUpdater updater(this);
|
||||
*value = sound_glu_.get_address_high();
|
||||
} break;
|
||||
case Write(0xc03f): {
|
||||
AudioUpdater updater(this);
|
||||
sound_glu_.set_address_high(*value);
|
||||
} break;
|
||||
case Read(0xc03c): *value = AudioUpdater(this)->control(); break;
|
||||
case Write(0xc03c): AudioUpdater(this)->set_control(*value); break;
|
||||
case Read(0xc03d): *value = AudioUpdater(this)->data(); break;
|
||||
case Write(0xc03d): AudioUpdater(this)->set_data(*value); break;
|
||||
case Read(0xc03e): *value = AudioUpdater(this)->address_low(); break;
|
||||
case Write(0xc03e): AudioUpdater(this)->set_address_low(*value); break;
|
||||
case Read(0xc03f): *value = AudioUpdater(this)->address_high(); break;
|
||||
case Write(0xc03f): AudioUpdater(this)->set_address_high(*value); break;
|
||||
|
||||
|
||||
// These were all dealt with by the call to memory_.access.
|
||||
@@ -675,8 +648,9 @@ public:
|
||||
break;
|
||||
|
||||
case Read(0xc030): case Write(0xc030): {
|
||||
AudioUpdater updater(this);
|
||||
audio_toggle_.set_output(!audio_toggle_.get_output());
|
||||
// TODO: restore audio toggle.
|
||||
// AudioUpdater updater(this);
|
||||
// audio_toggle_.set_output(!audio_toggle_.get_output());
|
||||
} break;
|
||||
|
||||
// 'Test Mode', whatever that is (?)
|
||||
@@ -908,7 +882,7 @@ public:
|
||||
void update_interrupts() {
|
||||
// Update the interrupt line.
|
||||
// TODO: add ADB controller as event source.
|
||||
m65816_.set_irq_line(video_.get()->get_interrupt_line() || sound_glu_.get_interrupt_line());
|
||||
m65816_.set_irq_line(video_.get()->get_interrupt_line() || sound_glu_.interrupt());
|
||||
}
|
||||
|
||||
// MARK: - Input.
|
||||
@@ -962,28 +936,35 @@ private:
|
||||
Apple::Disk::DiskIIDrive drives525_[2];
|
||||
|
||||
// The audio parts.
|
||||
Concurrency::AsyncTaskQueue<false> audio_queue_;
|
||||
// Concurrency::AsyncTaskQueue<false> audio_queue_;
|
||||
Apple::IIgs::Sound::GLU sound_glu_;
|
||||
Audio::Toggle audio_toggle_;
|
||||
using AudioSource = Outputs::Speaker::CompoundSource<Apple::IIgs::Sound::GLU, Audio::Toggle>;
|
||||
AudioSource mixer_;
|
||||
Outputs::Speaker::PullLowpass<AudioSource> speaker_;
|
||||
// Audio::Toggle audio_toggle_;
|
||||
// using AudioSource = Outputs::Speaker::CompoundSource<Apple::IIgs::Sound::GLU, Audio::Toggle>;
|
||||
// AudioSource mixer_;
|
||||
// Outputs::Speaker::PullLowpass<AudioSource> speaker_;
|
||||
|
||||
Cycles cycles_since_audio_update_;
|
||||
Cycles cycles_until_audio_event_;
|
||||
static constexpr int audio_divider = 16;
|
||||
void update_audio() {
|
||||
const auto divided_cycles = cycles_since_audio_update_.divide(audio_divider);
|
||||
sound_glu_.run_for(divided_cycles);
|
||||
speaker_.run_for(audio_queue_, divided_cycles);
|
||||
// speaker_.run_for(audio_queue_, divided_cycles);
|
||||
}
|
||||
class AudioUpdater {
|
||||
public:
|
||||
AudioUpdater(ConcreteMachine *machine) : machine_(machine) {
|
||||
AudioUpdater(ConcreteMachine *const machine) : machine_(machine) {
|
||||
machine_->update_audio();
|
||||
}
|
||||
~AudioUpdater() {
|
||||
machine_->cycles_until_audio_event_ = machine_->sound_glu_.next_sequence_point();
|
||||
}
|
||||
Apple::IIgs::Sound::GLU *operator ->() const {
|
||||
return &machine_->sound_glu_;
|
||||
}
|
||||
// Audio::Toggle &toggle() const {
|
||||
// return machine_->audio_toggle_;
|
||||
// }
|
||||
private:
|
||||
ConcreteMachine *machine_;
|
||||
};
|
||||
|
||||
+161
-169
@@ -16,49 +16,30 @@
|
||||
|
||||
using namespace Apple::IIgs::Sound;
|
||||
|
||||
GLU::GLU(Concurrency::AsyncTaskQueue<false> &audio_queue) : audio_queue_(audio_queue) {
|
||||
// Reset all pending stores.
|
||||
MemoryWrite disabled_write;
|
||||
disabled_write.enabled = false;
|
||||
for(int c = 0; c < StoreBufferSize; c++) {
|
||||
pending_stores_[c].store(disabled_write);
|
||||
}
|
||||
}
|
||||
|
||||
void GLU::set_data(uint8_t data) {
|
||||
if(local_.control & 0x40) {
|
||||
void GLU::set_data(const uint8_t data) {
|
||||
if(state_.control & 0x40) {
|
||||
// RAM access.
|
||||
local_.ram_[address_] = data;
|
||||
|
||||
MemoryWrite write;
|
||||
write.enabled = true;
|
||||
write.address = address_;
|
||||
write.value = data;
|
||||
write.time = pending_store_write_time_;
|
||||
pending_stores_[pending_store_write_].store(write, std::memory_order::release);
|
||||
|
||||
pending_store_write_ = (pending_store_write_ + 1) & (StoreBufferSize - 1);
|
||||
state_.ram[address_] = data;
|
||||
} else {
|
||||
// Register access.
|
||||
const auto address = address_; // To make sure I don't inadvertently 'capture' address_.
|
||||
local_.set_register(address, data);
|
||||
audio_queue_.enqueue([this, address, data] () {
|
||||
remote_.set_register(address, data);
|
||||
});
|
||||
state_.set_register(address, data);
|
||||
}
|
||||
|
||||
if(local_.control & 0x20) {
|
||||
if(state_.control & 0x20) {
|
||||
++address_;
|
||||
}
|
||||
}
|
||||
|
||||
void GLU::EnsoniqState::set_register(uint16_t address, uint8_t value) {
|
||||
void GLU::State::set_register(const uint16_t address, const uint8_t value) {
|
||||
switch(address & 0xe0) {
|
||||
case 0x00:
|
||||
oscillators[address & 0x1f].velocity = uint16_t((oscillators[address & 0x1f].velocity & 0xff00) | (value << 0));
|
||||
oscillators[address & 0x1f].velocity =
|
||||
uint16_t((oscillators[address & 0x1f].velocity & 0xff00) | (value << 0));
|
||||
break;
|
||||
case 0x20:
|
||||
oscillators[address & 0x1f].velocity = uint16_t((oscillators[address & 0x1f].velocity & 0x00ff) | (value << 8));
|
||||
oscillators[address & 0x1f].velocity =
|
||||
uint16_t((oscillators[address & 0x1f].velocity & 0x00ff) | (value << 8));
|
||||
break;
|
||||
case 0x40:
|
||||
oscillators[address & 0x1f].volume = value;
|
||||
@@ -100,28 +81,28 @@ void GLU::EnsoniqState::set_register(uint16_t address, uint8_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t GLU::get_data() {
|
||||
uint8_t GLU::data() {
|
||||
const auto address = address_;
|
||||
if(local_.control & 0x20) {
|
||||
if(state_.control & 0x20) {
|
||||
++address_;
|
||||
}
|
||||
|
||||
switch(address & 0xe0) {
|
||||
case 0x00: return local_.oscillators[address & 0x1f].velocity & 0xff;
|
||||
case 0x20: return local_.oscillators[address & 0x1f].velocity >> 8;
|
||||
case 0x40: return local_.oscillators[address & 0x1f].volume;
|
||||
case 0x60: return local_.oscillators[address & 0x1f].sample(local_.ram_); // i.e. look up what the sample was on demand.
|
||||
case 0x80: return local_.oscillators[address & 0x1f].address;
|
||||
case 0xa0: return local_.oscillators[address & 0x1f].control;
|
||||
case 0xc0: return local_.oscillators[address & 0x1f].table_size;
|
||||
case 0x00: return state_.oscillators[address & 0x1f].velocity & 0xff;
|
||||
case 0x20: return state_.oscillators[address & 0x1f].velocity >> 8;
|
||||
case 0x40: return state_.oscillators[address & 0x1f].volume;
|
||||
case 0x60: return state_.oscillators[address & 0x1f].sample(state_.ram);
|
||||
case 0x80: return state_.oscillators[address & 0x1f].address;
|
||||
case 0xa0: return state_.oscillators[address & 0x1f].control;
|
||||
case 0xc0: return state_.oscillators[address & 0x1f].table_size;
|
||||
|
||||
default:
|
||||
switch(address & 0xff) {
|
||||
case 0xe0: {
|
||||
// Find the first enabled oscillator that is signalling an interrupt and has interrupts enabled.
|
||||
for(int c = 0; c < local_.oscillator_count; c++) {
|
||||
if(local_.oscillators[c].interrupt_request && (local_.oscillators[c].control & 0x08)) {
|
||||
local_.oscillators[c].interrupt_request = false;
|
||||
for(int c = 0; c < state_.oscillator_count; c++) {
|
||||
if(state_.oscillators[c].interrupt_request && (state_.oscillators[c].control & 0x08)) {
|
||||
state_.oscillators[c].interrupt_request = false;
|
||||
return uint8_t(0x41 | (c << 1));
|
||||
}
|
||||
}
|
||||
@@ -129,7 +110,7 @@ uint8_t GLU::get_data() {
|
||||
// No interrupt found.
|
||||
return 0xc1;
|
||||
} break;
|
||||
case 0xe1: return uint8_t((local_.oscillator_count - 1) << 1); // TODO: should other bits be 0 or 1?
|
||||
case 0xe1: return uint8_t((state_.oscillator_count - 1) << 1); // TODO: should other bits be 0 or 1?
|
||||
case 0xe2: return 128; // Input audio. Unimplemented!
|
||||
}
|
||||
break;
|
||||
@@ -138,11 +119,11 @@ uint8_t GLU::get_data() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool GLU::get_interrupt_line() {
|
||||
bool GLU::interrupt() {
|
||||
// Return @c true if any oscillator currently has its interrupt request
|
||||
// set, and has interrupts enabled.
|
||||
for(int c = 0; c < local_.oscillator_count; c++) {
|
||||
if(local_.oscillators[c].interrupt_request && (local_.oscillators[c].control & 0x08)) {
|
||||
for(int c = 0; c < state_.oscillator_count; c++) {
|
||||
if(state_.oscillators[c].interrupt_request && (state_.oscillators[c].control & 0x08)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -151,18 +132,30 @@ bool GLU::get_interrupt_line() {
|
||||
|
||||
// MARK: - Time entry points.
|
||||
|
||||
void GLU::run_for(Cycles cycles) {
|
||||
// Update local state, without generating audio.
|
||||
skip_audio(local_, cycles.as<size_t>());
|
||||
void GLU::run_for(const Cycles duration) {
|
||||
const auto cycles = duration.as<uint32_t>();
|
||||
|
||||
// Update the timestamp for memory writes;
|
||||
pending_store_write_time_ += cycles.as<uint32_t>();
|
||||
for(int c = 0; c < state_.oscillator_count; c++) {
|
||||
// Don't do anything for halted oscillators.
|
||||
if(state_.oscillators[c].control & 1) continue;
|
||||
|
||||
// Update phase.
|
||||
state_.oscillators[c].position += state_.oscillators[c].velocity * cycles;
|
||||
|
||||
// Check for stops, and any interrupts that therefore flow.
|
||||
if((state_.oscillators[c].control & 2) && (state_.oscillators[c].position & state_.oscillators[c].overflow_mask)) {
|
||||
// Apply halt, set interrupt request flag.
|
||||
state_.oscillators[c].position = 0;
|
||||
state_.oscillators[c].control |= 1;
|
||||
state_.oscillators[c].interrupt_request = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <Outputs::Speaker::Action action>
|
||||
void GLU::apply_samples(std::size_t number_of_samples, Outputs::Speaker::MonoSample *target) {
|
||||
void GLU::apply_samples(std::size_t, Outputs::Speaker::MonoSample *) {
|
||||
// Update remote state, generating audio.
|
||||
generate_audio<action>(number_of_samples, target);
|
||||
// generate_audio<action>(number_of_samples, target);
|
||||
}
|
||||
template void GLU::apply_samples<Outputs::Speaker::Action::Mix>(std::size_t, Outputs::Speaker::MonoSample *);
|
||||
template void GLU::apply_samples<Outputs::Speaker::Action::Store>(std::size_t, Outputs::Speaker::MonoSample *);
|
||||
@@ -195,21 +188,18 @@ void GLU::set_sample_volume_range(std::int16_t range) {
|
||||
// MARK: - Interface boilerplate.
|
||||
|
||||
void GLU::set_control(uint8_t control) {
|
||||
local_.control = control;
|
||||
audio_queue_.enqueue([this, control] () {
|
||||
remote_.control = control;
|
||||
});
|
||||
state_.control = control;
|
||||
}
|
||||
|
||||
uint8_t GLU::get_control() {
|
||||
return local_.control;
|
||||
uint8_t GLU::control() {
|
||||
return state_.control;
|
||||
}
|
||||
|
||||
void GLU::set_address_low(uint8_t low) {
|
||||
address_ = uint16_t((address_ & 0xff00) | low);
|
||||
}
|
||||
|
||||
uint8_t GLU::get_address_low() {
|
||||
uint8_t GLU::address_low() {
|
||||
return address_ & 0xff;
|
||||
}
|
||||
|
||||
@@ -217,7 +207,7 @@ void GLU::set_address_high(uint8_t high) {
|
||||
address_ = uint16_t((high << 8) | (address_ & 0x00ff));
|
||||
}
|
||||
|
||||
uint8_t GLU::get_address_high() {
|
||||
uint8_t GLU::address_high() {
|
||||
return address_ >> 8;
|
||||
}
|
||||
|
||||
@@ -226,130 +216,132 @@ uint8_t GLU::get_address_high() {
|
||||
Cycles GLU::next_sequence_point() const {
|
||||
uint32_t result = std::numeric_limits<decltype(result)>::max();
|
||||
|
||||
for(int c = 0; c < local_.oscillator_count; c++) {
|
||||
for(int c = 0; c < state_.oscillator_count; c++) {
|
||||
// Don't do anything for halted oscillators, or for oscillators that can't hit stops.
|
||||
if((local_.oscillators[c].control&3) != 2) {
|
||||
if((state_.oscillators[c].control&3) != 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Determine how many cycles until a stop is hit and update the pending result
|
||||
// if this is the new soonest-to-expire oscillator.
|
||||
const auto first_overflow_value = (local_.oscillators[c].overflow_mask - 1) << 1;
|
||||
const auto time_until_stop = (first_overflow_value - local_.oscillators[c].position + local_.oscillators[c].velocity - 1) / local_.oscillators[c].velocity;
|
||||
const auto first_overflow_value = (state_.oscillators[c].overflow_mask - 1) << 1;
|
||||
const auto time_until_stop =
|
||||
(first_overflow_value - state_.oscillators[c].position + state_.oscillators[c].velocity - 1)
|
||||
/ state_.oscillators[c].velocity;
|
||||
result = std::min(result, time_until_stop);
|
||||
}
|
||||
return Cycles(result);
|
||||
}
|
||||
|
||||
void GLU::skip_audio(EnsoniqState &state, size_t number_of_samples) {
|
||||
// Just advance all oscillator pointers and check for interrupts.
|
||||
// If a read occurs to the current-output level, generate it then.
|
||||
for(int c = 0; c < state.oscillator_count; c++) {
|
||||
// Don't do anything for halted oscillators.
|
||||
if(state.oscillators[c].control&1) continue;
|
||||
|
||||
// Update phase.
|
||||
state.oscillators[c].position += state.oscillators[c].velocity * number_of_samples;
|
||||
|
||||
// Check for stops, and any interrupts that therefore flow.
|
||||
if((state.oscillators[c].control & 2) && (state.oscillators[c].position & state.oscillators[c].overflow_mask)) {
|
||||
// Apply halt, set interrupt request flag.
|
||||
state.oscillators[c].position = 0;
|
||||
state.oscillators[c].control |= 1;
|
||||
state.oscillators[c].interrupt_request = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//void GLU::skip_audio(State &state, size_t number_of_samples) {
|
||||
// // Just advance all oscillator pointers and check for interrupts.
|
||||
// // If a read occurs to the current-output level, generate it then.
|
||||
// for(int c = 0; c < state.oscillator_count; c++) {
|
||||
// // Don't do anything for halted oscillators.
|
||||
// if(state.oscillators[c].control&1) continue;
|
||||
//
|
||||
// // Update phase.
|
||||
// state.oscillators[c].position += state.oscillators[c].velocity * number_of_samples;
|
||||
//
|
||||
// // Check for stops, and any interrupts that therefore flow.
|
||||
// if((state.oscillators[c].control & 2) && (state.oscillators[c].position & state.oscillators[c].overflow_mask)) {
|
||||
// // Apply halt, set interrupt request flag.
|
||||
// state.oscillators[c].position = 0;
|
||||
// state.oscillators[c].control |= 1;
|
||||
// state.oscillators[c].interrupt_request = true;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
template <Outputs::Speaker::Action action>
|
||||
void GLU::generate_audio(size_t number_of_samples, Outputs::Speaker::MonoSample *target) {
|
||||
auto next_store = pending_stores_[pending_store_read_].load(std::memory_order::acquire);
|
||||
uint8_t next_amplitude = 255;
|
||||
for(size_t sample = 0; sample < number_of_samples; sample++) {
|
||||
|
||||
// TODO: there's a bit of a hack here where it is assumed that the input clock has been
|
||||
// divided in advance. Real hardware divides by 8, I think?
|
||||
|
||||
// Seed output as 0.
|
||||
int output = 0;
|
||||
|
||||
// Apply phase updates to all enabled oscillators.
|
||||
for(int c = 0; c < remote_.oscillator_count; c++) {
|
||||
// Don't do anything for halted oscillators.
|
||||
if(remote_.oscillators[c].control&1) continue;
|
||||
|
||||
remote_.oscillators[c].position += remote_.oscillators[c].velocity;
|
||||
|
||||
// Test for a new halting event.
|
||||
switch(remote_.oscillators[c].control & 6) {
|
||||
case 0: // Free-run mode; don't truncate the position at all, in case the
|
||||
// accumulator bits in use changes.
|
||||
output += remote_.oscillators[c].output(remote_.ram_);
|
||||
break;
|
||||
|
||||
case 2: // One-shot mode; check for end of run. Otherwise update sample.
|
||||
if(remote_.oscillators[c].position & remote_.oscillators[c].overflow_mask) {
|
||||
remote_.oscillators[c].position = 0;
|
||||
remote_.oscillators[c].control |= 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 4: // Sync/AM mode.
|
||||
if(c&1) {
|
||||
// Oscillator is odd-numbered; it will amplitude-modulate the next voice.
|
||||
next_amplitude = remote_.oscillators[c].sample(remote_.ram_);
|
||||
continue;
|
||||
} else {
|
||||
// Oscillator is even-numbered; it will 'sync' to the even voice, i.e. any
|
||||
// time it wraps around, it will reset the next oscillator.
|
||||
if(remote_.oscillators[c].position & remote_.oscillators[c].overflow_mask) {
|
||||
remote_.oscillators[c].position &= remote_.oscillators[c].overflow_mask;
|
||||
remote_.oscillators[c+1].position = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 6: // Swap mode; possibly trigger partner, and update sample.
|
||||
// Per tech note #11: "Whenever a swap occurs from a higher-numbered
|
||||
// oscillator to a lower-numbered one, the output signal from the corresponding
|
||||
// generator temporarily falls to the zero-crossing level (silence)"
|
||||
if(remote_.oscillators[c].position & remote_.oscillators[c].overflow_mask) {
|
||||
remote_.oscillators[c].control |= 1;
|
||||
remote_.oscillators[c].position = 0;
|
||||
remote_.oscillators[c^1].control &= ~1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Don't add output for newly-halted oscillators.
|
||||
if(remote_.oscillators[c].control&1) continue;
|
||||
|
||||
// Append new output.
|
||||
output += (remote_.oscillators[c].output(remote_.ram_) * next_amplitude) / 255;
|
||||
next_amplitude = 255;
|
||||
}
|
||||
|
||||
// Maximum total output was 32 channels times a 16-bit range. Map that down.
|
||||
// TODO: dynamic total volume?
|
||||
Outputs::Speaker::apply<action>(
|
||||
target[sample],
|
||||
Outputs::Speaker::MonoSample(
|
||||
(output * output_range_) >> 20
|
||||
)
|
||||
);
|
||||
|
||||
// Apply any RAM writes that interleave here.
|
||||
++pending_store_read_time_;
|
||||
if(!next_store.enabled) continue;
|
||||
if(next_store.time != pending_store_read_time_) continue;
|
||||
remote_.ram_[next_store.address] = next_store.value;
|
||||
next_store.enabled = false;
|
||||
pending_stores_[pending_store_read_].store(next_store, std::memory_order::relaxed);
|
||||
pending_store_read_ = (pending_store_read_ + 1) & (StoreBufferSize - 1);
|
||||
}
|
||||
// auto next_store = pending_stores_[pending_store_read_].load(std::memory_order::acquire);
|
||||
// uint8_t next_amplitude = 255;
|
||||
// for(size_t sample = 0; sample < number_of_samples; sample++) {
|
||||
//
|
||||
// // TODO: there's a bit of a hack here where it is assumed that the input clock has been
|
||||
// // divided in advance. Real hardware divides by 8, I think?
|
||||
//
|
||||
// // Seed output as 0.
|
||||
// int output = 0;
|
||||
//
|
||||
// // Apply phase updates to all enabled oscillators.
|
||||
// for(int c = 0; c < remote_.oscillator_count; c++) {
|
||||
// // Don't do anything for halted oscillators.
|
||||
// if(remote_.oscillators[c].control&1) continue;
|
||||
//
|
||||
// remote_.oscillators[c].position += remote_.oscillators[c].velocity;
|
||||
//
|
||||
// // Test for a new halting event.
|
||||
// switch(remote_.oscillators[c].control & 6) {
|
||||
// case 0: // Free-run mode; don't truncate the position at all, in case the
|
||||
// // accumulator bits in use changes.
|
||||
// output += remote_.oscillators[c].output(remote_.ram_);
|
||||
// break;
|
||||
//
|
||||
// case 2: // One-shot mode; check for end of run. Otherwise update sample.
|
||||
// if(remote_.oscillators[c].position & remote_.oscillators[c].overflow_mask) {
|
||||
// remote_.oscillators[c].position = 0;
|
||||
// remote_.oscillators[c].control |= 1;
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case 4: // Sync/AM mode.
|
||||
// if(c&1) {
|
||||
// // Oscillator is odd-numbered; it will amplitude-modulate the next voice.
|
||||
// next_amplitude = remote_.oscillators[c].sample(remote_.ram_);
|
||||
// continue;
|
||||
// } else {
|
||||
// // Oscillator is even-numbered; it will 'sync' to the even voice, i.e. any
|
||||
// // time it wraps around, it will reset the next oscillator.
|
||||
// if(remote_.oscillators[c].position & remote_.oscillators[c].overflow_mask) {
|
||||
// remote_.oscillators[c].position &= remote_.oscillators[c].overflow_mask;
|
||||
// remote_.oscillators[c+1].position = 0;
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case 6: // Swap mode; possibly trigger partner, and update sample.
|
||||
// // Per tech note #11: "Whenever a swap occurs from a higher-numbered
|
||||
// // oscillator to a lower-numbered one, the output signal from the corresponding
|
||||
// // generator temporarily falls to the zero-crossing level (silence)"
|
||||
// if(remote_.oscillators[c].position & remote_.oscillators[c].overflow_mask) {
|
||||
// remote_.oscillators[c].control |= 1;
|
||||
// remote_.oscillators[c].position = 0;
|
||||
// remote_.oscillators[c^1].control &= ~1;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// // Don't add output for newly-halted oscillators.
|
||||
// if(remote_.oscillators[c].control&1) continue;
|
||||
//
|
||||
// // Append new output.
|
||||
// output += (remote_.oscillators[c].output(remote_.ram_) * next_amplitude) / 255;
|
||||
// next_amplitude = 255;
|
||||
// }
|
||||
//
|
||||
// // Maximum total output was 32 channels times a 16-bit range. Map that down.
|
||||
// // TODO: dynamic total volume?
|
||||
// Outputs::Speaker::apply<action>(
|
||||
// target[sample],
|
||||
// Outputs::Speaker::MonoSample(
|
||||
// (output * output_range_) >> 20
|
||||
// )
|
||||
// );
|
||||
//
|
||||
// // Apply any RAM writes that interleave here.
|
||||
// ++pending_store_read_time_;
|
||||
// if(!next_store.enabled) continue;
|
||||
// if(next_store.time != pending_store_read_time_) continue;
|
||||
// remote_.ram_[next_store.address] = next_store.value;
|
||||
// next_store.enabled = false;
|
||||
// pending_stores_[pending_store_read_].store(next_store, std::memory_order::relaxed);
|
||||
// pending_store_read_ = (pending_store_read_ + 1) & (StoreBufferSize - 1);
|
||||
// }
|
||||
}
|
||||
|
||||
uint8_t GLU::EnsoniqState::Oscillator::sample(uint8_t *ram) {
|
||||
uint8_t GLU::State::Oscillator::sample(const uint8_t *const ram) {
|
||||
// Determines how many you'd have to shift a 16-bit pointer to the right for,
|
||||
// in order to hit only the position-supplied bits.
|
||||
const int pointer_shift = 8 - ((table_size >> 3) & 7);
|
||||
@@ -371,7 +363,7 @@ uint8_t GLU::EnsoniqState::Oscillator::sample(uint8_t *ram) {
|
||||
return ram[sample_address];
|
||||
}
|
||||
|
||||
int16_t GLU::EnsoniqState::Oscillator::output(uint8_t *ram) {
|
||||
int16_t GLU::State::Oscillator::output(const uint8_t *const ram) {
|
||||
const auto level = sample(ram);
|
||||
|
||||
// "An oscillator will halt when a zero is encountered in its waveform table."
|
||||
|
||||
@@ -18,20 +18,21 @@ namespace Apple::IIgs::Sound {
|
||||
|
||||
class GLU: public Outputs::Speaker::BufferSource<GLU, false> { // TODO: isn't this stereo?
|
||||
public:
|
||||
GLU(Concurrency::AsyncTaskQueue<false> &audio_queue);
|
||||
|
||||
void set_control(uint8_t);
|
||||
uint8_t get_control();
|
||||
uint8_t control();
|
||||
|
||||
void set_data(uint8_t);
|
||||
uint8_t get_data();
|
||||
uint8_t data();
|
||||
|
||||
void set_address_low(uint8_t);
|
||||
uint8_t get_address_low();
|
||||
uint8_t address_low();
|
||||
void set_address_high(uint8_t);
|
||||
uint8_t get_address_high();
|
||||
uint8_t address_high();
|
||||
|
||||
void run_for(Cycles);
|
||||
|
||||
Cycles next_sequence_point() const;
|
||||
bool get_interrupt_line();
|
||||
bool interrupt();
|
||||
|
||||
// SampleSource.
|
||||
template <Outputs::Speaker::Action action>
|
||||
@@ -40,32 +41,10 @@ public:
|
||||
bool is_zero_level() const { return false; } // TODO.
|
||||
|
||||
private:
|
||||
Concurrency::AsyncTaskQueue<false> &audio_queue_;
|
||||
|
||||
uint16_t address_ = 0;
|
||||
|
||||
// Use a circular buffer for piping memory alterations onto the audio
|
||||
// thread; it would be prohibitive to defer every write individually.
|
||||
//
|
||||
// Assumed: on most modern architectures, an atomic 64-bit read or
|
||||
// write can be achieved locklessly.
|
||||
struct MemoryWrite {
|
||||
uint32_t time;
|
||||
uint16_t address;
|
||||
uint8_t value;
|
||||
bool enabled;
|
||||
};
|
||||
static_assert(sizeof(MemoryWrite) == 8);
|
||||
static constexpr int StoreBufferSize = 16384;
|
||||
|
||||
std::atomic<MemoryWrite> pending_stores_[StoreBufferSize];
|
||||
uint32_t pending_store_read_ = 0, pending_store_read_time_ = 0;
|
||||
uint32_t pending_store_write_ = 0, pending_store_write_time_ = 0;
|
||||
|
||||
// Maintain state both 'locally' (i.e. on the emulation thread) and
|
||||
// 'remotely' (i.e. on the audio thread).
|
||||
struct EnsoniqState {
|
||||
uint8_t ram_[65536];
|
||||
struct State {
|
||||
uint8_t ram[65536];
|
||||
struct Oscillator {
|
||||
uint32_t position;
|
||||
|
||||
@@ -82,8 +61,8 @@ private:
|
||||
bool interrupt_request = false; // Will be non-zero if this channel would request an interrupt, were
|
||||
// it currently enabled to do so.
|
||||
|
||||
uint8_t sample(uint8_t *ram);
|
||||
int16_t output(uint8_t *ram);
|
||||
uint8_t sample(const uint8_t *ram);
|
||||
int16_t output(const uint8_t *ram);
|
||||
} oscillators[32];
|
||||
|
||||
// Some of these aren't actually needed on both threads.
|
||||
@@ -91,13 +70,13 @@ private:
|
||||
int oscillator_count = 1;
|
||||
|
||||
void set_register(uint16_t address, uint8_t value);
|
||||
} local_, remote_;
|
||||
} state_;
|
||||
|
||||
// Functions to update an EnsoniqState; these don't belong to the state itself
|
||||
// because they also access the pending stores (inter alia).
|
||||
template <Outputs::Speaker::Action action>
|
||||
void generate_audio(size_t number_of_samples, Outputs::Speaker::MonoSample *target);
|
||||
void skip_audio(EnsoniqState &state, size_t number_of_samples);
|
||||
// void skip_audio(EnsoniqState &state, size_t number_of_samples);
|
||||
|
||||
// Audio-thread state.
|
||||
int16_t output_range_ = 0;
|
||||
|
||||
Reference in new issue
Block a user