From 2dc1d4443ea9567e3c56cc90ca649e7e97afb756 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 18 Dec 2017 21:39:23 -0500 Subject: [PATCH] Separates LowpassFilter and SampleSource. --- Components/6560/6560.hpp | 3 +- Components/AY38910/AY38910.cpp | 2 + Components/AY38910/AY38910.hpp | 2 +- Machines/AmstradCPC/AmstradCPC.cpp | 1 + Machines/Atari2600/Bus.hpp | 1 + Machines/Atari2600/TIASound.hpp | 2 +- Machines/Electron/Electron.cpp | 2 +- Machines/Electron/SoundGenerator.hpp | 2 +- Machines/MSX/MSX.cpp | 2 + Machines/Oric/Oric.cpp | 1 + .../Clock Signal.xcodeproj/project.pbxproj | 10 ++--- OSBindings/SDL/main.cpp | 1 + .../Implementation/FilteringSpeaker.cpp | 9 ---- ...ilteringSpeaker.hpp => LowpassSpeaker.hpp} | 37 ++++----------- .../Speaker/Implementation/SampleSource.hpp | 45 +++++++++++++++++++ 15 files changed, 72 insertions(+), 48 deletions(-) delete mode 100644 Outputs/Speaker/Implementation/FilteringSpeaker.cpp rename Outputs/Speaker/Implementation/{FilteringSpeaker.hpp => LowpassSpeaker.hpp} (89%) create mode 100644 Outputs/Speaker/Implementation/SampleSource.hpp diff --git a/Components/6560/6560.hpp b/Components/6560/6560.hpp index 531ef5d40..0d17b0c45 100644 --- a/Components/6560/6560.hpp +++ b/Components/6560/6560.hpp @@ -12,7 +12,8 @@ #include "../../ClockReceiver/ClockReceiver.hpp" #include "../../Concurrency/AsyncTaskQueue.hpp" #include "../../Outputs/CRT/CRT.hpp" -#include "../../Outputs/Speaker/Implementation/FilteringSpeaker.hpp" +#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" +#include "../../Outputs/Speaker/Implementation/SampleSource.hpp" namespace MOS { diff --git a/Components/AY38910/AY38910.cpp b/Components/AY38910/AY38910.cpp index e9c321205..e9f4e46df 100644 --- a/Components/AY38910/AY38910.cpp +++ b/Components/AY38910/AY38910.cpp @@ -8,6 +8,8 @@ #include "AY38910.hpp" +#include + using namespace GI::AY38910; AY38910::AY38910(Concurrency::DeferringAsyncTaskQueue &task_queue) : task_queue_(task_queue) { diff --git a/Components/AY38910/AY38910.hpp b/Components/AY38910/AY38910.hpp index 203527835..93db05d26 100644 --- a/Components/AY38910/AY38910.hpp +++ b/Components/AY38910/AY38910.hpp @@ -9,7 +9,7 @@ #ifndef AY_3_8910_hpp #define AY_3_8910_hpp -#include "../../Outputs/Speaker/Implementation/FilteringSpeaker.hpp" +#include "../../Outputs/Speaker/Implementation/SampleSource.hpp" #include "../../Concurrency/AsyncTaskQueue.hpp" namespace GI { diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index e768e64f1..0bf059704 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -23,6 +23,7 @@ #include "../../Storage/Tape/Tape.hpp" #include "../../ClockReceiver/ForceInline.hpp" +#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" #include #include diff --git a/Machines/Atari2600/Bus.hpp b/Machines/Atari2600/Bus.hpp index 1f0b147b8..ffd63b64e 100644 --- a/Machines/Atari2600/Bus.hpp +++ b/Machines/Atari2600/Bus.hpp @@ -15,6 +15,7 @@ #include "TIASound.hpp" #include "../../ClockReceiver/ClockReceiver.hpp" +#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" namespace Atari2600 { diff --git a/Machines/Atari2600/TIASound.hpp b/Machines/Atari2600/TIASound.hpp index 78441489f..25c782d19 100644 --- a/Machines/Atari2600/TIASound.hpp +++ b/Machines/Atari2600/TIASound.hpp @@ -9,7 +9,7 @@ #ifndef Atari2600_TIASound_hpp #define Atari2600_TIASound_hpp -#include "../../Outputs/Speaker/Implementation/FilteringSpeaker.hpp" +#include "../../Outputs/Speaker/Implementation/SampleSource.hpp" #include "../../Concurrency/AsyncTaskQueue.hpp" namespace Atari2600 { diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index ab4524693..7022e7066 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -11,7 +11,7 @@ #include "../../ClockReceiver/ClockReceiver.hpp" #include "../../ClockReceiver/ForceInline.hpp" #include "../../Configurable/StandardOptions.hpp" -#include "../../Outputs/Speaker/Implementation/FilteringSpeaker.hpp" +#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" #include "../../Processors/6502/6502.hpp" #include "../../Storage/Tape/Tape.hpp" diff --git a/Machines/Electron/SoundGenerator.hpp b/Machines/Electron/SoundGenerator.hpp index dd6530b33..324d70a43 100644 --- a/Machines/Electron/SoundGenerator.hpp +++ b/Machines/Electron/SoundGenerator.hpp @@ -9,7 +9,7 @@ #ifndef Electron_SoundGenerator_hpp #define Electron_SoundGenerator_hpp -#include "../../Outputs/Speaker/Implementation/FilteringSpeaker.hpp" +#include "../../Outputs/Speaker/Implementation/SampleSource.hpp" #include "../../Concurrency/AsyncTaskQueue.hpp" namespace Electron { diff --git a/Machines/MSX/MSX.cpp b/Machines/MSX/MSX.cpp index b68a4155e..d61d19c81 100644 --- a/Machines/MSX/MSX.cpp +++ b/Machines/MSX/MSX.cpp @@ -21,6 +21,8 @@ #include "../ConfigurationTarget.hpp" #include "../KeyboardMachine.hpp" +#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" + namespace MSX { struct AYPortHandler: public GI::AY38910::PortHandler { diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp index 135433cee..03f2c48d6 100644 --- a/Machines/Oric/Oric.cpp +++ b/Machines/Oric/Oric.cpp @@ -24,6 +24,7 @@ #include "../../ClockReceiver/ForceInline.hpp" #include "../../Configurable/StandardOptions.hpp" +#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" #include #include diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 47ca85554..e396e0cb1 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -251,7 +251,6 @@ 4B8805F71DCFF6C9003085B1 /* Commodore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B8805F51DCFF6C9003085B1 /* Commodore.cpp */; }; 4B8805FB1DCFF807003085B1 /* Oric.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B8805F91DCFF807003085B1 /* Oric.cpp */; }; 4B8805FE1DD02552003085B1 /* Tape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B8805FC1DD02552003085B1 /* Tape.cpp */; }; - 4B8EF6081FE5AF830076CCDD /* FilteringSpeaker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B8EF6061FE5AF830076CCDD /* FilteringSpeaker.cpp */; }; 4B8FE21B1DA19D5F0090D3CE /* Atari2600Options.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B8FE2131DA19D5F0090D3CE /* Atari2600Options.xib */; }; 4B8FE21C1DA19D5F0090D3CE /* MachineDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B8FE2151DA19D5F0090D3CE /* MachineDocument.xib */; }; 4B8FE21D1DA19D5F0090D3CE /* ElectronOptions.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B8FE2171DA19D5F0090D3CE /* ElectronOptions.xib */; }; @@ -818,6 +817,7 @@ 4B643F391D77AD1900D431D6 /* CSStaticAnalyser.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CSStaticAnalyser.mm; path = StaticAnalyser/CSStaticAnalyser.mm; sourceTree = ""; }; 4B643F3C1D77AE5C00D431D6 /* CSMachine+Target.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CSMachine+Target.h"; sourceTree = ""; }; 4B643F3E1D77B88000D431D6 /* DocumentController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DocumentController.swift; sourceTree = ""; }; + 4B698D1A1FE768A100696C91 /* SampleSource.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = SampleSource.hpp; sourceTree = ""; }; 4B69FB3B1C4D908A00B5F0AA /* Tape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Tape.cpp; sourceTree = ""; }; 4B69FB3C1C4D908A00B5F0AA /* Tape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Tape.hpp; sourceTree = ""; }; 4B69FB421C4D941400B5F0AA /* TapeUEF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TapeUEF.cpp; sourceTree = ""; }; @@ -873,8 +873,7 @@ 4B8805FD1DD02552003085B1 /* Tape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Tape.hpp; path = ../../StaticAnalyser/Oric/Tape.hpp; sourceTree = ""; }; 4B8D287E1F77207100645199 /* TrackSerialiser.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = TrackSerialiser.hpp; sourceTree = ""; }; 4B8E4ECD1DCE483D003716C3 /* KeyboardMachine.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = KeyboardMachine.hpp; sourceTree = ""; }; - 4B8EF6061FE5AF830076CCDD /* FilteringSpeaker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FilteringSpeaker.cpp; sourceTree = ""; }; - 4B8EF6071FE5AF830076CCDD /* FilteringSpeaker.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = FilteringSpeaker.hpp; sourceTree = ""; }; + 4B8EF6071FE5AF830076CCDD /* LowpassSpeaker.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LowpassSpeaker.hpp; sourceTree = ""; }; 4B8FE2141DA19D5F0090D3CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/Atari2600Options.xib"; sourceTree = SOURCE_ROOT; }; 4B8FE2161DA19D5F0090D3CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/MachineDocument.xib"; sourceTree = SOURCE_ROOT; }; 4B8FE2181DA19D5F0090D3CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/ElectronOptions.xib"; sourceTree = SOURCE_ROOT; }; @@ -2022,8 +2021,8 @@ 4B8EF6051FE5AF830076CCDD /* Implementation */ = { isa = PBXGroup; children = ( - 4B8EF6061FE5AF830076CCDD /* FilteringSpeaker.cpp */, - 4B8EF6071FE5AF830076CCDD /* FilteringSpeaker.hpp */, + 4B8EF6071FE5AF830076CCDD /* LowpassSpeaker.hpp */, + 4B698D1A1FE768A100696C91 /* SampleSource.hpp */, ); path = Implementation; sourceTree = ""; @@ -3382,7 +3381,6 @@ 4BBFFEE61F7B27F1005F3FEB /* TrackSerialiser.cpp in Sources */, 4BC3B74F1CD194CC00F86E85 /* Shader.cpp in Sources */, 4B38F3481F2EC11D00D9235D /* AmstradCPC.cpp in Sources */, - 4B8EF6081FE5AF830076CCDD /* FilteringSpeaker.cpp in Sources */, 4B8FE2221DA19FB20090D3CE /* MachinePanel.swift in Sources */, 4B4518A41F75FD1C00926311 /* OricMFMDSK.cpp in Sources */, 4BBB14311CD2CECE00BDB55C /* IntermediateShader.cpp in Sources */, diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index 0527972bb..4704b8106 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -7,6 +7,7 @@ // #include +#include #include #include diff --git a/Outputs/Speaker/Implementation/FilteringSpeaker.cpp b/Outputs/Speaker/Implementation/FilteringSpeaker.cpp deleted file mode 100644 index a9730b7dc..000000000 --- a/Outputs/Speaker/Implementation/FilteringSpeaker.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// FilteringSpeaker.cpp -// Clock Signal -// -// Created by Thomas Harte on 15/12/2017. -// Copyright © 2017 Thomas Harte. All rights reserved. -// - -#include "FilteringSpeaker.hpp" diff --git a/Outputs/Speaker/Implementation/FilteringSpeaker.hpp b/Outputs/Speaker/Implementation/LowpassSpeaker.hpp similarity index 89% rename from Outputs/Speaker/Implementation/FilteringSpeaker.hpp rename to Outputs/Speaker/Implementation/LowpassSpeaker.hpp index c97efd2c7..406f8fe10 100644 --- a/Outputs/Speaker/Implementation/FilteringSpeaker.hpp +++ b/Outputs/Speaker/Implementation/LowpassSpeaker.hpp @@ -15,35 +15,16 @@ #include "../../../ClockReceiver/ClockReceiver.hpp" #include "../../../Concurrency/AsyncTaskQueue.hpp" +#include + namespace Outputs { namespace Speaker { /*! - A sample source is something that can provide a stream of audio. - This optional base class provides the interface expected to be exposed - by the template parameter to LowpassSpeaker. -*/ -class SampleSource { - public: - /*! - Should write the next @c number_of_samples to @c target. - */ - void get_samples(std::size_t number_of_samples, int16_t *target) {} - - /*! - Should skip the next @c number_of_samples. Subclasses of this SampleSource - need not implement this if it would no more efficient to do so than it is - merely to call get_samples and throw the result away, as per the default - implementation below. - */ - void skip_samples(const std::size_t number_of_samples) { - int16_t scratch_pad[number_of_samples]; - get_samples(number_of_samples, scratch_pad); - } -}; - -/*! - The low-pass speaker + The low-pass speaker expects an Outputs::Speaker::SampleSource-derived + template class, and uses the instance supplied to its constructor as the + source of a high-frequency stream of audio which it filters down to a + lower-frequency output. */ template class LowpassSpeaker: public Speaker { public: @@ -156,9 +137,9 @@ template class LowpassSpeaker: public Speaker { uint64_t steps = stepper_->step(); if(steps < input_buffer_.size()) { int16_t *input_buffer = input_buffer_.data(); - memmove( input_buffer, - &input_buffer[steps], - sizeof(int16_t) * (input_buffer_.size() - steps)); + std::memmove( input_buffer, + &input_buffer[steps], + sizeof(int16_t) * (input_buffer_.size() - steps)); input_buffer_depth_ -= steps; } else { if(steps > input_buffer_.size()) diff --git a/Outputs/Speaker/Implementation/SampleSource.hpp b/Outputs/Speaker/Implementation/SampleSource.hpp new file mode 100644 index 000000000..4235f2125 --- /dev/null +++ b/Outputs/Speaker/Implementation/SampleSource.hpp @@ -0,0 +1,45 @@ +// +// SampleSource.hpp +// Clock Signal +// +// Created by Thomas Harte on 17/12/2017. +// Copyright © 2017 Thomas Harte. All rights reserved. +// + +#ifndef SampleSource_hpp +#define SampleSource_hpp + +#include +#include + +namespace Outputs { +namespace Speaker { + +/*! + A sample source is something that can provide a stream of audio. + This optional base class provides the interface expected to be exposed + by the template parameter to LowpassSpeaker. +*/ +class SampleSource { + public: + /*! + Should write the next @c number_of_samples to @c target. + */ + void get_samples(std::size_t number_of_samples, std::int16_t *target) {} + + /*! + Should skip the next @c number_of_samples. Subclasses of this SampleSource + need not implement this if it would no more efficient to do so than it is + merely to call get_samples and throw the result away, as per the default + implementation below. + */ + void skip_samples(const std::size_t number_of_samples) { + std::int16_t scratch_pad[number_of_samples]; + get_samples(number_of_samples, scratch_pad); + } +}; + +} +} + +#endif /* SampleSource_hpp */