A Hopf, Skip and a Jump
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
AbstractDetector Class Referenceabstract

Base class for detectors using different numerical methods. More...

#include <detectors.h>

Inheritance diagram for AbstractDetector:
Inheritance graph
[legend]

Public Member Functions

 AbstractDetector (parameter_t f, parameter_t mu, parameter_t d, parameter_t sr, parameter_t detBw, parameter_t gain)
 
void processAudio (discriminator_t *target, const inputSample_t *start, std::size_t count)
 Process audio using the numerical method appropriate to the derived class. More...
 
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. More...
 
bool amplitudeNormalize (const parameter_t forcing_amplitude)
 Set the detector's a and iScale attributes by profiling an ideal detector response. More...
 
void scaleAmplitude ()
 Calculate amplitude scale factor.
 
void generateTone (inputSample_t *tone, const std::size_t duration, const parameter_t frequency)
 Generate a sine tone. More...
 
parameter_t getW (void) const
 Find the speficied characteristic frequency for this detector (post-modulation and -normalisation) More...
 
virtual void reset ()=0
 Reset the internal values used to calculate z to 0. More...
 

Protected Member Functions

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 output.
 
template<class Archive >
void save (Archive &archive) const
 Save the DetectorBank as a cereal archive. More...
 
template<class Archive >
void load (Archive &archive)
 Load the DetectorBank from a cereal archive. More...
 
void makeScaleVectors ()
 Make freq and factor vectors for given method and normalisation.
 
void getScaleValue (const parameter_t fr)
 Get a scale value for a given frequency.
 

Static Protected Member Functions

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. More...
 

Protected Attributes

parameter_t w
 Characteristic frequency.
 
parameter_t const mu
 Distance from the bifurcation point.
 
parameter_t const d
 Detector damping factor.
 
parameter_t const sr
 Sample rate.
 
parameter_t const detBw
 Detector bandwidth.
 
parameter_t const gain
 Detector gain.
 
discriminator_t aScale
 Amplitude scaling factor.
 
parameter_t iScale
 Scaling factor for imaginary part.
 
parameter_t b
 Detector's first Lyapunov coefficent.
 
discriminator_t scale
 Detector's scale factor.
 
bool nrml { false }
 If search normalisation has been applied.
 
std::vector< parameter_t > detScaleFreqs
 
std::vector< discriminator_t > detScaleFactors
 

Static Protected Attributes

static constexpr int maxNormIterations { 100 }
 The maximum number of iterations to find best response during search_normalization.
 
static constexpr double normConverged { 1.0028922878693671 }
 Ratio of discovered frequency to specification frequency to be considered "close enough" during seach_normalization. More...
 
static const std::array< std::vector< parameter_t >, 8 > scaleFreqs
 
static const std::array< std::vector< discriminator_t >, 8 > scaleFactors
 

Friends

class cereal::access
 
template<class Archive >
void DetectorBank::save (Archive &) const
 Permit cereal and the archive functions of the DetectorBank with which this detector is composed to read protected variables for archival purposes.
 
template<class Archive >
void DetectorBank::load (Archive &)
 Permit cereal and the archive functions of the DetectorBank with which this detector is composed to write protected variables for archival purposes.
 

Detailed Description

Base class for detectors using different numerical methods.

The process() method must be supplied by the derived classes.

Definition at line 21 of file detectors.h.

Constructor & Destructor Documentation

◆ AbstractDetector()

AbstractDetector::AbstractDetector ( parameter_t  f,
parameter_t  mu,
parameter_t  d,
parameter_t  sr,
parameter_t  detBw,
parameter_t  gain 
)
Parameters
fDetector centre frequency (Hz)
muDetector control parameter (should be in the region of 0)
dDetector damping ratio
srSample rate of input audio (should be 44.1kHz or 48kHz)
detBwDetector bandwidth (Hz)
gainDetector gain

Member Function Documentation

◆ amplitudeNormalize()

