78 #define MUTE_THRESHOLD_SEC 0.000333
82 #define S16_SCALE 32753.0f
85 #define LFG_SCALE (1.0f / (2.0f * INT32_MAX))
90 2.2374f, -0.7339f, -0.1251f, -0.6033f
94 0.9030f, 0.0116f, -0.5853f, -0.2571f
98 2.2061f, -0.4707f, -0.2534f, -0.6213f
102 1.0587f, 0.0676f, -0.6054f, -0.2738f
108 for (i = 0; i <
len; i++)
117 for (i = 0; i <
len; i++) {
127 for (i = 0; i <
len; i++)
131 #define SQRT_1_6 0.40824829046386301723f
138 for (i = 0; i < len - 2; i++)
139 src[i] = (-src[i] + 2 * src[i + 1] - src[i + 2]) *
SQRT_1_6;
146 int nb_samples =
FFALIGN(min_samples, 16) + 16;
147 int buf_samples = nb_samples *
149 unsigned int *noise_buf_ui;
158 noise_buf_ui = (
unsigned int *)state->
noise_buf;
161 for (i = 0; i < buf_samples; i++)
173 int16_t *dst,
const float *
src,
182 for (i = 0; i < nb_samples; i++) {
186 for (j = 0; j < 4; j++) {
190 for (j = 3; j > 0; j--) {
198 dst[i] = av_clip_int16(
lrintf(sample));
201 dst[i] = av_clip_int16(
lrintf(sample + dither[i]));
202 state->
dither_b[0] = av_clipf(dst[i] - sample, -1.5f, 1.5f);
212 int channels,
int nb_samples)
215 int aligned_samples =
FFALIGN(nb_samples, 16);
217 for (ch = 0; ch < channels; ch++) {
284 if (!(ptr_align % c->
ddsp.
ptr_align) && samples_align >= aligned_len) {
323 for (ch = 0; ch < c->
channels; ch++)
370 sample_rate != 48000 && sample_rate != 44100) {
372 "for triangular_ns dither. using triangular_hp instead.\n");
379 if (sample_rate == 48000) {
393 "dither s16 buffer");
398 channels, sample_rate, 0);
405 "dither flt buffer");
428 for (ch = 0; ch < channels; ch++) {
void ff_dither_free(DitherContext **cp)
Free a DitherContext.
int ff_audio_data_realloc(AudioData *a, int nb_samples)
Reallocate AudioData.
static const float ns_48_coef_b[4]
Audio buffer used for intermediate storage between conversion phases.
static int generate_dither_noise(DitherContext *c, DitherState *state, int min_samples)
enum AVResampleDitherMethod method
#define AV_LOG_WARNING
Something somehow does not look correct.
memory handling functions
AudioData * ff_audio_data_alloc(int channels, int nb_samples, enum AVSampleFormat sample_fmt, const char *name)
Allocate AudioData.
void(* quantize)(int16_t *dst, const float *src, float *dither, int len)
static const float ns_44_coef_a[4]
int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in)
Convert audio data from one sample format to another.
Macro definitions for various function/variable attributes.
int nb_samples
current number of samples
Triangular Dither with Noise Shaping.
Triangular Dither with High Pass.
static void dither_int_to_float_rectangular_c(float *dst, int *src, int len)
AudioConvert * ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map)
Allocate and initialize AudioConvert context for sample format conversion.
static int convert_samples(DitherContext *c, int16_t **dst, float *const *src, int channels, int nb_samples)
static void quantize_c(int16_t *dst, const float *src, float *dither, int len)
enum AVResampleDitherMethod dither_method
dither method
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ptr_align
src and dst constraits for quantize()
int channels
channel count
static const uint8_t dither[8][8]
void ff_audio_convert_free(AudioConvert **ac)
Free AudioConvert.
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
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.
int ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src)
Convert audio sample format with dithering.
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
ChannelMapInfo ch_map_info
static const float ns_48_coef_a[4]
static const float ns_44_coef_b[4]
int samples_align
len constraits for quantize()
int mute_dither_threshold
AVSampleFormat
Audio sample formats.
uint8_t * data[AVRESAMPLE_MAX_CHANNELS]
data plane pointers
static void dither_highpass_filter(float *src, int len)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static void quantize_triangular_ns(DitherContext *c, DitherState *state, int16_t *dst, const float *src, int nb_samples)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static void dither_int_to_float_triangular_c(float *dst, int *src0, int len)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
int samples_align
allocated samples alignment
int ff_audio_data_copy(AudioData *dst, AudioData *src, ChannelMapInfo *map)
Copy data from one AudioData to another.
static av_cold void dither_init(DitherDSPContext *ddsp, enum AVResampleDitherMethod method)
common internal and external API header
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
void(* dither_int_to_float)(float *dst, int *src0, int len)
Convert dither noise from int to float with triangular distribution.
enum AVSampleFormat sample_fmt
sample format
void ff_audio_data_free(AudioData **a)
Free AudioData.
void ff_dither_init_x86(DitherDSPContext *ddsp, enum AVResampleDitherMethod method)
int ptr_align
minimum data pointer alignment
ChannelMapInfo * ch_map_info
void(* quantize)(int16_t *dst, const float *src, float *dither, int len)
Convert samples from flt to s16 with added dither noise.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define MUTE_THRESHOLD_SEC