diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index fc4dddc4a..c9510be1b 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -493,25 +493,44 @@ void Machine::set_key_state(Key key, bool isPressed) } } -void Machine::Speaker::get_sample_range(uint64_t start_time, int number_of_samples, int16_t *target) +void Machine::Speaker::get_samples(unsigned int number_of_samples, int16_t *target) { - if(!_is_enabled) +// if(!_is_enabled) +// { +// *target = 0; +// } +// else { - *target = 0; + *target = _output_level; + _output_level++; + if(_output_level&64) + { + _output_level ^= (8192 | 64); + } } - else + skip_samples(number_of_samples); +} + +void Machine::Speaker::skip_samples(unsigned int number_of_samples) +{ + while(number_of_samples--) { - *target = ((start_time / (_divider+1))&1) ? 255 : 0; + _counter ++; + if(_counter > _divider) + { + _counter = 0; +// _output_level ^= 8192; + } } } void Machine::Speaker::set_divider(uint8_t divider) { - _divider = divider; - _time_base = 0; +// _divider = divider; +// _time_base = 0; } void Machine::Speaker::set_is_enabled(bool is_enabled) { - _is_enabled = is_enabled; +// _is_enabled = is_enabled; } diff --git a/Machines/Electron/Electron.hpp b/Machines/Electron/Electron.hpp index 4efc1fa04..8547f7ed2 100644 --- a/Machines/Electron/Electron.hpp +++ b/Machines/Electron/Electron.hpp @@ -103,11 +103,16 @@ class Machine: public CPU6502::Processor { 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, int16_t *target); + void get_samples(unsigned int number_of_samples, int16_t *target); + void skip_samples(unsigned int number_of_samples); + + Speaker() : _counter(0), _divider(0x32), _is_enabled(false), _output_level(0) {} private: + unsigned int _counter; uint8_t _divider; bool _is_enabled; + int16_t _output_level; } _speaker; }; diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp index 4e22a8c1e..c7114ca46 100644 --- a/Outputs/Speaker.hpp +++ b/Outputs/Speaker.hpp @@ -51,6 +51,8 @@ class Speaker { set_needs_updated_filter_coefficients(); } + Speaker() : _buffer_in_progress_pointer(0) {} + protected: int16_t *_buffer_in_progress; int _buffer_size; @@ -78,7 +80,8 @@ 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_samples(1, &_buffer_in_progress[_buffer_in_progress_pointer]); +// _buffer_in_progress[_buffer_in_progress_pointer] = (_buffer_in_progress_pointer&64) ? 8192 : 0; _buffer_in_progress_pointer++; // announce to delegate if full @@ -92,13 +95,10 @@ template class Filter: public Speaker { } // determine how many source samples to step - _time_base += _stepper->update(); + static_cast(this)->skip_samples((unsigned int)_stepper->update()); } } - protected: - uint64_t _time_base; - private: SignalProcessing::Stepper *_stepper;