History

avcodec/g728_template: do_hybrid_window() template

intended for use by RealAudio 2.0 (28.8k) and G.728 decoders.

Peter Ross committed 1 year ago

Commit 93368021 parent b1172b82 files · +68 −47Browse files

Unified · Split

2 files
  1. libavcodec/g728_template.c +65 −0
  2. libavcodec/ra288.c +3 −47
libavcodec/g728_template.c+65−0
@@ -0,0 +1,65 @@
1+/*
2+ * G.728 / RealAudio 2.0 (28.8K) decoder
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+static void convolve(float *tgt, const float *src, int len, int n)
22+{
23+ for (; n >= 0; n--)
24+ tgt[n] = ff_scalarproduct_float_c(src, src - n, len);
25+
26+}
27+
28+/**
29+ * Hybrid window filtering, see blocks 36 and 49 of the G.728 specification.
30+ *
31+ * @param order filter order
32+ * @param n input length
33+ * @param non_rec number of non-recursive samples
34+ * @param out filter output
35+ * @param hist pointer to the input history of the filter
36+ * @param out pointer to the non-recursive part of the output
37+ * @param out2 pointer to the recursive part of the output
38+ * @param window pointer to the windowing function table
39+ */
40+static void do_hybrid_window(void (*vector_fmul)(float *dst, const float *src0, const float *src1, int len),
41+ int order, int n, int non_rec, float *out,
42+ float *hist, float *out2, const float *window)
43+{
44+ int i;
45+ float buffer1[MAX_BACKWARD_FILTER_ORDER + 1];
46+ float buffer2[MAX_BACKWARD_FILTER_ORDER + 1];
47+ LOCAL_ALIGNED(32, float, work, [FFALIGN(MAX_BACKWARD_FILTER_ORDER +
48+ MAX_BACKWARD_FILTER_LEN +
49+ MAX_BACKWARD_FILTER_NONREC, 16)]);
50+
51+ av_assert2(order>=0);
52+
53+ vector_fmul(work, window, hist, FFALIGN(order + n + non_rec, 16));
54+
55+ convolve(buffer1, work + order , n , order);
56+ convolve(buffer2, work + order + n, non_rec, order);
57+
58+ for (i=0; i <= order; i++) {
59+ out2[i] = out2[i] * ATTEN + buffer1[i];
60+ out [i] = out2[i] + buffer2[i];
61+ }
62+
63+ /* Multiply by the white noise correcting factor (WNCF). */
64+ *out *= 257.0 / 256.0;
65+}
libavcodec/ra288.c+3−47
@@ -37,6 +37,8 @@ · 36 unmodified lines
3737 #define MAX_BACKWARD_FILTER_ORDER 36
3838 #define MAX_BACKWARD_FILTER_LEN 40
3939 #define MAX_BACKWARD_FILTER_NONREC 35
40+#define ATTEN 0.5625
41+#include "g728_template.c"
4042
4143 #define RA288_BLOCK_SIZE 5
4244 #define RA288_BLOCKS_PER_FRAME 32
@@ -87,13 +89,6 @@ static av_cold int ra288_decode_init(AVCodecContext *avctx) · 44 unmodified lines
8789 return 0;
8890 }
8991
90−static void convolve(float *tgt, const float *src, int len, int n)
91−{
92− for (; n >= 0; n--)
93− tgt[n] = ff_scalarproduct_float_c(src, src - n, len);
94−
95−}
96−
9792 static void decode(RA288Context *ractx, float gain, int cb_coef)
9893 {
9994 int i;
@@ -131,45 +126,6 @@ static void decode(RA288Context *ractx, float gain, int cb_coef) · 31 unmodified lines
131126 ff_celp_lp_synthesis_filterf(block, ractx->sp_lpc, buffer, 5, 36);
132127 }
133128
134−/**
135− * Hybrid window filtering, see blocks 36 and 49 of the G.728 specification.
136− *
137− * @param order filter order
138− * @param n input length
139− * @param non_rec number of non-recursive samples
140− * @param out filter output
141− * @param hist pointer to the input history of the filter
142− * @param out pointer to the non-recursive part of the output
143− * @param out2 pointer to the recursive part of the output
144− * @param window pointer to the windowing function table
145− */
146−static void do_hybrid_window(RA288Context *ractx,
147− int order, int n, int non_rec, float *out,
148− float *hist, float *out2, const float *window)
149−{
150− int i;
151− float buffer1[MAX_BACKWARD_FILTER_ORDER + 1];
152− float buffer2[MAX_BACKWARD_FILTER_ORDER + 1];
153− LOCAL_ALIGNED(32, float, work, [FFALIGN(MAX_BACKWARD_FILTER_ORDER +
154− MAX_BACKWARD_FILTER_LEN +
155− MAX_BACKWARD_FILTER_NONREC, 16)]);
156−
157− av_assert2(order>=0);
158−
159− ractx->vector_fmul(work, window, hist, FFALIGN(order + n + non_rec, 16));
160−
161− convolve(buffer1, work + order , n , order);
162− convolve(buffer2, work + order + n, non_rec, order);
163−
164− for (i=0; i <= order; i++) {
165− out2[i] = out2[i] * 0.5625 + buffer1[i];
166− out [i] = out2[i] + buffer2[i];
167− }
168−
169− /* Multiply by the white noise correcting factor (WNCF). */
170− *out *= 257.0 / 256.0;
171−}
172−
173129 /**
174130 * Backward synthesis filter, find the LPC coefficients from past speech data.
175131 */
@@ -180,7 +136,7 @@ static void backward_filter(RA288Context *ractx, · 4 unmodified lines
180136 {
181137 float temp[MAX_BACKWARD_FILTER_ORDER+1];
182138
183− do_hybrid_window(ractx, order, n, non_rec, temp, hist, rec, window);
139+ do_hybrid_window(ractx->vector_fmul, order, n, non_rec, temp, hist, rec, window);
184140
185141 if (!compute_lpc_coefs(temp, order, lpc, 0, 1, 1))
186142 ractx->vector_fmul(lpc, lpc, tab, FFALIGN(order, 16));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t