yading@11: /* yading@11: * Copyright (c) 2012 Justin Ruggles yading@11: * yading@11: * This file is part of Libav. yading@11: * yading@11: * Libav is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * Libav is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with Libav; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVRESAMPLE_DITHER_H yading@11: #define AVRESAMPLE_DITHER_H yading@11: yading@11: #include "avresample.h" yading@11: #include "audio_data.h" yading@11: yading@11: typedef struct DitherContext DitherContext; yading@11: yading@11: typedef struct DitherDSPContext { yading@11: /** yading@11: * Convert samples from flt to s16 with added dither noise. yading@11: * yading@11: * @param dst destination float array, range -0.5 to 0.5 yading@11: * @param src source int array, range INT_MIN to INT_MAX. yading@11: * @param dither float dither noise array yading@11: * @param len number of samples yading@11: */ yading@11: void (*quantize)(int16_t *dst, const float *src, float *dither, int len); yading@11: yading@11: int ptr_align; ///< src and dst constraits for quantize() yading@11: int samples_align; ///< len constraits for quantize() yading@11: yading@11: /** yading@11: * Convert dither noise from int to float with triangular distribution. yading@11: * yading@11: * @param dst destination float array, range -0.5 to 0.5 yading@11: * constraints: 32-byte aligned yading@11: * @param src0 source int array, range INT_MIN to INT_MAX. yading@11: * the array size is len * 2 yading@11: * constraints: 32-byte aligned yading@11: * @param len number of output noise samples yading@11: * constraints: multiple of 16 yading@11: */ yading@11: void (*dither_int_to_float)(float *dst, int *src0, int len); yading@11: } DitherDSPContext; yading@11: yading@11: /** yading@11: * Allocate and initialize a DitherContext. yading@11: * yading@11: * The parameters in the AVAudioResampleContext are used to initialize the yading@11: * DitherContext. yading@11: * yading@11: * @param avr AVAudioResampleContext yading@11: * @return newly-allocated DitherContext yading@11: */ yading@11: DitherContext *ff_dither_alloc(AVAudioResampleContext *avr, yading@11: enum AVSampleFormat out_fmt, yading@11: enum AVSampleFormat in_fmt, yading@11: int channels, int sample_rate, int apply_map); yading@11: yading@11: /** yading@11: * Free a DitherContext. yading@11: * yading@11: * @param c DitherContext yading@11: */ yading@11: void ff_dither_free(DitherContext **c); yading@11: yading@11: /** yading@11: * Convert audio sample format with dithering. yading@11: * yading@11: * @param c DitherContext yading@11: * @param dst destination audio data yading@11: * @param src source audio data yading@11: * @return 0 if ok, negative AVERROR code on failure yading@11: */ yading@11: int ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src); yading@11: yading@11: /* arch-specific initialization functions */ yading@11: yading@11: void ff_dither_init_x86(DitherDSPContext *ddsp, yading@11: enum AVResampleDitherMethod method); yading@11: yading@11: #endif /* AVRESAMPLE_DITHER_H */