[FFmpeg-devel] [PATCH 3/8] avcodec/lpc_functions: compute_lpc_coefs: add starting lpc order and err cache parameters
Peter Ross
pross at xvid.org
Sun Jan 12 04:37:13 EET 2025
---
libavcodec/aac/aacdec_dsp_template.c | 2 +-
libavcodec/aacenc_tns.c | 2 +-
libavcodec/lpc.c | 2 +-
libavcodec/lpc_functions.h | 18 +++++++++++++-----
libavcodec/ra288.c | 2 +-
5 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/libavcodec/aac/aacdec_dsp_template.c b/libavcodec/aac/aacdec_dsp_template.c
index 8d31af22f8..b64944d548 100644
--- a/libavcodec/aac/aacdec_dsp_template.c
+++ b/libavcodec/aac/aacdec_dsp_template.c
@@ -185,7 +185,7 @@ static void AAC_RENAME(apply_tns)(void *_coef_param, TemporalNoiseShaping *tns,
continue;
// tns_decode_coef
- compute_lpc_coefs(tns->AAC_RENAME(coef)[w][filt], order, lpc, 0, 0, 0);
+ compute_lpc_coefs(tns->AAC_RENAME(coef)[w][filt], 0, order, lpc, 0, 0, 0, NULL);
start = ics->swb_offset[FFMIN(bottom, mmm)];
end = ics->swb_offset[FFMIN( top, mmm)];
diff --git a/libavcodec/aacenc_tns.c b/libavcodec/aacenc_tns.c
index fa3cd2af39..cb151d91d8 100644
--- a/libavcodec/aacenc_tns.c
+++ b/libavcodec/aacenc_tns.c
@@ -117,7 +117,7 @@ void ff_aac_apply_tns(AACEncContext *s, SingleChannelElement *sce)
continue;
// tns_decode_coef
- compute_lpc_coefs(tns->coef[w][filt], order, lpc, 0, 0, 0);
+ compute_lpc_coefs(tns->coef[w][filt], 0, order, lpc, 0, 0, 0, NULL);
start = ics->swb_offset[FFMIN(bottom, mmm)];
end = ics->swb_offset[FFMIN( top, mmm)];
diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c
index e793e54038..38c78d9521 100644
--- a/libavcodec/lpc.c
+++ b/libavcodec/lpc.c
@@ -267,7 +267,7 @@ int ff_lpc_calc_coefs(LPCContext *s,
s->lpc_compute_autocorr(s->windowed_samples, blocksize, max_order, autoc);
- compute_lpc_coefs(autoc, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1);
+ compute_lpc_coefs(autoc, 0, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1, NULL);
for(i=0; i<max_order; i++)
ref[i] = fabs(lpc[i][i]);
diff --git a/libavcodec/lpc_functions.h b/libavcodec/lpc_functions.h
index 57bcfab900..ea5f8868b9 100644
--- a/libavcodec/lpc_functions.h
+++ b/libavcodec/lpc_functions.h
@@ -51,22 +51,27 @@ typedef float LPC_TYPE_U;
* Levinson-Durbin recursion.
* Produce LPC coefficients from autocorrelation data.
*/
-static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order,
+static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int i, int max_order,
LPC_TYPE *lpc, int lpc_stride, int fail,
- int normalize)
+ int normalize, LPC_TYPE *err_ptr)
{
LPC_TYPE err = 0;
LPC_TYPE *lpc_last = lpc;
av_assert2(normalize || !fail);
- if (normalize)
- err = *autoc++;
+ if (normalize) {
+ if (i == 0)
+ err = *autoc++;
+ else {
+ err = *err_ptr;
+ }
+ }
if (fail && (autoc[max_order - 1] == 0 || err <= 0))
return -1;
- for(int i = 0; i < max_order; i++) {
+ for( ; i < max_order; i++) {
LPC_TYPE r = LPC_SRA_R(-autoc[i], 5);
if (normalize) {
@@ -94,6 +99,9 @@ static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order,
lpc += lpc_stride;
}
+ if (err_ptr)
+ *err_ptr = err;
+
return 0;
}
diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c
index 9c69f49d81..65acaf34e0 100644
--- a/libavcodec/ra288.c
+++ b/libavcodec/ra288.c
@@ -138,7 +138,7 @@ static void backward_filter(RA288Context *ractx,
do_hybrid_window(ractx->vector_fmul, order, n, non_rec, temp, hist, rec, window);
- if (!compute_lpc_coefs(temp, order, lpc, 0, 1, 1))
+ if (!compute_lpc_coefs(temp, 0, order, lpc, 0, 1, 1, NULL))
ractx->vector_fmul(lpc, lpc, tab, FFALIGN(order, 16));
memmove(hist, hist + n, move_size*sizeof(*hist));
--
2.45.2
-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250112/65908a4d/attachment.sig>
More information about the ffmpeg-devel
mailing list