1From 1a98ba56da8ba7cebf136922fcf7006cd4c9d51f Mon Sep 17 00:00:00 2001
2From: Jiajian Wu <jair.wu@rock-chips.com>
3Date: Tue, 11 Oct 2022 09:21:10 +0800
4Subject: [PATCH 14/14] riff: Fix bps caculation error for ADPCM
5
6The bps shall be caculated according to:
7ADPCM: rate * blockalign / ((blockalign - ch * 7) / ch * 2)
8DVI ADPCM: rate * blockalign / ((blockalign - ch * 4) / ch * 2)
9cus the sample size is 4bit in ADPCM witch is half
10of raw pcm.
11
12Signed-off-by: Jiajian Wu <jair.wu@rock-chips.com>
13---
14 gst-libs/gst/riff/riff-media.c | 4 ++--
15 1 file changed, 2 insertions(+), 2 deletions(-)
16
17diff --git a/gst-libs/gst/riff/riff-media.c b/gst-libs/gst/riff/riff-media.c
18index 74f99d6..6298884 100644
19--- a/gst-libs/gst/riff/riff-media.c
20+++ b/gst-libs/gst/riff/riff-media.c
21@@ -1310,7 +1310,7 @@ gst_riff_create_audio_caps (guint16 codec_id,
22          * would probably confuse timing */
23         strf->av_bps = 0;
24         if (strf->channels != 0 && strf->rate != 0 && strf->blockalign != 0) {
25-          int spb = ((strf->blockalign - strf->channels * 7) / 2) * 2;
26+          int spb = ((strf->blockalign - strf->channels * 7) / strf->channels) * 2;
27           strf->av_bps =
28               gst_util_uint64_scale_int (strf->rate, strf->blockalign, spb);
29           GST_DEBUG ("fixing av_bps to calculated value %d of MS ADPCM",
30@@ -1432,7 +1432,7 @@ gst_riff_create_audio_caps (guint16 codec_id,
31          * as this would probably confuse timing */
32         strf->av_bps = 0;
33         if (strf->channels != 0 && strf->rate != 0 && strf->blockalign != 0) {
34-          int spb = ((strf->blockalign - strf->channels * 4) / 2) * 2;
35+          int spb = ((strf->blockalign - strf->channels * 4) / strf->channels) * 2;
36           strf->av_bps =
37               gst_util_uint64_scale_int (strf->rate, strf->blockalign, spb);
38           GST_DEBUG ("fixing av_bps to calculated value %d of IMA DVI ADPCM",
39--
402.20.1
41
42