Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCHv3 0/8] G.728 decoding
@ 2025-06-09 10:05 Peter Ross
  2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 1/8] avcodec/g728_template: do_hybrid_window() template Peter Ross
                   ` (7 more replies)
  0 siblings, 8 replies; 14+ messages in thread
From: Peter Ross @ 2025-06-09 10:05 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1: Type: text/plain, Size: 1884 bytes --]

Sample: https://pross.sdf.org/sandpit/CW5.g728

Peter Ross (8):
  avcodec/g728_template: do_hybrid_window() template
  avcodec/g728_template: make hist parameter constant
  avcodec/lpc_functions: compute_lpc_coefs: add starting lpc order and
    err cache parameters
  avcodec/g728dec: G.728 decoder
  avformat/g728dec: raw G.728 demuxer
  avformat/riff: G.728 muxing and demuxing
  avformat/aiff: G.728 muxing and demuxing
  avformat/rtp: G.728 muxing and demuxing

 libavcodec/Makefile                  |   1 +
 libavcodec/aac/aacdec_dsp_template.c |   2 +-
 libavcodec/aacenc_tns.c              |   2 +-
 libavcodec/allcodecs.c               |   1 +
 libavcodec/codec_desc.c              |   7 +
 libavcodec/codec_id.h                |   1 +
 libavcodec/g728_template.c           |  65 ++++++++
 libavcodec/g728data.h                |  70 +++++++++
 libavcodec/g728dec.c                 | 220 +++++++++++++++++++++++++++
 libavcodec/lpc.c                     |   2 +-
 libavcodec/lpc_functions.h           |  18 ++-
 libavcodec/ra288.c                   |  52 +------
 libavcodec/utils.c                   |   1 +
 libavformat/Makefile                 |   1 +
 libavformat/aiff.c                   |   1 +
 libavformat/aiffdec.c                |   3 +
 libavformat/allformats.c             |   1 +
 libavformat/g728dec.c                |  58 +++++++
 libavformat/riff.c                   |   2 +
 libavformat/riffenc.c                |   1 +
 libavformat/rtp.c                    |   2 +-
 libavformat/rtpenc.c                 |   1 +
 22 files changed, 455 insertions(+), 57 deletions(-)
 create mode 100644 libavcodec/g728_template.c
 create mode 100644 libavcodec/g728data.h
 create mode 100644 libavcodec/g728dec.c
 create mode 100644 libavformat/g728dec.c

-- 
2.47.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [FFmpeg-devel] [PATCHv3 1/8] avcodec/g728_template: do_hybrid_window() template
  2025-06-09 10:05 [FFmpeg-devel] [PATCHv3 0/8] G.728 decoding Peter Ross
@ 2025-06-09 10:06 ` Peter Ross
  2025-06-09 21:56   ` Tomas Härdin
  2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 2/8] avcodec/g728_template: make hist parameter constant Peter Ross
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Peter Ross @ 2025-06-09 10:06 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1: Type: text/plain, Size: 6174 bytes --]

intended for use by RealAudio 2.0 (28.8k) and G.728 decoders.
---
 libavcodec/g728_template.c | 65 ++++++++++++++++++++++++++++++++++++++
 libavcodec/ra288.c         | 50 ++---------------------------
 2 files changed, 68 insertions(+), 47 deletions(-)
 create mode 100644 libavcodec/g728_template.c

diff --git a/libavcodec/g728_template.c b/libavcodec/g728_template.c
new file mode 100644
index 0000000000..b60122ee37
--- /dev/null
+++ b/libavcodec/g728_template.c
@@ -0,0 +1,65 @@
+/*
+ * G.728 / RealAudio 2.0 (28.8K) decoder
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+static void convolve(float *tgt, const float *src, int len, int n)
+{
+    for (; n >= 0; n--)
+        tgt[n] = ff_scalarproduct_float_c(src, src - n, len);
+
+}
+
+/**
+ * Hybrid window filtering, see blocks 36 and 49 of the G.728 specification.
+ *
+ * @param order   filter order
+ * @param n       input length
+ * @param non_rec number of non-recursive samples
+ * @param out     filter output
+ * @param hist    pointer to the input history of the filter
+ * @param out     pointer to the non-recursive part of the output
+ * @param out2    pointer to the recursive part of the output
+ * @param window  pointer to the windowing function table
+ */
+static void do_hybrid_window(void (*vector_fmul)(float *dst, const float *src0, const float *src1, int len),
+                             int order, int n, int non_rec, float *out,
+                             float *hist, float *out2, const float *window)
+{
+    int i;
+    float buffer1[MAX_BACKWARD_FILTER_ORDER + 1];
+    float buffer2[MAX_BACKWARD_FILTER_ORDER + 1];
+    LOCAL_ALIGNED(32, float, work, [FFALIGN(MAX_BACKWARD_FILTER_ORDER +
+                                            MAX_BACKWARD_FILTER_LEN   +
+                                            MAX_BACKWARD_FILTER_NONREC, 16)]);
+
+    av_assert2(order>=0);
+
+    vector_fmul(work, window, hist, FFALIGN(order + n + non_rec, 16));
+
+    convolve(buffer1, work + order    , n      , order);
+    convolve(buffer2, work + order + n, non_rec, order);
+
+    for (i=0; i <= order; i++) {
+        out2[i] = out2[i] * ATTEN + buffer1[i];
+        out [i] = out2[i]         + buffer2[i];
+    }
+
+    /* Multiply by the white noise correcting factor (WNCF). */
+    *out *= 257.0 / 256.0;
+}
diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c
index aa499506b7..a1ee3f7eba 100644
--- a/libavcodec/ra288.c
+++ b/libavcodec/ra288.c
@@ -37,6 +37,8 @@
 #define MAX_BACKWARD_FILTER_ORDER  36
 #define MAX_BACKWARD_FILTER_LEN    40
 #define MAX_BACKWARD_FILTER_NONREC 35
+#define ATTEN 0.5625
+#include "g728_template.c"
 
 #define RA288_BLOCK_SIZE        5
 #define RA288_BLOCKS_PER_FRAME 32
@@ -87,13 +89,6 @@ static av_cold int ra288_decode_init(AVCodecContext *avctx)
     return 0;
 }
 
-static void convolve(float *tgt, const float *src, int len, int n)
-{
-    for (; n >= 0; n--)
-        tgt[n] = ff_scalarproduct_float_c(src, src - n, len);
-
-}
-
 static void decode(RA288Context *ractx, float gain, int cb_coef)
 {
     int i;
@@ -131,45 +126,6 @@ static void decode(RA288Context *ractx, float gain, int cb_coef)
     ff_celp_lp_synthesis_filterf(block, ractx->sp_lpc, buffer, 5, 36);
 }
 
-/**
- * Hybrid window filtering, see blocks 36 and 49 of the G.728 specification.
- *
- * @param order   filter order
- * @param n       input length
- * @param non_rec number of non-recursive samples
- * @param out     filter output
- * @param hist    pointer to the input history of the filter
- * @param out     pointer to the non-recursive part of the output
- * @param out2    pointer to the recursive part of the output
- * @param window  pointer to the windowing function table
- */
-static void do_hybrid_window(RA288Context *ractx,
-                             int order, int n, int non_rec, float *out,
-                             float *hist, float *out2, const float *window)
-{
-    int i;
-    float buffer1[MAX_BACKWARD_FILTER_ORDER + 1];
-    float buffer2[MAX_BACKWARD_FILTER_ORDER + 1];
-    LOCAL_ALIGNED(32, float, work, [FFALIGN(MAX_BACKWARD_FILTER_ORDER +
-                                            MAX_BACKWARD_FILTER_LEN   +
-                                            MAX_BACKWARD_FILTER_NONREC, 16)]);
-
-    av_assert2(order>=0);
-
-    ractx->vector_fmul(work, window, hist, FFALIGN(order + n + non_rec, 16));
-
-    convolve(buffer1, work + order    , n      , order);
-    convolve(buffer2, work + order + n, non_rec, order);
-
-    for (i=0; i <= order; i++) {
-        out2[i] = out2[i] * 0.5625 + buffer1[i];
-        out [i] = out2[i]          + buffer2[i];
-    }
-
-    /* Multiply by the white noise correcting factor (WNCF). */
-    *out *= 257.0 / 256.0;
-}
-
 /**
  * Backward synthesis filter, find the LPC coefficients from past speech data.
  */
@@ -180,7 +136,7 @@ static void backward_filter(RA288Context *ractx,
 {
     float temp[MAX_BACKWARD_FILTER_ORDER+1];
 
-    do_hybrid_window(ractx, order, n, non_rec, temp, hist, rec, window);
+    do_hybrid_window(ractx->vector_fmul, order, n, non_rec, temp, hist, rec, window);
 
     if (!compute_lpc_coefs(temp, order, lpc, 0, 1, 1))
         ractx->vector_fmul(lpc, lpc, tab, FFALIGN(order, 16));
-- 
2.47.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [FFmpeg-devel] [PATCHv3 2/8] avcodec/g728_template: make hist parameter constant
  2025-06-09 10:05 [FFmpeg-devel] [PATCHv3 0/8] G.728 decoding Peter Ross
  2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 1/8] avcodec/g728_template: do_hybrid_window() template Peter Ross
@ 2025-06-09 10:06 ` Peter Ross
  2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 3/8] avcodec/lpc_functions: compute_lpc_coefs: add starting lpc order and err cache parameters Peter Ross
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Peter Ross @ 2025-06-09 10:06 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1: Type: text/plain, Size: 852 bytes --]

