From 383b2be4c689dbe7d7bc1746409d392583d2cabd Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 14 Jan 2016 21:33:27 -0500 Subject: [PATCH] Fixed one off-by-one error. --- Machines/Electron/Electron.cpp | 23 +++++++++-------------- Outputs/Speaker.hpp | 5 +++-- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index c9510be1b..1f4176edc 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -495,18 +495,13 @@ void Machine::set_key_state(Key key, bool isPressed) void Machine::Speaker::get_samples(unsigned int number_of_samples, int16_t *target) { -// if(!_is_enabled) -// { -// *target = 0; -// } -// else + if(!_is_enabled) + { + *target = 0; + } + else { *target = _output_level; - _output_level++; - if(_output_level&64) - { - _output_level ^= (8192 | 64); - } } skip_samples(number_of_samples); } @@ -519,18 +514,18 @@ void Machine::Speaker::skip_samples(unsigned int number_of_samples) if(_counter > _divider) { _counter = 0; -// _output_level ^= 8192; + _output_level ^= 8192; } } } void Machine::Speaker::set_divider(uint8_t divider) { -// _divider = divider; -// _time_base = 0; + _divider = divider; } void Machine::Speaker::set_is_enabled(bool is_enabled) { -// _is_enabled = is_enabled; + _is_enabled = is_enabled; + _counter = 0; } diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp index c7114ca46..74f29975c 100644 --- a/Outputs/Speaker.hpp +++ b/Outputs/Speaker.hpp @@ -81,7 +81,6 @@ template class Filter: public Speaker { { // get a sample for the current location 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 @@ -95,7 +94,9 @@ template class Filter: public Speaker { } // determine how many source samples to step - static_cast(this)->skip_samples((unsigned int)_stepper->update()); + uint64_t steps = _stepper->update(); + if(steps > 1) + static_cast(this)->skip_samples((unsigned int)(steps-1)); } }