bool AbstractDetector::amplitudeNormalize ( const parameter_t  forcing_amplitude)

Set the detector's a and iScale attributes by profiling an ideal detector response.

These can then be used to normalise the detector's amplitude response to the range 0-1.

Parameters
forcingAmplitudeGain that was applied to the input signal
Returns
true
Exceptions
std::stringInvalid detector type while attempting amplitude normalization

◆ generateTone()

void AbstractDetector::generateTone ( inputSample_t *  tone,
const std::size_t  duration,
const parameter_t  frequency 
)

Generate a sine tone.

Parameters
toneArray for output tone
durationTone duration (in samples)
frequencyFrequency at which to generate tone (Hz)

◆ getLyapunov()

static const parameter_t AbstractDetector::getLyapunov ( const parameter_t  bw,
const parameter_t  amp 
)
staticprotected

Find the first Lyapunov coefficient required for a given bandwidth, with a given forcing amplitude.

If the desired bandwidth is given as zero, the returned value will be zero. This will create a detetor with the narrowest possible bandwidth (~1.5Hz)

Parameters
bwDesired bandwidth
ampForcing amplitude
Returns
First Lyapunov coefficient

◆ getW()

parameter_t AbstractDetector::getW ( void  ) const
inline

Find the speficied characteristic frequency for this detector (post-modulation and -normalisation)

Returns
Characterisic frequency in rad/s

Definition at line 104 of file detectors.h.

◆ load()

template<class Archive >
void AbstractDetector::load ( Archive &  archive)
inlineprotected

Load the DetectorBank from a cereal archive.

Parameters
archiveThe archive from which properties are read.

Definition at line 164 of file detectors.h.

◆ processAudio()

void AbstractDetector::processAudio ( discriminator_t *  target,
const inputSample_t *  start,
std::size_t  count 
)

Process audio using the numerical method appropriate to the derived class.

The derived class's process() method is called and if amplitude normalisation is required, the predetermined gain and stiffness constant is applied to the result.

Parameters
targetPointer to output array. This should have the correct dimensions for your desired detector bank: height = number of detectors, length = length of audio input.
startPointer to beginning of audio
countNumber of frames to process

◆ reset()

virtual void AbstractDetector::reset ( )
pure virtual

Reset the internal values used to calculate z to 0.

This is called when DetectorBank.seek() is called. Overridden in derived classes.

Implemented in RK4Detector, and CDDetector.

◆ save()

template<class Archive >
void AbstractDetector::save ( Archive &  archive) const
inlineprotected

Save the DetectorBank as a cereal archive.

Parameters
archiveThe archive to which properties are written.

Definition at line 150 of file detectors.h.

◆ searchNormalize()

bool AbstractDetector::searchNormalize ( parameter_t  searchStart,
parameter_t  searchEnd,
const parameter_t  toneDuration,
const parameter_t  forcing_amplitude 
)

Normalise the detector frequency using an iterative scheme.

The lower and upper bounds of the search must be respectively lower and higher than the actual characteristic frequency of the detector. The search iterates by moving the worst performing bounding frequency half way towards the mean of the two current bounds until the maximum number of iterations or is exceeded or the specified accuracy is achieved (see maxNormIterations and normConverged).

Parameters
searchStartLower bound of search (ratio of specified f0)
searchEndUpper bound of search (ratio of specified f0)
toneDurationLength constant test tone to be generaated
Exceptions
std::stringInvalid detector type while attempting search-normalisation
std::stringSearching for normalised charactersitc frequency: test range does not span maximum response.

Member Data Documentation

◆ normConverged

constexpr double AbstractDetector::normConverged { 1.0028922878693671 }
staticprotected

Ratio of discovered frequency to specification frequency to be considered "close enough" during seach_normalization.

1.0057929410678534 = 2^(1/120) = 10 cents; 1.0028922878693671 = 2^(1/240) = 5 cents

Definition at line 196 of file detectors.h.


The documentation for this class was generated from the following file: