DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::detail::SampleReader< T > Class Template Reference

One voice's position in a zone and its band-limited read. More...

#include <SampleReader.h>

Public Types

enum class  Frame { Ended , Produced , Last }
 What one call produced. More...
 

Public Member Functions

void allocate ()
 Allocates the scatter accumulators (setup thread).
 
void start (const SampleZoneData< T > &z, double ratio) noexcept
 Starts reading a zone from its start offset. A reader that starts above the recording's rate (ratio > 1) scatters for the rest of the note, otherwise it gathers.
 
void release () noexcept
 The key is released: a Sustain loop plays on past its end.
 
bool scatters () const noexcept
 True when this reader scatters (it started above the recording's rate).
 
double minRate () const noexcept
 Lowest rate next() accepts for this reader.
 
const SampleZoneData< T > * zone () const noexcept
 The zone being read (null before start()).
 
Frame next (double ratio, int outChannels, T *weights, double &a0, double &a1) noexcept
 One output frame at ratio recording samples per output sample.
 

Static Public Member Functions

static const std::vector< double > & kernelTable ()
 
static const std::vector< T > & polyphaseTable ()
 

Static Public Attributes

static constexpr int kHalfTaps = 32
 Zero crossings on each side of the kernel at unit rate: 64 taps.
 
static constexpr int kTablePerUnit = 2048
 Table points per zero crossing (linear interpolation between them).
 
static constexpr double kMaxRate = 8.0
 Highest playback rate; the kernel then spans 8 x 64 taps.
 
static constexpr double kMinScatterRate = 1.0 / kMaxRate
 Lowest rate of the scatter form, whose kernel widens as the rate falls.
 
static constexpr double kMinGatherRate = 1.0 / 8192.0
 
static constexpr int kMaxHalfTaps = static_cast<int>(kHalfTaps * kMaxRate)
 
static constexpr double kCutoff = 0.9
 
static constexpr double kBeta = 10.06
 
static constexpr int kPhases = 2048
 Phases of the unit-rate polyphase table (rows interpolated linearly).
 
static constexpr int kTaps = 2 * kHalfTaps
 
static constexpr int kWeightsLength = 2 * kMaxHalfTaps + 2
 Scratch weights a caller provides to next().
 
static constexpr int kAccLength = 4 * kMaxHalfTaps + 256
 

Detailed Description

template<FloatType T>
class dspark::detail::SampleReader< T >

One voice's position in a zone and its band-limited read.

Definition at line 284 of file SampleReader.h.

Member Enumeration Documentation

◆ Frame

template<FloatType T>
enum class dspark::detail::SampleReader::Frame
strong

What one call produced.

Enumerator
Ended 

The zone ended before this sample: nothing produced.

Produced 

A frame was produced.

Last 

A frame was produced and it was the last one.

Definition at line 313 of file SampleReader.h.

Member Function Documentation

◆ allocate()

template<FloatType T>
void dspark::detail::SampleReader< T >::allocate ( )
inline

Allocates the scatter accumulators (setup thread).

Definition at line 376 of file SampleReader.h.

◆ kernelTable()

template<FloatType T>
static const std::vector< double > & dspark::detail::SampleReader< T >::kernelTable ( )
inlinestatic

Kernel h(t) for t >= 0 in zero crossings, sampled kTablePerUnit per unit.

Definition at line 321 of file SampleReader.h.

◆ minRate()

template<FloatType T>
double dspark::detail::SampleReader< T >::minRate ( ) const
inlinenoexcept

Lowest rate next() accepts for this reader.

Definition at line 414 of file SampleReader.h.

◆ next()

template<FloatType T>
Frame dspark::detail::SampleReader< T >::next ( double  ratio,
int  outChannels,
T *  weights,
double &  a0,
double &  a1 
)
inlinenoexcept

One output frame at ratio recording samples per output sample.

Parameters
ratioPlayback rate, within [minRate(), kMaxRate].
outChannelsOutput channels: 1 mixes the zone's channels to one, 2 or more read its first two.
weightsScratch of kWeightsLength values.
a0The frame's first (or only) channel.
a1The frame's second channel; not meaningful for one output channel or a mono zone, where a0 is used.

Definition at line 430 of file SampleReader.h.

◆ polyphaseTable()

template<FloatType T>
static const std::vector< T > & dspark::detail::SampleReader< T >::polyphaseTable ( )
inlinestatic

The unit-rate kernel as rows: row q holds the 64 tap weights for a fractional position q / kPhases, taps k = -31 .. 32 at distance k - frac. A voice at or below the recording's rate blends two adjacent rows, which is the same kernel as the scalar table read tap by tap, laid out so the blend and the dot products run over contiguous memory.

Definition at line 357 of file SampleReader.h.

◆ release()

template<FloatType T>
void dspark::detail::SampleReader< T >::release ( )
inlinenoexcept

The key is released: a Sustain loop plays on past its end.

Definition at line 405 of file SampleReader.h.

◆ scatters()

template<FloatType T>
bool dspark::detail::SampleReader< T >::scatters ( ) const
inlinenoexcept

True when this reader scatters (it started above the recording's rate).

Definition at line 411 of file SampleReader.h.

◆ start()

template<FloatType T>
void dspark::detail::SampleReader< T >::start ( const SampleZoneData< T > &  z,
double  ratio 
)
inlinenoexcept

Starts reading a zone from its start offset. A reader that starts above the recording's rate (ratio > 1) scatters for the rest of the note, otherwise it gathers.

Definition at line 386 of file SampleReader.h.

◆ zone()

template<FloatType T>
const SampleZoneData< T > * dspark::detail::SampleReader< T >::zone ( ) const
inlinenoexcept

The zone being read (null before start()).

Definition at line 417 of file SampleReader.h.

Member Data Documentation

◆ kAccLength

template<FloatType T>
constexpr int dspark::detail::SampleReader< T >::kAccLength = 4 * kMaxHalfTaps + 256
staticconstexpr

Scatter accumulator per channel: room for the widest kernel plus a stretch of output before it slides back.

Definition at line 310 of file SampleReader.h.

◆ kBeta

template<FloatType T>
constexpr double dspark::detail::SampleReader< T >::kBeta = 10.06
staticconstexpr

Definition at line 302 of file SampleReader.h.

◆ kCutoff

template<FloatType T>
constexpr double dspark::detail::SampleReader< T >::kCutoff = 0.9
staticconstexpr

Cutoff at 0.45 of the sample rate (normalised to Nyquist): passband to 0.40, stopband from 0.50, the width a 64-tap Kaiser needs for 100 dB.

Definition at line 301 of file SampleReader.h.

◆ kHalfTaps

template<FloatType T>
constexpr int dspark::detail::SampleReader< T >::kHalfTaps = 32
staticconstexpr

Zero crossings on each side of the kernel at unit rate: 64 taps.

Definition at line 288 of file SampleReader.h.

◆ kMaxHalfTaps

template<FloatType T>
constexpr int dspark::detail::SampleReader< T >::kMaxHalfTaps = static_cast<int>(kHalfTaps * kMaxRate)
staticconstexpr

Definition at line 298 of file SampleReader.h.

◆ kMaxRate

template<FloatType T>
constexpr double dspark::detail::SampleReader< T >::kMaxRate = 8.0
staticconstexpr

Highest playback rate; the kernel then spans 8 x 64 taps.

Definition at line 292 of file SampleReader.h.

◆ kMinGatherRate

template<FloatType T>
constexpr double dspark::detail::SampleReader< T >::kMinGatherRate = 1.0 / 8192.0
staticconstexpr

Lowest rate of the gather form, whose kernel keeps its width: only a guard against a stopped read, 13 octaves down.

Definition at line 297 of file SampleReader.h.

◆ kMinScatterRate

template<FloatType T>
constexpr double dspark::detail::SampleReader< T >::kMinScatterRate = 1.0 / kMaxRate
staticconstexpr

Lowest rate of the scatter form, whose kernel widens as the rate falls.

Definition at line 294 of file SampleReader.h.

◆ kPhases

template<FloatType T>
constexpr int dspark::detail::SampleReader< T >::kPhases = 2048
staticconstexpr

Phases of the unit-rate polyphase table (rows interpolated linearly).

Definition at line 304 of file SampleReader.h.

◆ kTablePerUnit

template<FloatType T>
constexpr int dspark::detail::SampleReader< T >::kTablePerUnit = 2048
staticconstexpr

Table points per zero crossing (linear interpolation between them).

Definition at line 290 of file SampleReader.h.

◆ kTaps

template<FloatType T>
constexpr int dspark::detail::SampleReader< T >::kTaps = 2 * kHalfTaps
staticconstexpr

Definition at line 305 of file SampleReader.h.

◆ kWeightsLength

template<FloatType T>
constexpr int dspark::detail::SampleReader< T >::kWeightsLength = 2 * kMaxHalfTaps + 2
staticconstexpr

Scratch weights a caller provides to next().

Definition at line 307 of file SampleReader.h.


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