# HG changeset patch # User Matti Hamalainen # Date 1349088126 -10800 # Node ID 182e5fac93f597a8e4eeb463b801c9ca1c90d049 # Parent b51c7fc264abbf6c1a82227fd88c640c6b4119a4 Cleanups. diff -r b51c7fc264ab -r 182e5fac93f5 mod2wav.c --- a/mod2wav.c Mon Oct 01 13:32:18 2012 +0300 +++ b/mod2wav.c Mon Oct 01 13:42:06 2012 +0300 @@ -215,9 +215,9 @@ { DMResource *inFile = NULL; FILE *outFile = NULL; - JSSModule *m = NULL; - JSSMixer *d = NULL; - JSSPlayer *p = NULL; + JSSModule *mod = NULL; + JSSMixer *dev = NULL; + JSSPlayer *plr = NULL; int result = -1; size_t bufLen = 1024*4, dataTotal, dataWritten, sampSize; Uint8 *mb = NULL; @@ -251,7 +251,7 @@ fprintf(stderr, "Reading file: %s\n", srcFilename); #ifdef JSS_SUP_XM fprintf(stderr, "* Trying XM...\n"); - result = jssLoadXM(inFile, &m); + result = jssLoadXM(inFile, &mod); #endif #ifdef JSS_SUP_JSSMOD if (result != 0) @@ -266,7 +266,7 @@ bufgot, dmferror(inFile), dmErrorStr(dmferror(inFile))); return 2; } - result = jssLoadJSSMOD(buf, bufsize, &m); + result = jssLoadJSSMOD(buf, bufsize, &mod); dmFree(buf); } #endif @@ -279,7 +279,7 @@ } // Try to convert it - if ((result = jssConvertModuleForPlaying(m)) != DMERR_OK) + if ((result = jssConvertModuleForPlaying(mod)) != DMERR_OK) { fprintf(stderr, "Could not convert module for playing, %d: %s\n", result, dmErrorStr(result)); @@ -287,52 +287,52 @@ } // Open mixer - d = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); - if (!d) + dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); + if (dev == NULL) { fprintf(stderr, "jvmInit() returned NULL\n"); return 4; } - sampSize = jvmGetSampleSize(d); + sampSize = jvmGetSampleSize(dev); mb = dmMalloc(bufLen * sampSize); - if (!mb) + if (mb == NULL) { fprintf(stderr, "Could not allocate mixing buffer\n"); return 5; } dmMsg(1, "Using fmt=%d, bits=%d, channels=%d, freq=%d [%d / sample]\n", - optOutFormat, jvmGetSampleRes(d), optOutChannels, optOutFreq, + optOutFormat, jvmGetSampleRes(dev), optOutChannels, optOutFreq, sampSize); // Initialize player - p = jmpInit(d); - if (!p) { + if ((plr = jmpInit(dev)) == NULL) + { fprintf(stderr, "jmpInit() returned NULL\n"); return 6; } // Set callback - jvmSetCallback(d, jmpExec, p); + jvmSetCallback(dev, jmpExec, plr); // Initialize playing - jmpSetModule(p, m); + jmpSetModule(plr, mod); if (optStartOrder >= 0) { dmMsg(1, "Starting from song order #%d\n", optStartOrder); } else optStartOrder = 0; - jmpPlayOrder(p, optStartOrder); - jvmSetGlobalVol(d, 50); + jmpPlayOrder(plr, optStartOrder); + jvmSetGlobalVol(dev, 50); - if (optMuteOChannels > 0 && optMuteOChannels <= m->nchannels) + if (optMuteOChannels > 0 && optMuteOChannels <= mod->nchannels) { int i; - for (i = 0; i < m->nchannels; i++) - jvmMute(d, i, TRUE); - jvmMute(d, optMuteOChannels - 1, FALSE); + for (i = 0; i < mod->nchannels; i++) + jvmMute(dev, i, TRUE); + jvmMute(dev, optMuteOChannels - 1, FALSE); } // Open output file @@ -343,7 +343,7 @@ } // Write initial header - jssWriteWAVHeader(outFile, jvmGetSampleRes(d), optOutFreq, optOutChannels, 1024); + jssWriteWAVHeader(outFile, jvmGetSampleRes(dev), optOutFreq, optOutChannels, 1024); // Render audio data and output to file if (optUsePlayTime) @@ -354,7 +354,7 @@ optPlayTime *= optOutFreq; dataTotal = 0; dataWritten = 1; - while (p->isPlaying && dataWritten > 0) + while (plr->isPlaying && dataWritten > 0) { size_t writeLen = bufLen; if (optUsePlayTime && (writeLen + dataTotal) > optPlayTime) @@ -362,7 +362,7 @@ if (writeLen > 0) { - jvmRenderAudio(d, mb, writeLen); + jvmRenderAudio(dev, mb, writeLen); #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) jssEncodeSample16((Uint16 *)mb, writeLen * optOutChannels, jsampSwapEndianess); #endif @@ -387,11 +387,16 @@ return 9; } - jssWriteWAVHeader(outFile, jvmGetSampleRes(d), optOutFreq, optOutChannels, dataTotal); + jssWriteWAVHeader(outFile, jvmGetSampleRes(dev), optOutFreq, optOutChannels, dataTotal); // Done! fclose(outFile); - jssFreeModule(m); + + jmpClose(plr); + jvmClose(dev); + jssFreeModule(mod); + jssClose(); + dmMsg(1, "OK.\n"); return 0; }