changeset 206:9b6c0ed66960

Use the routines factored into dmwav module.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 07 Oct 2012 14:17:36 +0300
parents 9622c139cb9f
children 69a77cd47af7
files mod2wav.c
diffstat 1 files changed, 3 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/mod2wav.c	Sun Oct 07 14:16:11 2012 +0300
+++ b/mod2wav.c	Sun Oct 07 14:17:36 2012 +0300
@@ -6,7 +6,6 @@
  * Please read file 'COPYING' for information on license and distribution.
  */
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
 #include <errno.h>
 #include "jss.h"
@@ -15,41 +14,7 @@
 #include "jssplr.h"
 #include "dmlib.h"
 #include "dmargs.h"
-#include "dmfile.h"
-
-
-#define JSS_WAVE_FORMAT_PCM     (1)
-#define JSS_WAVE_RIFF_ID        "RIFF"
-#define JSS_WAVE_WAVE_ID        "WAVE"
-#define JSS_WAVE_FMT_ID         "fmt "
-#define JSS_WAVE_DATA_ID        "data"
-
-
-typedef struct
-{
-    Uint8     chunkID[4];
-    Uint32    chunkSize;
-} JSSWaveChunk; 
-
-
-typedef struct
-{
-    Uint8     riffID[4];
-    Uint32    fileSize;
-    Uint8     riffType[4];
-
-    JSSWaveChunk chFormat;
-
-    Uint16    wFormatTag;
-    Uint16    nChannels;
-    Uint32    nSamplesPerSec;
-    Uint32    nAvgBytesPerSec;
-    Uint16    nBlockAlign;
-    Uint16    wBitsPerSample;
-
-    JSSWaveChunk chData;
-    // Data follows here
-} JSSWaveFile;
+#include "dmwav.h"
 
 
 char    *srcFilename = NULL, *destFilename = NULL;
@@ -157,60 +122,6 @@
 }
 
 
-BOOL jssWriteChunk(FILE * f, JSSWaveChunk *ch)
-{
-    if (!dm_fwrite_str(f, ch->chunkID, 4)) return FALSE;
-    return dm_fwrite_le32(f, ch->chunkSize);
-}
-
-
-void jssMakeChunk(JSSWaveChunk *ch, const char *chunkID, const Uint32 chunkSize)
-{
-    memcpy(&(ch->chunkID), (const void *) chunkID, 4);
-    ch->chunkSize = chunkSize;
-}
-
-
-void jssWriteWAVHeader(FILE *outFile, int sampBits, int sampFreq, int sampChn, size_t sampLen)
-{
-    JSSWaveFile wav;
-    
-    // PCM WAVE chunk
-    jssMakeChunk(&wav.chFormat, JSS_WAVE_FMT_ID, (2 + 2 + 4 + 4 + 2 + 2));
-
-    wav.wFormatTag = JSS_WAVE_FORMAT_PCM;
-    wav.nChannels = sampChn;
-    wav.nSamplesPerSec = sampFreq;
-    wav.nAvgBytesPerSec = (sampBits * sampChn * sampFreq) / 8;
-    wav.nBlockAlign = (sampBits * sampChn) / 8;
-    wav.wBitsPerSample = sampBits;
-
-    // Data chunk
-    jssMakeChunk(&wav.chData, JSS_WAVE_DATA_ID, (sampLen * wav.nBlockAlign));
-
-    // RIFF header
-    memcpy(&wav.riffID, (const void *) JSS_WAVE_RIFF_ID, 4);
-    memcpy(&wav.riffType, (const void *) JSS_WAVE_WAVE_ID, 4);
-    wav.fileSize = ((4 + 4 + 4) + wav.chFormat.chunkSize + wav.chData.chunkSize);
-
-    // Write header
-    dm_fwrite_str(outFile, wav.riffID, sizeof(wav.riffID));
-    dm_fwrite_le32(outFile, wav.fileSize);
-    
-    dm_fwrite_str(outFile, wav.riffType, sizeof(wav.riffType));
-    jssWriteChunk(outFile, &wav.chFormat);
-    
-    dm_fwrite_le16(outFile, wav.wFormatTag);
-    dm_fwrite_le16(outFile, wav.nChannels);
-    dm_fwrite_le32(outFile, wav.nSamplesPerSec);
-    dm_fwrite_le32(outFile, wav.nAvgBytesPerSec);
-    dm_fwrite_le16(outFile, wav.nBlockAlign);
-    dm_fwrite_le16(outFile, wav.wBitsPerSample);
-    
-    jssWriteChunk(outFile, &wav.chData);
-}
-
-
 int main(int argc, char *argv[])
 {
     DMResource *inFile = NULL;
@@ -343,7 +254,7 @@
     }
 
     // Write initial header
-    jssWriteWAVHeader(outFile, jvmGetSampleRes(dev), optOutFreq, optOutChannels, 1024);
+    dmWriteWAVHeader(outFile, jvmGetSampleRes(dev), optOutFreq, optOutChannels, 1024);
 
     // Render audio data and output to file
     if (optUsePlayTime)
@@ -387,7 +298,7 @@
         return 9;
     }
     
-    jssWriteWAVHeader(outFile, jvmGetSampleRes(dev), optOutFreq, optOutChannels, dataTotal);
+    dmWriteWAVHeader(outFile, jvmGetSampleRes(dev), optOutFreq, optOutChannels, dataTotal);
     
     // Done!
     fclose(outFile);