From 3437781abdc91b5758842f619806df717da4980c Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 12 Jan 2016 16:54:09 -0500 Subject: [PATCH] Started sketching out an interface for sound generation. Which made me realise that the CRT in CRTDelegate was redundant, since C++ has namespaces. --- .../Clock Signal.xcodeproj/project.pbxproj | 6 ++++ .../Mac/Clock Signal/Wrappers/CSAtari2600.mm | 2 +- .../Mac/Clock Signal/Wrappers/CSElectron.mm | 2 +- .../Wrappers/CSMachine+Subclassing.h | 2 +- .../Mac/Clock Signal/Wrappers/CSMachine.mm | 4 +-- Outputs/CRT.cpp | 2 +- Outputs/CRT.hpp | 6 ++-- Outputs/Speaker.cpp | 9 ++++++ Outputs/Speaker.hpp | 32 +++++++++++++++++++ 9 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 Outputs/Speaker.cpp create mode 100644 Outputs/Speaker.hpp diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 9f1210530..af606077c 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 4B14145E1B5887AA00E04248 /* CPU6502AllRAM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1414591B58879D00E04248 /* CPU6502AllRAM.cpp */; }; 4B1414601B58885000E04248 /* WolfgangLorenzTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B14145F1B58885000E04248 /* WolfgangLorenzTests.swift */; }; 4B1414621B58888700E04248 /* KlausDormannTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1414611B58888700E04248 /* KlausDormannTests.swift */; }; + 4B2409551C45AB05004DA684 /* Speaker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2409531C45AB05004DA684 /* Speaker.cpp */; }; 4B2E2D951C399D1200138695 /* ElectronDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B2E2D931C399D1200138695 /* ElectronDocument.xib */; }; 4B2E2D9A1C3A06EC00138695 /* Atari2600.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E2D971C3A06EC00138695 /* Atari2600.cpp */; }; 4B2E2D9D1C3A070400138695 /* Electron.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E2D9B1C3A070400138695 /* Electron.cpp */; }; @@ -327,6 +328,8 @@ 4B14145A1B58879D00E04248 /* CPU6502AllRAM.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CPU6502AllRAM.hpp; sourceTree = ""; }; 4B14145F1B58885000E04248 /* WolfgangLorenzTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WolfgangLorenzTests.swift; sourceTree = ""; }; 4B1414611B58888700E04248 /* KlausDormannTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KlausDormannTests.swift; sourceTree = ""; }; + 4B2409531C45AB05004DA684 /* Speaker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Speaker.cpp; path = ../../Outputs/Speaker.cpp; sourceTree = ""; }; + 4B2409541C45AB05004DA684 /* Speaker.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Speaker.hpp; path = ../../Outputs/Speaker.hpp; sourceTree = ""; }; 4B2632551B631A510082A461 /* CRTFrame.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CRTFrame.h; path = ../../Outputs/CRTFrame.h; sourceTree = ""; }; 4B2E2D941C399D1200138695 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ElectronDocument.xib; sourceTree = ""; }; 4B2E2D971C3A06EC00138695 /* Atari2600.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Atari2600.cpp; sourceTree = ""; }; @@ -708,6 +711,8 @@ 4B366DFA1B5C165A0026627B /* CRT.cpp */, 4B366DFB1B5C165A0026627B /* CRT.hpp */, 4B2632551B631A510082A461 /* CRTFrame.h */, + 4B2409531C45AB05004DA684 /* Speaker.cpp */, + 4B2409541C45AB05004DA684 /* Speaker.hpp */, ); name = Outputs; sourceTree = ""; @@ -1532,6 +1537,7 @@ 4B55CE4B1C3B3B0C0093A61B /* CSAtari2600.mm in Sources */, 4B55CE581C3B7D360093A61B /* Atari2600Document.swift in Sources */, 4B55CE5F1C3B7D960093A61B /* MachineDocument.swift in Sources */, + 4B2409551C45AB05004DA684 /* Speaker.cpp in Sources */, 4B55CE4E1C3B3BDA0093A61B /* CSMachine.mm in Sources */, 4B2E2D9D1C3A070400138695 /* Electron.cpp in Sources */, 4B55CE5D1C3B7D6F0093A61B /* CSCathodeRayView.m in Sources */, diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm index d7006d766..49c47e6c3 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm @@ -70,7 +70,7 @@ [view setSignalDecoder:[NSString stringWithUTF8String:_atari2600.get_signal_decoder()] type:CSCathodeRayViewSignalTypeNTSC]; } -- (void)setCRTDelegate:(Outputs::CRT::CRTDelegate *)delegate{ +- (void)setCRTDelegate:(Outputs::CRT::Delegate *)delegate{ _atari2600.get_crt()->set_delegate(delegate); } diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm index a0110d815..630666989 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm @@ -27,7 +27,7 @@ _electron.set_rom(Electron::ROMSlotBASIC, rom.length, (const uint8_t *)rom.bytes); } -- (void)setCRTDelegate:(Outputs::CRT::CRTDelegate *)delegate{ +- (void)setCRTDelegate:(Outputs::CRT::Delegate *)delegate{ _electron.get_crt()->set_delegate(delegate); } diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine+Subclassing.h b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine+Subclassing.h index 1aa88b268..6ca467be8 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine+Subclassing.h +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine+Subclassing.h @@ -11,7 +11,7 @@ @interface CSMachine (Subclassing) -- (void)setCRTDelegate:(Outputs::CRT::CRTDelegate *)delegate; +- (void)setCRTDelegate:(Outputs::CRT::Delegate *)delegate; - (void)doRunForNumberOfCycles:(int)numberOfCycles; - (void)crt:(Outputs::CRT *)crt didEndFrame:(CRTFrame *)frame didDetectVSync:(BOOL)didDetectVSync; diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm index 696c78438..e5b98a87d 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm @@ -9,7 +9,7 @@ #import "CSMachine.h" #import "CSMachine+Subclassing.h" -struct CRTDelegate: public Outputs::CRT::CRTDelegate { +struct CRTDelegate: public Outputs::CRT::Delegate { __weak CSMachine *machine; void crt_did_end_frame(Outputs::CRT *crt, CRTFrame *frame, bool did_detect_vsync) { [machine crt:crt didEndFrame:frame didDetectVSync:did_detect_vsync]; @@ -60,7 +60,7 @@ typedef NS_ENUM(NSInteger, CSAtari2600RunningState) { return self; } -- (void)setCRTDelegate:(Outputs::CRT::CRTDelegate *)delegate {} +- (void)setCRTDelegate:(Outputs::CRT::Delegate *)delegate {} - (void)doRunForNumberOfCycles:(int)numberOfCycles {} @end diff --git a/Outputs/CRT.cpp b/Outputs/CRT.cpp index 6d5ad9f0a..e36e01bec 100644 --- a/Outputs/CRT.cpp +++ b/Outputs/CRT.cpp @@ -335,7 +335,7 @@ void CRT::return_frame() #pragma mark - delegate -void CRT::set_delegate(CRTDelegate *delegate) +void CRT::set_delegate(Delegate *delegate) { _delegate = delegate; } diff --git a/Outputs/CRT.hpp b/Outputs/CRT.hpp index 50dd0948c..89e981da1 100644 --- a/Outputs/CRT.hpp +++ b/Outputs/CRT.hpp @@ -58,11 +58,11 @@ class CRT { void output_level(unsigned int number_of_cycles); void output_data(unsigned int number_of_cycles); - class CRTDelegate { + class Delegate { public: virtual void crt_did_end_frame(CRT *crt, CRTFrame *frame, bool did_detect_vsync) = 0; }; - void set_delegate(CRTDelegate *delegate); + void set_delegate(Delegate *delegate); void return_frame(); void allocate_write_area(int required_length); @@ -90,7 +90,7 @@ class CRT { CRTFrameBuilder *_current_frame_builder; int _frames_with_delegate; int _frame_read_pointer; - CRTDelegate *_delegate; + Delegate *_delegate; // outer elements of sync separation bool _is_receiving_sync; // true if the CRT is currently receiving sync (i.e. this is for edge triggering of horizontal sync) diff --git a/Outputs/Speaker.cpp b/Outputs/Speaker.cpp new file mode 100644 index 000000000..fa8c60291 --- /dev/null +++ b/Outputs/Speaker.cpp @@ -0,0 +1,9 @@ +// +// Speaker.cpp +// Clock Signal +// +// Created by Thomas Harte on 12/01/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#include "Speaker.hpp" diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp new file mode 100644 index 000000000..21312d5b2 --- /dev/null +++ b/Outputs/Speaker.hpp @@ -0,0 +1,32 @@ +// +// Speaker.hpp +// Clock Signal +// +// Created by Thomas Harte on 12/01/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#ifndef Speaker_hpp +#define Speaker_hpp + +#include + +namespace Speaker { + +class Delegate { + public: + virtual void speaker_did_complete_samples(uint8_t *buffer); +}; + +template class Filter { + public: + void set_output_rate(int cycles_per_second); + void set_delegate(Delegate *delegate); + + void set_input_rate(int cycles_per_second); + void run_for_cycles(int input_cycles); +}; + +} + +#endif /* Speaker_hpp */