1 #ifndef _ABSTRACTDETECTOR_H_ 2 #define _ABSTRACTDETECTOR_H_ 9 #include <cereal/cereal.hpp> 10 #include <cereal/access.hpp> 11 #include <cereal/archives/xml.hpp> 12 #include <cereal/types/complex.hpp> 14 #include "detectorbank.h" 15 #include "detectortypes.h" 33 parameter_t
d, parameter_t
sr,
50 const inputSample_t* start, std::size_t count);
71 parameter_t searchEnd,
72 const parameter_t toneDuration,
73 const parameter_t forcing_amplitude);
95 const std::size_t duration,
96 const parameter_t frequency);
104 parameter_t
getW(
void)
const {
return w; };
110 virtual void reset() = 0;
117 virtual void process(discriminator_t* target,
118 const inputSample_t* start, std::size_t count) = 0;
130 static const parameter_t
getLyapunov(
const parameter_t bw,
const parameter_t amp);
145 friend class cereal::access;
150 template <
class Archive>
void save(Archive& archive)
const 152 archive.setNextName(
"AbstractDetector");
154 archive(cereal::make_nvp(
"w_adjusted",
w),
158 archive.finishNode();
164 template <
class Archive>
void load(Archive& archive)
168 archive(cereal::make_nvp(
"w_adjusted",
w),
173 archive.finishNode();
177 parameter_t
const mu;
179 parameter_t
const sr;
204 std::vector<parameter_t> detScaleFreqs;
205 std::vector<discriminator_t> detScaleFactors;
206 static const std::array<std::vector<parameter_t>, 8> scaleFreqs;
207 static const std::array<std::vector<discriminator_t>, 8> scaleFactors;
234 const parameter_t
d,
const parameter_t
sr,
235 const parameter_t
detBw,
const parameter_t
gain);
241 virtual void reset();
251 virtual void process(discriminator_t* target,
252 const inputSample_t* start,
253 const std::size_t count)
override;
256 std::complex<parameter_t>
zp;
257 std::complex<parameter_t>
zpp;
303 const parameter_t
d,
const parameter_t
sr,
304 const parameter_t
detBw,
const parameter_t
gain);
309 virtual void reset();
319 virtual void process(discriminator_t* target,
320 const inputSample_t* start,
321 const std::size_t count)
override;
323 std::complex<parameter_t>
zp;
324 std::complex<parameter_t>
zpp;
parameter_t const detBw
Detector bandwidth.
virtual void process(discriminator_t *target, const inputSample_t *start, std::size_t count)=0
This method gets overridden in derived classes to produce an unnormalised version of the required out...
void load(Archive &archive)
Load the DetectorBank from a cereal archive.
static constexpr double normConverged
Ratio of discovered frequency to specification frequency to be considered "close enough" during seach...
parameter_t const sr
Sample rate.
AbstractDetector(parameter_t f, parameter_t mu, parameter_t d, parameter_t sr, parameter_t detBw, parameter_t gain)
parameter_t iScale
Scaling factor for imaginary part.
void getScaleValue(const parameter_t fr)
Get a scale value for a given frequency.
static constexpr int maxNormIterations
The maximum number of iterations to find best response during search_normalization.
parameter_t getW(void) const
Find the speficied characteristic frequency for this detector (post-modulation and -normalisation) ...
bool nrml
If search normalisation has been applied.
parameter_t const d
Detector damping factor.
parameter_t const mu
Distance from the bifurcation point.
virtual void reset()=0
Reset the internal values used to calculate z to 0.
Base class for detectors using different numerical methods.
Use the fourth order Runge-Kutta method to calculate the output.
void load(Archive &archive)
Write the relevant properties of the detector bank to an archive.
parameter_t w
Characteristic frequency.
std::complex< parameter_t > zp
previous z value
parameter_t b
Detector's first Lyapunov coefficent.
void scaleAmplitude()
Calculate amplitude scale factor.
std::complex< parameter_t > zpp
z value two samples ago
bool searchNormalize(parameter_t searchStart, parameter_t searchEnd, const parameter_t toneDuration, const parameter_t forcing_amplitude)
Normalise the detector frequency using an iterative scheme.
void save(Archive &archive) const
Save the DetectorBank as a cereal archive.
inputSample_t xpp
audio input sample two samples ago
inputSample_t xp
previous audio input sample
void makeScaleVectors()
Make freq and factor vectors for given method and normalisation.
std::complex< parameter_t > zpp
z value two samples ago
inputSample_t xp
previous audio input sample
discriminator_t aScale
Amplitude scaling factor.
Use the central-difference approximation to calculate the output.
discriminator_t scale
Detector's scale factor.
static const parameter_t getLyapunov(const parameter_t bw, const parameter_t amp)
Find the first Lyapunov coefficient required for a given bandwidth, with a given forcing amplitude...
void save(Archive &archive) const
Write the relevant properties of the detector bank to an archive.
void processAudio(discriminator_t *target, const inputSample_t *start, std::size_t count)
Process audio using the numerical method appropriate to the derived class.
bool amplitudeNormalize(const parameter_t forcing_amplitude)
Set the detector's a and iScale attributes by profiling an ideal detector response.
void generateTone(inputSample_t *tone, const std::size_t duration, const parameter_t frequency)
Generate a sine tone.
std::complex< parameter_t > zp
previous z value
parameter_t const gain
Detector gain.