27template <
typename SampleType>
38 m_delaySeconds (delaySeconds)
49 m_delaySeconds (other.m_delaySeconds),
50 m_delayFrames (other.m_delayFrames),
51 m_bufferSizeFrames (other.m_bufferSizeFrames),
52 m_writeIndex (other.m_writeIndex),
53 m_buffers (other.m_buffers)
61 DSP<SampleType,
TimeShift<SampleType>> (std::move (other)),
62 m_delaySeconds (other.m_delaySeconds),
63 m_delayFrames (other.m_delayFrames),
64 m_bufferSizeFrames (other.m_bufferSizeFrames),
65 m_writeIndex (other.m_writeIndex),
66 m_buffers (std::move (other.m_buffers))
68 other.m_delayFrames = 0;
69 other.m_bufferSizeFrames = 0;
70 other.m_writeIndex = 0;
81 DSP<SampleType,
TimeShift<SampleType>>::operator= (other);
83 m_delaySeconds = other.m_delaySeconds;
84 m_delayFrames = other.m_delayFrames;
85 m_bufferSizeFrames = other.m_bufferSizeFrames;
86 m_writeIndex = other.m_writeIndex;
87 m_buffers = other.m_buffers;
100 DSP<SampleType,
TimeShift<SampleType>>::operator= (std::move (other));
102 m_delaySeconds = other.m_delaySeconds;
103 m_delayFrames = other.m_delayFrames;
104 m_bufferSizeFrames = other.m_bufferSizeFrames;
105 m_writeIndex = other.m_writeIndex;
106 m_buffers = std::move (other.m_buffers);
108 other.m_delayFrames = 0;
109 other.m_bufferSizeFrames = 0;
110 other.m_writeIndex = 0;
119 size_t numInputChannels,
120 size_t numOutputChannels,
124 hassert (numInputChannels == numOutputChannels)
125 const size_t numChannels = numInputChannels;
130 if (m_delayFrames == 0)
133 m_bufferSizeFrames = m_delayFrames + 1;
137 m_buffers.resize (numChannels);
139 for (size_t channel = 0; channel < numChannels; ++channel)
140 m_buffers[channel].assign (m_bufferSizeFrames,
static_cast<SampleType> (0));
146 const EnvelopeBuffers& ,
150 const size_t numFrames = input.getNumFrames();
151 const size_t numChannels = input.getNumChannels();
153 for (size_t frame = 0; frame < numFrames; ++frame)
155 const size_t readIndex = (m_writeIndex + m_bufferSizeFrames - m_delayFrames) % m_bufferSizeFrames;
157 for (size_t channel = 0; channel < numChannels; ++channel)
159 const SampleType inputSample = input[channel][frame];
160 output[channel][frame] = m_buffers[channel][readIndex];
161 m_buffers[channel][m_writeIndex] = inputSample;
164 m_writeIndex = (m_writeIndex + 1) % m_bufferSizeFrames;
175 return numInputChannels == numOutputChannels;
180 return sampleRateHz > 0.0;
185 stream <<
"TimeShift (" <<
secPrecision << m_delaySeconds <<
")";
194 double m_delaySeconds = 0.0;
195 size_t m_delayFrames = 0;
196 size_t m_bufferSizeFrames = 0;
197 size_t m_writeIndex = 0;
199 std::vector<std::vector<SampleType>> m_buffers;
Container for audio data.
A set of boolean flags mapped to each audio channel.
Shifts an audio signal forward in time by a fixed amount.
TimeShift & operator=(const TimeShift &other)
Creates a TimeShift processor by copying other one.
~TimeShift() override=default
TimeShift & operator=(TimeShift &&other) noexcept
Creates a TimeShift processor by moving other one.
TimeShift(double delaySeconds)
Creates a TimeShift processor with a fixed delay.
bool supportsSampleRate(double sampleRateHz) const override
Tells whether this effect supports given sample rate.
TimeShift(const TimeShift &other)
Creates a TimeShift processor by copying other one.
void setValue(int, double) override
Sets DSP value.
void process(const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output, const EnvelopeBuffers &, ChannelFlags) override
Processes the audio.
void represent(std::ostream &stream) const override
Makes a text representation of this DSP effect for test failure outputs.
TimeShift(TimeShift &&other) noexcept
Creates a TimeShift processor by moving other one.
void prepare(double sampleRateHz, size_t numInputChannels, size_t numOutputChannels, size_t) override
Prepare for processing.
bool supportsEnvelopeFor(int) const override
Tells whether this effect accepts automation envelopes for a particular parameter.
bool supportsChannelLayout(size_t numInputChannels, size_t numOutputChannels) const override
Tells the runner (host) whether this effect supports a specific i/o configuration.
Thrown when an inappropriate value is encountered.
#define HART_DSP_COPYABLE(ClassName)
Implements a generic hart::DSP::copy() method.
#define HART_DSP_MOVABLE(ClassName)
Implements a generic hart::DSP::move() method.
#define HART_THROW_OR_RETURN_VOID(ExceptionType, message)
Throws an exception if HART_DO_NOT_THROW_EXCEPTIONS is set, prints a message and returns otherwise.
#define hassert(condition)
Triggers a HartAssertException if the condition is false
std::ostream & secPrecision(std::ostream &stream)
Sets number of decimal places for values in seconds.
static size_t roundToSizeT(SampleType x)
Rounds a floating point value to a size_t value.
static SampleType floatsEqual(SampleType a, SampleType b, SampleType epsilon=(SampleType) 1e-8)
Compares two floating point numbers within a given tolerance.
#define HART_DSP_DECLARE_ALIASES_FOR(ClassName)