Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::audio::DecimationResampler Class Reference

Decimating resampler. More...

#include <decimation_resampler.h>

Inheritance diagram for roc::audio::DecimationResampler:
Collaboration diagram for roc::audio::DecimationResampler:

Public Member Functions

 DecimationResampler (const core::SharedPtr< IResampler > &inner_resampler, core::IArena &arena, FrameFactory &frame_factory, const SampleSpec &in_spec, const SampleSpec &out_spec)
 Initialize. More...
 
virtual bool is_valid () const
 Check if object is successfully constructed. More...
 
virtual bool set_scaling (size_t input_rate, size_t output_rate, float multiplier)
 Set new resample factor. More...
 
virtual const core::Slice< sample_t > & begin_push_input ()
 Get buffer to be filled with input data. More...
 
virtual void end_push_input ()
 Commit buffer with input data. More...
 
virtual size_t pop_output (sample_t *out_data, size_t out_size)
 Read samples from input frame and fill output frame. More...
 
virtual float n_left_to_process () const
 How many samples were pushed but not processed yet. More...
 
- Public Member Functions inherited from roc::audio::IResampler
 IResampler (core::IArena &arena)
 Initialization. More...
 
virtual ~IResampler ()
 Deinitialization. More...
 
- Public Member Functions inherited from roc::core::RefCounted< IResampler, core::ArenaAllocation >
 RefCounted ()
 Initialize. More...
 
 RefCounted (const core::ArenaAllocation &policy)
 Initialize. More...
 
int getref () const
 Get reference counter. More...
 
void incref () const
 Increment reference counter. More...
 
void decref () const
 Decrement reference counter. More...
 

Additional Inherited Members

- Protected Member Functions inherited from roc::core::ArenaAllocation
IArenaarena () const
 Get arena. More...
 
 ArenaAllocation (IArena &arena)
 Initialize. More...
 
template<class T >
void destroy (T &object)
 Destroy object and return memory to arena. More...
 

Detailed Description

Decimating resampler.

Acts as decorator for another resampler instance.

Performs resampling in two stages:

  • first, uses underlying resampler to apply constant part of scaling factor based on input and output rates; if these rates are equal, first stage is skipped
  • then, uses decimation or duplication to apply dynamic part of scaling factor, a.k.a. multiplier, by dropping or duplicating samples

When input and output rates are the same, this backend implements fastest possible resampling algorithm working almost at the speed of memcpy().

Although decimation usually degrades quality a lot, it's not so dramatic in this specific case because we use it only for dynamic part of scaling factor, which in practice is very close to 1.0, and typically we remove or insert up to 20 samples per second or so on 48kHz, which corresponds to ~ 0.4ms/second.

When input and output rates are different, this backend uses another, underlying resampler, but only for converting between input and output rates. It still uses decimation or duplication for applying dynamic part of scaling factor.

Definition at line 50 of file decimation_resampler.h.

Constructor & Destructor Documentation

◆ DecimationResampler()

roc::audio::DecimationResampler::DecimationResampler ( const core::SharedPtr< IResampler > &  inner_resampler,
core::IArena arena,
FrameFactory frame_factory,
const SampleSpec in_spec,
const SampleSpec out_spec 
)

Initialize.

Member Function Documentation

◆ begin_push_input()

virtual const core::Slice<sample_t>& roc::audio::DecimationResampler::begin_push_input ( )
virtual

Get buffer to be filled with input data.

Implements roc::audio::IResampler.

◆ end_push_input()

virtual void roc::audio::DecimationResampler::end_push_input ( )
virtual

Commit buffer with input data.

Implements roc::audio::IResampler.

◆ is_valid()

virtual bool roc::audio::DecimationResampler::is_valid ( ) const
virtual

Check if object is successfully constructed.

Implements roc::audio::IResampler.

◆ n_left_to_process()

virtual float roc::audio::DecimationResampler::n_left_to_process ( ) const
virtual

How many samples were pushed but not processed yet.

Implements roc::audio::IResampler.

◆ pop_output()

virtual size_t roc::audio::DecimationResampler::pop_output ( sample_t out_data,
size_t  out_size 
)
virtual

Read samples from input frame and fill output frame.

Implements roc::audio::IResampler.

◆ set_scaling()

virtual bool roc::audio::DecimationResampler::set_scaling ( size_t  input_rate,
size_t  output_rate,
float  multiplier 
)
virtual

Set new resample factor.

Implements roc::audio::IResampler.


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