+/** @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);
+ }
+}
+