Please find attached a patch, which adds wma2wav to samples/misc. The patch 
was initially created by Michal Moskal ([EMAIL PROTECTED]) and already 
posted to this list. I only adopted it to the 0.7.9 release.

rgds, Rainer
diff -urN avifile-0.6.0.20011207/samples/misc/Makefile.am avifile-0.6.0.20011207-/samples/misc/Makefile.am
--- avifile-0.6.0.20011207/samples/misc/Makefile.am     Mon Dec  3 11:38:01 2001
+++ avifile-0.6.0.20011207-/samples/misc/Makefile.am    Wed Dec 19 01:58:31 2001
@@ -8,6 +8,7 @@
 avitype_SOURCES=avitype.cpp
 
 extractor_SOURCES=extractor.cpp
+wma2wav_SOURCES=wma2wav.cpp
 test_SOURCES=test.cpp
 #plustest_SOURCES=plustest.cpp
 #imtest_SOURCES=imtest.cpp
@@ -24,6 +25,7 @@
 avitype_LDADD = $(LIBRARY)
 
 extractor_LDADD = $(LIBRARY)
+wma2wav_LDADD = $(LIBRARY)
 
 if AMM_USE_JPEGLIB
 avimake_SOURCES = avimake.cpp
@@ -33,7 +35,7 @@
 PROG_AVIMAKE =
 endif
 
-bin_PROGRAMS = avibench avicat avitype $(PROG_AVIMAKE)
+bin_PROGRAMS = avibench avicat avitype wma2wav $(PROG_AVIMAKE)
 check_PROGRAMS = avitest extractor test
 #asfdump asftest 
 EXTRA_DIST =  imtest.cpp plustest.cpp qualtest.cpp test.cpp
diff -u -b -B --new-file avifile0.7-0.7.9/samples/misc/wma2wav.cpp avifile0.7-0.7.9/samples/misc2/wma2wav.cpp
--- avifile0.7-0.7.9/samples/misc/wma2wav.cpp	Thu Jan  1 01:00:00 1970
+++ avifile0.7-0.7.9/samples/misc2/wma2wav.cpp	Thu Jul 18 16:35:52 2002
@@ -0,0 +1,116 @@
+/*
+ * Convert .wma files to .wav (so they can be treated with lame to produce
+ * more reasonable output :^)
+ * Copyright (c) 2001 Michal Moskal ([EMAIL PROTECTED])
+ *
+ * I was motivated to write this simple cuple of lines by Piotr Modrzyk,
+ * and I wish to thank him here ;)
+ *
+ * This program could be probably also used to extract soundtrack from 
+ * movies, but I don't mind and hence the name...
+ */
+
+#include <avifile.h>
+#include <aviplay.h>
+#include <fourcc.h>
+#include <except.h>
+#include <utils.h>
+#include <version.h>
+#include <unistd.h>		// for getopt()
+
+#include <iostream>
+#include <iomanip>
+#include <string>
+#include <strstream.h>
+#include <fcntl.h>
+
+
+#define __MODULE__ "wma2wav"
+
+using namespace std;
+
+int main(int argc, const char **argv)
+{
+  IAviReadFile *ac = 0;
+  IAviReadStream *as = 0;
+  uint8_t *zz = 0;
+  int out_fd;
+  const char *infile, *outfile;
+
+  if (argc != 3) {
+    cerr << "\n\nUSAGE: " << argv[0] << " inputfile outputfile\n" << endl;
+    exit(1);
+  }
+       
+  if ( GetAvifileVersion() != AVIFILE_VERSION) {
+    cout << "This binary was compiled for Avifile ver. "
+	 << AVIFILE_VERSION
+	 << ", but the library is ver. "
+	 << GetAvifileVersion()
+	 << ". Aborting."
+	 << endl;
+    return 0;
+  }
+       
+  infile = argv[1];
+  outfile = argv[2];
+       
+  out_fd = open(outfile, O_WRONLY|O_TRUNC|O_CREAT, 0666);
+  if (out_fd < 0) {
+    cerr << outfile << endl;
+    exit(1);
+  }
+       
+  try {
+    ac = CreateIAviReadFile(infile);
+    if (ac == NULL) {
+      cerr << infile << ": can't read it" << endl;
+      exit(1);
+    }
+
+    as = ac->GetStream(0, AviStream::Audio);
+    if (ac == NULL) {
+      cerr << infile << ": doesn't contains audio stream" << endl; 
+      exit(1);
+    }
+
+    const int buffer_size = 2 * 1024 * 1024;
+    zz = new uint8_t[buffer_size];
+    size_t samp_read, bytes_read, sz;
+    WAVEFORMATEX hdr;
+
+    memset(&hdr, 0, sizeof(hdr));
+    as->GetAudioFormatInfo(&hdr, NULL);
+
+    write(out_fd, "RIFF\x0f\xff\xff\xffWAVEfmt \x10\0\0\0", 20);
+    // override
+    hdr.wFormatTag = 1;
+    write(out_fd, &hdr, 16);
+    write(out_fd, "data\x0f\xff\xff\xff", 8);
+
+    as->StopStreaming();
+    as->StartStreaming();
+    while (!as->Eof()) {
+      sz = as->GetFrameSize();
+      if (sz > (size_t)buffer_size)
+	sz = buffer_size;
+      as->ReadFrames(zz, sz, sz, samp_read, bytes_read);
+      if (write(out_fd, zz, bytes_read) != (int)bytes_read) {
+	cerr << "write" << endl;;
+	exit(1);
+      }
+    }
+
+    close(out_fd);
+  } catch(FatalError & error) {
+    cerr << "Fatal error:" << endl;
+    error.Print();
+    exit(1);
+  }
+  if (ac)
+    delete ac;
+  if (zz)
+    delete zz;
+               
+  return 0;
+}

Reply via email to