A Hopf, Skip and a Jump
|
Cache results from a detectorbank. More...
#include <detectorcache.h>
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. | |
Producer & | p |
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::Producer & | sp |
The producer to call to fill a segment. | |
Cache results from a detectorbank.
Definition at line 168 of file detectorcache.h.
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.
p | The segment producer for this cache. |
num_segs | Number of historical segments to remember. |
seg_len | Number of audio samples per segment. |
start_chan | First channel for this cache. |
num_chans | Number of channels in this cache. |
|
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.
|
inline |
Get the total number of samples the cache can return.
Definition at line 256 of file detectorcache.h.
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.
chan | Channel for which to provide history |
currentSample | Index from which to roll back |
samples | Pointer to target storage |
numSamples | Number of samples to copy to target (currentSample being the last) |
slidingbuffer::ExpiredIndexException | If the requested number of samples exceeds that in the cache. |
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.
ch | Channel number of the output sample. |
n | Sample's time-index. |
slidingbuffer::NegativeIndexException | If n < 0 |