A Hopf, Skip and a Jump
Public Member Functions | Protected Attributes | List of all members
detectorcache::DetectorCache Class Reference

Cache results from a detectorbank. More...

#include <detectorcache.h>

Inheritance diagram for detectorcache::DetectorCache:
Inheritance graph
[legend]
Collaboration diagram for detectorcache::DetectorCache:
Collaboration graph
[legend]

Public Member Functions

 DetectorCache (Producer &p, const std::size_t num_segs, const std::size_t seg_len, const std::size_t start_chan, const std::size_t num_chans)
 Construct a DetectorCache. More...
 
 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. More...
 
result_t getResultItem (long int ch, long int n)
 Return the absolute value of the DetectorBank output at the given channel and sample time. More...
 
std::size_t getPreviousResults (const std::size_t chan, const std::size_t currentSample, result_t *samples, std::size_t numSamples)
 Efficiently copy a range of cached data from a given cache channel to the designated target. More...
 
std::size_t end (void)
 Get the total number of samples the cache can return. More...
 
parameter_t getSR (void) const
 Get the sample rate of the associtaed DetectorBank.
 
std::size_t getChans (void)
 Get the number of channels in the cache.
 
- Public Member Functions inherited from slidingbuffer::SlidingBuffer< result_t *, detectorcache::Segment, detectorcache::Producer >
 SlidingBuffer (detectorcache::Producer &sp, const std::size_t max_segs, const std::size_t seg_size)
 Create a SlidingBuffer. More...
 
virtual ~SlidingBuffer ()
 Destructor.
 
result_t * & operator[] (long int idx)
 Access an element of the SlidingBuffer. More...
 

Protected Attributes

const std::size_t chans
 Number of analysis channels.
 
const std::size_t seg_len
 Number of audio samples per segment.
 
Producerp
 This Producer for this DetectorCache.
 
const std::size_t start_chan
 Channel in DetectorBank at which to start.
 
- Protected Attributes inherited from slidingbuffer::SlidingBuffer< result_t *, detectorcache::Segment, detectorcache::Producer >
std::size_t origin
 Lowest index in buffer.
 
const std::size_t max_segs
 The largest number of segments in the buffer A history of at least \(seg_size\cdot(max_segs-1)\) entities will be made available subject to sufficient data having been read from the data stream.
 
const std::size_t seg_size
 The number of entities in each segment.
 
std::deque< detectorcache::Segment *, UniqueAllocator< detectorcache::Segment *> > segs
 Segments held by the buffer.
 
detectorcache::Producersp
 The producer to call to fill a segment.
 

Detailed Description

Cache results from a detectorbank.

Definition at line 168 of file detectorcache.h.

Constructor & Destructor Documentation

◆ DetectorCache() [1/2]

detectorcache::DetectorCache::DetectorCache ( Producer p,
const std::size_t  num_segs,
const std::size_t  seg_len,
const std::size_t  start_chan,
const std::size_t  num_chans 
)

Construct a DetectorCache.

Parameters
pThe segment producer for this cache.
num_segsNumber of historical segments to remember.
seg_lenNumber of audio samples per segment.
start_chanFirst channel for this cache.
num_chansNumber of channels in this cache.

◆ DetectorCache() [2/2]

detectorcache::DetectorCache::DetectorCache ( detectorcache::Producer p,
const std::size_t  num_segs,
const std::size_t  seg_len,
const std::size_t  start_chan = 0 
)
inline

Construct a DetectorCache with default start and size.

If the start channel parameter is omitted, assume 0. If the number of channels is omitted, use the value obtained by querying the supplied producer.

Definition at line 194 of file detectorcache.h.

Member Function Documentation

◆ end()

std::size_t detectorcache::DetectorCache::end ( void  )
inline

Get the total number of samples the cache can return.

Returns
Length of the associated DetectorBank's audio input buffer in samples.

Definition at line 256 of file detectorcache.h.

◆ getPreviousResults()

std::size_t detectorcache::DetectorCache::getPreviousResults ( const std::size_t  chan,
const std::size_t  currentSample,
result_t *  samples,
std::size_t  numSamples 
)

Efficiently copy a range of cached data from a given cache channel to the designated target.

The caller must allocate sufficient memory for the requested number of result_t data, and pass its address and the number of results desired. The supplied memory is filled with results from the detectorcache, ending at the given index.

This permits an external onset detecting algorithm to request the history of a detector channel once an onset threshold has been achieved in order to refine its estimate of the precise onset time.

Parameters
chanChannel for which to provide history
currentSampleIndex from which to roll back
samplesPointer to target storage
numSamplesNumber of samples to copy to target (currentSample being the last)
Returns
The number of samples actually copied.
Exceptions
slidingbuffer::ExpiredIndexExceptionIf the requested number of samples exceeds that in the cache.
See also
DetectorCacheDesign

◆ getResultItem()

result_t detectorcache::DetectorCache::getResultItem ( long int  ch,
long int  n 
)

Return the absolute value of the DetectorBank output at the given channel and sample time.

The sample time must be positive, and not be too old to have been deleted by the detectorcache.

If the sample time is negative, a slidingbuffer::NegativeIndexException will be thrown. This must be done explicitly here, as the DetectorCache is a 2D representation of a SlidingBuffer, where the channel is the SlidingBuffer index, so only a negative channel will result in a NegativeIndexException thrown by the SlidingBuffer itself.

If the sample time exceeds the length of the audio buffer, getResultItem will return 0.

Parameters
chChannel number of the output sample.
nSample's time-index.
Returns
The value of the detector's output at that time.
Exceptions
slidingbuffer::NegativeIndexExceptionIf n < 0

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