From e617bd2bb33e272b08cf6f1e7ec98d2a68dd8818 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 6 Apr 2016 21:12:22 -0400 Subject: [PATCH] Turned audio quality up to the maximum, at least for now. --- Machines/Electron/Electron.cpp | 14 ++++++-------- Machines/Electron/Electron.hpp | 2 +- OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 8eae7e05c..e68efbab1 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -67,10 +67,9 @@ void Machine::setup_output() _crt->set_output_device(Outputs::CRT::Monitor); // The maximum output frequency is 62500Hz and all other permitted output frequencies are integral divisions of that; - // nevertheless sampling only at 62500Hz may introduce aliasing errors as setting the speaker on or off can happen on - // any 2Mhz cycle, and I've no idea whether it has an immediate effect or happens only on the next clock. If it turns - // out that the former is the case, I'll need to turn this up to 2000000. - _speaker.set_input_rate(62500); + // however setting the speaker on or off can happen on any 2Mhz cycle, and probably (?) takes effect immediately. So + // run the speaker at a 2000000Hz input rate, at least for the time being. + _speaker.set_input_rate(2000000); } unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) @@ -431,7 +430,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin _frameCycles = nextFrameCycles; } - if(!(_frameCycles&31)) + if(!(_frameCycles&16383)) update_audio(); _tape.run_for_cycles(cycles); @@ -495,9 +494,8 @@ inline void Machine::evaluate_interrupts() inline void Machine::update_audio() { int difference = (int)_frameCycles - _audioOutputPosition; + _speaker.run_for_cycles(difference); _audioOutputPosition = (int)_frameCycles; - _speaker.run_for_cycles((_audioOutputPositionError + difference) >> 5); - _audioOutputPositionError = (_audioOutputPositionError + difference)&31; } inline void Machine::start_pixel_line() @@ -852,7 +850,7 @@ void Speaker::skip_samples(unsigned int number_of_samples) void Speaker::set_divider(uint8_t divider) { - _divider = divider; + _divider = divider * 32; } void Speaker::set_is_enabled(bool is_enabled) diff --git a/Machines/Electron/Electron.hpp b/Machines/Electron/Electron.hpp index dd5bf2a77..9a7b44172 100644 --- a/Machines/Electron/Electron.hpp +++ b/Machines/Electron/Electron.hpp @@ -128,7 +128,7 @@ class Speaker: public ::Outputs::Filter { private: unsigned int _counter; - uint8_t _divider; + unsigned int _divider; bool _is_enabled; }; diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm index b98f0b413..4809a2a27 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm @@ -60,7 +60,7 @@ - (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate { @synchronized(self) { _electron.get_speaker()->set_output_rate(sampleRate, 256); - _electron.get_speaker()->set_output_quality(15); + _electron.get_speaker()->set_output_quality(47); _electron.get_speaker()->set_delegate(delegate); return YES; }