From 5430ca31bc276a9d07c932383910ef600ef08c87 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 21 Feb 2007 14:15:52 +0000 Subject: Add SBC utilities --- sbc/sbcdec.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 sbc/sbcdec.c (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c new file mode 100644 index 00000000..208cdfd8 --- /dev/null +++ b/sbc/sbcdec.c @@ -0,0 +1,33 @@ +/* + * + * Bluetooth low-complexity, subband codec (SBC) library + * + * Copyright (C) 2004-2007 Marcel Holtmann + * + * + * 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 +#endif + +#include "sbc.h" + +int main(int argc, char *argv[]) +{ + return 0; +} -- cgit From 1d6beece31584c71a7ce730133923f2e1d0d3b7d Mon Sep 17 00:00:00 2001 From: Brad Midgley Date: Sat, 24 Mar 2007 02:56:52 +0000 Subject: add Marcel's original, unmodified sbcdec/enc clients to sbc --- sbc/sbcdec.c | 195 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 194 insertions(+), 1 deletion(-) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index 208cdfd8..0617fe04 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -1,6 +1,6 @@ /* * - * Bluetooth low-complexity, subband codec (SBC) library + * Bluetooth low-complexity, subband codec (SBC) decoder * * Copyright (C) 2004-2007 Marcel Holtmann * @@ -25,9 +25,202 @@ #include #endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "sbc.h" +#define BUF_SIZE 8192 + +static void decode(char *filename, char *audiodevice, int tofile) +{ + unsigned char buf[BUF_SIZE], *stream; + struct stat st; + off_t filesize; + sbc_t sbc; + int fd, ad, pos, streamlen, framelen, count, format = AFMT_S16_BE; + + if (stat(filename, &st) < 0) { + fprintf(stderr, "Can't get size of file %s: %s\n", + filename, strerror(errno)); + return; + } + + filesize = st.st_size; + stream = malloc(st.st_size); + + if (!stream) { + fprintf(stderr, "Can't allocate memory for %s: %s\n", + filename, strerror(errno)); + return; + } + + fd = open(filename, O_RDONLY); + if (fd < 0) { + fprintf(stderr, "Can't open file %s: %s\n", + filename, strerror(errno)); + goto free; + } + + if (read(fd, stream, st.st_size) != st.st_size) { + fprintf(stderr, "Can't read content of %s: %s\n", + filename, strerror(errno)); + close(fd); + goto free; + } + + close(fd); + + pos = 0; + streamlen = st.st_size; + + ad = open(audiodevice, O_WRONLY | (tofile ? (O_CREAT | O_TRUNC) : 0), tofile ? 0644 : 0); + if (ad < 0) { + fprintf(stderr, "Can't open audio device %s: %s\n", + audiodevice, strerror(errno)); + goto free; + } + + sbc_init(&sbc, 0L); + + framelen = sbc_decode(&sbc, stream, streamlen); + printf("%d Hz, %d channels\n", sbc.rate, sbc.channels); + if (!tofile) { + if (ioctl(ad, SNDCTL_DSP_SETFMT, &format) < 0) { + fprintf(stderr, "Can't set audio format on %s: %s\n", + audiodevice, strerror(errno)); + goto close; + } + if (ioctl(ad, SNDCTL_DSP_CHANNELS, &sbc.channels) < 0) { + fprintf(stderr, "Can't set number of channels on %s: %s\n", + audiodevice, strerror(errno)); + goto close; + } + + if (ioctl(ad, SNDCTL_DSP_SPEED, &sbc.rate) < 0) { + fprintf(stderr, "Can't set audio rate on %s: %s\n", + audiodevice, strerror(errno)); + goto close; + } + } + + count = 0; + while (framelen > 0) { + // we have completed an sbc_decode at this point + // sbc.len is the length of the frame we just decoded + // count is the number of decoded bytes yet to be written + + if (count + sbc.len > BUF_SIZE) { + // buffer is too full to stuff decoded audio in + // so it must be written to the device + write(ad, buf, count); + count = 0; + } + + // sanity check + if(count + sbc.len > BUF_SIZE) { + fprintf(stderr, "buffer size of %d is too small for decoded data (%d)\n", BUF_SIZE, sbc.len + count); + exit(1); + } + + // move the latest decoded data into buf and increase the count + memcpy(buf + count, sbc.data, sbc.len); + count += sbc.len; + + // push the pointer in the file forward to the next bit to be decoded + // tell the decoder to decode up to the remaining length of the file (!) + pos += framelen; + framelen = sbc_decode(&sbc, stream + pos, streamlen - pos); + } + + if (count > 0) + write(ad, buf, count); + +close: + sbc_finish(&sbc); + + close(ad); + +free: + free(stream); +} + +static void usage(void) +{ + printf("SBC decoder utility ver %s\n", VERSION); + printf("Copyright (c) 2004 Marcel Holtmann\n\n"); + + printf("Usage:\n" + "\tsbcdec [options] file(s)\n" + "\n"); + + printf("Options:\n" + "\t-h, --help Display help\n" + "\t-d, --device Sound device\n" + "\t-v, --verbose Verbose mode\n" + "\t-f, --file Decode to a file\n" + "\n"); +} + +static struct option main_options[] = { + { "help", 0, 0, 'h' }, + { "device", 1, 0, 'd' }, + { "verbose", 0, 0, 'v' }, + { "file", 1, 0, 'f' }, + { 0, 0, 0, 0 } +}; + int main(int argc, char *argv[]) { + char *device = NULL; + char *file = NULL; + int i, opt, verbose = 0, tofile = 0; + + while ((opt = getopt_long(argc, argv, "+hd:vf:", main_options, NULL)) != -1) { + switch(opt) { + case 'h': + usage(); + exit(0); + + case 'd': + device = strdup(optarg); + break; + + case 'v': + verbose = 1; + break; + case 'f' : + file = strdup(optarg); + tofile = 1; + break; + + default: + exit(1); + } + } + + argc -= optind; + argv += optind; + optind = 0; + + if (argc < 1) { + usage(); + exit(1); + } + + for (i = 0; i < argc; i++) + decode(argv[i], device ? device : file ? file : "/dev/dsp", tofile); + + if (device) + free(device); + return 0; } -- cgit From 0c96c8790268b67d973339ca4547c8021474bf1c Mon Sep 17 00:00:00 2001 From: Brad Midgley Date: Sat, 24 Mar 2007 13:58:21 +0000 Subject: examine the result of write() ops, avoid warnings --- sbc/sbcdec.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index 0617fe04..3435e8f8 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -46,7 +46,7 @@ static void decode(char *filename, char *audiodevice, int tofile) struct stat st; off_t filesize; sbc_t sbc; - int fd, ad, pos, streamlen, framelen, count, format = AFMT_S16_BE; + int fd, ad, pos, streamlen, framelen, count, format = AFMT_S16_BE, written; if (stat(filename, &st) < 0) { fprintf(stderr, "Can't get size of file %s: %s\n", @@ -121,8 +121,8 @@ static void decode(char *filename, char *audiodevice, int tofile) if (count + sbc.len > BUF_SIZE) { // buffer is too full to stuff decoded audio in // so it must be written to the device - write(ad, buf, count); - count = 0; + written = write(ad, buf, count); + if(written > 0) count -= written; } // sanity check @@ -141,8 +141,10 @@ static void decode(char *filename, char *audiodevice, int tofile) framelen = sbc_decode(&sbc, stream + pos, streamlen - pos); } - if (count > 0) - write(ad, buf, count); + if (count > 0) { + written = write(ad, buf, count); + if(written > 0) count -= written; + } close: sbc_finish(&sbc); -- cgit From a745805cb3961ccf88f0119f28dc919ed9c571e5 Mon Sep 17 00:00:00 2001 From: Brad Midgley Date: Sat, 24 Mar 2007 14:01:31 +0000 Subject: whitespace fixes --- sbc/sbcdec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index 3435e8f8..decd758d 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -122,11 +122,11 @@ static void decode(char *filename, char *audiodevice, int tofile) // buffer is too full to stuff decoded audio in // so it must be written to the device written = write(ad, buf, count); - if(written > 0) count -= written; + if (written > 0) count -= written; } // sanity check - if(count + sbc.len > BUF_SIZE) { + if (count + sbc.len > BUF_SIZE) { fprintf(stderr, "buffer size of %d is too small for decoded data (%d)\n", BUF_SIZE, sbc.len + count); exit(1); } @@ -143,7 +143,7 @@ static void decode(char *filename, char *audiodevice, int tofile) if (count > 0) { written = write(ad, buf, count); - if(written > 0) count -= written; + if (written > 0) count -= written; } close: -- cgit From b28533ef8bb61744e06c94f2df6704beedabd2f4 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 24 Mar 2007 22:22:54 +0000 Subject: Update coding style --- sbc/sbcdec.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index decd758d..b5305550 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -46,7 +46,7 @@ static void decode(char *filename, char *audiodevice, int tofile) struct stat st; off_t filesize; sbc_t sbc; - int fd, ad, pos, streamlen, framelen, count, format = AFMT_S16_BE, written; + int fd, ad, pos, streamlen, framelen, count, written, format = AFMT_S16_BE; if (stat(filename, &st) < 0) { fprintf(stderr, "Can't get size of file %s: %s\n", @@ -122,7 +122,8 @@ static void decode(char *filename, char *audiodevice, int tofile) // buffer is too full to stuff decoded audio in // so it must be written to the device written = write(ad, buf, count); - if (written > 0) count -= written; + if (written > 0) + count -= written; } // sanity check @@ -143,7 +144,8 @@ static void decode(char *filename, char *audiodevice, int tofile) if (count > 0) { written = write(ad, buf, count); - if (written > 0) count -= written; + if (written > 0) + count -= written; } close: -- cgit From b1618922db92f9bc65b0841f66eb71742bc1b553 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 21 Aug 2007 21:32:09 +0000 Subject: Add swap member to sbc struct and fix pcm plugin to not swap the buffer. --- sbc/sbcdec.c | 1 + 1 file changed, 1 insertion(+) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index b5305550..d84a631b 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -90,6 +90,7 @@ static void decode(char *filename, char *audiodevice, int tofile) } sbc_init(&sbc, 0L); + sbc.swap = 1; framelen = sbc_decode(&sbc, stream, streamlen); printf("%d Hz, %d channels\n", sbc.rate, sbc.channels); -- cgit From 60dc1ff7491b901c9a849f4c0a1d60a9ed12bf68 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 25 Aug 2007 13:27:46 +0000 Subject: Fix output handling of decoder --- sbc/sbcdec.c | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index d84a631b..ebf9ae7c 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -40,7 +40,7 @@ #define BUF_SIZE 8192 -static void decode(char *filename, char *audiodevice, int tofile) +static void decode(char *filename, char *output, int tofile) { unsigned char buf[BUF_SIZE], *stream; struct stat st; @@ -82,10 +82,14 @@ static void decode(char *filename, char *audiodevice, int tofile) pos = 0; streamlen = st.st_size; - ad = open(audiodevice, O_WRONLY | (tofile ? (O_CREAT | O_TRUNC) : 0), tofile ? 0644 : 0); + if (tofile) + ad = open(output, O_WRONLY | O_CREAT | O_TRUNC, 0644); + else + ad = open(output, O_WRONLY, 0); + if (ad < 0) { - fprintf(stderr, "Can't open audio device %s: %s\n", - audiodevice, strerror(errno)); + fprintf(stderr, "Can't open output %s: %s\n", + output, strerror(errno)); goto free; } @@ -97,18 +101,18 @@ static void decode(char *filename, char *audiodevice, int tofile) if (!tofile) { if (ioctl(ad, SNDCTL_DSP_SETFMT, &format) < 0) { fprintf(stderr, "Can't set audio format on %s: %s\n", - audiodevice, strerror(errno)); + output, strerror(errno)); goto close; } if (ioctl(ad, SNDCTL_DSP_CHANNELS, &sbc.channels) < 0) { fprintf(stderr, "Can't set number of channels on %s: %s\n", - audiodevice, strerror(errno)); + output, strerror(errno)); goto close; } if (ioctl(ad, SNDCTL_DSP_SPEED, &sbc.rate) < 0) { fprintf(stderr, "Can't set audio rate on %s: %s\n", - audiodevice, strerror(errno)); + output, strerror(errno)); goto close; } } @@ -161,7 +165,7 @@ free: static void usage(void) { printf("SBC decoder utility ver %s\n", VERSION); - printf("Copyright (c) 2004 Marcel Holtmann\n\n"); + printf("Copyright (c) 2004-2007 Marcel Holtmann\n\n"); printf("Usage:\n" "\tsbcdec [options] file(s)\n" @@ -169,9 +173,9 @@ static void usage(void) printf("Options:\n" "\t-h, --help Display help\n" - "\t-d, --device Sound device\n" "\t-v, --verbose Verbose mode\n" - "\t-f, --file Decode to a file\n" + "\t-d, --device Sound device\n" + "\t-f, --file Decode to a file\n" "\n"); } @@ -185,25 +189,30 @@ static struct option main_options[] = { int main(int argc, char *argv[]) { - char *device = NULL; - char *file = NULL; + char *output = NULL; int i, opt, verbose = 0, tofile = 0; - while ((opt = getopt_long(argc, argv, "+hd:vf:", main_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "+hvd:f:", main_options, NULL)) != -1) { switch(opt) { case 'h': usage(); exit(0); - case 'd': - device = strdup(optarg); - break; - case 'v': verbose = 1; break; + + case 'd': + if (output) + free(output); + output = strdup(optarg); + tofile = 0; + break; + case 'f' : - file = strdup(optarg); + if (output) + free(output); + output = strdup(optarg); tofile = 1; break; @@ -222,10 +231,10 @@ int main(int argc, char *argv[]) } for (i = 0; i < argc; i++) - decode(argv[i], device ? device : file ? file : "/dev/dsp", tofile); + decode(argv[i], output ? output : "/dev/dsp", tofile); - if (device) - free(device); + if (output) + free(output); return 0; } -- cgit From 9138f99acb799d7ce702afb357c134042f933f4b Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 1 Nov 2007 15:27:38 +0000 Subject: Coding style cleanup --- sbc/sbcdec.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index ebf9ae7c..866b8448 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -46,7 +46,8 @@ static void decode(char *filename, char *output, int tofile) struct stat st; off_t filesize; sbc_t sbc; - int fd, ad, pos, streamlen, framelen, count, written, format = AFMT_S16_BE; + int fd, ad, pos, streamlen, framelen, count, written; + int format = AFMT_S16_BE; if (stat(filename, &st) < 0) { fprintf(stderr, "Can't get size of file %s: %s\n", @@ -101,48 +102,53 @@ static void decode(char *filename, char *output, int tofile) if (!tofile) { if (ioctl(ad, SNDCTL_DSP_SETFMT, &format) < 0) { fprintf(stderr, "Can't set audio format on %s: %s\n", - output, strerror(errno)); + output, strerror(errno)); goto close; } if (ioctl(ad, SNDCTL_DSP_CHANNELS, &sbc.channels) < 0) { - fprintf(stderr, "Can't set number of channels on %s: %s\n", - output, strerror(errno)); + fprintf(stderr, + "Can't set number of channels on %s: %s\n", + output, strerror(errno)); goto close; } if (ioctl(ad, SNDCTL_DSP_SPEED, &sbc.rate) < 0) { fprintf(stderr, "Can't set audio rate on %s: %s\n", - output, strerror(errno)); + output, strerror(errno)); goto close; } } count = 0; while (framelen > 0) { - // we have completed an sbc_decode at this point - // sbc.len is the length of the frame we just decoded - // count is the number of decoded bytes yet to be written + /* we have completed an sbc_decode at this point sbc.len is the + * length of the frame we just decoded count is the number of + * decoded bytes yet to be written */ if (count + sbc.len > BUF_SIZE) { - // buffer is too full to stuff decoded audio in - // so it must be written to the device + /* buffer is too full to stuff decoded audio in so it + * must be written to the device */ written = write(ad, buf, count); if (written > 0) count -= written; } - // sanity check + /* sanity check */ if (count + sbc.len > BUF_SIZE) { - fprintf(stderr, "buffer size of %d is too small for decoded data (%d)\n", BUF_SIZE, sbc.len + count); + fprintf(stderr, + "buffer size of %d is too small for decoded" + " data (%d)\n", BUF_SIZE, sbc.len + count); exit(1); } - // move the latest decoded data into buf and increase the count + /* move the latest decoded data into buf and increase + * the count */ memcpy(buf + count, sbc.data, sbc.len); count += sbc.len; - // push the pointer in the file forward to the next bit to be decoded - // tell the decoder to decode up to the remaining length of the file (!) + /* push the pointer in the file forward to the next bit to be + * decoded tell the decoder to decode up to the remaining + * length of the file (!) */ pos += framelen; framelen = sbc_decode(&sbc, stream + pos, streamlen - pos); } -- cgit From 397d6c2b3bc7661f978c1777442d33fd86ada21e Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 12 Nov 2007 18:15:59 +0000 Subject: Make sbc codec to write directly in application buffers and so avoiding memcpys. --- sbc/sbcdec.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index 866b8448..09a211a1 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -46,7 +46,7 @@ static void decode(char *filename, char *output, int tofile) struct stat st; off_t filesize; sbc_t sbc; - int fd, ad, pos, streamlen, framelen, count, written; + int fd, ad, pos, streamlen, framelen, count, written, len; int format = AFMT_S16_BE; if (stat(filename, &st) < 0) { @@ -97,7 +97,7 @@ static void decode(char *filename, char *output, int tofile) sbc_init(&sbc, 0L); sbc.swap = 1; - framelen = sbc_decode(&sbc, stream, streamlen); + framelen = sbc_decode(&sbc, stream, streamlen, buf, sizeof(buf), &len); printf("%d Hz, %d channels\n", sbc.rate, sbc.channels); if (!tofile) { if (ioctl(ad, SNDCTL_DSP_SETFMT, &format) < 0) { @@ -125,7 +125,7 @@ static void decode(char *filename, char *output, int tofile) * length of the frame we just decoded count is the number of * decoded bytes yet to be written */ - if (count + sbc.len > BUF_SIZE) { + if (count + len > BUF_SIZE) { /* buffer is too full to stuff decoded audio in so it * must be written to the device */ written = write(ad, buf, count); @@ -134,23 +134,23 @@ static void decode(char *filename, char *output, int tofile) } /* sanity check */ - if (count + sbc.len > BUF_SIZE) { + if (count + len > BUF_SIZE) { fprintf(stderr, "buffer size of %d is too small for decoded" - " data (%d)\n", BUF_SIZE, sbc.len + count); + " data (%d)\n", BUF_SIZE, len + count); exit(1); } - /* move the latest decoded data into buf and increase - * the count */ - memcpy(buf + count, sbc.data, sbc.len); - count += sbc.len; + /* increase the count */ + count += len; /* push the pointer in the file forward to the next bit to be * decoded tell the decoder to decode up to the remaining * length of the file (!) */ pos += framelen; - framelen = sbc_decode(&sbc, stream + pos, streamlen - pos); + framelen = sbc_decode(&sbc, stream + pos, streamlen - pos, + buf + count, sizeof(buf) - count, + &len); } if (count > 0) { -- cgit From a0832282a87d370ec5383b036015b013277d9041 Mon Sep 17 00:00:00 2001 From: Brad Midgley Date: Wed, 30 Jan 2008 20:28:37 +0000 Subject: fix off-by-one in sbcdec --- sbc/sbcdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index 09a211a1..2fa3cbb9 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -125,7 +125,7 @@ static void decode(char *filename, char *output, int tofile) * length of the frame we just decoded count is the number of * decoded bytes yet to be written */ - if (count + len > BUF_SIZE) { + if (count + len >= BUF_SIZE) { /* buffer is too full to stuff decoded audio in so it * must be written to the device */ written = write(ad, buf, count); @@ -134,7 +134,7 @@ static void decode(char *filename, char *output, int tofile) } /* sanity check */ - if (count + len > BUF_SIZE) { + if (count + len >= BUF_SIZE) { fprintf(stderr, "buffer size of %d is too small for decoded" " data (%d)\n", BUF_SIZE, len + count); -- cgit From e823c15e43a6f924779e466d434c51157002d9ee Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 2 Feb 2008 03:37:05 +0000 Subject: Update copyright information --- sbc/sbcdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index 2fa3cbb9..6c0b4bfa 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -2,7 +2,7 @@ * * Bluetooth low-complexity, subband codec (SBC) decoder * - * Copyright (C) 2004-2007 Marcel Holtmann + * Copyright (C) 2004-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify @@ -171,7 +171,7 @@ free: static void usage(void) { printf("SBC decoder utility ver %s\n", VERSION); - printf("Copyright (c) 2004-2007 Marcel Holtmann\n\n"); + printf("Copyright (c) 2004-2008 Marcel Holtmann\n\n"); printf("Usage:\n" "\tsbcdec [options] file(s)\n" -- cgit From ce342bf2524b69b19ea5a4ad604faf1aa40ad19c Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 19 Feb 2008 19:47:25 +0000 Subject: Introduce sbc new API. --- sbc/sbcdec.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'sbc/sbcdec.c') diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index 6c0b4bfa..5ac02b44 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -47,7 +47,7 @@ static void decode(char *filename, char *output, int tofile) off_t filesize; sbc_t sbc; int fd, ad, pos, streamlen, framelen, count, written, len; - int format = AFMT_S16_BE; + int format = AFMT_S16_BE, frequency, channels; if (stat(filename, &st) < 0) { fprintf(stderr, "Can't get size of file %s: %s\n", @@ -95,24 +95,45 @@ static void decode(char *filename, char *output, int tofile) } sbc_init(&sbc, 0L); - sbc.swap = 1; + sbc.endian = SBC_BE; framelen = sbc_decode(&sbc, stream, streamlen, buf, sizeof(buf), &len); - printf("%d Hz, %d channels\n", sbc.rate, sbc.channels); + channels = sbc.mode == SBC_MODE_MONO ? 1 : 2; + switch (sbc.frequency) { + case SBC_FREQ_16000: + frequency = 16000; + break; + + case SBC_FREQ_32000: + frequency = 32000; + break; + + case SBC_FREQ_44100: + frequency = 44100; + break; + + case SBC_FREQ_48000: + frequency = 48000; + break; + default: + frequency = 0; + } + + printf("%d Hz, %d channels\n", frequency, channels); if (!tofile) { if (ioctl(ad, SNDCTL_DSP_SETFMT, &format) < 0) { fprintf(stderr, "Can't set audio format on %s: %s\n", output, strerror(errno)); goto close; } - if (ioctl(ad, SNDCTL_DSP_CHANNELS, &sbc.channels) < 0) { + if (ioctl(ad, SNDCTL_DSP_CHANNELS, &channels) < 0) { fprintf(stderr, "Can't set number of channels on %s: %s\n", output, strerror(errno)); goto close; } - if (ioctl(ad, SNDCTL_DSP_SPEED, &sbc.rate) < 0) { + if (ioctl(ad, SNDCTL_DSP_SPEED, &frequency) < 0) { fprintf(stderr, "Can't set audio rate on %s: %s\n", output, strerror(errno)); goto close; -- cgit