# HG changeset patch # User Matti Hamalainen # Date 1348798040 -10800 # Node ID c42ee907de9ca601bce886f212d9ac58ee70c6c7 # Parent fc097f7717dfd2c3654501893aadffccff58d18e Various improvements in xm2jss output. diff -r fc097f7717df -r c42ee907de9c xm2jss.c --- a/xm2jss.c Fri Sep 28 04:47:10 2012 +0300 +++ b/xm2jss.c Fri Sep 28 05:07:20 2012 +0300 @@ -414,7 +414,7 @@ int jssSaveJSSMOD(FILE *outFile, JSSModule *m, int patMode, int flags8, int flags16) { JSSMODHeader jssH; - int i, pattern, order, instr; + int i, pattern, order, instr, totalSize; const size_t patBufSize = 64*1024; // 64kB pattern buffer Uint8 *patBuf; @@ -428,7 +428,6 @@ m->nchannels, m->npatterns, m->norders); // Create the JSSMOD header - dmMsg(2," * Writing JSSMOD-header 0x%04x.\n", JSSMOD_VERSION); jssH.idMagic[0] = 'J'; jssH.idMagic[1] = 'M'; jssH.idVersion = JSSMOD_VERSION; @@ -445,30 +444,35 @@ jssH.patMode = patMode; // Write header + totalSize = sizeof(jssH); if (fwrite(&jssH, sizeof(jssH), 1, outFile) != 1) JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Could not write JSSMOD header!\n"); + dmMsg(1," * JSSMOD-header 0x%04x, %d bytes.\n", JSSMOD_VERSION, totalSize); + // Write orders list - dmMsg(2," * Writing %d item orders list.\n", m->norders); - for (order = 0; order < m->norders; order++) + for (totalSize = order = 0; order < m->norders; order++) { Uint16 tmp = m->orderList[order]; + totalSize += sizeof(tmp); if (fwrite(&tmp, sizeof(tmp), 1, outFile) != 1) JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Could not write JSSMOD orders list.\n"); } + dmMsg(1," * %d item orders list, %d bytes.\n", + m->norders, totalSize); + // Allocate pattern compression buffer if ((patBuf = dmMalloc(patBufSize)) == NULL) JSSERROR(DMERR_MALLOC, DMERR_MALLOC, "Error allocating memory for pattern compression buffer.\n"); + // Write patterns - dmMsg(2," * Writing %d patterns.\n", m->npatterns); - for (pattern = 0; pattern < m->npatterns; pattern++) + for (totalSize = pattern = 0; pattern < m->npatterns; pattern++) { JSSMODPattern patHead; size_t finalSize = 0; - i = -1; switch (patMode) { @@ -488,6 +492,7 @@ i = jssConvertPatternRawElem(patBuf, patBufSize, &finalSize, m->patterns[pattern]); break; default: + i = DMERR_INVALID_DATA; dmFree(patBuf); JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, "Unsupported pattern conversion mode %d.\n", patMode); @@ -504,6 +509,7 @@ dmMsg(3, " - Pattern %d size %d bytes\n", pattern, finalSize); patHead.nrows = m->patterns[pattern]->nrows; patHead.size = finalSize; + totalSize += finalSize + sizeof(patHead); if (fwrite(&patHead, sizeof(patHead), 1, outFile) != 1) { @@ -520,12 +526,11 @@ } } } - dmFree(patBuf); + dmMsg(1," * %d patterns, %d bytes.\n", m->npatterns, totalSize); // Write extended instruments - dmMsg(2," * Writing %d Extended Instruments.\n", m->nextInstruments); - for (instr = 0; instr < m->nextInstruments; instr++) + for (totalSize = instr = 0; instr < m->nextInstruments; instr++) { JSSMODExtInstrument jssE; JSSExtInstrument *einst = m->extInstruments[instr]; @@ -552,15 +557,16 @@ JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, "Extended instrument #%i NULL!\n", instr); // Write to file + totalSize += sizeof(jssE); if (fwrite(&jssE, sizeof(jssE), 1, outFile) != 1) JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Could not write JSSMOD extended instrument #%i to file!\n", instr); } + dmMsg(1," * %d Extended Instruments, %d bytes.\n", m->nextInstruments, totalSize); // Write sample instrument headers - dmMsg(2," * Writing %d Instrument headers.\n", m->ninstruments); - for (instr = 0; instr < m->ninstruments; instr++) + for (totalSize = instr = 0; instr < m->ninstruments; instr++) { JSSMODInstrument jssI; JSSInstrument *pInst = m->instruments[instr]; @@ -586,14 +592,15 @@ JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, "Instrument #%i NULL!\n", instr); // Write to file + totalSize += sizeof(jssI); if (fwrite(&jssI, sizeof(jssI), 1, outFile) != 1) JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Could not write JSSMOD instrument #%i to file!\n", instr); } + dmMsg(1," * %d Instrument headers, %d bytes.\n", m->ninstruments, totalSize); // Write sample data - dmMsg(2," * Writing %d samples.\n", m->ninstruments); - for (instr = 0; instr < m->ninstruments; instr++) + for (totalSize = instr = 0; instr < m->ninstruments; instr++) if (m->instruments[instr]) { JSSInstrument *inst = m->instruments[instr]; @@ -610,12 +617,14 @@ jssEncodeSample8(inst->data, inst->size, flags8); res = fwrite(inst->data, sizeof(Uint8), inst->size, outFile); } - + + totalSize += inst->size; if (res != inst->size) JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Could not write JSSMOD sample #%i to file!\n", instr); } } + dmMsg(1," * %d samples, %d bytes.\n", m->ninstruments, totalSize); return DMERR_OK; } @@ -693,7 +702,7 @@ if (n->instrument >= 0 && n->instrument < m->nextInstruments) usedExtInstruments[n->instrument] = TRUE; else - dmMsg(3, "Pattern 0x%x, row=0x%x, chn=%d has invalid instrument 0x%x\n", + dmMsg(2, "Pattern 0x%x, row=0x%x, chn=%d has invalid instrument 0x%x\n", pattern, row, channel, n->instrument); } } @@ -737,7 +746,7 @@ // Create pattern mappings r->npatterns = 0; - dmMsg(2, "Unused patterns: "); + dmMsg(1, "Unused patterns: "); for (i = 0; i <= jsetMaxPatterns; i++) if (m->patterns[i] != NULL) @@ -763,7 +772,7 @@ // Re-map instruments - dmMsg(2, "Unused instruments: "); + dmMsg(1, "Unused instruments: "); for (n8 = n16 = i = 0; i <= jsetMaxInstruments; i++) if (m->instruments[i] != NULL) { @@ -792,7 +801,7 @@ n16, n8, r->ninstruments); // Re-map ext.instruments - dmMsg(2, "Unused ext.instruments: "); + dmMsg(1, "Unused ext.instruments: "); for (i = 0; i < jsetMaxInstruments; i++) if (usedExtInstruments[i]) { @@ -980,7 +989,7 @@ return 1; } - dmMsg(1, "Writing JSSMOD-format file [patMode=0x%x, samp8=0x%2x, samp16=0x%2x]\n", + dmMsg(1, "Writing JSSMOD-format file [patMode=0x%04x, samp8=0x%02x, samp16=0x%02x]\n", optPatternMode, optSampMode8, optSampMode16); result = jssSaveJSSMOD(dfile, dm, optPatternMode, optSampMode8, optSampMode16);