OSDN Git Service

Let the decoder write Sun/NeXT audio S16_BE files
authorMarcel Holtmann <marcel@holtmann.org>
Sun, 26 Oct 2008 00:04:44 +0000 (02:04 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Sun, 26 Oct 2008 00:04:44 +0000 (02:04 +0200)
sbc/Makefile.am
sbc/formats.h [new file with mode: 0644]
sbc/sbcdec.c
sbc/sbcenc.c

index 9079305..c42f162 100644 (file)
@@ -14,8 +14,10 @@ libsbc_la_CFLAGS = -finline-functions -funswitch-loops -fgcse-after-reload
 
 noinst_PROGRAMS = sbcinfo sbcdec sbcenc $(sndfile_programs)
 
+sbcdec_SOURCES = sbcdec.c formats.h
 sbcdec_LDADD = libsbc.la
 
+sbcenc_SOURCES = sbcenc.c formats.h
 sbcenc_LDADD = libsbc.la
 
 if SNDFILE
diff --git a/sbc/formats.h b/sbc/formats.h
new file mode 100644 (file)
index 0000000..eabbaf9
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *
+ *  Bluetooth low-complexity, subband codec (SBC) library
+ *
+ *  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
+ *
+ */
+
+#include <byteswap.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define COMPOSE_ID(a,b,c,d)    ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24))
+#define LE_SHORT(v)            (v)
+#define LE_INT(v)              (v)
+#define BE_SHORT(v)            bswap_16(v)
+#define BE_INT(v)              bswap_32(v)
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define COMPOSE_ID(a,b,c,d)    ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24))
+#define LE_SHORT(v)            bswap_16(v)
+#define LE_INT(v)              bswap_32(v)
+#define BE_SHORT(v)            (v)
+#define BE_INT(v)              (v)
+#else
+#error "Wrong endian"
+#endif
+
+#define AU_MAGIC               COMPOSE_ID('.','s','n','d')
+
+#define AU_FMT_ULAW            1
+#define AU_FMT_LIN8            2
+#define AU_FMT_LIN16           3
+
+struct au_header {
+       uint32_t magic;         /* '.snd' */
+       uint32_t hdr_size;      /* size of header (min 24) */
+       uint32_t data_size;     /* size of data */
+       uint32_t encoding;      /* see to AU_FMT_XXXX */
+       uint32_t sample_rate;   /* sample rate */
+       uint32_t channels;      /* number of channels (voices) */
+};
index 5029d31..555ace5 100644 (file)
@@ -37,6 +37,7 @@
 #include <sys/soundcard.h>
 
 #include "sbc.h"
+#include "formats.h"
 
 #define BUF_SIZE 8192
 
@@ -120,12 +121,28 @@ static void decode(char *filename, char *output, int tofile)
        }
 
        printf("%d Hz, %d channels\n", frequency, channels);
-       if (!tofile) {
+       if (tofile) {
+               struct au_header au_hdr;
+
+               au_hdr.magic       = AU_MAGIC;
+               au_hdr.hdr_size    = BE_INT(24);
+               au_hdr.data_size   = BE_INT(0);
+               au_hdr.encoding    = BE_INT(AU_FMT_LIN16);
+               au_hdr.sample_rate = BE_INT(frequency);
+               au_hdr.channels    = BE_INT(channels);
+
+               written = write(ad, &au_hdr, sizeof(au_hdr));
+               if (written < sizeof(au_hdr)) {
+                       fprintf(stderr, "Failed to write header\n");
+                       goto close;
+               }
+       } else {
                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, &channels) < 0) {
                        fprintf(stderr,
                                "Can't set number of channels on %s: %s\n",
index 6a5dde7..38670a9 100644 (file)
 #include <stdint.h>
 #include <string.h>
 #include <getopt.h>
-#include <byteswap.h>
 #include <sys/stat.h>
 
 #include "sbc.h"
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define COMPOSE_ID(a,b,c,d)    ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24))
-#define LE_SHORT(v)            (v)
-#define LE_INT(v)              (v)
-#define BE_SHORT(v)            bswap_16(v)
-#define BE_INT(v)              bswap_32(v)
-#elif __BYTE_ORDER == __BIG_ENDIAN
-#define COMPOSE_ID(a,b,c,d)    ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24))
-#define LE_SHORT(v)            bswap_16(v)
-#define LE_INT(v)              bswap_32(v)
-#define BE_SHORT(v)            (v)
-#define BE_INT(v)              (v)
-#else
-#error "Wrong endian"
-#endif
-
-#define AU_MAGIC               COMPOSE_ID('.','s','n','d')
-
-#define AU_FMT_ULAW            1
-#define AU_FMT_LIN8            2
-#define AU_FMT_LIN16           3
-
-struct au_header {
-       uint32_t magic;         /* '.snd' */
-       uint32_t hdr_size;      /* size of header (min 24) */
-       uint32_t data_size;     /* size of data */
-       uint32_t encoding;      /* see to AU_FMT_XXXX */
-       uint32_t sample_rate;   /* sample rate */
-       uint32_t channels;      /* number of channels (voices) */
-};
+#include "formats.h"
 
 static ssize_t __read(int fd, void *buf, size_t count)
 {