LMMS
Loading...
Searching...
No Matches
shaping_clipper Class Reference

#include <shaping_clipper.h>

Public Member Functions

 shaping_clipper (int sample_rate, int fft_size, float clip_level=16384)
 ~shaping_clipper ()
void feed (const float *in_smaples, float *out_samples, bool diff_only=false, float *total_margin_shift=NULL)
int get_feed_size ()
void set_clip_level (float clip_level)
void set_iterations (int iterations)
void set_adaptive_distortion_strength (float strength)
void set_margin_curve (int points[][2], int num_points)

Private Member Functions

void generate_hann_window ()
void generate_spread_table ()
void apply_window (const float *in_frame, float *out_frame, const bool add_to_out_frame=false)
void clip_to_window (const float *windowed_frame, float *clipping_delta, float delta_boost=1.0)
void calculate_mask_curve (const float *spectrum, float *mask_curve)
void limit_clip_spectrum (float *clip_spectrum, const float *mask_curve)

Private Attributes

int size
int overlap
int num_psy_bins
PFFFT_Setuppffft
float sample_rate
float clip_level
float iterations
float adaptive_distortion_strength
std::vector< float > in_frame
std::vector< float > out_dist_frame
std::vector< float > margin_curve
std::vector< float > window
std::vector< float > inv_window
std::vector< float > spread_table
std::vector< intspread_table_index
std::vector< std::pair< int, int > > spread_table_range

Constructor & Destructor Documentation

◆ shaping_clipper()

shaping_clipper::shaping_clipper ( int sample_rate,
int fft_size,
float clip_level = 16384 )

sample_rate is only used to generate the margin_curve. fftSize should be a multiple of 4. clip_level means symmetric clipping from -clip_level to +clip_level

◆ ~shaping_clipper()

shaping_clipper::~shaping_clipper ( )

Member Function Documentation

◆ apply_window()

void shaping_clipper::apply_window ( const float * in_frame,
float * out_frame,
const bool add_to_out_frame = false )
private

Applies the window to the in_frame and store the result in the out_frame If add_to_out_frame is true, the results is added to the out_frame instead

◆ calculate_mask_curve()

void shaping_clipper::calculate_mask_curve ( const float * spectrum,
float * mask_curve )
private

Calculates the original signal level considering psychoacoustic masking. mask_curve is in linear scale.

◆ clip_to_window()

void shaping_clipper::clip_to_window ( const float * windowed_frame,
float * clipping_delta,
float delta_boost = 1.0 )
private

Clips the windowed_frame to the window scaled by the clip_level. The clipping distortion is multiplied by delta_boost The existing values in clipping_delta is applied to the windowed_frame to get the effective sample values, taking previous clipping iterations into account. Should only be used with windowed input

◆ feed()

void shaping_clipper::feed ( const float * in_smaples,
float * out_samples,
bool diff_only = false,
float * total_margin_shift = NULL )

Put fftSize/4 samples in in_smaples and get fftSize/4 samples out in out_samples. The output in out_samples corresponds to the input 3 calls ago. total_margin_shift is an optional parameter that can be used to get the total margin adjustment in the frame

◆ generate_hann_window()

void shaping_clipper::generate_hann_window ( )
private

Generate the Hann window and inverse window.

◆ generate_spread_table()

void shaping_clipper::generate_spread_table ( )
private

Generate the spreading functions used by calculate_mask_curve The spread_table contains entries of size/2 values each. To save memory, only 2 entries are stored per octave, and each entry is shared by a range of bins. The spread scale proportionally with frequency. The spread_table entries are normalized to add up to 1.

Eacn entry is centred, meaning the num_psy_bins/2'th value is the peak of the tent-shaped function.

◆ get_feed_size()

int shaping_clipper::get_feed_size ( )

Returns fftSize/4

◆ limit_clip_spectrum()

void shaping_clipper::limit_clip_spectrum ( float * clip_spectrum,
const float * mask_curve )
private

Limit the magnitude of each bin to the mask_curve

◆ set_adaptive_distortion_strength()

void shaping_clipper::set_adaptive_distortion_strength ( float strength)

Set the adaptive distortion strength. The adaptive distortion strength affects how easily the clipper gives up distortion control to reach the clip level target.

◆ set_clip_level()

void shaping_clipper::set_clip_level ( float clip_level)

Set the clipping level in sample value

◆ set_iterations()

void shaping_clipper::set_iterations ( int iterations)

Set the number of clipping iterations. Setting iterations to 0 effectively works as a bypass.

◆ set_margin_curve()

void shaping_clipper::set_margin_curve ( int points[][2],
int num_points )

Sets the margin_curve from a list of (Hz, dB) tuples. The curve is linearly interpolated between the points The first point must be at 0Hz. margin_curve represents the minimum ratio between the clean input and the clipping distortion at each frequency

Member Data Documentation

◆ adaptive_distortion_strength

float shaping_clipper::adaptive_distortion_strength
private

◆ clip_level

float shaping_clipper::clip_level
private

◆ in_frame

std::vector<float> shaping_clipper::in_frame
private

in_frame: unmodified input audio out_dist_frame: clipping distortion multiplied by 1.5. The 1.5 factor is due to overlap and add. margin_curve: see generateMarginCurve window: the Hann window inv_window: inverse of the Hann window used to calculate the unwindowed peak spread_table: see generate_spread_table

◆ inv_window

std::vector<float> shaping_clipper::inv_window
private

◆ iterations

float shaping_clipper::iterations
private

◆ margin_curve

std::vector<float> shaping_clipper::margin_curve
private

◆ num_psy_bins

int shaping_clipper::num_psy_bins
private

◆ out_dist_frame

std::vector<float> shaping_clipper::out_dist_frame
private

◆ overlap

int shaping_clipper::overlap
private

◆ pffft

PFFFT_Setup* shaping_clipper::pffft
private

◆ sample_rate

float shaping_clipper::sample_rate
private

◆ size

int shaping_clipper::size
private

◆ spread_table

std::vector<float> shaping_clipper::spread_table
private

◆ spread_table_index

std::vector<int> shaping_clipper::spread_table_index
private

spreadtableIndex: for each bin, which entry in the spread table to use (eacn entry is num_psy_bins values) spread_table_range: for each entry in the spread table, what is the range of bins (ie. -2 to +4) that are non-zero

◆ spread_table_range

std::vector<std::pair<int, int> > shaping_clipper::spread_table_range
private

◆ window

std::vector<float> shaping_clipper::window
private

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