HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart_nyquist_signal.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <memory>
5
8#include "signals/hart_signal.hpp"
9#include "hart_utils.hpp"
10
11namespace hart
12{
13
14/// @brief Produces a Nyquist signal
15/// @details Regardless of sample rate, outputs an alternating squence like:
16/// {+1, -1, +1, -1, +1, ...} at 0 dB sample peak.
17/// @ingroup Signals
18template<typename SampleType>
20 public Signal<SampleType, NyquistSignal<SampleType>>
21{
22public:
23 NyquistSignal() = default;
24 bool supportsNumChannels (size_t /* numChannels */) const override { return true; };
25 void prepare (double /* sampleRateHz */, size_t /* numOutputChannels */, size_t /*maxBlockSizeFrames*/) override {}
26
27 void renderNextBlock (AudioBuffer<SampleType>& output) override
28 {
29 hassert (output.getNumChannels() >= 1);
30 const size_t numFrames = output.getNumFrames();
31
32 for (size_t channel = 0; channel < output.getNumChannels(); ++channel)
33 {
34 SampleType* channelData = output[channel];
35
36 const SampleType evenFrameValues = m_nextBlockStartValue;
37 const SampleType oddFrameValues = -m_nextBlockStartValue;
38
39 for (size_t frame = 0; frame < numFrames; frame += 2)
40 channelData[frame] = evenFrameValues;
41
42 for (size_t frame = 1; frame < numFrames; frame += 2)
43 channelData[frame] = oddFrameValues;
44 }
45
46 if (numFrames % 2 != 0)
47 m_nextBlockStartValue = -m_nextBlockStartValue;
48 }
49
50 void reset() override
51 {
52 m_nextBlockStartValue = 1.0;
53 }
54
56
57private:
58 SampleType m_nextBlockStartValue = 1.0;
59};
60
62
63} // namespace hart
Container for audio data.
Produces a Nyquist signal.
void renderNextBlock(AudioBuffer< SampleType > &output) override
Renders next block audio for the signal.
NyquistSignal()=default
bool supportsNumChannels(size_t) const override
Tells the host whether this Signal is capable of generating audio for a certain amount of channels.
void prepare(double, size_t, size_t) override
Prepare the signal for rendering.
void reset() override
Resets the Signal to initial state.
Base class for signals.
#define hassert(condition)
Triggers a HartAssertException if the condition is false
#define HART_DEFINE_GENERIC_REPRESENT(ClassName)
Defines a basic string representation of your class.
#define HART_SIGNAL_DECLARE_ALIASES_FOR(ClassName)