Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
frequency_shifter.hpp
Go to the documentation of this file.
1#pragma once
2
22
24
25#include <cmath>
26
27namespace pulp::signal {
28
34template <typename SampleType = double>
36
53template <typename SampleType = float>
55public:
56 void set_sample_rate(double sr) {
57 sample_rate_ = sr > 0.0 ? sr : sample_rate_;
58 update();
59 }
60
62 void set_shift_hz(double hz) {
63 shift_hz_ = hz;
64 update();
65 }
66
67 double shift_hz() const { return shift_hz_; }
68
69 void reset() {
70 hilbert_.reset();
71 phase_ = 0.0;
72 }
73
74 SampleType process(SampleType input) {
75 const auto pair = hilbert_.process(static_cast<double>(input));
76
77 phase_ += increment_;
78 phase_ -= std::floor(phase_);
79
80 const double angle = 2.0 * 3.14159265358979323846 * phase_;
81 return static_cast<SampleType>(pair.in_phase * std::cos(angle) -
82 pair.quadrature * std::sin(angle));
83 }
84
85private:
86 void update() { increment_ = shift_hz_ / sample_rate_; }
87
88 HilbertPairT<double> hilbert_;
89 double sample_rate_ = 44100.0;
90 double shift_hz_ = 0.0;
91 double increment_ = 0.0;
92 double phase_ = 0.0;
93};
94
98
99} // namespace pulp::signal
Shifts every frequency in a signal by the same number of Hz.
Definition frequency_shifter.hpp:54
SampleType process(SampleType input)
Definition frequency_shifter.hpp:74
void set_sample_rate(double sr)
Definition frequency_shifter.hpp:56
double shift_hz() const
Definition frequency_shifter.hpp:67
void reset()
Definition frequency_shifter.hpp:69
void set_shift_hz(double hz)
Amount to add to every frequency, in Hz. Negative shifts downward.
Definition frequency_shifter.hpp:62
A pair of allpass cascades whose outputs stand a quarter cycle apart across nearly the whole band — t...
Definition frequency_shifter_ssb.hpp:210
The single-sideband (Bode/Moog) frequency shifter: a Hilbert phase-difference network,...
Definition additive_bank.hpp:218
HilbertPairT< double > HilbertPair
Definition frequency_shifter.hpp:95
FrequencyShifterT< float > FrequencyShifter
Definition frequency_shifter.hpp:96
FrequencyShifterT< double > FrequencyShifter64
Definition frequency_shifter.hpp:97
HilbertQuadratureNetworkT< SampleType > HilbertPairT
A pair of allpass chains whose outputs stand a quarter cycle apart across the audio band — the analyt...
Definition frequency_shifter.hpp:35