linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Frédéric Dalleau" <frederic.dalleau@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: "Frédéric Dalleau" <frederic.dalleau@linux.intel.com>
Subject: [PATCH v4 15/16] sbc: Update sbcinfo for msbc
Date: Tue, 30 Oct 2012 10:39:34 +0100	[thread overview]
Message-ID: <1351589975-22640-16-git-send-email-frederic.dalleau@linux.intel.com> (raw)
In-Reply-To: <1351589975-22640-1-git-send-email-frederic.dalleau@linux.intel.com>

---
 src/sbcinfo.c |   51 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 15 deletions(-)

diff --git a/src/sbcinfo.c b/src/sbcinfo.c
index 8cfb54a..01426b8 100644
--- a/src/sbcinfo.c
+++ b/src/sbcinfo.c
@@ -61,12 +61,11 @@ struct sbc_frame_hdr {
 #error "Unknown byte order"
 #endif
 
-static int calc_frame_len(struct sbc_frame_hdr *hdr)
+static int calc_frame_len(struct sbc_frame_hdr *hdr, int nrof_blocks)
 {
-	int tmp, nrof_subbands, nrof_blocks;
+	int tmp, nrof_subbands;
 
 	nrof_subbands = (hdr->subbands + 1) * 4;
-	nrof_blocks = (hdr->blocks + 1) * 4;
 
 	switch (hdr->channel_mode) {
 	case 0x00:
@@ -89,13 +88,12 @@ static int calc_frame_len(struct sbc_frame_hdr *hdr)
 	return (nrof_subbands + ((tmp + 7) / 8));
 }
 
-static double calc_bit_rate(struct sbc_frame_hdr *hdr)
+static double calc_bit_rate(struct sbc_frame_hdr *hdr, int nrof_blocks)
 {
-	int nrof_subbands, nrof_blocks;
+	int nrof_subbands;
 	double f;
 
 	nrof_subbands = (hdr->subbands + 1) * 4;
-	nrof_blocks = (hdr->blocks + 1) * 4;
 
 	switch (hdr->sampling_frequency) {
 	case 0:
@@ -114,7 +112,7 @@ static double calc_bit_rate(struct sbc_frame_hdr *hdr)
 		return 0;
 	}
 
-	return ((8 * (calc_frame_len(hdr) + 4) * f) /
+	return ((8 * (calc_frame_len(hdr, nrof_blocks) + 4) * f) /
 			(nrof_subbands * nrof_blocks));
 }
 
@@ -175,7 +173,7 @@ static int analyze_file(char *filename)
 	double rate;
 	int bitpool[SIZE], frame_len[SIZE];
 	int subbands, blocks, freq, method;
-	int n, p1, p2, fd, size, num;
+	int n, p1, p2, fd, size, num, msbc;
 	ssize_t len;
 	unsigned int count;
 
@@ -191,17 +189,30 @@ static int analyze_file(char *filename)
 		fd = fileno(stdin);
 
 	len = __read(fd, &hdr, sizeof(hdr));
-	if (len != sizeof(hdr) || hdr.syncword != 0x9c) {
+	if (len != sizeof(hdr) || !(hdr.syncword == 0x9c ||
+			hdr.syncword == 0xad)) {
 		fprintf(stderr, "Not a SBC audio file\n");
 		return -1;
 	}
+	msbc = (hdr.syncword == 0xad) ? 1 : 0;
+
+	if (msbc) {
+		hdr.subbands = 1; /* 8 */
+		hdr.sampling_frequency = 0x00; /* 16000 */
+		hdr.allocation_method = 0; /* Loudness */
+		hdr.bitpool = 26;
+		hdr.channel_mode = 0x00; /* Mono */
+
+		blocks = 15;
+	} else {
+		blocks = (hdr.blocks + 1) * 4;
+	}
 
 	subbands = (hdr.subbands + 1) * 4;
-	blocks = (hdr.blocks + 1) * 4;
 	freq = hdr.sampling_frequency;
 	method = hdr.allocation_method;
 
-	count = calc_frame_len(&hdr);
+	count = calc_frame_len(&hdr, blocks);
 
 	bitpool[0] = hdr.bitpool;
 	frame_len[0] = count + 4;
@@ -213,7 +224,7 @@ static int analyze_file(char *filename)
 
 	if (lseek(fd, 0, SEEK_SET) < 0) {
 		num = 1;
-		rate = calc_bit_rate(&hdr);
+		rate = calc_bit_rate(&hdr, blocks);
 		while (count) {
 			size = count > sizeof(buf) ? sizeof(buf) : count;
 			len = __read(fd, buf, size);
@@ -237,14 +248,23 @@ static int analyze_file(char *filename)
 		if (len == 0)
 			break;
 
-		if ((size_t) len < sizeof(hdr) || hdr.syncword != 0x9c) {
+		if ((size_t) len < sizeof(hdr) || !(hdr.syncword == 0x9c ||
+				hdr.syncword == 0xad)) {
 			fprintf(stderr, "Corrupted SBC stream "
 					"(len %zd syncword 0x%02x)\n",
 					len, hdr.syncword);
 			break;
 		}
 
-		count = calc_frame_len(&hdr);
+		if (msbc) {
+			hdr.subbands = 1; /* 8 */
+			hdr.sampling_frequency = 0x00; /* 16000 */
+			hdr.allocation_method = 0; /* Loudness */
+			hdr.bitpool = 26;
+			hdr.channel_mode = 0x00; /* Mono */
+		}
+
+		count = calc_frame_len(&hdr, blocks);
 		len = count + 4;
 
 		p1 = -1;
@@ -273,10 +293,11 @@ static int analyze_file(char *filename)
 			count -= len;
 		}
 
-		rate += calc_bit_rate(&hdr);
+		rate += calc_bit_rate(&hdr, blocks);
 		num++;
 	}
 
+	printf("mSBC\t\t\t%d\n", msbc);
 	printf("Subbands\t\t%d\n", subbands);
 	printf("Block length\t\t%d\n", blocks);
 	printf("Sampling frequency\t%s\n", freq2str(freq));
-- 
1.7.9.5


  parent reply	other threads:[~2012-10-30  9:39 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-30  9:39 [PATCH v4 00/16] mSBC tests Frédéric Dalleau
2012-10-30  9:39 ` [PATCH v4 01/16] sbc: Add encoder_state to analysis functions Frédéric Dalleau
2012-10-30  9:39 ` [PATCH v4 02/16] sbc: Break 4 blocks processing to variable steps Frédéric Dalleau
2012-10-30  9:39 ` [PATCH v4 03/16] sbc: Rename sbc_analyze_4b_xx to sbc_analyze_xx Frédéric Dalleau
2012-10-30  9:39 ` [PATCH v4 04/16] sbc: add odd member variable to sbc_encoder_state Frédéric Dalleau
2012-10-30  9:39 ` [PATCH v4 05/16] sbc: Add mmx primitive for 1b 8s analysis Frédéric Dalleau
2012-11-14 15:43   ` Frédéric Dalleau
2012-11-14 20:23     ` Siarhei Siamashka
2012-10-30  9:39 ` [PATCH v4 06/16] sbc: Add armv6 " Frédéric Dalleau
2012-10-30  9:39 ` [PATCH v4 07/16] sbc: Add iwmmxt primitive for 1b 8s encoding Frédéric Dalleau
2012-10-30  9:39 ` [PATCH v4 08/16] sbc: Add simd primitive for 1b 8s analysis Frédéric Dalleau
2012-10-30  9:39 ` [PATCH v4 09/16] sbc: Use simd primitive if doing msbc on neon Frédéric Dalleau
2012-11-14 19:27   ` Siarhei Siamashka
2012-11-15 10:23     ` Frédéric Dalleau
2012-11-18 23:46       ` Siarhei Siamashka
2012-10-30  9:39 ` [PATCH v4 10/16] sbc: simd support for 8 multiples block size Frédéric Dalleau
2012-11-14 19:09   ` Siarhei Siamashka
2012-10-30  9:39 ` [PATCH v4 11/16] sbc: Add SBC_MSBC flag to enable 15 block encoding Frédéric Dalleau
2012-11-14 14:49   ` Marcel Holtmann
2012-11-14 15:34     ` Frédéric Dalleau
2012-11-14 23:20       ` Marcel Holtmann
2012-10-30  9:39 ` [PATCH v4 12/16] sbc: Add support for mSBC frame header Frédéric Dalleau
2012-10-30  9:39 ` [PATCH v4 13/16] sbc: Update sbcdec for msbc Frédéric Dalleau
2012-10-30  9:39 ` [PATCH v4 14/16] sbc: Update sbcenc " Frédéric Dalleau
2012-10-30  9:39 ` Frédéric Dalleau [this message]
2012-10-30  9:39 ` [PATCH v4 16/16] sbc: Update copyrights Frédéric Dalleau
2012-11-14 10:00 ` [PATCH v4 00/16] mSBC tests Frédéric Dalleau
2012-11-14 14:50   ` Marcel Holtmann
2012-11-14 19:57     ` Siarhei Siamashka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1351589975-22640-16-git-send-email-frederic.dalleau@linux.intel.com \
    --to=frederic.dalleau@linux.intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).