This is an automated email from the git hooks/post-receive script.
Git pushed a commit to branch master
in repository ffmpeg.
The following commit(s) were added to refs/heads/master by this push:
new 9e4041d5ea avcodec/opus: use precomputed NLSF weights for Silk decoder
9e4041d5ea is described below
commit 9e4041d5ea657a36c9039a0815b5869e30bf4fb5
Author: Hassan Hany <[email protected]>
AuthorDate: Sun Feb 15 21:32:54 2026 +0200
Commit: Lynne <[email protected]>
CommitDate: Fri Apr 17 14:39:20 2026 +0000
avcodec/opus: use precomputed NLSF weights for Silk decoder
Precompute the SILK NLSF residual weights from the stage-1 codebooks and
use the table during LPC decode. This removes the per-coefficient mandated
fixed-point weight calculation in silk_decode_lpc() while preserving the same
decoded values.
---
libavcodec/opus/silk.c | 14 +++-------
libavcodec/opus/tab.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++
libavcodec/opus/tab.h | 3 ++-
3 files changed, 75 insertions(+), 12 deletions(-)
diff --git a/libavcodec/opus/silk.c b/libavcodec/opus/silk.c
index ffa2ec996b..3e07877a7c 100644
--- a/libavcodec/opus/silk.c
+++ b/libavcodec/opus/silk.c
@@ -353,20 +353,12 @@ static inline void silk_decode_lpc(SilkContext *s,
SilkFrame *frame,
for (i = 0; i < order; i++) {
const uint8_t * codebook = s->wb ? ff_silk_lsf_codebook_wb [lsf_i1] :
ff_silk_lsf_codebook_nbmb[lsf_i1];
- int cur, prev, next, weight_sq, weight, ipart, fpart, y, value;
+ int cur, weight, value;
/* find the weight of the residual */
- /* TODO: precompute */
cur = codebook[i];
- prev = i ? codebook[i - 1] : 0;
- next = i + 1 < order ? codebook[i + 1] : 256;
- weight_sq = (1024 / (cur - prev) + 1024 / (next - cur)) << 16;
-
- /* approximate square-root with mandated fixed-point arithmetic */
- ipart = opus_ilog(weight_sq);
- fpart = (weight_sq >> (ipart-8)) & 127;
- y = ((ipart & 1) ? 32768 : 46214) >> ((32 - ipart)>>1);
- weight = y + ((213 * fpart * y) >> 16);
+ weight = s->wb ? ff_silk_model_lsf_weight_wb[lsf_i1][i] :
+ ff_silk_model_lsf_weight_nbmb[lsf_i1][i];
value = cur * 128 + (lsf_res[i] * 16384) / weight;
nlsf[i] = av_clip_uintp2(value, 15);
diff --git a/libavcodec/opus/tab.c b/libavcodec/opus/tab.c
index 5147b66b69..ed8f018bf9 100644
--- a/libavcodec/opus/tab.c
+++ b/libavcodec/opus/tab.c
@@ -734,6 +734,76 @@ const int8_t ff_silk_ltp_filter2_taps[32][5] = {
{ 2, 0, 9, 10, 88}
};
+const uint16_t ff_silk_model_lsf_weight_nbmb[32][10] = {
+ { 2897, 2314, 2314, 2314, 2287, 2287, 2314, 2300, 2327, 2287},
+ { 2888, 2580, 2394, 2367, 2314, 2274, 2274, 2274, 2274, 2194},
+ { 2487, 2340, 2340, 2314, 2314, 2314, 2340, 2340, 2367, 2354},
+ { 3216, 2766, 2340, 2340, 2314, 2274, 2221, 2207, 2261, 2194},
+ { 2460, 2474, 2367, 2394, 2394, 2394, 2394, 2367, 2407, 2314},
+ { 3479, 3056, 2127, 2207, 2274, 2274, 2274, 2287, 2314, 2261},
+ { 3282, 3141, 2580, 2394, 2247, 2221, 2207, 2194, 2194, 2114},
+ { 4096, 3845, 2221, 2620, 2620, 2407, 2314, 2394, 2367, 2074},
+ { 3178, 3244, 2367, 2221, 2553, 2434, 2340, 2314, 2167, 2221},
+ { 3338, 3488, 2726, 2194, 2261, 2460, 2354, 2367, 2207, 2101},
+ { 2354, 2420, 2327, 2367, 2394, 2420, 2420, 2420, 2460, 2367},
+ { 3779, 3629, 2434, 2527, 2367, 2274, 2274, 2300, 2207, 2048},
+ { 3254, 3225, 2713, 2846, 2447, 2327, 2300, 2300, 2274, 2127},
+ { 3263, 3300, 2753, 2806, 2447, 2261, 2261, 2247, 2127, 2101},
+ { 2873, 2981, 2633, 2367, 2407, 2354, 2194, 2247, 2247, 2114},
+ { 3225, 3197, 2633, 2580, 2274, 2181, 2247, 2221, 2221, 2141},
+ { 3178, 3310, 2740, 2407, 2274, 2274, 2274, 2287, 2194, 2114},
+ { 3141, 3272, 2460, 2061, 2287, 2500, 2367, 2487, 2434, 2181},
+ { 3507, 3282, 2314, 2700, 2647, 2474, 2367, 2394, 2340, 2127},
+ { 3423, 3535, 3038, 3056, 2300, 1950, 2221, 2274, 2274, 2274},
+ { 3404, 3366, 2087, 2687, 2873, 2354, 2420, 2274, 2474, 2540},
+ { 3760, 3488, 1950, 2660, 2897, 2527, 2394, 2367, 2460, 2261},
+ { 3028, 3272, 2740, 2888, 2740, 2154, 2127, 2287, 2234, 2247},
+ { 3695, 3657, 2025, 1969, 2660, 2700, 2580, 2500, 2327, 2367},
+ { 3207, 3413, 2354, 2074, 2888, 2888, 2340, 2487, 2247, 2167},
+ { 3338, 3366, 2846, 2780, 2327, 2154, 2274, 2287, 2114, 2061},
+ { 2327, 2300, 2181, 2167, 2181, 2367, 2633, 2700, 2700, 2553},
+ { 2407, 2434, 2221, 2261, 2221, 2221, 2340, 2420, 2607, 2700},
+ { 3038, 3244, 2806, 2888, 2474, 2074, 2300, 2314, 2354, 2380},
+ { 2221, 2154, 2127, 2287, 2500, 2793, 2793, 2620, 2580, 2367},
+ { 3676, 3713, 2234, 1838, 2181, 2753, 2726, 2673, 2513, 2207},
+ { 2793, 3160, 2726, 2553, 2846, 2513, 2181, 2394, 2221, 2181}
+};
+
+const uint16_t ff_silk_model_lsf_weight_wb[32][16] = {
+ { 3657, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925,
2963, 2963, 2925, 2846},
+ { 3216, 3085, 2972, 3056, 3056, 3010, 3010, 3010, 2963, 2963, 3010, 2972,
2888, 2846, 2846, 2726},
+ { 3920, 4014, 2981, 3207, 3207, 2934, 3056, 2846, 3122, 3244, 2925, 2846,
2620, 2553, 2780, 2925},
+ { 3516, 3197, 3010, 3103, 3019, 2888, 2925, 2925, 2925, 2925, 2888, 2888,
2888, 2888, 2888, 2753},
+ { 5054, 5054, 2934, 3573, 3385, 3056, 3085, 2793, 3160, 3160, 2972, 2846,
2513, 2540, 2753, 2888},
+ { 4428, 4149, 2700, 2753, 2972, 3010, 2925, 2846, 2981, 3019, 2925, 2925,
2925, 2925, 2888, 2726},
+ { 3620, 3019, 2972, 3056, 3056, 2873, 2806, 3056, 3216, 3047, 2981, 3291,
3291, 2981, 3310, 2991},
+ { 5227, 5014, 2540, 3338, 3526, 3385, 3197, 3094, 3376, 2981, 2700, 2647,
2687, 2793, 2846, 2673},
+ { 5081, 5174, 4615, 4428, 2460, 2897, 3047, 3207, 3169, 2687, 2740, 2888,
2846, 2793, 2846, 2700},
+ { 3122, 2888, 2963, 2925, 2925, 2925, 2925, 2963, 2963, 2963, 2963, 2925,
2925, 2963, 2963, 2963},
+ { 4202, 3207, 2981, 3103, 3010, 2888, 2888, 2925, 2972, 2873, 2916, 3019,
2972, 3010, 3197, 2873},
+ { 3760, 3760, 3244, 3103, 2981, 2888, 2925, 2888, 2972, 2934, 2793, 2793,
2846, 2888, 2888, 2660},
+ { 3854, 4014, 3207, 3122, 3244, 2934, 3047, 2963, 2963, 3085, 2846, 2793,
2793, 2793, 2793, 2580},
+ { 3845, 4080, 3357, 3516, 3094, 2740, 3010, 2934, 3122, 3085, 2846, 2846,
2647, 2647, 2846, 2806},
+ { 5147, 4894, 3225, 3845, 3441, 3169, 2897, 3413, 3451, 2700, 2580, 2673,
2740, 2846, 2806, 2753},
+ { 4109, 3789, 3291, 3160, 2925, 2888, 2888, 2925, 2793, 2740, 2793, 2740,
2793, 2846, 2888, 2806},
+ { 5081, 5054, 3047, 3545, 3244, 3056, 3085, 2944, 3103, 2897, 2740, 2740,
2740, 2846, 2793, 2620},
+ { 4309, 4309, 2860, 2527, 3207, 3376, 3376, 3075, 3075, 3376, 3056, 2846,
2647, 2580, 2726, 2753},
+ { 3056, 2916, 2806, 2888, 2740, 2687, 2897, 3103, 3150, 3150, 3216, 3169,
3056, 3010, 2963, 2846},
+ { 4375, 3882, 2925, 2888, 2846, 2888, 2846, 2846, 2888, 2888, 2888, 2846,
2888, 2925, 2888, 2846},
+ { 2981, 2916, 2916, 2981, 2981, 3056, 3122, 3216, 3150, 3056, 3010, 2972,
2972, 2972, 2925, 2740},
+ { 4229, 4149, 3310, 3347, 2925, 2963, 2888, 2981, 2981, 2846, 2793, 2740,
2846, 2846, 2846, 2793},
+ { 4080, 4014, 3103, 3010, 2925, 2925, 2925, 2888, 2925, 2925, 2846, 2846,
2846, 2793, 2888, 2780},
+ { 4615, 4575, 3169, 3441, 3207, 2981, 2897, 3038, 3122, 2740, 2687, 2687,
2687, 2740, 2793, 2700},
+ { 4149, 4269, 3789, 3657, 2726, 2780, 2888, 2888, 3010, 2972, 2925, 2846,
2687, 2687, 2793, 2888},
+ { 4215, 3554, 2753, 2846, 2846, 2888, 2888, 2888, 2925, 2925, 2888, 2925,
2925, 2925, 2963, 2888},
+ { 5174, 4921, 2261, 3432, 3789, 3479, 3347, 2846, 3310, 3479, 3150, 2897,
2460, 2487, 2753, 2925},
+ { 3451, 3685, 3122, 3197, 3357, 3047, 3207, 3207, 2981, 3216, 3085, 2925,
2925, 2687, 2540, 2434},
+ { 2981, 3010, 2793, 2793, 2740, 2793, 2846, 2972, 3056, 3103, 3150, 3150,
3150, 3103, 3010, 3010},
+ { 2944, 2873, 2687, 2726, 2780, 3010, 3432, 3545, 3357, 3244, 3056, 3010,
2963, 2925, 2888, 2846},
+ { 3019, 2944, 2897, 3010, 3010, 2972, 3019, 3103, 3056, 3056, 3010, 2888,
2846, 2925, 2925, 2888},
+ { 3920, 3967, 3010, 3197, 3357, 3216, 3291, 3291, 3479, 3704, 3441, 2726,
2181, 2460, 2580, 2607}
+};
+
const uint16_t ff_silk_ltp_scale_factor[] = {15565, 12288, 8192};
const uint8_t ff_silk_shell_blocks[3][2] = {
diff --git a/libavcodec/opus/tab.h b/libavcodec/opus/tab.h
index 04d2a59bb6..c1d38f9e69 100644
--- a/libavcodec/opus/tab.h
+++ b/libavcodec/opus/tab.h
@@ -63,7 +63,8 @@ extern const uint16_t ff_silk_model_pitch_contour_nb10ms[];
extern const uint16_t ff_silk_model_pitch_contour_nb20ms[];
extern const uint16_t ff_silk_model_pitch_contour_mbwb10ms[];
extern const uint16_t ff_silk_model_pitch_contour_mbwb20ms[];
-
+extern const uint16_t ff_silk_model_lsf_weight_nbmb[32][10];
+extern const uint16_t ff_silk_model_lsf_weight_wb[32][16];
extern const uint16_t ff_silk_model_ltp_filter[];
extern const uint16_t ff_silk_model_ltp_filter0_sel[];
extern const uint16_t ff_silk_model_ltp_filter1_sel[];
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]