From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 486784EC8E for ; Sun, 15 Feb 2026 19:45:38 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'ltRJhsdTrUOgyMxfDHFkO0LuESVL8NMBGFo3uilWfLU=', expected b'RE5vuvykT67oTdSC9zZxH5P7Bm8unEwsnLGC5MeEW5s=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1771184725; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=ltRJhsdTrUOgyMxfDHFkO0LuESVL8NMBGFo3uilWfLU=; b=qMYxRqCbJ4GSsXA5+rcE8aj0o7C3PCBisJkol2OYWogNbQqtM5Cfnp9VUhqfCeQgXRMOI gXoAva9IOsToYuWGGV/cMrl1fBe2vl1fFSBKBQHvLduGSuySX7/n9Ad9baY5raPz9pPJcTF luTVSozr2Uwwpr1N3SLYfm+XgMxmd6Ap8lNN1WH+FkTDRO89Dyb9gLIcNpRYDb6dSwWCkw6 0WTPNEOuEtKsofmupeJQj2kDLsrELtokQgBJ95PM9B1E4RjLPT2KiuSCcokavovj4PA3CSj WObHEoL7scxnWax9fubbm/GTlujnk5KT0RzYMP41N4MwW9TE4YJpxp0GOcow== Received: from [172.20.0.3] (unknown [172.20.0.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 30A0F691448; Sun, 15 Feb 2026 21:45:25 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1771184714; b=ri2Y7IzJpJb6mJw2onWq2rBRsDcHbPXLWUnAWVfpVxCB7XRmVxIJn1m1Gyl6EzLX2cZIF VOV1OZMIvZxd20jsiZkVzjfE2CPxz8XjTVFvdagwxFKq1k+W0vDhbK+rLePzB3i1N9gfnzp 8P7Ik5aQCsYutc8hnq55ayLhLTviH3+fYqkq5wfynr57132iBrEkAp7elDn5THYfU9xr1yb uvpSu8rQalMZDspraR5dPiVA6xjpc5rMRc7Cx9uni6ga0sr2OVTYV97SdP7dC4B43avsXfW 5HHYvuLEEgqZeQIFfBoAVBNWFnqGQJnYdaWaAr4+QlMG/mCcGgXJCvj+RSJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1771184714; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=PQDZj/qeTsc4syS0tIqOJkxA82GvJExHaemvyfHVl/s=; b=JV1DaEHR3pNd9/WVXGjjwPGE3UWO5eQOJXEOb6UhmgvalCE9rb3YixVOyeHmhNllCZTC/ 4+wRB/SwfLjBs2CEoYjKB6YYN6+XJAwdmymERhcv40id71oRKk+iQ96L6xvCupAd5yeHFLQ S0pThGVl1JOZr4IAjrLQMZCDjB0mHb/Y8fSyLg+5abMeMizBNGOAoVJsqIoXPcsDpWvXKpP /pFLPW1CCM4hKEGYioT+8BYaiwqBm+34OQUk6R4NGetsOhMb+FIvjBCeXV/9ORfxaQCplce NpyRtjs5iYvDmdytekGOllUiAnQEy/MVHkQ72aZ6iKs/IQsGrff8RPvrunFA== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1771184706; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=RE5vuvykT67oTdSC9zZxH5P7Bm8unEwsnLGC5MeEW5s=; b=eQjsFG+H1wuVfDEcBvz7twCkCOrpUgXA773bUNqpYiBSVKkD1Uxx0IF5yrSpqq3co6dal us+y0WbiIevMIwOcWRxtLOYSYgcBxEG2UbFxSfwJD2EmIvcKFxAJ0mGSN1fjlKhlUm9WiEp eklK71L3qVaDuysJjYGK3nyq8Aekj6Lo+DkEd8hYpoP5DH4NNHPcjg/7W2ko4COQ5qT0OSt kIusFDTZjsKcb0ZjOjEbpyKEeUNIxEdTZHm0COvYasVEW1dT7rKx8eNNDgyVWoPb3z1c3gk h42Es+boo0vPrpC742rBwPkNx2wiuGQemdEsXMaJR3uMhrE8A163/w2ah22A== Received: from c8d966988b92 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id A968E6913F4 for ; Sun, 15 Feb 2026 21:45:06 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Sun, 15 Feb 2026 19:45:06 -0000 Message-ID: <177118470682.25.14560419941143358218@009cbcb3d8cd> Message-ID-Hash: SEJWWRPZUTJ3AFQMIBUBWM6XRMCG5CF3 X-Message-ID-Hash: SEJWWRPZUTJ3AFQMIBUBWM6XRMCG5CF3 X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PR] avcodec/opus: use precomputed NLSF weights for Silk decoder (PR #21767) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: hassanhany via ffmpeg-devel Cc: hassanhany Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21767 opened by hassanhany URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21767 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21767.patch Uses precomputed table of weights for NLSF decoding >>From 885f68c72b55c4dadb51e3594f9ec088fa512821 Mon Sep 17 00:00:00 2001 From: Hassan Hany Date: Sun, 15 Feb 2026 21:32:54 +0200 Subject: [PATCH] avcodec/opus: use precomputed NLSF weights for Silk decoder --- 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..6a06f49161 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[]; -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org