---
 libavcodec/g728_template.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/g728_template.c b/libavcodec/g728_template.c
index b60122ee37..dd1b1a4415 100644
--- a/libavcodec/g728_template.c
+++ b/libavcodec/g728_template.c
@@ -39,7 +39,7 @@ static void convolve(float *tgt, const float *src, int len, int n)
  */
 static void do_hybrid_window(void (*vector_fmul)(float *dst, const float *src0, const float *src1, int len),
                              int order, int n, int non_rec, float *out,
-                             float *hist, float *out2, const float *window)
+                             const float *hist, float *out2, const float *window)
 {
     int i;
     float buffer1[MAX_BACKWARD_FILTER_ORDER + 1];
-- 
2.47.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [FFmpeg-devel] [PATCHv3 3/8] avcodec/lpc_functions: compute_lpc_coefs: add starting lpc order and err cache parameters
  2025-06-09 10:05 [FFmpeg-devel] [PATCHv3 0/8] G.728 decoding Peter Ross
  2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 1/8] avcodec/g728_template: do_hybrid_window() template Peter Ross
  2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 2/8] avcodec/g728_template: make hist parameter constant Peter Ross
@ 2025-06-09 10:06 ` Peter Ross
  2025-06-09 10:07 ` [FFmpeg-devel] [PATCHv3 4/8] avcodec/g728dec: G.728 decoder Peter Ross
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Peter Ross @ 2025-06-09 10:06 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1: Type: text/plain, Size: 4169 bytes --]

