1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com> 3cabdff1aSopenharmony_ci * 4cabdff1aSopenharmony_ci * This file is part of FFmpeg. 5cabdff1aSopenharmony_ci * 6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 7cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 8cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 9cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 10cabdff1aSopenharmony_ci * 11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14cabdff1aSopenharmony_ci * Lesser General Public License for more details. 15cabdff1aSopenharmony_ci * 16cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 17cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 18cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19cabdff1aSopenharmony_ci */ 20cabdff1aSopenharmony_ci 21cabdff1aSopenharmony_ci#ifndef AVRESAMPLE_DITHER_H 22cabdff1aSopenharmony_ci#define AVRESAMPLE_DITHER_H 23cabdff1aSopenharmony_ci 24cabdff1aSopenharmony_ci#include "avresample.h" 25cabdff1aSopenharmony_ci#include "audio_data.h" 26cabdff1aSopenharmony_ci 27cabdff1aSopenharmony_citypedef struct DitherContext DitherContext; 28cabdff1aSopenharmony_ci 29cabdff1aSopenharmony_citypedef struct DitherDSPContext { 30cabdff1aSopenharmony_ci /** 31cabdff1aSopenharmony_ci * Convert samples from flt to s16 with added dither noise. 32cabdff1aSopenharmony_ci * 33cabdff1aSopenharmony_ci * @param dst destination float array, range -0.5 to 0.5 34cabdff1aSopenharmony_ci * @param src source int array, range INT_MIN to INT_MAX. 35cabdff1aSopenharmony_ci * @param dither float dither noise array 36cabdff1aSopenharmony_ci * @param len number of samples 37cabdff1aSopenharmony_ci */ 38cabdff1aSopenharmony_ci void (*quantize)(int16_t *dst, const float *src, float *dither, int len); 39cabdff1aSopenharmony_ci 40cabdff1aSopenharmony_ci int ptr_align; ///< src and dst constraints for quantize() 41cabdff1aSopenharmony_ci int samples_align; ///< len constraints for quantize() 42cabdff1aSopenharmony_ci 43cabdff1aSopenharmony_ci /** 44cabdff1aSopenharmony_ci * Convert dither noise from int to float with triangular distribution. 45cabdff1aSopenharmony_ci * 46cabdff1aSopenharmony_ci * @param dst destination float array, range -0.5 to 0.5 47cabdff1aSopenharmony_ci * constraints: 32-byte aligned 48cabdff1aSopenharmony_ci * @param src0 source int array, range INT_MIN to INT_MAX. 49cabdff1aSopenharmony_ci * the array size is len * 2 50cabdff1aSopenharmony_ci * constraints: 32-byte aligned 51cabdff1aSopenharmony_ci * @param len number of output noise samples 52cabdff1aSopenharmony_ci * constraints: multiple of 16 53cabdff1aSopenharmony_ci */ 54cabdff1aSopenharmony_ci void (*dither_int_to_float)(float *dst, int *src0, int len); 55cabdff1aSopenharmony_ci} DitherDSPContext; 56cabdff1aSopenharmony_ci 57cabdff1aSopenharmony_ci/** 58cabdff1aSopenharmony_ci * Allocate and initialize a DitherContext. 59cabdff1aSopenharmony_ci * 60cabdff1aSopenharmony_ci * The parameters in the AVAudioResampleContext are used to initialize the 61cabdff1aSopenharmony_ci * DitherContext. 62cabdff1aSopenharmony_ci * 63cabdff1aSopenharmony_ci * @param avr AVAudioResampleContext 64cabdff1aSopenharmony_ci * @return newly-allocated DitherContext 65cabdff1aSopenharmony_ci */ 66cabdff1aSopenharmony_ciDitherContext *ff_dither_alloc(AVAudioResampleContext *avr, 67cabdff1aSopenharmony_ci enum AVSampleFormat out_fmt, 68cabdff1aSopenharmony_ci enum AVSampleFormat in_fmt, 69cabdff1aSopenharmony_ci int channels, int sample_rate, int apply_map); 70cabdff1aSopenharmony_ci 71cabdff1aSopenharmony_ci/** 72cabdff1aSopenharmony_ci * Free a DitherContext. 73cabdff1aSopenharmony_ci * 74cabdff1aSopenharmony_ci * @param c DitherContext 75cabdff1aSopenharmony_ci */ 76cabdff1aSopenharmony_civoid ff_dither_free(DitherContext **c); 77cabdff1aSopenharmony_ci 78cabdff1aSopenharmony_ci/** 79cabdff1aSopenharmony_ci * Convert audio sample format with dithering. 80cabdff1aSopenharmony_ci * 81cabdff1aSopenharmony_ci * @param c DitherContext 82cabdff1aSopenharmony_ci * @param dst destination audio data 83cabdff1aSopenharmony_ci * @param src source audio data 84cabdff1aSopenharmony_ci * @return 0 if ok, negative AVERROR code on failure 85cabdff1aSopenharmony_ci */ 86cabdff1aSopenharmony_ciint ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src); 87cabdff1aSopenharmony_ci 88cabdff1aSopenharmony_ci/* arch-specific initialization functions */ 89cabdff1aSopenharmony_ci 90cabdff1aSopenharmony_civoid ff_dither_init_x86(DitherDSPContext *ddsp, 91cabdff1aSopenharmony_ci enum AVResampleDitherMethod method); 92cabdff1aSopenharmony_ci 93cabdff1aSopenharmony_ci#endif /* AVRESAMPLE_DITHER_H */ 94