/*1* Copyright (c) 2012 Justin Ruggles <[email protected]>2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920#ifndef AVRESAMPLE_DITHER_H21#define AVRESAMPLE_DITHER_H2223#include "avresample.h"24#include "audio_data.h"2526typedef struct DitherContext DitherContext;2728typedef struct DitherDSPContext {29/**30* Convert samples from flt to s16 with added dither noise.31*32* @param dst destination float array, range -0.5 to 0.533* @param src source int array, range INT_MIN to INT_MAX.34* @param dither float dither noise array35* @param len number of samples36*/37void (*quantize)(int16_t *dst, const float *src, float *dither, int len);3839int ptr_align; ///< src and dst constraits for quantize()40int samples_align; ///< len constraits for quantize()4142/**43* Convert dither noise from int to float with triangular distribution.44*45* @param dst destination float array, range -0.5 to 0.546* constraints: 32-byte aligned47* @param src0 source int array, range INT_MIN to INT_MAX.48* the array size is len * 249* constraints: 32-byte aligned50* @param len number of output noise samples51* constraints: multiple of 1652*/53void (*dither_int_to_float)(float *dst, int *src0, int len);54} DitherDSPContext;5556/**57* Allocate and initialize a DitherContext.58*59* The parameters in the AVAudioResampleContext are used to initialize the60* DitherContext.61*62* @param avr AVAudioResampleContext63* @return newly-allocated DitherContext64*/65DitherContext *ff_dither_alloc(AVAudioResampleContext *avr,66enum AVSampleFormat out_fmt,67enum AVSampleFormat in_fmt,68int channels, int sample_rate, int apply_map);6970/**71* Free a DitherContext.72*73* @param c DitherContext74*/75void ff_dither_free(DitherContext **c);7677/**78* Convert audio sample format with dithering.79*80* @param c DitherContext81* @param dst destination audio data82* @param src source audio data83* @return 0 if ok, negative AVERROR code on failure84*/85int ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src);8687/* arch-specific initialization functions */8889void ff_dither_init_x86(DitherDSPContext *ddsp,90enum AVResampleDitherMethod method);9192#endif /* AVRESAMPLE_DITHER_H */939495