From 39492555cd1d64e2f8a3474038f61d28c5c56de5 Mon Sep 17 00:00:00 2001 From: "rjk@greenend.org.uk" <> Date: Fri, 28 Sep 2007 15:16:26 +0100 Subject: [PATCH] disorder-decode now works for MP3s --- .bzrignore | 1 + server/decode.c | 46 +++++++++++++++++++--------------------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/.bzrignore b/.bzrignore index c07af06..1bf7866 100644 --- a/.bzrignore +++ b/.bzrignore @@ -105,3 +105,4 @@ debian/disorder-playrtp debian/disobedience server/disorder-decode server/disorder-normalize +doc/disorder-normalize.8.html diff --git a/server/decode.c b/server/decode.c index 434ad00..c63ca20 100644 --- a/server/decode.c +++ b/server/decode.c @@ -33,11 +33,11 @@ #include #include #include -#include #include "log.h" #include "syscalls.h" #include "defs.h" +#include "speaker-protocol.h" /** @brief Encoding lookup table type */ struct decoder { @@ -89,19 +89,17 @@ static inline void output_16(uint16_t n) { */ static void output_header(int rate, int channels, - int bits) { - static int already_written_header; - struct ao_sample_format format; - - if(!already_written_header) { - format.rate = rate; - format.bits = bits; - format.channels = channels; - format.byte_format = AO_FMT_BIG; - if(fwrite(&format, sizeof format, 1, outputfp) < 1) - fatal(errno, "decoding %s: writing format header", path); - already_written_header = 1; - } + int bits, + int nbytes) { + struct stream_header header; + + header.rate = rate; + header.bits = bits; + header.channels = channels; + header.endian = ENDIAN_BIG; + header.nbytes = nbytes; + if(fwrite(&header, sizeof header, 1, outputfp) < 1) + fatal(errno, "decoding %s: writing format header", path); } /** @brief Dithering state @@ -184,7 +182,8 @@ static enum mad_flow mp3_output(void attribute((unused)) *data, output_header(header->samplerate, pcm->channels, - 16); + 16, + 2 * pcm->channels * pcm->length); switch(pcm->channels) { case 1: while(n--) @@ -218,17 +217,10 @@ static enum mad_flow mp3_input(void attribute((unused)) *data, static enum mad_flow mp3_error(void attribute((unused)) *data, struct mad_stream *stream, struct mad_frame attribute((unused)) *frame) { - error(0, "decoding %s: %s (%#04x)", - path, mad_stream_errorstr(stream), stream->error); - return MAD_FLOW_CONTINUE; -} - -/** @brief MP3 header callback */ -static enum mad_flow mp3_header(void attribute((unused)) *data, - struct mad_header const *header) { - output_header(header->samplerate, - MAD_NCHANNELS(header), - 16); + if(0) + /* Just generates pointless verbosity l-( */ + error(0, "decoding %s: %s (%#04x)", + path, mad_stream_errorstr(stream), stream->error); return MAD_FLOW_CONTINUE; } @@ -237,7 +229,7 @@ static void decode_mp3(void) { struct mad_decoder mad[1]; open_input(); - mad_decoder_init(mad, 0/*data*/, mp3_input, mp3_header, 0/*filter*/, + mad_decoder_init(mad, 0/*data*/, mp3_input, 0/*header*/, 0/*filter*/, mp3_output, mp3_error, 0/*message*/); if(mad_decoder_run(mad, MAD_DECODER_MODE_SYNC)) exit(1); -- 2.11.0