FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
celp_filters.h
Go to the documentation of this file.
1 /*
2  * various filters for CELP-based codecs
3  *
4  * Copyright (c) 2008 Vladimir Voroshilov
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #ifndef AVCODEC_CELP_FILTERS_H
24 #define AVCODEC_CELP_FILTERS_H
25 
26 #include <stdint.h>
27 
28 typedef struct CELPFContext {
29  /**
30  * LP synthesis filter.
31  * @param[out] out pointer to output buffer
32  * - the array out[-filter_length, -1] must
33  * contain the previous result of this filter
34  * @param filter_coeffs filter coefficients.
35  * @param in input signal
36  * @param buffer_length amount of data to process
37  * @param filter_length filter length (10 for 10th order LP filter). Must be
38  * greater than 4 and even.
39  *
40  * @note Output buffer must contain filter_length samples of past
41  * speech data before pointer.
42  *
43  * Routine applies 1/A(z) filter to given speech data.
44  */
45  void (*celp_lp_synthesis_filterf)(float *out, const float *filter_coeffs,
46  const float *in, int buffer_length,
47  int filter_length);
48 
49  /**
50  * LP zero synthesis filter.
51  * @param[out] out pointer to output buffer
52  * @param filter_coeffs filter coefficients.
53  * @param in input signal
54  * - the array in[-filter_length, -1] must
55  * contain the previous input of this filter
56  * @param buffer_length amount of data to process (should be a multiple of eight)
57  * @param filter_length filter length (10 for 10th order LP filter;
58  * should be a multiple of two)
59  *
60  * @note Output buffer must contain filter_length samples of past
61  * speech data before pointer.
62  *
63  * Routine applies A(z) filter to given speech data.
64  */
65  void (*celp_lp_zero_synthesis_filterf)(float *out, const float *filter_coeffs,
66  const float *in, int buffer_length,
67  int filter_length);
68 
70 
71 /**
72  * Initialize CELPFContext.
73  */
76 
77 /**
78  * Circularly convolve fixed vector with a phase dispersion impulse
79  * response filter (D.6.2 of G.729 and 6.1.5 of AMR).
80  * @param fc_out vector with filter applied
81  * @param fc_in source vector
82  * @param filter phase filter coefficients
83  *
84  * fc_out[n] = sum(i,0,len-1){ fc_in[i] * filter[(len + n - i)%len] }
85  *
86  * @note fc_in and fc_out should not overlap!
87  */
88 void ff_celp_convolve_circ(int16_t *fc_out, const int16_t *fc_in,
89  const int16_t *filter, int len);
90 
91 /**
92  * Add an array to a rotated array.
93  *
94  * out[k] = in[k] + fac * lagged[k-lag] with wrap-around
95  *
96  * @param out result vector
97  * @param in samples to be added unfiltered
98  * @param lagged samples to be rotated, multiplied and added
99  * @param lag lagged vector delay in the range [0, n]
100  * @param fac scalefactor for lagged samples
101  * @param n number of samples
102  */
103 void ff_celp_circ_addf(float *out, const float *in,
104  const float *lagged, int lag, float fac, int n);
105 
106 /**
107  * LP synthesis filter.
108  * @param[out] out pointer to output buffer
109  * @param filter_coeffs filter coefficients (-0x8000 <= (3.12) < 0x8000)
110  * @param in input signal
111  * @param buffer_length amount of data to process
112  * @param filter_length filter length (10 for 10th order LP filter)
113  * @param stop_on_overflow 1 - return immediately if overflow occurs
114  * 0 - ignore overflows
115  * @param shift the result is shifted right by this value
116  * @param rounder the amount to add for rounding (usually 0x800 or 0xfff)
117  *
118  * @return 1 if overflow occurred, 0 - otherwise
119  *
120  * @note Output buffer must contain filter_length samples of past
121  * speech data before pointer.
122  *
123  * Routine applies 1/A(z) filter to given speech data.
124  */
125 int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs,
126  const int16_t *in, int buffer_length,
127  int filter_length, int stop_on_overflow,
128  int shift, int rounder);
129 
130 /**
131  * LP synthesis filter.
132  * @param[out] out pointer to output buffer
133  * - the array out[-filter_length, -1] must
134  * contain the previous result of this filter
135  * @param filter_coeffs filter coefficients.
136  * @param in input signal
137  * @param buffer_length amount of data to process
138  * @param filter_length filter length (10 for 10th order LP filter). Must be
139  * greater than 4 and even.
140  *
141  * @note Output buffer must contain filter_length samples of past
142  * speech data before pointer.
143  *
144  * Routine applies 1/A(z) filter to given speech data.
145  */
146 void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs,
147  const float *in, int buffer_length,
148  int filter_length);
149 
150 /**
151  * LP zero synthesis filter.
152  * @param[out] out pointer to output buffer
153  * @param filter_coeffs filter coefficients.
154  * @param in input signal
155  * - the array in[-filter_length, -1] must
156  * contain the previous input of this filter
157  * @param buffer_length amount of data to process
158  * @param filter_length filter length (10 for 10th order LP filter)
159  *
160  * @note Output buffer must contain filter_length samples of past
161  * speech data before pointer.
162  *
163  * Routine applies A(z) filter to given speech data.
164  */
165 void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs,
166  const float *in, int buffer_length,
167  int filter_length);
168 
169 #endif /* AVCODEC_CELP_FILTERS_H */
static int shift(int a, int b)
Definition: sonic.c:82
void(* celp_lp_synthesis_filterf)(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP synthesis filter.
Definition: celp_filters.h:45
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, uint8_t clip)
Definition: cfhd.c:82
int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs, const int16_t *in, int buffer_length, int filter_length, int stop_on_overflow, int shift, int rounder)
LP synthesis filter.
Definition: celp_filters.c:60
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
int n
Definition: avisynth_c.h:547
void ff_celp_convolve_circ(int16_t *fc_out, const int16_t *fc_in, const int16_t *filter, int len)
Circularly convolve fixed vector with a phase dispersion impulse response filter (D.6.2 of G.729 and 6.1.5 of AMR).
Definition: celp_filters.c:30
FILE * out
Definition: movenc-test.c:54
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP zero synthesis filter.
Definition: celp_filters.c:199
void ff_celp_circ_addf(float *out, const float *in, const float *lagged, int lag, float fac, int n)
Add an array to a rotated array.
Definition: celp_filters.c:50
void(* celp_lp_zero_synthesis_filterf)(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP zero synthesis filter.
Definition: celp_filters.h:65
void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP synthesis filter.
Definition: celp_filters.c:84
static double c[64]
int len
void ff_celp_filter_init(CELPFContext *c)
Initialize CELPFContext.
Definition: celp_filters.c:212
void ff_celp_filter_init_mips(CELPFContext *c)