---
 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 7884c035cb..2f27444025 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 a1ee3f7eba..550af7f29f 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.47.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [FFmpeg-devel] [PATCHv3 4/8] avcodec/g728dec: G.728 decoder
  2025-06-09 10:05 [FFmpeg-devel] [PATCHv3 0/8] G.728 decoding Peter Ross
                   ` (2 preceding siblings ...)
  2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 3/8] avcodec/lpc_functions: compute_lpc_coefs: add starting lpc order and err cache parameters Peter Ross
@ 2025-06-09 10:07 ` Peter Ross
  2025-06-09 10:07 ` [FFmpeg-devel] [PATCHv3 5/8] avformat/g728dec: raw G.728 demuxer Peter Ross
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Peter Ross @ 2025-06-09 10:07 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1: Type: text/plain, Size: 14701 bytes --]

---
 libavcodec/Makefile     |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/codec_desc.c |   7 ++
 libavcodec/codec_id.h   |   1 +
 libavcodec/g728data.h   |  70 +++++++++++++
 libavcodec/g728dec.c    | 220 ++++++++++++++++++++++++++++++++++++++++
 libavcodec/utils.c      |   1 +
 7 files changed, 301 insertions(+)
 create mode 100644 libavcodec/g728data.h
 create mode 100644 libavcodec/g728dec.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cfbec99889..508b114956 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -395,6 +395,7 @@ OBJS-$(CONFIG_G723_1_DECODER)          += g723_1dec.o g723_1.o \
                                           acelp_vectors.o celp_filters.o celp_math.o
 OBJS-$(CONFIG_G723_1_ENCODER)          += g723_1enc.o g723_1.o \
                                           acelp_vectors.o celp_filters.o celp_math.o
+OBJS-$(CONFIG_G728_DECODER)            += g728dec.o
 OBJS-$(CONFIG_G729_DECODER)            += g729dec.o lsp.o celp_math.o celp_filters.o acelp_filters.o acelp_pitch_delay.o acelp_vectors.o g729postfilter.o
 OBJS-$(CONFIG_GDV_DECODER)             += gdv.o
 OBJS-$(CONFIG_GEM_DECODER)             += gemdec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index cd4f6ecd59..4b11ad3a75 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -477,6 +477,7 @@ extern const FFCodec ff_flac_decoder;
 extern const FFCodec ff_ftr_decoder;
 extern const FFCodec ff_g723_1_encoder;
 extern const FFCodec ff_g723_1_decoder;
+extern const FFCodec ff_g728_decoder;
 extern const FFCodec ff_g729_decoder;
 extern const FFCodec ff_gsm_decoder;
 extern const FFCodec ff_gsm_ms_decoder;
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 88fed478a3..5b6aaab88e 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3473,6 +3473,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .long_name = NULL_IF_CONFIG_SMALL("LC3 (Low Complexity Communication Codec)"),
         .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
     },
+    {
+        .id        = AV_CODEC_ID_G728,
+        .type      = AVMEDIA_TYPE_AUDIO,
+        .name      = "g728",
+        .long_name = NULL_IF_CONFIG_SMALL("G.728"),
+        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+    },
 
     /* subtitle codecs */
     {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index be0a65bcb9..09dff29886 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -553,6 +553,7 @@ enum AVCodecID {
     AV_CODEC_ID_OSQ,
     AV_CODEC_ID_QOA,
     AV_CODEC_ID_LC3,
+    AV_CODEC_ID_G728,
 
     /* subtitle codecs */
     AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,          ///< A dummy ID pointing at the start of subtitle codecs.
diff --git a/libavcodec/g728data.h b/libavcodec/g728data.h
new file mode 100644
index 0000000000..a2ddf5682d
--- /dev/null
+++ b/libavcodec/g728data.h
@@ -0,0 +1,70 @@
+/*
+ * G.728 decoder
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_G728DATA_H
+#define AVCODEC_G728DATA_H
+
+#include <stdint.h>
+#include "libavutil/macros.h"
+
+#define IDIM 5 /* Vector dimension (excitation block size) */
+#define LPC 50 /* Synthesis filter order */
+#define LPCLG 10 /* Log-gain predictor order */
+#define NFRSZ 20 /* Frame size (adaptation cycle size in samples */
+#define NONR 35 /* Number of non-recursive window samples for synthesis filter */
+#define NONRLG 20 /* Number of non-recursive window samples for log-gain predictor */
+#define NUPDATE 4 /* Predictor update period (in terms of vectors) */
+
+#define NSBSZ (LPC + NONR + NFRSZ)
+#define NSBGSZ (LPCLG + NONRLG + NUPDATE)
+
+// Hybrid window for the synthesis filter
+static const uint16_t g728_wnr[NSBSZ] = {
+     1565,  3127,  4681,  6225,  7755,  9266, 10757, 12223, 13661, 15068,
+    16441, 17776, 19071, 20322, 21526, 22682, 23786, 24835, 25828, 26761,
+    27634, 28444, 29188, 29866, 30476, 31016, 31486, 31884, 32208, 32460,
+    32637, 32739, 32767, 32721, 32599, 32403, 32171, 31940, 31711, 31484,
+    31259, 31034, 30812, 30591, 30372, 30154, 29938, 29724, 29511, 29299,
+    29089, 28881, 28674, 28468, 28264, 28062, 27861, 27661, 27463, 27266,
+    27071, 26877, 26684, 26493, 26303, 26114, 25927, 25742, 25557, 25374,
+    25192, 25012, 24832, 24654, 24478, 24302, 24128, 23955, 23784, 23613,
+    23444, 23276, 23109, 22943, 22779, 22616, 22454, 22293, 22133, 21974,
+    21817, 21661, 21505, 21351, 21198, 21046, 20896, 20746, 20597, 20450,
+    20303, 20157, 20013, 19870, 19727
+};
+
+// Hybrid window for the log-gain predictor
+static const uint16_t g728_wnrg[NSBGSZ] = {
+     3026,  6025,  8973, 11845, 14615, 17261, 19759, 22088, 24228, 26162,
+    27872, 29344, 30565, 31525, 32216, 32631, 32767, 32625, 32203, 31506,
+    30540, 29461, 28420, 27416, 26448, 25514, 24613, 23743, 22905, 22096,
+    21315, 20562, 19836, 19135
+};
+
+// Values for bandwidth broadcasting
+static const uint16_t g728_facv[LPC] = {
+    16192, 16002, 15815, 15629, 15446, 15265, 15086, 14910, 14735, 14562,
+    14391, 14223, 14056, 13891, 13729, 13568, 13409, 13252, 13096, 12943,
+    12791, 12641, 12493, 12347, 12202, 12059, 11918, 11778, 11640, 11504,
+    11369, 11236, 11104, 10974, 10845, 10718, 10593, 10468, 10346, 10225,
+    10105,  9986,  9869,  9754,  9639,  9526,  9415,  9304,  9195,  9088
+};
+
+#endif /* AVCODEC_G728DATA_H */
diff --git a/libavcodec/g728dec.c b/libavcodec/g728dec.c
new file mode 100644
index 0000000000..fdaf0a853e
--- /dev/null
+++ b/libavcodec/g728dec.c
@@ -0,0 +1,220 @@
+/*
+ * G.728 decoder
+ * Copyright (c) 2025 Peter Ross
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "celp_filters.h"
+#include "codec_internal.h"
+#include "decode.h"
+#include "get_bits.h"
+#include "g728data.h"
+#include "lpc_functions.h"
+#include "ra288.h"
+#include "libavutil/float_dsp.h"
+#include "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
+#include "libavutil/opt.h"
+#include "libavutil/thread.h"
+
+#define MAX_BACKWARD_FILTER_ORDER  LPC
+#define MAX_BACKWARD_FILTER_LEN    NFRSZ
+#define MAX_BACKWARD_FILTER_NONREC NONR
+#define ATTEN 0.75f
+#include "g728_template.c"
+
+#define LPCW 10 /* Perceptual weighting filter order */
+#define GOFF 32.0f /* Log-gain offset value */
+
+static float g728_gq_db[8];
+static float g728_y_db[128];
+static float g728_wnr_r[FFALIGN(NSBSZ,16)];
+static float g728_wnrg_r[FFALIGN(NSBGSZ, 16)];
+static float g728_facv_f[FFALIGN(LPC, 16)];
+
+static av_cold void g728_init_static_data(void)
+{
+    for(int i = 0; i < FF_ARRAY_ELEMS(amptable); i++)
+        g728_gq_db[i] = 10.0f*log10f(amptable[i] * amptable[i]);
+
+    for (int i = 0; i < FF_ARRAY_ELEMS(codetable); i++) {
+        float cby[IDIM];
+        for (int j = 0; j < IDIM; j++)
+            cby[j] = codetable[i][j] * (1.0f/(1<<11));
+        g728_y_db[i] = 10.0f*log10f(ff_scalarproduct_float_c(cby, cby, IDIM) / IDIM);
+    }
+
+    for (int i = 0; i < NSBSZ; i++)
+        g728_wnr_r[i] = g728_wnr[NSBSZ - 1 - i] * (1.0f/(1<<15));
+    for (int i = 0; i < NSBGSZ; i++)
+        g728_wnrg_r[i] = g728_wnrg[NSBGSZ - 1 - i] * (1.0f/(1<<15));
+    for (int i = 0; i < LPC; i++)
+        g728_facv_f[i] = g728_facv[i] * (1.0f/(1<<14));
+}
+
+typedef struct {
+    AVFloatDSPContext *fdsp;
+    int valid;
+    float a[LPC];
+    DECLARE_ALIGNED(32, float, sb)[NSBSZ];
+    DECLARE_ALIGNED(32, float, sbg)[NSBGSZ];
+    DECLARE_ALIGNED(32, float, gp)[FFALIGN(LPCLG, 16)];
+    DECLARE_ALIGNED(32, float, atmp)[FFALIGN(LPC, 16)];
+    float rexp[LPC + 1];
+    float rexpg[LPCLG + 1];
+    float r[LPC + 1];
+    float alpha;
+} G728Context;
+
+static av_cold int g728_decode_init(AVCodecContext *avctx)
+{
+    static AVOnce init_static_once = AV_ONCE_INIT;
+    G728Context *s = avctx->priv_data;
+
+    s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
+    if (!s->fdsp)
+        return AVERROR(ENOMEM);
+
+    s->gp[0] = -1.0f;
+    for (int i = 0; i < NUPDATE; i++)
+        s->sbg[NSBGSZ - 1 -i] = -GOFF;
+
+    avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
+
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+
+    ff_thread_once(&init_static_once, g728_init_static_data);
+    return 0;
+}
+
+static av_cold int g728_decode_close(AVCodecContext *avctx)
+{
+    G728Context *s = avctx->priv_data;
+    av_freep(&s->fdsp);
+    return 0;
+}
+
+static int hybrid_window(AVFloatDSPContext *fdsp,
+                         int order, int n, int non_rec, float *out,
+                         const float *hist, float *out2, const float *window)
+{
+    do_hybrid_window(fdsp->vector_fmul, order, n, non_rec, out, hist, out2, window);
+    return out[order] != 0.0f;
+}
+
+static void decode_frame(G728Context *s, GetBitContext *gb, float *dst)
+{
+    float *gstate = s->sbg + NSBGSZ - 2;
+
+    for (int idx = 0; idx < NUPDATE; idx++) {
+        DECLARE_ALIGNED(32, float, et)[IDIM];
+        float *statelpc = s->sb + NSBSZ - NFRSZ + idx*IDIM;
+        float gain, gain_db;
+        int is, ig;
+
+        gain_db = 0.0f;
+        for (int i = 0; i < LPCLG; i++)
+            gain_db -= s->gp[i] * gstate[-i];
+        gain_db = av_clipf(gain_db, -GOFF, 28.0f);
+
+        is = get_bits(gb, 7); // shape index
+        ig = get_bits(gb, 3); // gain index
+
+        gain = powf(10.0f, (gain_db + GOFF) * .05f) * amptable[ig] * (1.0f/(1<<11));
+        for (int i = 0; i < IDIM; i++)
+            et[i] = codetable[is][i] * gain;
+
+        ff_celp_lp_synthesis_filterf(statelpc, s->a, et, IDIM, LPC);
+
+        for (int i = 0; i < IDIM; i++) {
+            statelpc[i] = av_clipf(statelpc[i], -4095.0f, 4095.0f);
+            dst[idx*IDIM + i] = statelpc[i] * (1.0f/(1<<12));
+        }
+
+        gstate++;
+        *gstate = FFMAX(-GOFF, g728_gq_db[ig] + g728_y_db[is] + gain_db);
+
+        if (idx == 0) {
+            DECLARE_ALIGNED(32, float, gptmp)[FFALIGN(LPCLG, 16)];
+            if (s->valid && (s->valid = !compute_lpc_coefs(s->r + 1, LPCW, LPC, s->atmp, 0, 0, 1, &s->alpha))) {
+                s->fdsp->vector_fmul(s->atmp, s->atmp, g728_facv_f, FFALIGN(LPC, 16));
+            }
+            if (hybrid_window(s->fdsp, LPCLG, NUPDATE, NONRLG, s->r, s->sbg, s->rexpg, g728_wnrg_r) &&
+                    !compute_lpc_coefs(s->r, 0, LPCLG, gptmp, 0, 0, 1, &s->alpha)) {
+                s->fdsp->vector_fmul(s->gp, gptmp, gain_bw_tab, FFALIGN(LPCLG, 16));
+            }
+            memmove(s->sbg, s->sbg + NUPDATE, sizeof(float)*(LPCLG + NONRLG));
+            gstate = s->sbg + NSBGSZ - 1 - NUPDATE;
+        } else if (idx == 1) {
+            if (s->valid)
+                memcpy(s->a, s->atmp, sizeof(float)*LPC);
+        }
+    }
+
+    s->valid = 0;
+    if (hybrid_window(s->fdsp, LPC, NFRSZ, NONR, s->r, s->sb, s->rexp, g728_wnr_r)) {
+        s->valid = !compute_lpc_coefs(s->r, 0, LPCW, s->atmp, 0, 0, 1, &s->alpha);
+    }
+
+    memmove(s->sb, s->sb + NFRSZ, sizeof(float)*(LPC + NONR));
+}
+
+static int g728_decode_frame(AVCodecContext *avctx, AVFrame *frame,
+                            int *got_frame_ptr, AVPacket *avpkt)
+{
+    G728Context *s = avctx->priv_data;
+    GetBitContext gb;
+    int ret;
+    int nb_frames = avpkt->size / 5;
+
+    if (!nb_frames)
+        return AVERROR_INVALIDDATA;
+
+    if ((ret = init_get_bits8(&gb, avpkt->data, avpkt->size)) < 0)
+        return ret;
+
+#define SAMPLES_PER_FRAME 20
+
+    frame->nb_samples = nb_frames * SAMPLES_PER_FRAME;
+    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
+        return ret;
+
+    for (int i = 0; i < nb_frames; i++)
+        decode_frame(s, &gb, (float *)frame->data[0] + i * 20);
+
+    *got_frame_ptr = 1;
+
+    return nb_frames * 5;
+}
+
+const FFCodec ff_g728_decoder = {
+    .p.name         = "g728",
+    CODEC_LONG_NAME("G.728)"),
+    .p.type         = AVMEDIA_TYPE_AUDIO,
+    .p.id           = AV_CODEC_ID_G728,
+    .priv_data_size = sizeof(G728Context),
+    .init           = g728_decode_init,
+    .close          = g728_decode_close,
+    FF_CODEC_DECODE_CB(g728_decode_frame),
+    .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
+                      AV_CODEC_CAP_DR1,
+    .p.sample_fmts  = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT,
+                                                      AV_SAMPLE_FMT_NONE },
+};
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 90867ed6b1..f2686b6863 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -550,6 +550,7 @@ int av_get_bits_per_sample(enum AVCodecID codec_id)
     case AV_CODEC_ID_DFPWM:
         return 1;
     case AV_CODEC_ID_ADPCM_SBPRO_2:
+    case AV_CODEC_ID_G728:
         return 2;
     case AV_CODEC_ID_ADPCM_SBPRO_3:
         return 3;
-- 
2.47.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [FFmpeg-devel] [PATCHv3 5/8] avformat/g728dec: raw G.728 demuxer
  2025-06-09 10:05 [FFmpeg-devel] [PATCHv3 0/8] G.728 decoding Peter Ross
                   ` (3 preceding siblings ...)
  2025-06-09 10:07 ` [FFmpeg-devel] [PATCHv3 4/8] avcodec/g728dec: G.728 decoder Peter Ross
@ 2025-06-09 10:07 ` Peter Ross
  2025-06-09 10:08 ` [FFmpeg-devel] [PATCHv3 6/8] avformat/riff: G.728 muxing and demuxing Peter Ross
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Peter Ross @ 2025-06-09 10:07 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1: Type: text/plain, Size: 3728 bytes --]

---
 libavformat/Makefile     |  1 +
 libavformat/allformats.c |  1 +
 libavformat/g728dec.c    | 58 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+)
 create mode 100644 libavformat/g728dec.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 9884b4a4cb..2e73f1325e 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -247,6 +247,7 @@ OBJS-$(CONFIG_G726_DEMUXER)              += g726.o
 OBJS-$(CONFIG_G726_MUXER)                += rawenc.o
 OBJS-$(CONFIG_G726LE_DEMUXER)            += g726.o
 OBJS-$(CONFIG_G726LE_MUXER)              += rawenc.o
+OBJS-$(CONFIG_G728_DEMUXER)              += g728dec.o
 OBJS-$(CONFIG_G729_DEMUXER)              += g729dec.o
 OBJS-$(CONFIG_GDV_DEMUXER)               += gdv.o
 OBJS-$(CONFIG_GENH_DEMUXER)              += genh.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 17215d733d..4e9958bd18 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -191,6 +191,7 @@ extern const FFInputFormat  ff_g726_demuxer;
 extern const FFOutputFormat ff_g726_muxer;
 extern const FFInputFormat  ff_g726le_demuxer;
 extern const FFOutputFormat ff_g726le_muxer;
+extern const FFInputFormat  ff_g728_demuxer;
 extern const FFInputFormat  ff_g729_demuxer;
 extern const FFInputFormat  ff_gdv_demuxer;
 extern const FFInputFormat  ff_genh_demuxer;
diff --git a/libavformat/g728dec.c b/libavformat/g728dec.c
new file mode 100644
index 0000000000..dbf5e64d05
--- /dev/null
+++ b/libavformat/g728dec.c
@@ -0,0 +1,58 @@
+/*
+ * G.728 raw demuxer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "demux.h"
+#include "internal.h"
+
+static int g728_read_header(AVFormatContext *s)
+{
+    AVStream *st = avformat_new_stream(s, NULL);
+    if (!st)
+        return AVERROR(ENOMEM);
+
+    st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
+    st->codecpar->codec_id    = ffifmt(s->iformat)->raw_codec_id;
+    st->codecpar->sample_rate = 8000;
+    st->codecpar->bit_rate    = 16000;
+    st->codecpar->block_align = 5;
+    st->codecpar->ch_layout   = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+    avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
+
+    return 0;
+}
+
+static int g728_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    int ret = av_get_packet(s->pb, pkt, 1020); // a size similar to RAW_PACKET_SIZE divisible by 5
+    pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+    pkt->duration = (pkt->size / 5) * 20;
+    return ret;
+}
+
+const FFInputFormat ff_g728_demuxer = {
+    .p.name         = "g728",
+    .p.long_name    = NULL_IF_CONFIG_SMALL("raw G.728"),
+    .p.extensions   = "g728",
+    .p.flags        = AVFMT_GENERIC_INDEX,
+    .read_header    = g728_read_header,
+    .read_packet    = g728_read_packet,
+    .raw_codec_id   = AV_CODEC_ID_G728,
+};
-- 
2.47.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [FFmpeg-devel] [PATCHv3 6/8] avformat/riff: G.728 muxing and demuxing
  2025-06-09 10:05 [FFmpeg-devel] [PATCHv3 0/8] G.728 decoding Peter Ross
                   ` (4 preceding siblings ...)
  2025-06-09 10:07 ` [FFmpeg-devel] [PATCHv3 5/8] avformat/g728dec: raw G.728 demuxer Peter Ross
@ 2025-06-09 10:08 ` Peter Ross
  2025-06-09 10:08 ` [FFmpeg-devel] [PATCHv3 7/8] avformat/aiff: " Peter Ross
  2025-06-09 10:08 ` [FFmpeg-devel] [PATCHv3 8/8] avformat/rtp: " Peter Ross
  7 siblings, 0 replies; 14+ messages in thread
