From 956b90e20310f1c17169ae58f91cb951c21b3137 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 18 Jan 2016 23:55:52 -0500 Subject: [PATCH] Attempted further to improve latency; added view adjustment for non-4:3 output aspect ratios. The 4:3 is currently hardcoded, so further work will be required. --- Machines/Electron/Electron.cpp | 5 +---- .../Mac/Clock Signal/Views/CSCathodeRayView.m | 17 ++++++++++++++--- .../Mac/Clock Signal/Wrappers/CSElectron.mm | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index cd48d9f57..ee5d4bf44 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -248,6 +248,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin switch(_frameCycles) { case 64*128: + case 196*128: update_audio(); break; @@ -256,10 +257,6 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin signal_interrupt(InterruptRealTimeClock); break; - case 196*128: - update_audio(); - break; - case 284*128: update_audio(); signal_interrupt(InterruptDisplayEnd); diff --git a/OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.m b/OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.m index 3fea768ab..f8ef0992c 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.m +++ b/OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.m @@ -37,6 +37,8 @@ CSCathodeRayViewSignalType _signalType; int32_t _signalDecoderGeneration; int32_t _compiledSignalDecoderGeneration; + + CGRect _aspectRatioCorrectedBounds; } - (GLuint)textureForImageNamed:(NSString *)name @@ -155,14 +157,23 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt { if(_shaderProgram) { + NSPoint viewSize = [self backingViewSize]; if(_windowSizeUniform >= 0) { - NSPoint viewSize = [self backingViewSize]; glUniform2f(_windowSizeUniform, (GLfloat)viewSize.x, (GLfloat)viewSize.y); } - if(_boundsOriginUniform >= 0) glUniform2f(_boundsOriginUniform, (GLfloat)_frameBounds.origin.x, (GLfloat)_frameBounds.origin.y); - if(_boundsSizeUniform >= 0) glUniform2f(_boundsSizeUniform, (GLfloat)_frameBounds.size.width, (GLfloat)_frameBounds.size.height); + CGFloat outputAspectRatioMultiplier = (viewSize.x / viewSize.y) / (4.0 / 3.0); + +// NSLog(@"%0.2f v %0.2f", outputAspectRatio, desiredOutputAspectRatio); + _aspectRatioCorrectedBounds = _frameBounds; + + CGFloat bonusWidth = (outputAspectRatioMultiplier - 1.0f) * _frameBounds.size.width; + _aspectRatioCorrectedBounds.origin.x -= bonusWidth * 0.5f * _aspectRatioCorrectedBounds.size.width; + _aspectRatioCorrectedBounds.size.width *= outputAspectRatioMultiplier; + + if(_boundsOriginUniform >= 0) glUniform2f(_boundsOriginUniform, (GLfloat)_aspectRatioCorrectedBounds.origin.x, (GLfloat)_aspectRatioCorrectedBounds.origin.y); + if(_boundsSizeUniform >= 0) glUniform2f(_boundsSizeUniform, (GLfloat)_aspectRatioCorrectedBounds.size.width, (GLfloat)_aspectRatioCorrectedBounds.size.height); } } diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm index a7b47dbb0..eaf1c4cac 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm @@ -54,7 +54,7 @@ } - (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate { - _electron.get_speaker()->set_output_rate(sampleRate, 512); + _electron.get_speaker()->set_output_rate(sampleRate, 256); _electron.get_speaker()->set_output_quality(15); _electron.get_speaker()->set_delegate(delegate); return YES;