FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
dither.c File Reference

Dithered Audio Sample Quantization. More...

#include <math.h>
#include <stdint.h>
#include "libavutil/common.h"
#include "libavutil/lfg.h"
#include "libavutil/mem.h"
#include "libavutil/samplefmt.h"
#include "audio_convert.h"
#include "dither.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  DitherState
 
struct  DitherContext
 

Macros

#define MUTE_THRESHOLD_SEC   0.000333
 
#define S16_SCALE   32753.0f
 
#define LFG_SCALE   (1.0f / (2.0f * INT32_MAX))
 
#define SQRT_1_6   0.40824829046386301723f
 

Functions

static void dither_int_to_float_rectangular_c (float *dst, int *src, int len)
 
static void dither_int_to_float_triangular_c (float *dst, int *src0, int len)
 
static void quantize_c (int16_t *dst, const float *src, float *dither, int len)
 
static void dither_highpass_filter (float *src, int len)
 
static int generate_dither_noise (DitherContext *c, DitherState *state, int min_samples)
 
static void quantize_triangular_ns (DitherContext *c, DitherState *state, int16_t *dst, const float *src, int nb_samples)
 
static int convert_samples (DitherContext *c, int16_t **dst, float *const *src, int channels, int nb_samples)
 
int ff_convert_dither (DitherContext *c, AudioData *dst, AudioData *src)
 Convert audio sample format with dithering.
 
void ff_dither_free (DitherContext **cp)
 Free a DitherContext.
 
static void dither_init (DitherDSPContext *ddsp, enum AVResampleDitherMethod method)
 
DitherContextff_dither_alloc (AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map)
 Allocate and initialize a DitherContext.
 

Variables

static const float ns_48_coef_b [4]
 
static const float ns_48_coef_a [4]
 
static const float ns_44_coef_b [4]
 
static const float ns_44_coef_a [4]
 

Detailed Description

Dithered Audio Sample Quantization.

Converts from dbl, flt, or s32 to s16 using dithering.

Definition in file dither.c.

Macro Definition Documentation

#define MUTE_THRESHOLD_SEC   0.000333

Definition at line 77 of file dither.c.

Referenced by ff_dither_alloc().

#define S16_SCALE   32753.0f

Definition at line 81 of file dither.c.

Referenced by quantize_c(), and quantize_triangular_ns().

#define LFG_SCALE   (1.0f / (2.0f * INT32_MAX))

Definition at line 84 of file dither.c.

Referenced by dither_int_to_float_rectangular_c(), and dither_int_to_float_triangular_c().

#define SQRT_1_6   0.40824829046386301723f

Definition at line 130 of file dither.c.

Referenced by dither_highpass_filter().

Function Documentation

static void dither_int_to_float_rectangular_c ( float *  dst,
int *  src,
int  len 
)
static

Definition at line 104 of file dither.c.

Referenced by dither_init().

static void dither_int_to_float_triangular_c ( float *  dst,
int *  src0,
int  len 
)
static

Definition at line 111 of file dither.c.

Referenced by dither_init().

static void quantize_c ( int16_t *  dst,
const float *  src,
float *  dither,
int  len 
)
static

Definition at line 123 of file dither.c.

Referenced by dither_init(), and ff_convert_dither().

static void dither_highpass_filter ( float *  src,
int  len 
)
static

Definition at line 132 of file dither.c.

Referenced by generate_dither_noise().

static int generate_dither_noise ( DitherContext c,
DitherState state,
int  min_samples 
)
static

Definition at line 141 of file dither.c.

Referenced by convert_samples(), and ff_dither_alloc().

static void quantize_triangular_ns ( DitherContext c,
DitherState state,
int16_t *  dst,
const float *  src,
int  nb_samples 
)
static

Definition at line 171 of file dither.c.

Referenced by convert_samples().

static int convert_samples ( DitherContext c,
int16_t **  dst,
float *const *  src,
int  channels,
int  nb_samples 
)
static

Definition at line 210 of file dither.c.

Referenced by ff_convert_dither().

int ff_convert_dither ( DitherContext c,
AudioData dst,
AudioData src 
)

Convert audio sample format with dithering.

Parameters
cDitherContext
dstdestination audio data
srcsource audio data
Returns
0 if ok, negative AVERROR code on failure

Definition at line 241 of file dither.c.

void ff_dither_free ( DitherContext **  c)

Free a DitherContext.

Parameters
cDitherContext

Definition at line 311 of file dither.c.

Referenced by ff_dither_alloc().

static void dither_init ( DitherDSPContext ddsp,
enum AVResampleDitherMethod  method 
)
static

Definition at line 328 of file dither.c.

Referenced by ff_dither_alloc().

DitherContext* ff_dither_alloc ( AVAudioResampleContext avr,
enum AVSampleFormat  out_fmt,
enum AVSampleFormat  in_fmt,
int  channels,
int  sample_rate,
int  apply_map 
)

Allocate and initialize a DitherContext.

The parameters in the AVAudioResampleContext are used to initialize the DitherContext.

Parameters
avrAVAudioResampleContext
Returns
newly-allocated DitherContext

Definition at line 344 of file dither.c.

Variable Documentation

const float ns_48_coef_b[4]
static
Initial value:
= {
2.2374f, -0.7339f, -0.1251f, -0.6033f
}

Definition at line 88 of file dither.c.

Referenced by ff_dither_alloc().

const float ns_48_coef_a[4]
static
Initial value:
= {
0.9030f, 0.0116f, -0.5853f, -0.2571f
}

Definition at line 92 of file dither.c.

Referenced by ff_dither_alloc().

const float ns_44_coef_b[4]
static
Initial value:
= {
2.2061f, -0.4707f, -0.2534f, -0.6213f
}

Definition at line 96 of file dither.c.

Referenced by ff_dither_alloc().

const float ns_44_coef_a[4]
static
Initial value:
= {
1.0587f, 0.0676f, -0.6054f, -0.2738f
}

Definition at line 100 of file dither.c.

Referenced by ff_dither_alloc().