From: Peter Ross @ 2025-06-09 10:08 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1: Type: text/plain, Size: 1791 bytes --]

---
 libavformat/riff.c    | 2 ++
 libavformat/riffenc.c | 1 +
 2 files changed, 3 insertions(+)

diff --git a/libavformat/riff.c b/libavformat/riff.c
index 017a0658ef..151563e9f2 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -555,6 +555,7 @@ const AVCodecTag ff_codec_wav_tags[] = {
     { AV_CODEC_ID_ADPCM_G726,      0x0045 },
     { AV_CODEC_ID_ADPCM_G726,      0x0014 },  /* g723 Antex */
     { AV_CODEC_ID_ADPCM_G726,      0x0040 },  /* g721 Antex */
+    { AV_CODEC_ID_G728,            0x0041 },
     { AV_CODEC_ID_MP2,             0x0050 },
     { AV_CODEC_ID_MP3,             0x0055 },
     { AV_CODEC_ID_AMR_NB,          0x0057 },
@@ -611,6 +612,7 @@ const AVCodecTag ff_codec_wav_tags[] = {
     { AV_CODEC_ID_G723_1,          0xA100 }, /* Comverse Infosys Ltd. G723 1 */
     { AV_CODEC_ID_AAC,             0xA106 },
     { AV_CODEC_ID_SPEEX,           0xA109 },
+    { AV_CODEC_ID_G728,            0xCD02 },
     { AV_CODEC_ID_FLAC,            0xF1AC },
     /* DFPWM does not have an assigned format tag; it uses a GUID in WAVEFORMATEX instead */
     { AV_CODEC_ID_DFPWM,           0xFFFE },
diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index 59c9932c36..df98b3b117 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -92,6 +92,7 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb,
     avio_wl32(pb, par->sample_rate);
     if (par->codec_id == AV_CODEC_ID_ATRAC3 ||
         par->codec_id == AV_CODEC_ID_G723_1 ||
+        par->codec_id == AV_CODEC_ID_G728   ||
         par->codec_id == AV_CODEC_ID_MP2    ||
         par->codec_id == AV_CODEC_ID_MP3    ||
         par->codec_id == AV_CODEC_ID_GSM_MS) {
-- 
2.47.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [FFmpeg-devel] [PATCHv3 7/8] avformat/aiff: G.728 muxing and demuxing
  2025-06-09 10:05 [FFmpeg-devel] [PATCHv3 0/8] G.728 decoding Peter Ross
                   ` (5 preceding siblings ...)
  2025-06-09 10:08 ` [FFmpeg-devel] [PATCHv3 6/8] avformat/riff: G.728 muxing and demuxing Peter Ross
@ 2025-06-09 10:08 ` Peter Ross
  2025-06-09 22:25   ` Andreas Rheinhardt
  2025-06-09 10:08 ` [FFmpeg-devel] [PATCHv3 8/8] avformat/rtp: " Peter Ross
  7 siblings, 1 reply; 14+ messages in thread
From: Peter Ross @ 2025-06-09 10:08 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1: Type: text/plain, Size: 1303 bytes --]

---
 libavformat/aiff.c    | 1 +
 libavformat/aiffdec.c | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/libavformat/aiff.c b/libavformat/aiff.c
index 1ceac69a70..907f7d8d28 100644
--- a/libavformat/aiff.c
+++ b/libavformat/aiff.c
@@ -40,6 +40,7 @@ const AVCodecTag ff_codec_aiff_tags[] = {
     { AV_CODEC_ID_GSM,          MKTAG('G','S','M',' ') },
     { AV_CODEC_ID_ADPCM_G722,   MKTAG('G','7','2','2') },
     { AV_CODEC_ID_ADPCM_G726LE, MKTAG('G','7','2','6') },
+    { AV_CODEC_ID_G728,         MKTAG('G','7','2','8') },
     { AV_CODEC_ID_PCM_S16BE,    MKTAG('t','w','o','s') },
     { AV_CODEC_ID_PCM_S16LE,    MKTAG('s','o','w','t') },
     { AV_CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index bd5bd2e4bb..aeb00cccd0 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -174,6 +174,9 @@ static int get_aiff_header(AVFormatContext *s, int64_t size,
         case AV_CODEC_ID_GSM:
             par->block_align = 33;
             break;
+        case AV_CODEC_ID_G728:
+            par->block_align = 5;
+            break;
         default:
             aiff->block_duration = 1;
             break;
-- 
2.47.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [FFmpeg-devel] [PATCHv3 8/8] avformat/rtp: G.728 muxing and demuxing
  2025-06-09 10:05 [FFmpeg-devel] [PATCHv3 0/8] G.728 decoding Peter Ross
                   ` (6 preceding siblings ...)
  2025-06-09 10:08 ` [FFmpeg-devel] [PATCHv3 7/8] avformat/aiff: " Peter Ross
@ 2025-06-09 10:08 ` Peter Ross
  7 siblings, 0 replies; 14+ messages in thread
From: Peter Ross @ 2025-06-09 10:08 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1: Type: text/plain, Size: 1349 bytes --]

---
 libavformat/rtp.c    | 2 +-
 libavformat/rtpenc.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/rtp.c b/libavformat/rtp.c
index 564489b613..5bde171cf4 100644
--- a/libavformat/rtp.c
+++ b/libavformat/rtp.c
@@ -53,7 +53,7 @@ static const struct {
   {13, "CN",         AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_NONE, 8000, 1},
   {14, "MPA",        AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_MP2, -1, -1},
   {14, "MPA",        AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_MP3, -1, -1},
-  {15, "G728",       AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_NONE, 8000, 1},
+  {15, "G728",       AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_G728, 8000, 1},
   {16, "DVI4",       AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_NONE, 11025, 1},
   {17, "DVI4",       AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_NONE, 22050, 1},
   {18, "G729",       AVMEDIA_TYPE_AUDIO,   AV_CODEC_ID_NONE, 8000, 1},
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index b220a941a2..795229aca3 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -89,6 +89,7 @@ static int is_supported(enum AVCodecID id)
     case AV_CODEC_ID_OPUS:
     case AV_CODEC_ID_RAWVIDEO:
     case AV_CODEC_ID_BITPACKED:
+    case AV_CODEC_ID_G728:
         return 1;
     default:
         return 0;
-- 
2.47.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [FFmpeg-devel] [PATCHv3 1/8] avcodec/g728_template: do_hybrid_window() template
  2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 1/8] avcodec/g728_template: do_hybrid_window() template Peter Ross
@ 2025-06-09 21:56   ` Tomas Härdin
  0 siblings, 0 replies; 14+ messages in thread
From: Tomas Härdin @ 2025-06-09 21:56 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

mån 2025-06-09 klockan 20:06 +1000 skrev Peter Ross:
> +static void convolve(float *tgt, const float *src, int len, int n)
> +{
> +    for (; n >= 0; n--)
> +        tgt[n] = ff_scalarproduct_float_c(src, src - n, len);
> +
> +}

This should probably use an FFT since this implementation is O(n²).
That doesn't need to hold up this patch though, since it just moves the
existing implementation

/Tomas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [FFmpeg-devel] [PATCHv3 7/8] avformat/aiff: G.728 muxing and demuxing
  2025-06-09 10:08 ` [FFmpeg-devel] [PATCHv3 7/8] avformat/aiff: " Peter Ross
@ 2025-06-09 22:25   ` Andreas Rheinhardt
  2025-06-10  0:07     ` compn
  2025-06-10  0:29     ` Peter Ross
  0 siblings, 2 replies; 14+ messages in thread
From: Andreas Rheinhardt @ 2025-06-09 22:25 UTC (permalink / raw)
  To: ffmpeg-devel

Peter Ross:
> ---
>  libavformat/aiff.c    | 1 +
>  libavformat/aiffdec.c | 3 +++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/libavformat/aiff.c b/libavformat/aiff.c
> index 1ceac69a70..907f7d8d28 100644
> --- a/libavformat/aiff.c
> +++ b/libavformat/aiff.c
> @@ -40,6 +40,7 @@ const AVCodecTag ff_codec_aiff_tags[] = {
>      { AV_CODEC_ID_GSM,          MKTAG('G','S','M',' ') },
>      { AV_CODEC_ID_ADPCM_G722,   MKTAG('G','7','2','2') },
>      { AV_CODEC_ID_ADPCM_G726LE, MKTAG('G','7','2','6') },
> +    { AV_CODEC_ID_G728,         MKTAG('G','7','2','8') },
>      { AV_CODEC_ID_PCM_S16BE,    MKTAG('t','w','o','s') },
>      { AV_CODEC_ID_PCM_S16LE,    MKTAG('s','o','w','t') },
>      { AV_CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
> diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
> index bd5bd2e4bb..aeb00cccd0 100644
> --- a/libavformat/aiffdec.c
> +++ b/libavformat/aiffdec.c
> @@ -174,6 +174,9 @@ static int get_aiff_header(AVFormatContext *s, int64_t size,
>          case AV_CODEC_ID_GSM:
>              par->block_align = 33;
>              break;
> +        case AV_CODEC_ID_G728:
> +            par->block_align = 5;
> +            break;
>          default:
>              aiff->block_duration = 1;
>              break;
> 
Is this and the riff patch based on some spec or are you just inventing
things here?

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [FFmpeg-devel] [PATCHv3 7/8] avformat/aiff: G.728 muxing and demuxing
  2025-06-09 22:25   ` Andreas Rheinhardt
@ 2025-06-10  0:07     ` compn
  2025-06-10  0:29     ` Peter Ross
  1 sibling, 0 replies; 14+ messages in thread
From: compn @ 2025-06-10  0:07 UTC (permalink / raw)
  To: ffmpeg-devel

On Tue, 10 Jun 2025 00:25:24 +0200, Andreas Rheinhardt wrote:

> Peter Ross:
> > ---
> >  libavformat/aiff.c    | 1 +
> >  libavformat/aiffdec.c | 3 +++
> >  2 files changed, 4 insertions(+)
> > 
> > diff --git a/libavformat/aiff.c b/libavformat/aiff.c
> > index 1ceac69a70..907f7d8d28 100644
> > --- a/libavformat/aiff.c
> > +++ b/libavformat/aiff.c
> > @@ -40,6 +40,7 @@ const AVCodecTag ff_codec_aiff_tags[] = {
> >      { AV_CODEC_ID_GSM,          MKTAG('G','S','M',' ') },
> >      { AV_CODEC_ID_ADPCM_G722,   MKTAG('G','7','2','2') },
> >      { AV_CODEC_ID_ADPCM_G726LE, MKTAG('G','7','2','6') },
> > +    { AV_CODEC_ID_G728,         MKTAG('G','7','2','8') },
> >      { AV_CODEC_ID_PCM_S16BE,    MKTAG('t','w','o','s') },
> >      { AV_CODEC_ID_PCM_S16LE,    MKTAG('s','o','w','t') },
> >      { AV_CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
> > diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
> > index bd5bd2e4bb..aeb00cccd0 100644
> > --- a/libavformat/aiffdec.c
> > +++ b/libavformat/aiffdec.c
> > @@ -174,6 +174,9 @@ static int get_aiff_header(AVFormatContext *s, int64_t size,
> >          case AV_CODEC_ID_GSM:
> >              par->block_align = 33;
> >              break;
> > +        case AV_CODEC_ID_G728:
> > +            par->block_align = 5;
> > +            break;
> >          default:
> >              aiff->block_duration = 1;
> >              break;
> >   
> Is this and the riff patch based on some spec or are you just inventing
> things here?

maybe i can help.

https://wiki.multimedia.cx/index.php/G.728
lists 0xCD02 and 0x0041
according to the history of that wiki page, the 0xCD02 comes from
"plcmg728.acm" binary codec.

other list of twocc here: https://wiki.multimedia.cx/index.php/TwoCC

i havent myself tested plcmg728.acm , but its on my list to investigate
here https://wiki.multimedia.cx/index.php/Category_talk:Audio_Codecs

plcmg728.acm should be included with the software:
Polycom PVX
"Create video conferences with a USB webcam"

did Polycom make up that entry or should we support it anyways? i say
support it until another 0xCD02 shows up. and then we deal with the
conflict at that time.

if you go to the spec page
https://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/AIFF.html
and click samples
https://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/Samples.html
at the bottom is g728 sample
 o2_728.aiff (1 kB) *
    AIFF-C file: G.728 data (compression code: G728)

hopefully that answers all riff/aiff questions.

-compn
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [FFmpeg-devel] [PATCHv3 7/8] avformat/aiff: G.728 muxing and demuxing
  2025-06-09 22:25   ` Andreas Rheinhardt
  2025-06-10  0:07     ` compn
@ 2025-06-10  0:29     ` Peter Ross
  2025-06-11 14:45       ` compn
  1 sibling, 1 reply; 14+ messages in thread
From: Peter Ross @ 2025-06-10  0:29 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 2057 bytes --]

On Tue, Jun 10, 2025 at 12:25:24AM +0200, Andreas Rheinhardt wrote:
> Peter Ross:
> > ---
> >  libavformat/aiff.c    | 1 +
> >  libavformat/aiffdec.c | 3 +++
> >  2 files changed, 4 insertions(+)
> > 
> > diff --git a/libavformat/aiff.c b/libavformat/aiff.c
> > index 1ceac69a70..907f7d8d28 100644
> > --- a/libavformat/aiff.c
> > +++ b/libavformat/aiff.c
> > @@ -40,6 +40,7 @@ const AVCodecTag ff_codec_aiff_tags[] = {
> >      { AV_CODEC_ID_GSM,          MKTAG('G','S','M',' ') },
> >      { AV_CODEC_ID_ADPCM_G722,   MKTAG('G','7','2','2') },
> >      { AV_CODEC_ID_ADPCM_G726LE, MKTAG('G','7','2','6') },
> > +    { AV_CODEC_ID_G728,         MKTAG('G','7','2','8') },
> >      { AV_CODEC_ID_PCM_S16BE,    MKTAG('t','w','o','s') },
> >      { AV_CODEC_ID_PCM_S16LE,    MKTAG('s','o','w','t') },
> >      { AV_CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
> > diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
> > index bd5bd2e4bb..aeb00cccd0 100644
> > --- a/libavformat/aiffdec.c
> > +++ b/libavformat/aiffdec.c
> > @@ -174,6 +174,9 @@ static int get_aiff_header(AVFormatContext *s, int64_t size,
> >          case AV_CODEC_ID_GSM:
> >              par->block_align = 33;
> >              break;
> > +        case AV_CODEC_ID_G728:
> > +            par->block_align = 5;
> > +            break;
> >          default:
> >              aiff->block_duration = 1;
> >              break;
> > 
> Is this and the riff patch based on some spec or are you just inventing
> things here?

No inventions.

The aiff patch is based on sample here:
https://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/Samples.html
Search for G.728. I am unsure what software was used to create that sample.

The riff twocc's originate from binary G.728 ACM DLLs:
	kdg728.acm "Kedacom G.728" 0x0041 
	plcmg728.acm "Polycom G.728" 0xCD02

I have tested remuxing raw G.728 into riff wav using ffmpeg, and playing them
back on windows using the ACM DLLs.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [FFmpeg-devel] [PATCHv3 7/8] avformat/aiff: G.728 muxing and demuxing
  2025-06-10  0:29     ` Peter Ross
@ 2025-06-11 14:45       ` compn
  0 siblings, 0 replies; 14+ messages in thread
From: compn @ 2025-06-11 14:45 UTC (permalink / raw)
  To: ffmpeg-devel

On Tue, 10 Jun 2025 10:29:40 +1000, Peter Ross wrote:

> The aiff patch is based on sample here:
> https://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/Samples.html
> Search for G.728. I am unsure what software was used to create that sample.

i grabbed the samples from that spec page
( ftp://ftp-ccrma.stanford.edu/pub/Lisp/sf.tar.gz )
and extracted it to https://samples.ffmpeg.org/A-codecs/sf/
for future testing.

-compn
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-06-11 14:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-09 10:05 [FFmpeg-devel] [PATCHv3 0/8] G.728 decoding Peter Ross
2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 1/8] avcodec/g728_template: do_hybrid_window() template Peter Ross
2025-06-09 21:56   ` Tomas Härdin
2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 2/8] avcodec/g728_template: make hist parameter constant Peter Ross
2025-06-09 10:06 ` [FFmpeg-devel] [PATCHv3 3/8] avcodec/lpc_functions: compute_lpc_coefs: add starting lpc order and err cache parameters Peter Ross
2025-06-09 10:07 ` [FFmpeg-devel] [PATCHv3 4/8] avcodec/g728dec: G.728 decoder Peter Ross
2025-06-09 10:07 ` [FFmpeg-devel] [PATCHv3 5/8] avformat/g728dec: raw G.728 demuxer Peter Ross
2025-06-09 10:08 ` [FFmpeg-devel] [PATCHv3 6/8] avformat/riff: G.728 muxing and demuxing Peter Ross
2025-06-09 10:08 ` [FFmpeg-devel] [PATCHv3 7/8] avformat/aiff: " Peter Ross
2025-06-09 22:25   ` Andreas Rheinhardt
2025-06-10  0:07     ` compn
2025-06-10  0:29     ` Peter Ross
2025-06-11 14:45       ` compn
2025-06-09 10:08 ` [FFmpeg-devel] [PATCHv3 8/8] avformat/rtp: " Peter Ross

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git