From 439d452e2368d5271cdc95156d483848033c0d62 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 13 Jan 2016 22:11:33 -0500 Subject: [PATCH] Resolved some errors. --- Machines/Electron/Electron.cpp | 29 +++++++++++++++++++++++------ Machines/Electron/Electron.hpp | 11 +++++++++-- Outputs/Speaker.hpp | 6 +++--- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 403a592da..0d45a9e3c 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -138,9 +138,8 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin case 0x6: if(!isReadOperation(operation)) { - if(_speaker.is_enabled) - update_audio(); - _speaker.divider = *value; + update_audio(); + _speaker.set_divider(*value); } break; case 0x7: @@ -164,10 +163,10 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // update speaker mode bool new_speaker_is_enabled = (*value & 6) == 2; - if(new_speaker_is_enabled != _speaker.is_enabled) + if(new_speaker_is_enabled != _speaker.get_is_enabled()) { update_audio(); - _speaker.is_enabled = new_speaker_is_enabled; + _speaker.set_is_enabled(new_speaker_is_enabled); } // TODO: tape mode, tape motor, caps lock LED @@ -496,5 +495,23 @@ void Machine::set_key_state(Key key, bool isPressed) void Machine::Speaker::get_sample_range(uint64_t start_time, int number_of_samples, uint16_t *target) { - *target = 0; + if(!_is_enabled) + { + *target = 0; + } + else + { + *target = ((start_time / _divider)&1) ? 255 : 0; + } +} + +void Machine::Speaker::set_divider(uint8_t divider) +{ + _divider = divider; + _time_base = 0; +} + +void Machine::Speaker::set_is_enabled(bool is_enabled) +{ + _is_enabled = false; } diff --git a/Machines/Electron/Electron.hpp b/Machines/Electron/Electron.hpp index d2fa989bf..fb2a944a5 100644 --- a/Machines/Electron/Electron.hpp +++ b/Machines/Electron/Electron.hpp @@ -98,10 +98,17 @@ class Machine: public CPU6502::Processor { class Speaker: public ::Outputs::Filter { public: - uint8_t divider; - bool is_enabled; + void set_divider(uint8_t divider); + + void set_is_enabled(bool is_enabled); + inline bool get_is_enabled() { return _is_enabled; } void get_sample_range(uint64_t start_time, int number_of_samples, uint16_t *target); + + private: + uint8_t _divider; + bool _is_enabled; + } _speaker; }; diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp index 09eb974d6..8dfcd6dc1 100644 --- a/Outputs/Speaker.hpp +++ b/Outputs/Speaker.hpp @@ -78,7 +78,7 @@ template class Filter: public Speaker { while(input_cycles--) { // get a sample for the current location - static_cast(this)->get_sample_range(time_base, 1, &_buffer_in_progress[_buffer_in_progress_pointer]); + static_cast(this)->get_sample_range(_time_base, 1, &_buffer_in_progress[_buffer_in_progress_pointer]); _buffer_in_progress_pointer++; // announce to delegate if full @@ -92,12 +92,12 @@ template class Filter: public Speaker { } // determine how many source samples to step - time_base += _stepper->update(); + _time_base += _stepper->update(); } } protected: - uint64_t time_base; + uint64_t _time_base; private: SignalProcessing::Stepper *_stepper;