A Hopf, Skip and a Jump
detectorcache.h
1 #ifndef _DETECTORCACHE_H_
2 #define _DETECTORCACHE_H_
3 
4 #include "slidingbuffer.h"
5 #include "detectorbank.h"
6 
7 namespace detectorcache {
8 
19  class Producer : public slidingbuffer::SegmentProducer<result_t *>
20  {
21  public:
48  std::istream* is = nullptr)
49  : db{db}
50  , audiostream{is} {};
64  virtual std::size_t generate(result_t* seg[],
65  const std::size_t idx,
66  const std::size_t size);
73  virtual bool more(void) { return db.tell() < db.getBuflen(); }; //const?
82  void set_num_samps(std::size_t n) { seg_len = n; }; // private? Friend function of Detectorcache?
86  void set_start_chan(std::size_t c) { start_chan = c; };
87 
88  // ACCESS FUNCTIONS - return values from the DetectorBank
89 
93  parameter_t getSR(void) const { return db.getSR(); };
99  std::size_t getChans(void) { return db.getChans(); }; //const?
106  std::size_t getBuflen(void) { return db.getBuflen(); }; //const?
114  parameter_t getW(std::size_t ch) {return db.getW(ch);};
121  parameter_t getFreqIn(std::size_t ch) {return db.getFreqIn(ch);};
122 
123  protected:
124  DetectorBank& db;
125  std::size_t seg_len;
127  std::istream* audiostream;
130  std::size_t start_chan;
131  };
132 
138  class Segment : public slidingbuffer::Segment<result_t *, detectorcache::Producer>
139  {
140  public:
156  Segment(const std::size_t size, const std::size_t origin,
157  Producer& sp);
162  virtual ~Segment();
163 
164  friend class Producer;
165  };
166 
169  : public slidingbuffer::SlidingBuffer<result_t *,
170  detectorcache::Segment,
171  detectorcache::Producer>
172  {
173  public:
183  const std::size_t num_segs,
184  const std::size_t seg_len,
185  const std::size_t start_chan,
186  const std::size_t num_chans);
187 
195  const std::size_t num_segs,
196  const std::size_t seg_len,
197  const std::size_t start_chan = 0)
198  : DetectorCache(p,
199  num_segs,
200  seg_len,
201  start_chan,
202  p.getChans()) { }
203 
224  result_t getResultItem(long int ch, long int n);
249  std::size_t getPreviousResults(const std::size_t chan,
250  const std::size_t currentSample,
251  result_t* samples, std::size_t numSamples);
256  std::size_t end(void) { return p.getBuflen(); };
259  parameter_t getSR(void) const { return p.getSR(); };
262  std::size_t getChans(void) { return chans; };
263 
264  protected:
265  const std::size_t chans;
266  const std::size_t seg_len;
268  const std::size_t start_chan;
269  };
270 
271 };
272 
273 #endif
std::size_t end(void)
Get the total number of samples the cache can return.
Producer & p
This Producer for this DetectorCache.
Producer(DetectorBank &db, std::istream *is=nullptr)
Construct a Producer given a DetectorBank.
Definition: detectorcache.h:47
const std::size_t seg_len
Number of audio samples per segment.
A Segment is an aggregation of base data with a SlidingBuffer.
void set_start_chan(std::size_t c)
Set the startChan for getZ.
Definition: detectorcache.h:86
std::size_t getChans(void) const
Return the number of detectors currently maintained by this DetectorBank.
Definition: detectorbank.h:167
parameter_t getFreqIn(std::size_t ch) const
Find the input frequency of a given channel&#39;s detector.
Use multiple detectors to find note onsets at given frequencies (with multithreading).
Definition: detectorbank.h:25
std::size_t seg_len
Block-length (number of audio samples) to request on each call to generate()
Cache results from a detectorbank.
virtual bool more(void)
Establish wheter there is further data to be read from the DetectorBank associated with this cache...
Definition: detectorcache.h:73
Specialisation of the slidingbuffer::SegmentProducer class to create blocks of DetectorBank analysis ...
Definition: detectorcache.h:19
parameter_t getSR(void) const
Get the sample rate associated with this DetectorBank.
Definition: detectorbank.h:163
std::size_t getChans(void)
Get the number of channels in the cache.
std::istream * audiostream
In stream mode (datastream non-null), the istream from which inputSample_t samples are to be read...
std::size_t start_chan
Channel in DetectorBank at which to start.
parameter_t getW(std::size_t ch)
Find the frequency of a given channel&#39;s detector.
std::size_t getBuflen(void) const
Find out the total number of samples currently available.
Definition: detectorbank.h:171
DetectorCache(detectorcache::Producer &p, const std::size_t num_segs, const std::size_t seg_len, const std::size_t start_chan=0)
Construct a DetectorCache with default start and size.
const std::size_t start_chan
Channel in DetectorBank at which to start.
std::size_t getChans(void)
Enquire the number of channles for which data is produced.
Definition: detectorcache.h:99
parameter_t getSR(void) const
Get the sample rate of the associtaed DetectorBank.
virtual std::size_t generate(result_t *seg[], const std::size_t idx, const std::size_t size)
Generate a DetectorBank result block of the length specified by our associated DetectorCache after it...
The producer class enabling a slidingbuffer::SlidingBuffer to be deployed as a cache for the two-dime...
parameter_t getW(std::size_t ch) const
Find the frequency of a given channel&#39;s detector.
Template of a pure virtual class which populates a Segment with entities.
Definition: slidingbuffer.h:92
DetectorBank & db
The DetectorBank which produces the results.
SlidingBuffer is class template which can be used when reading a data stream to provide access to the...
std::size_t getBuflen(void)
Enquire the length of the data stored in the Producer&#39;s associated DetectorBank.
parameter_t getSR(void) const
Get the sample rate associated with this DetectorBank.
Definition: detectorcache.h:93
void set_num_samps(std::size_t n)
Set the block length (in samples) of each audio block which the Producer must generate.
Definition: detectorcache.h:82
std::size_t tell(void) const
Get the index of current input sample.
Definition: detectorbank.h:159
parameter_t getFreqIn(std::size_t ch)
Get the input frequency of a given channel&#39;s detector.