public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] Bad encoding performance of Linux SBC audio codec
@ 2008-10-27  9:54 Christian Hoene
  2008-10-27 18:03 ` Marcel Holtmann
  2008-10-27 19:13 ` Brad Midgley
  0 siblings, 2 replies; 6+ messages in thread
From: Christian Hoene @ 2008-10-27  9:54 UTC (permalink / raw)
  To: bluez-devel; +Cc: 'Frans de Bont'

Hello,

I have made some extensive study on the compression performance of Linux's
SBC audio codec in comparison to the reference implementation.

I am sorry to say that the audio quality of the open source version of SBC
is far worse than the reference implementation.

Can anybody confirm these results?
Do you have any idea why the performance is so worse?

With best regards,

 Christian


--------------------------------------------------------
Dr.-Ing. Christian Hoene
Computer Networks and Internet, University of T=FCbingen
Sand 13, 72076 T=FCbingen, Germany, Phone +49 7071 2970532
http://net.informatik.uni-tuebingen.de/~hoene




-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great priz=
es
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=3D100&url=3D/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

* Re: [Bluez-devel] Bad encoding performance of Linux SBC audio codec
  2008-10-27  9:54 [Bluez-devel] Bad encoding performance of Linux SBC audio codec Christian Hoene
@ 2008-10-27 18:03 ` Marcel Holtmann
  2008-10-27 19:13 ` Brad Midgley
  1 sibling, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2008-10-27 18:03 UTC (permalink / raw)
  To: BlueZ development; +Cc: 'Frans de Bont'

Hi Christian,

> I have made some extensive study on the compression performance of Linux's
> SBC audio codec in comparison to the reference implementation.
> 
> I am sorry to say that the audio quality of the open source version of SBC
> is far worse than the reference implementation.
> 
> Can anybody confirm these results?
> Do you have any idea why the performance is so worse?

are you talking about the encoder or the decoder. For the encoder, I
can't see the big difference. For the decoder you can clearly hear that
we get the volume wrong.

Regards

Marcel



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

* Re: [Bluez-devel] Bad encoding performance of Linux SBC audio codec
  2008-10-27  9:54 [Bluez-devel] Bad encoding performance of Linux SBC audio codec Christian Hoene
  2008-10-27 18:03 ` Marcel Holtmann
@ 2008-10-27 19:13 ` Brad Midgley
  2008-10-27 19:41   ` Marcel Holtmann
  1 sibling, 1 reply; 6+ messages in thread
From: Brad Midgley @ 2008-10-27 19:13 UTC (permalink / raw)
  To: BlueZ development

Christian

> I am sorry to say that the audio quality of the open source version of SBC
> is far worse than the reference implementation.

If you are using the standalone "sbc" project at sourceforge, then you
should try the version inside bluez. The standalone used to simply be
slower, but we identified & fixed some quality issues too that should
be backported.

-- 
Brad Midgley

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

* Re: [Bluez-devel] Bad encoding performance of Linux SBC audio codec
  2008-10-27 19:13 ` Brad Midgley
@ 2008-10-27 19:41   ` Marcel Holtmann
  2008-10-29 15:30     ` [Bluez-devel] REALLY " Christian Hoene
  0 siblings, 1 reply; 6+ messages in thread
From: Marcel Holtmann @ 2008-10-27 19:41 UTC (permalink / raw)
  To: BlueZ development

Hi Brad,

> > I am sorry to say that the audio quality of the open source version of SBC
> > is far worse than the reference implementation.
> 
> If you are using the standalone "sbc" project at sourceforge, then you
> should try the version inside bluez. The standalone used to simply be
> slower, but we identified & fixed some quality issues too that should
> be backported.

the standalone version should not be used at all at the moment. All
efforts should go into the version included in bluez-4.x.tar.gz.

Regards

Marcel



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

* Re: [Bluez-devel] REALLY Bad encoding performance of Linux SBC audio codec
  2008-10-27 19:41   ` Marcel Holtmann
@ 2008-10-29 15:30     ` Christian Hoene
  2008-10-29 22:27       ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Hoene @ 2008-10-29 15:30 UTC (permalink / raw)
  To: 'BlueZ development'; +Cc: 'Frans de Bont'

