This page is for tracking development issues in the SBC codec and the plugins that use it.

Open issues

* The gstreamer plugin seems to use much more cpu than it should when encoding and transmitting; we need to figure out if this is in sbcenc or a2dpsink or both. (Tests were on a pxa270 under openembedded)

* decoder could be better optimized

* We have no gstreamer plugin support for voice audio

* More audio clients would work with us if we made a native pulseaudio plugin. Work out a way for pulse to connect through the alsa plugin in the interim for hifi and voice (or using gstreamer if it gets voice support added in).

* We have no automated regression tests

* If you modify SBC and want to test the changes with gstreamer or alsa, you need to force the plugins to rebuild before make install:

make -C sbc && make -C audio clean all && sudo make -C audio install

Trying pulse

This reportedly works for pulse:

Make audio service autostart.

.asoundrc:

pcm.headset {
       type bluetooth
       device "XX:XX:XX:XX:XX:XX"
       profile "hifi"
}

On each boot manually run:

pactl load-module module-alsa-sink device=headset

Then use pavucontrol to make the headset sink the default

Complete gstreamer plugin tests

To check the codec, any wav should suffice if you've maximized its dynamic range. (I've been using mono and stereo voice recordings http://www.xmission.com/~bmidgley/mono.wav and http://www.xmission.com/~bmidgley/stereo.wav).

gst-launch filesrc location=mono.wav ! wavparse ! audioconvert ! sbcenc ! capsfilter caps="audio/x-sbc, subbands = (int) 4, bitpool = (int) 53" ! sbcdec ! alsasink

Codec development

The SBC codec needs some improvements in quality but especially improvements in performance.

Get comfortable with the command-line utilities for exercising the codec.

cd bluez-utils
make
cd sbc
mpg321 --au music.au music.mp3
./sbcenc music.au >music.sbc
./sbcdec music.sbc

If esd is running, you have to work around it (sbcdec is a plain old oss app). I don't have a great answer for this, but here's something that works:

./sbcdec -f music.raw music.sbc
sox -2 -c 2 -r 44100 -s -t cdr music.raw -t wav music.wav
aplay music.wav

gstreamer is simpler and gives you instant results. Be sure you configure with --enable-gstreamer and rerun make install after any changes.

gst-launch filesrc location=music.mp3 ! mad ! audioconvert ! sbcenc ! sbcdec ! alsasink

or with parameters:

gst-launch filesrc location=music.mp3 ! mad ! audioconvert ! sbcenc subbands=4 allocation=snr blocks=16 ! sbcdec ! alsasink

Objective quality measures

To use sbctester to see what impact changes on the code have on audio quality, you'll ideally have the reference codec (a windows binary) but in a pinch you could use the floating point sbcenc/sbcdec from the bluetooth-alsa project's btsco module (cvs -d:pserver:anonymous@bluetooth-alsa.cvs.sourceforge.net:/cvsroot/bluetooth-alsa co btsco).

Testing the encoder:

./sbcenc.btsco music.au >reference.sbc
./sbcenc music.au >test.sbc
./sbcdec.btsco -f reference.raw reference.sbc
./sbcdec.btsco -f test.raw test.sbc
sox -2 -c 2 -r 44100 -s -t cdr reference.raw -t wav reference.wav
sox -2 -c 2 -r 44100 -s -t cdr test.raw -t wav test.wav
./sbctester reference.wav test.wav

Testing the decoder:

./sbcenc.btsco music.au >music.sbc
./sbcdec.btsco -f reference.raw music.sbc
./sbcdec -f test.raw music.sbc
sox -2 -c 2 -r 44100 -s -t cdr reference.raw -t wav reference.wav
sox -2 -c 2 -r 44100 -s -t cdr test.raw -t wav test.wav
./sbctester reference.wav test.wav

Profiling

I was adding #define inline at the end of the defines in sbc.c so the profiler can identify individual functions. The -finstrument-functions compiler directive is probably better.