1 #ifndef _DETECTORBANK_H_ 2 #define _DETECTORBANK_H_ 15 #include <condition_variable> 16 #include <cereal/access.hpp> 18 #include "detectortypes.h" 19 #include "thread_pool.h" 64 const inputSample_t* inputBuffer,
65 const std::size_t inputBufferSize);
93 const inputSample_t* inputBuffer,
94 const std::size_t inputBufferSize,
95 std::size_t numThreads,
97 parameter_t*
bw =
nullptr,
100 parameter_t damping = 0.0001,
101 const parameter_t
gain = 25.0);
112 const std::size_t inputBufferSize);
124 int getZ(discriminator_t* frames,
125 std::size_t chans, std::size_t numFrames,
126 const std::size_t startChan = 0);
141 result_t
absZ(result_t* absFrames,
142 std::size_t absChans,
143 const std::size_t absNumFrames,
144 discriminator_t* frames,
145 std::size_t maxThreads = 0
152 bool seek(
long int offset);
179 parameter_t
getW(std::size_t ch)
const;
187 parameter_t
getFreqIn(std::size_t ch)
const;
190 std::string
toXML(
void)
const;
209 void amplify(
const inputSample_t*& signal,
210 std::size_t signalSize,
211 const parameter_t
gain);
238 std::size_t start, end;
262 friend class cereal::access;
265 template<
class Archive>
void save(Archive& archive)
const;
268 template<
class Archive>
void load(Archive& archive);
271 std::vector<std::unique_ptr<AbstractDetector>>
detectors;
332 const parameter_t* bandwidths,
333 const std::size_t numDetectors);
355 const parameter_t mu,
357 const parameter_t sr,
360 const parameter_t gain);
parameter_t sr
Operating sample rate.
Iteratively adjust response.
parameter_t d
Detector damping factor.
static const parameter_t EDO12_pf[]
Standard tuning set for a 12EDO piano keyboard.
void amplify(const inputSample_t *&signal, std::size_t signalSize, const parameter_t gain)
Apply a gain to the inputBuffer.
std::size_t inBufSize
Size of the current audio input buffer.
std::size_t getChans(void) const
Return the number of detectors currently maintained by this DetectorBank.
const parameter_t f_in
The caller's requested frequency.
void stringToFeatures(const std::string &desc)
Set this DetectorBank's features from a human-readable string using featuresToStringMap.
void getZDelegate(void *args)
Perform one thread's worth of work on the given channels.
parameter_t getFreqIn(std::size_t ch) const
Find the input frequency of a given channel's detector.
Use multiple detectors to find note onsets at given frequencies (with multithreading).
Fourth order Runge-Kutta.
std::size_t firstChannel
First channel to process.
parameter_t getSR(void) const
Get the sample rate associated with this DetectorBank.
result_t absZ(result_t *absFrames, std::size_t absChans, const std::size_t absNumFrames, discriminator_t *frames, std::size_t maxThreads=0) const
Take z-frames and fill a given array of the same dimensions (absFrames) with their absolute values...
static const int EDO12_pf_size
Size of standard 12EDO piano keyboard.
Struct to pass absZ thread parameters to a worker thread.
const parameter_t f_actual
The frequency of the detector used.
std::unique_ptr< ThreadPool > threadPool
Thread manager for concurrent sections.
Metaparameters for a detector.
Base class for detectors using different numerical methods.
void saveProfile(std::string name)
Save the current profile so that a DetectorBank can be constructed conveniently in future...
static const std::map< int, std::string > featuresToStringMap
Printable string representations of the flags in the Features enum Use the provided routines through ...
static ProfileManager profileManager
The profile manager responsible for loading and saving detectorbank properties.
std::string toXML(void) const
Return description of the detectorbank serialised in XML form.
void load(Archive &archive)
Write the relevant properties of the detector bank to an archive.
discriminator_t * frames
Output array.
const parameter_t bandwidth
Detector bandwdith.
std::size_t getBuflen(void) const
Find out the total number of samples currently available.
void makeDetectors(const std::size_t numDetectors, const parameter_t mu, const parameter_t d, const parameter_t sr, const Features features, const parameter_t gain)
Utility routine to make the appropriate detectors and tune them according to the required feature set...
Scale real and imaginary parts of the response.
Features features
Detector method & normalistion.
DetectorBank(const std::string &profile, const inputSample_t *inputBuffer, const std::size_t inputBufferSize)
Construct a DetectorBank from archived parameters.
std::size_t numChannels
Number of channels to process.
Without amplitude normalisation.
std::map< int, std::unique_ptr< inputSample_t[]> > input_pool
Mapping of ratio of requested frequency to the maximum used detector frequency for this solver and no...
int getZ(discriminator_t *frames, std::size_t chans, std::size_t numFrames, const std::size_t startChan=0)
Get the next numFrames of detector bank output.
parameter_t modF
Frequency above which the signal should be modulated.
bool auto_bw
Has DetectorBank created its own array of zeros for bandwidth?
void setDBComponents(const parameter_t *frequencies, const parameter_t *bandwidths, const std::size_t numDetectors)
Create the detector_components required for each detector in the detector bank.
parameter_t * bw
Array of bandwidths.
std::unique_ptr< inputSample_t[]> gainBuf
If a gain is applied to the input signal, this pointer refers to the locally allocated buffer contain...
const inputSample_t * inBuf
The current input buffer.
const inputSample_t * signal
Pointer to a frequency-shifted version of the input data.
std::size_t numFrames
Number of frames left to process.
std::size_t framesPerChannel
Number of frames per channel.
const std::string featuresToString(void) const
Produce a human-readable string describing this DetectorBank's features using featuresToStringMap.
static constexpr int ampNormalizationMask
Bit mask for specifying the amplitude normalisation method.
parameter_t gain
Audio input gain to be applided.
static constexpr int solverMask
Bit mask for specifying the solver method.
static constexpr int freqNormalizationMask
Bit mask for specifying the frequency normalisation method.
std::vector< std::unique_ptr< AbstractDetector > > detectors
Detectors to be run by this detector bank.
parameter_t getW(std::size_t ch) const
Find the frequency of a given channel's detector.
void setInputBuffer(const inputSample_t *inputBuffer, const std::size_t inputBufferSize)
Change the input, without recreating the detector bank.
bool seek(long int offset)
Set input sample at which to start the detection.
std::size_t currentSample
How far along the input for next read.
Struct to pass getZ thread parameters to a worker thread.
Without frequency normalisation.
std::size_t tell(void) const
Get the index of current input sample.
void save(Archive &archive) const
Write the relevant properties of the detector bank to an archive.
Features
Specify numerical and normalisation methods for this detector bank.
std::vector< detector_components > dbComponents
Vector of detector_components describing each AbstractDetector in the vector detectors.
void fromXML(std::string xml)
Set the state of the detectorbank according to a previously serialised XML description.
Default is Runge-Kutta, unnormalised frequency, normalised amplitude.