Thread: AVS to WAV
View Single Post
Old 24th June 2007, 01:38   #8  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,915
Quote:
Originally Posted by alvarez View Post
I also wrote a small command line utility for that purpose a while ago (just to try out how such stuff works), ...
Looks like Bepipe but, maybe without .NET Framework dependence?

Don't work with SoundOut (like Bepipe) but the STDOUT can be piped to encoders and obtain the finals ac3, aac, ... without intermediate wav files.

I'm very interested in Wavi but, like bepipe, have two problems with easy solution:

1) The wav header have a little bug, in wavi.c line 162:
*(LPDWORD)(wavHeader + headerPos) = (DWORD) fileSize + 8;
must be:
*(LPDWORD)(wavHeader + headerPos) = (DWORD) fileSize;

2) There are extra bytes written at end of file, then the RiffLength (well calculated) seems erroneous and some software can reject the wav files.
Maybe we can test something like (in wavi.c, line 200):
Code:
while (nextSample < streamInfo.dwLength) {
      if (userBreak) CleanupAndExit(1);
      bytesToWrite = 0;
      if (AVIStreamRead(aviStream, nextSample, samplesInBuffer, buffer, bufferSize, & bytesToWrite, & samplesRead) || (! bytesToWrite)) {
              fprintf(stderr, "Error: Could not read audio data from \"%s\".\n", inputFile);
              if (! toStdOut) CloseHandle(outputHandle);
              CleanupAndExit(1);
      }

      nextSample += samplesRead;  // moved
// New line:
      if (nextSample > streamInfo.dwLength) bytesToWrite = bytesToWrite - sampleSize * (nextSample - streamInfo.dwLength);

      if (! WriteFile(outputHandle, buffer, bytesToWrite, & bytesWritten, NULL) || (bytesWritten != bytesToWrite)) {
              if (toStdOut) {
                      fprintf(stderr, "Error: Could not write to the standard output.\n");
              } else {
                      fprintf(stderr, "Error: Could not write file \"%s\".\n", outputFile);
                      CloseHandle(outputHandle);
              }
              CleanupAndExit(1);
      }
//    nextSample += samplesRead;
}
Thanks.

EDIT: Seems work fine with these corrections.

Last edited by tebasuna51; 24th June 2007 at 12:17.
tebasuna51 is offline   Reply With Quote