chiark / gitweb /
ogg decoding in disorder-decode
authorrjk@greenend.org.uk <>
Fri, 28 Sep 2007 17:21:31 +0000 (18:21 +0100)
committerrjk@greenend.org.uk <>
Fri, 28 Sep 2007 17:21:31 +0000 (18:21 +0100)
plugins/Makefile.am
server/Makefile.am
server/decode.c

index 6afc43351965ef04ddd4569e970fa00a21fb9be7..0f6ca75e72247fc1b9fa54694cce7a8f1ef309e2 100644 (file)
@@ -27,7 +27,7 @@ notify_la_LDFLAGS=-module
 
 tracklength_la_SOURCES=tracklength.c mad.c madshim.h
 tracklength_la_LDFLAGS=-module
-tracklength_la_LIBADD=@LIBVORBISFILE@ @LIBMAD@
+tracklength_la_LIBADD=$(LIBVORBISFILE) $(LIBMAD)
 
 fs_la_SOURCES=fs.c
 fs_la_LDFLAGS=-module
index 548ac2a57b59c628b340ccfb73a44a8f52f2b0b2..fef174e98bdee300749aed0f5c078d47d5b6dcd9 100644 (file)
@@ -54,7 +54,7 @@ disorder_speaker_DEPENDENCIES=../lib/libdisorder.a
 
 disorder_decode_SOURCES=decode.c
 disorder_decode_LDADD=$(LIBOBJS) ../lib/libdisorder.a \
-       $(LIBMAD)
+       $(LIBMAD) $(LIBVORBISFILE)
 disorder_decode_DEPENDENCIES=../lib/libdisorder.a
 
 disorder_normalize_SOURCES=normalize.c
index c63ca2020738290b86cdda7070fdb8aa2a1c46e9..f462f58c3c6a15dccda69423430954925eba28ad 100644 (file)
@@ -33,6 +33,7 @@
 #include <assert.h>
 #include <fnmatch.h>
 #include <mad.h>
+#include <vorbis/vorbisfile.h>
 
 #include "log.h"
 #include "syscalls.h"
@@ -57,7 +58,7 @@ static FILE *outputfp;
 static const char *path;
 
 /** @brief Input buffer */
-static unsigned char buffer[1048576];
+static char buffer[1048576];
 
 /** @brief Open the input file */
 static void open_input(void) {
@@ -205,10 +206,10 @@ static enum mad_flow mp3_output(void attribute((unused)) *data,
 static enum mad_flow mp3_input(void attribute((unused)) *data,
                               struct mad_stream *stream) {
   const size_t n = fill();
-  fprintf(stderr, "n=%zu\n", n);
+
   if(!n)
     return MAD_FLOW_STOP;
-  mad_stream_buffer(stream, buffer, n);
+  mad_stream_buffer(stream, (unsigned char *)buffer, n);
   return MAD_FLOW_CONTINUE;
 }
 
@@ -236,10 +237,41 @@ static void decode_mp3(void) {
   mad_decoder_finish(mad);
 }
 
+/** @brief OGG decoder */
+static void decode_ogg(void) {
+  FILE *fp;
+  OggVorbis_File vf[1];
+  int err;
+  long n;
+  int bitstream;
+  vorbis_info *vi;
+
+  if(!(fp = fopen(path, "rb")))
+    fatal(errno, "cannot open %s", path);
+  /* There doesn't seem to be any standard function for mapping the error codes
+   * to strings l-( */
+  if((err = ov_open(fp, vf, 0/*initial*/, 0/*ibytes*/)))
+    fatal(0, "ov_fopen %s: %d", path, err);
+  if(!(vi = ov_info(vf, 0/*link*/)))
+    fatal(0, "ov_info %s: failed", path);
+  while((n = ov_read(vf, buffer, sizeof buffer, 1/*bigendianp*/,
+                     2/*bytes/word*/, 1/*signed*/, &bitstream))) {
+    if(n < 0)
+      fatal(0, "ov_read %s: %ld", path, n);
+    if(bitstream > 0)
+      fatal(0, "only single-bitstream ogg files are supported");
+    output_header(vi->rate, vi->channels, 16/*bits*/, n);
+    if(fwrite(buffer, 1, n, outputfp) < (size_t)n)
+      fatal(errno, "decoding %s: writing sample data", path);
+  }
+}
+
 /** @brief Lookup table of decoders */
 static const struct decoder decoders[] = {
   { "*.mp3", decode_mp3 },
   { "*.MP3", decode_mp3 },
+  { "*.ogg", decode_ogg },
+  { "*.OGG", decode_ogg },
   { 0, 0 }
 };