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--) {
215 int aligned_samples =
FFALIGN(nb_samples, 16);
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");
AV_RESAMPLE_DITHER_TRIANGULAR_HP
Triangular Dither with High Pass.
Context structure for the Lagged Fibonacci PRNG.
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.
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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void(* quantize)(int16_t *dst, const float *src, float *dither, int len)
Macro definitions for various function/variable attributes.
int nb_samples
current number of samples
static void dither_int_to_float_rectangular_c(float *dst, int *src, int len)
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
void(* quantize)(int16_t *dst, const float *src, float *dither, int len)
Convert samples from flt to s16 with added dither noise.
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)
AV_RESAMPLE_DITHER_TRIANGULAR_NS
Triangular Dither with Noise Shaping.
enum AVResampleDitherMethod dither_method
dither method
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ptr_align
src and dst constraints for quantize()
int channels
channel count
static const uint8_t dither[8][8]
void(* dither_int_to_float)(float *dst, int *src0, int len)
Convert dither noise from int to float with triangular distribution.
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 constraints 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)
enum attribute_deprecated AVResampleDitherMethod
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.
AV_RESAMPLE_DITHER_RECTANGULAR
Rectangular Dither.
static int quantize(CinepakEncContext *s, int h, uint8_t *data[4], int linesize[4], int v1mode, strip_info *info, mb_encoding encoding)
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
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
ChannelMapInfo * ch_map_info
#define MUTE_THRESHOLD_SEC