[-- Attachment #1: Type: text/plain, Size: 2493 bytes --]

Hello,

Sorry Bad news. 
the encoding and decodng performance of bluez's SBC is really bad. 
I just used the latest sbcenc program from bluez-4.17 and compared it to the
reference

Attached you will find wav-files encoded with the Bluetooth reference
implementation and bluez

Filelist
========
compare.sh	        is the scrip that I use to compare both codec
versions
refsop01.wav        the original sample
tmp.ref.sbc         with reference encoded
tmp.bluez.sbc       with bluez encoded
tmp.ref.sw.wav      with reference encoded and decoded (has good quality)
tmp.bluez.sw.wav    with bluez encoded and decoded (has bad quality ODG=)
tmp.refbluez.sw.wav with reference encoded and with bluez decoded (has bad
quality)
tmp.bluezref.sw.wav with bluez encoded and with reference decoded (has
medium quality)

Both the bluez encoder and decoder do not work as good as the reference
implementation.

I also conducted some perceptual audio tests with ITU BS.1387 (PEAQ), which
confirm these results.

With best regards,

 Christian

PS:
Attached also an enhanced version for sbc/sbcenc.c, which considers more
command line options.



> -----Original Message-----
> From: Marcel Holtmann [mailto:marcel@holtmann.org]
> Sent: Monday, October 27, 2008 8:42 PM
> To: BlueZ development
> Subject: Re: [Bluez-devel] Bad encoding performance of Linux SBC audio
> codec
> 
> Hi Brad,
> 
> > > I am sorry to say that the audio quality of the open source version
> of SBC
> > > is far worse than the reference implementation.
> >
> > If you are using the standalone "sbc" project at sourceforge, then
> you
> > should try the version inside bluez. The standalone used to simply be
> > slower, but we identified & fixed some quality issues too that should
> > be backported.
> 
> the standalone version should not be used at all at the moment. All
> efforts should go into the version included in bluez-4.x.tar.gz.
> 
> Regards
> 
> Marcel
> 
> 
> 
> -----------------------------------------------------------------------
> --
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel

[-- Attachment #2: sbcenc.c --]
[-- Type: application/octet-stream, Size: 6060 bytes --]

/*
 *
 *  Bluetooth low-complexity, subband codec (SBC) encoder
 *
 *  Copyright (C) 2004-2008  Marcel Holtmann <marcel@holtmann.org>
 *
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <getopt.h>
#include <sys/stat.h>

#include "sbc.h"
#include "formats.h"

int verbose=0;

static ssize_t __read(int fd, void *buf, size_t count)
{
	ssize_t len, pos = 0;

	while (count > 0) {
		len = read(fd, buf + pos, count);
		if (len <= 0)
			return len;

		count -= len;
		pos   += len;
	}

	return pos;
}

static ssize_t __write(int fd, const void *buf, size_t count)
{
	ssize_t len, pos = 0;

	while (count > 0) {
		len = write(fd, buf + pos, count);
		if (len <= 0)
			return len;

		count -= len;
		pos   += len;
	}

	return pos;
}

static void encode(char *filename, int subbands, int bitpool, int joint, int SNR)
{
	struct au_header *au_hdr;
	unsigned char input[2048], output[2048];
	sbc_t sbc;
	int fd, len, size, count, encoded;

	if (strcmp(filename, "-")) {
		fd = open(filename, O_RDONLY);
		if (fd < 0) {
			fprintf(stderr, "Can't open file %s: %s\n",
						filename, strerror(errno));
			return;
		}
	} else
		fd = fileno(stdin);

	len = __read(fd, input, sizeof(input));
	if (len < sizeof(*au_hdr)) {
		if (fd > fileno(stderr))
			fprintf(stderr, "Can't read header from file %s: %s\n",
						filename, strerror(errno));
		else
			perror("Can't read audio header");
		goto done;
	}

	au_hdr = (struct au_header *) input;

	if (au_hdr->magic != AU_MAGIC ||
			BE_INT(au_hdr->hdr_size) > 128 ||
			BE_INT(au_hdr->hdr_size) < 24 ||
			BE_INT(au_hdr->encoding) != AU_FMT_LIN16) {
		fprintf(stderr, "Data is not in Sun/NeXT audio S16_BE format\n");
		goto done;
	}


	sbc_init(&sbc, 0L);

	switch (BE_INT(au_hdr->sample_rate)) {
	case 16000:
		sbc.frequency = SBC_FREQ_16000;
		break;
	case 32000:
		sbc.frequency = SBC_FREQ_32000;
		break;
	case 44100:
		sbc.frequency = SBC_FREQ_44100;
		break;
	case 48000:
		sbc.frequency = SBC_FREQ_48000;
		break;
	}
	int srate = BE_INT(au_hdr->sample_rate);

	sbc.subbands = subbands == 4 ? SBC_SB_4 : SBC_SB_8;

	if (BE_INT(au_hdr->channels) == 1)
		sbc.mode = SBC_MODE_MONO;
	else if (joint)
		sbc.mode = SBC_MODE_JOINT_STEREO;
	else
		sbc.mode = SBC_MODE_STEREO;

	sbc.endian = SBC_BE;
	count = BE_INT(au_hdr->data_size);
	size = len - BE_INT(au_hdr->hdr_size);
	memmove(input, input + BE_INT(au_hdr->hdr_size), size);

	sbc.bitpool = bitpool;
	sbc.allocation = SNR ? SBC_AM_SNR : SBC_AM_LOUDNESS;

	if(verbose) {
	  fprintf(stderr,"encoding %s with rate %d, %d subbands, %d bits, AM %s, and mode %s\n",
		  filename,srate,subbands,bitpool,
		  sbc.allocation==SBC_AM_SNR?"SNR":"LOUDNESS",
		  sbc.mode==SBC_MODE_MONO?"MONO":sbc.mode==SBC_MODE_STEREO?"STEREO":"JOINTSTEREO");
	}

	while (1) {
		if (size < sizeof(input)) {
			len = __read(fd, input + size, sizeof(input) - size);
			if (len == 0 && size == 0)
				break;

			if (len < 0) {
				perror("Can't read audio data");
				break;
			}

			size += len;
		}

		len = sbc_encode(&sbc, input, size,
					output, sizeof(output), &encoded);
		if (len < size)
			memmove(input, input + len, size - len);

		size -= len;

		len = __write(fileno(stdout), output, encoded);
		if (len == 0)
			break;

		if (len < 0 || len != encoded) {
			perror("Can't write SBC output");
			break;
		}
	}

	sbc_finish(&sbc);

done:
	if (fd > fileno(stderr))
		close(fd);
}

static void usage(void)
{
	printf("SBC encoder utility ver %s\n", VERSION);
	printf("Copyright (c) 2004-2008  Marcel Holtmann\n\n");

	printf("Usage:\n"
		"\tsbcenc [options] file(s)\n"
		"\n");

	printf("Options:\n"
		"\t-h, --help           Display help\n"
		"\t-v, --verbose        Verbose mode\n"
		"\t-s, --subbands       Number of subbands to use (4 or 8)\n"
		"\t-b, --bitpool        Bitpool value (default is 32)\n"
		"\t-j, --joint          Joint stereo\n"
	        "\t-S, --SNR            Use SNR mode (default is loudness)\n"
		"\n");
}

static struct option main_options[] = {
	{ "help",	0, 0, 'h' },
	{ "verbose",	0, 0, 'v' },
	{ "subbands",	1, 0, 's' },
	{ "bitpool",	1, 0, 'b' },
	{ "joint",	0, 0, 'j' },
	{ "SNR",        0, 0, 'S' },
	{ 0, 0, 0, 0 }
};

int main(int argc, char *argv[])
{
  int i, opt, subbands = 8, bitpool = 32, joint = 0, SNR=0;

  while ((opt = getopt_long(argc, argv, "+hvs:b:jS", main_options, NULL)) != -1) {
		switch(opt) {
		case 'h':
			usage();
			exit(0);

		case 'v':
			verbose = 1;
			break;

		case 's':
			subbands = atoi(optarg);
			if (subbands != 8 && subbands != 4) {
				fprintf(stderr, "Invalid subbands %d!\n",
						subbands);
				exit(1);
			}
			break;

		case 'b':
			bitpool = atoi(optarg);
			break;

		case 'j':
			joint = 1;
			break;

		case 'S':
		  SNR = 1;
		  break;

		default:
			exit(1);
		}
	}

	argc -= optind;
	argv += optind;
	optind = 0;

	if (argc < 1) {
		usage();
		exit(1);
	}

	for (i = 0; i < argc; i++)
	  encode(argv[i], subbands, bitpool, joint, SNR);

	return 0;
}

[-- Attachment #3: compare.tar.gz --]
[-- Type: application/octet-stream, Size: 6122532 bytes --]

[-- Attachment #4: Type: text/plain, Size: 363 bytes --]

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

[-- Attachment #5: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

* Re: [Bluez-devel] REALLY Bad encoding performance of Linux SBC audio codec
  2008-10-29 15:30     ` [Bluez-devel] REALLY " Christian Hoene
@ 2008-10-29 22:27       ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2008-10-29 22:27 UTC (permalink / raw)
  To: BlueZ development; +Cc: Frans de Bont

Hello,

Thanks for doing those tests, we never really have a method for
testing the sbc codec, so PEAQ could be a good start. By looking the
results it seems that our decoder is not really in good shape, which
is not a surprise since we normally only use the encoder part. As for
comparison with the reference implementation, bluez sbc codec does not
use floating point as the reference codec seems to be using, so this
may well be impacting on quality, although we probably gain some
speed.

Other points we might need to consider:
  - Test with different audio source/parameter. (48000hz/mono/28
bitpool is not that common to be used as reference)
  - Mono seems to surfer from quality problems which may cause the problem.
  - Consider working on a gstreamer element for doing live tests based
on ITU BS.1387 (PEAQ)
  - Also consider using liboil as alternative for using floating point.

BTW, don't assume something is bad just because it produces different
results than the reference, as far I can tell you one cannot really
notice _any_ difference between bluez sbc codec and logitech freepulse
e(enhanced)sbc, so on real world we are not that _bad_.

-- =

Luiz Augusto von Dentz
Engenheiro de Computa=E7=E3o

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great priz=
es
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=3D100&url=3D/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

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

end of thread, other threads:[~2008-10-29 22:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-27  9:54 [Bluez-devel] Bad encoding performance of Linux SBC audio codec Christian Hoene
2008-10-27 18:03 ` Marcel Holtmann
2008-10-27 19:13 ` Brad Midgley
2008-10-27 19:41   ` Marcel Holtmann
2008-10-29 15:30     ` [Bluez-devel] REALLY " Christian Hoene
2008-10-29 22:27       ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox