Go to the documentation of this file.
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
117 for (
i = 0;
i <
len;
i++) {
131 #define SQRT_1_6 0.40824829046386301723f
138 for (
i = 0;
i <
len - 2;
i++)
146 int nb_samples =
FFALIGN(min_samples, 16) + 16;
147 int buf_samples = nb_samples *
149 unsigned int *noise_buf_ui;
152 state->noise_buf_size =
state->noise_buf_ptr = 0;
155 if (!
state->noise_buf)
158 noise_buf_ui = (
unsigned int *)
state->noise_buf;
161 for (
i = 0;
i < buf_samples;
i++)
164 c->ddsp.dither_int_to_float(
state->noise_buf, noise_buf_ui, nb_samples);
173 int16_t *dst,
const float *
src,
179 if (
state->mute >
c->mute_reset_threshold)
180 memset(
state->dither_a, 0,
sizeof(
state->dither_a));
182 for (
i = 0;
i < nb_samples;
i++) {
186 for (j = 0; j < 4; j++) {
187 err +=
c->ns_coef_b[j] *
state->dither_b[j] -
188 c->ns_coef_a[j] *
state->dither_a[j];
190 for (j = 3; j > 0; j--) {
194 state->dither_a[0] = err;
197 if (
state->mute >
c->mute_dither_threshold) {
199 state->dither_b[0] = 0;
215 int aligned_samples =
FFALIGN(nb_samples, 16);
220 if (
state->noise_buf_size < aligned_samples) {
224 }
else if (
state->noise_buf_size -
state->noise_buf_ptr < aligned_samples) {
225 state->noise_buf_ptr = 0;
231 c->quantize(dst[ch],
src[ch],
233 FFALIGN(nb_samples,
c->samples_align));
236 state->noise_buf_ptr += aligned_samples;
262 flt_data =
c->flt_data;
270 }
else if (
c->apply_map) {
282 int aligned_len =
FFALIGN(
src->nb_samples,
c->ddsp.samples_align);
284 if (!(ptr_align %
c->ddsp.ptr_align) && samples_align >= aligned_len) {
285 c->quantize =
c->ddsp.quantize;
286 c->samples_align =
c->ddsp.samples_align;
289 c->samples_align = 1;
294 (
float *
const *)flt_data->
data,
src->channels,
299 c->s16_data->nb_samples =
src->nb_samples;
323 for (ch = 0; ch <
c->channels; ch++)
365 c->apply_map = apply_map;
372 "for triangular_ns dither. using triangular_hp instead.\n");
393 "dither s16 buffer");
405 "dither flt buffer");
424 c->mute_reset_threshold =
c->mute_dither_threshold * 4;
430 state->mute =
c->mute_reset_threshold + 1;
@ AV_SAMPLE_FMT_FLTP
float, planar
void ff_audio_convert_free(AudioConvert **ac)
Free AudioConvert.
#define AV_LOG_WARNING
Something somehow does not look correct.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
AudioData * ff_audio_data_alloc(int channels, int nb_samples, enum AVSampleFormat sample_fmt, const char *name)
Allocate AudioData.
static const float ns_48_coef_b[4]
uint8_t * data[AVRESAMPLE_MAX_CHANNELS]
data plane pointers
enum AVResampleDitherMethod method
void ff_audio_data_free(AudioData **a)
Free AudioData.
static int convert_samples(DitherContext *c, int16_t **dst, float *const *src, int channels, int nb_samples)
static void dither_int_to_float_rectangular_c(float *dst, int *src, int len)
Audio buffer used for intermediate storage between conversion phases.
ChannelMapInfo ch_map_info
void ff_dither_init_x86(DitherDSPContext *ddsp, enum AVResampleDitherMethod method)
static void quantize_c(int16_t *dst, const float *src, float *dither, int len)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int samples_align
allocated samples alignment
int ptr_align
src and dst constraints for quantize()
void(* quantize)(int16_t *dst, const float *src, float *dither, int len)
Convert samples from flt to s16 with added dither noise.
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
ChannelMapInfo * ch_map_info
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.
enum AVSampleFormat sample_fmt
sample format
void(* dither_int_to_float)(float *dst, int *src0, int len)
Convert dither noise from int to float with triangular distribution.
AV_RESAMPLE_DITHER_TRIANGULAR_NS
Triangular Dither with Noise Shaping.
void(* quantize)(int16_t *dst, const float *src, float *dither, int len)
int ptr_align
minimum data pointer alignment
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Context structure for the Lagged Fibonacci PRNG.
static const float ns_48_coef_a[4]
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.
static void dither_int_to_float_triangular_c(float *dst, int *src0, int len)
static void dither_highpass_filter(float *src, int len)
static const float ns_44_coef_b[4]
static void quantize_triangular_ns(DitherContext *c, DitherState *state, int16_t *dst, const float *src, int nb_samples)
int ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src)
Convert audio sample format with dithering.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
enum AVResampleDitherMethod dither_method
dither method
static av_cold void dither_init(DitherDSPContext *ddsp, enum AVResampleDitherMethod method)
int samples_align
len constraints for quantize()
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16
signed 16 bits
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int ff_audio_data_realloc(AudioData *a, int nb_samples)
Reallocate AudioData.
int mute_dither_threshold
AV_RESAMPLE_DITHER_RECTANGULAR
Rectangular Dither.
enum attribute_deprecated AVResampleDitherMethod
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
#define MUTE_THRESHOLD_SEC
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.
AV_RESAMPLE_DITHER_TRIANGULAR_HP
Triangular Dither with High Pass.
void ff_dither_free(DitherContext **cp)
Free a DitherContext.
static int generate_dither_noise(DitherContext *c, DitherState *state, int min_samples)
int ff_audio_data_copy(AudioData *dst, AudioData *src, ChannelMapInfo *map)
Copy data from one AudioData to another.
int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in)
Convert audio data from one sample format to another.
static const float ns_44_coef_a[4]
static const uint8_t dither[8][8]