Ticket #8707: SoC Tools Update #3.patch

File SoC Tools Update #3.patch, 73.3 KB (added by SF/lightcast, 17 years ago)

Fix for SoC Tools Update #2.patch

  • compress.c

     
    3535        int nominalBitr;
    3636        int minBitr;
    3737        int maxBitr;
    38         int quality;
     38        float quality;
    3939        bool silent;
    4040} oggencparams;
    4141
    42 /* FIXME: This is an evil way to pass on the params to FLAC.
    43  It makes it near impossible to reliably pass default params to the
    44  encoder.
    45 */
    4642typedef struct {
    47         char * const* argv;
    48         int numArgs;
     43        int compressionLevel;
     44        int blocksize;
     45        bool verify;
     46        bool silent;
    4947} flaccparams;
    5048
    5149typedef struct {
    52         bool isLittleEndian;
    53         bool isStereo;
    54         bool isUnsigned;
     50        bool isLittleEndian, isStereo;
    5551        uint8 bitsPerSample;
    5652} rawtype;
    5753
    5854lameparams encparms = { minBitrDef, maxBitrDef, false, algqualDef, vbrqualDef, 0 };
    5955oggencparams oggparms = { -1, -1, -1, oggqualDef, 0 };
    60 flaccparams flacparms;
    61 rawtype rawAudioType = { false, false, false, 8 };
     56flaccparams flacparms = { flacCompressDef, flacBlocksizeDef, false, false };
     57rawtype rawAudioType = { false, false, 8 };
    6258
    6359const char *tempEncoded = TEMP_MP3;
    6460
    65 void setRawAudioType(bool isLittleEndian, bool isStereo, bool isUnsigned, uint8 bitsPerSample) {
     61void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample) {
    6662        rawAudioType.isLittleEndian = isLittleEndian;
    6763        rawAudioType.isStereo = isStereo;
    68         rawAudioType.isUnsigned = isUnsigned;
    6964        rawAudioType.bitsPerSample = bitsPerSample;
    7065}
    7166
     
    105100}
    106101
    107102void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, CompressMode compmode) {
     103        bool err = false;
    108104        char fbuf[2048];
    109105        char *tmp = fbuf;
    110         int i;
    111         bool err = false;
    112106
    113         switch (compmode) {
    114         case kVorbisMode:
    115                 tmp += sprintf(tmp, "oggenc ");
    116                 if (rawInput) {
    117                         tmp += sprintf(tmp, "--raw ");
    118                         tmp += sprintf(tmp, "--raw-chan=%d ", (rawAudioType.isStereo ? 2 : 1));
    119                         tmp += sprintf(tmp, "--raw-bits=%d ", rawAudioType.bitsPerSample);
    120                         tmp += sprintf(tmp, "--raw-rate=%d ", rawSamplerate);
    121                         tmp += sprintf(tmp, "--raw-endianness=%d ", (rawAudioType.isLittleEndian ? 0 : 1));
    122                 }
    123 
    124                 if (oggparms.nominalBitr != -1)
    125                         tmp += sprintf(tmp, "--bitrate=%d ", oggparms.nominalBitr);
    126                 if (oggparms.minBitr != -1)
    127                         tmp += sprintf(tmp, "--min-bitrate=%d ", oggparms.minBitr);
    128                 if (oggparms.maxBitr != -1)
    129                         tmp += sprintf(tmp, "--max-bitrate=%d ", oggparms.maxBitr);
    130                 if (oggparms.silent)
    131                         tmp += sprintf(tmp, "--quiet ");
    132                 tmp += sprintf(tmp, "--quality=%d ", oggparms.quality);
    133                 tmp += sprintf(tmp, "--output=\"%s\" ", outname);
    134                 tmp += sprintf(tmp, "\"%s\" ", inname);
    135                 err = system(fbuf) != 0;
    136                 break;
    137 
    138         case kMP3Mode:
     107        if (compmode == kMP3Mode) {
    139108                tmp += sprintf(tmp, "lame -t ");
    140109                if (rawInput) {
    141110                        tmp += sprintf(tmp, "-r ");
    142111                        tmp += sprintf(tmp, "--bitwidth %d ", rawAudioType.bitsPerSample);
    143                         if (rawAudioType.isLittleEndian)
     112
     113                        if (rawAudioType.isLittleEndian) {
    144114                                tmp += sprintf(tmp, "-x ");
     115                        }
     116                       
    145117                        tmp += sprintf(tmp, (rawAudioType.isStereo ? "-m j " : "-m m "));
    146118                        tmp += sprintf(tmp, "-s %d ", rawSamplerate);
    147119                }
    148120
    149                 if (encparms.abr)
     121                if (encparms.abr) {
    150122                        tmp += sprintf(tmp, "--abr %d ", encparms.minBitr);
    151                 else
     123                } else {
    152124                        tmp += sprintf(tmp, "--vbr-new -b %d ", encparms.minBitr);
     125                }
    153126
    154127                /* Explicitly specify a target sample rate, to work around a bug (?)
    155                  * in newer lame versions (>= 3.95) which causes it to malfunction
    156                  * for odd sample rates when in VBR mode. See also bug #934026.
    157                  * We essentially duplicate the old behaviour of lame (found in e.g.
    158                  * version 3.93.1): we round the input sample rate up to the next
    159                  * higher valid MP3 sample rate, with a margin of 3%.
    160                  */
    161                 if (rawSamplerate != -1)
     128                * in newer lame versions (>= 3.95) which causes it to malfunction
     129                * for odd sample rates when in VBR mode. See also bug #934026.
     130                * We essentially duplicate the old behaviour of lame (found in e.g.
     131                * version 3.93.1): we round the input sample rate up to the next
     132                * higher valid MP3 sample rate, with a margin of 3%.
     133                */
     134                if (rawSamplerate != -1) {
    162135                        tmp += sprintf(tmp, "--resample %d ", map2MP3Frequency(97 * rawSamplerate / 100));
     136                }
    163137
    164                 if (encparms.silent)
     138                if (encparms.silent) {
    165139                        tmp += sprintf(tmp, " --silent ");
     140                }
     141
    166142                tmp += sprintf(tmp, "-q %d ", encparms.algqual);
    167143                tmp += sprintf(tmp, "-V %d ", encparms.vbrqual);
    168144                tmp += sprintf(tmp, "-B %d ", encparms.maxBitr);
    169145                tmp += sprintf(tmp, "\"%s\" \"%s\" ", inname, outname);
     146
    170147                err = system(fbuf) != 0;
    171                 break;
    172148
    173         case kFlacMode:
    174                 /* --lax is needed to allow 11kHz, we dont need place for meta-tags, and no seektable */
    175                 /* -f is reqired to force override of unremoved temp file. See bug #1294648 */
    176                 tmp += sprintf(tmp, "flac --best -b 1152 -f --lax --no-padding --no-seektable --no-ogg ");
     149                if (err) {
     150                        printf("Got error from encoder. (check your parameters)\n");
     151                        printf("Encoder Commandline: %s\n", fbuf );
     152                        exit(-1);
     153                } else {
     154                        return;
     155                }
     156        }
    177157
     158#ifdef DISABLE_OGG
     159                if (compmode == kVorbisMode) {
     160                        tmp += sprintf(tmp, "oggenc ");
     161                        if (rawInput) {
     162                                tmp += sprintf(tmp, "--raw ");
     163                                tmp += sprintf(tmp, "--raw-chan=%d ", (rawAudioType.isStereo ? 2 : 1));
     164                                tmp += sprintf(tmp, "--raw-bits=%d ", rawAudioType.bitsPerSample);
     165                                tmp += sprintf(tmp, "--raw-rate=%d ", rawSamplerate);
     166                                tmp += sprintf(tmp, "--raw-endianness=%d ", (rawAudioType.isLittleEndian ? 0 : 1));
     167                        }
     168                       
     169                        if (oggparms.nominalBitr != -1) {
     170                                tmp += sprintf(tmp, "--bitrate=%d ", oggparms.nominalBitr);
     171                        } else {
     172                                tmp += sprintf(tmp, "--quality=%d ", oggparms.quality);
     173                        }
     174
     175                        if (oggparms.minBitr != -1) {
     176                                tmp += sprintf(tmp, "--min-bitrate=%d ", oggparms.minBitr);
     177                        }
     178                       
     179                        if (oggparms.maxBitr != -1) {
     180                                tmp += sprintf(tmp, "--max-bitrate=%d ", oggparms.maxBitr);
     181                        }
     182               
     183                        if (oggparms.silent) {
     184                                tmp += sprintf(tmp, "--quiet ");
     185                        }
     186
     187                        tmp += sprintf(tmp, "--output=\"%s\" ", outname);
     188                        tmp += sprintf(tmp, "\"%s\" ", inname);
     189
     190                        err = system(fbuf) != 0;
     191                       
     192                        if (err) {
     193                                printf("Got error from encoder. (check your parameters)\n");
     194                                printf("Encoder Commandline: %s\n", fbuf );
     195                                exit(-1);
     196                        } else {
     197                                return;
     198                        }
     199                }
     200#endif
     201
     202#ifdef DISABLE_FLAC
     203                if (compmode == kFlacMode) {
     204                        /* --lax is needed to allow 11kHz, we dont need place for meta-tags, and no seektable */
     205                        /* -f is reqired to force override of unremoved temp file. See bug #1294648 */
     206                        tmp += sprintf(tmp, "flac -f --lax --no-padding --no-seektable --no-ogg ");
     207
     208                        if (rawInput) {
     209                                tmp += sprintf(tmp, "--force-raw-format ");
     210                                tmp += sprintf(tmp, "--sign=%s ", ((rawAudioType.bitsPerSample == 8) ? "unsigned" : "signed"));
     211                                tmp += sprintf(tmp, "--channels=%d ", (rawAudioType.isStereo ? 2 : 1));
     212                                tmp += sprintf(tmp, "--bps=%d ", rawAudioType.bitsPerSample);
     213                                tmp += sprintf(tmp, "--sample-rate=%d ", rawSamplerate);
     214                                tmp += sprintf(tmp, "--endian=%s ", (rawAudioType.isLittleEndian ? "little" : "big"));
     215                        }
     216
     217                        if (flacparms.silent) {
     218                                tmp += sprintf(tmp, "--silent ");
     219                        }
     220
     221                        if (flacparms.verify) {
     222                                tmp += sprintf(tmp, "--verify ");
     223                        }
     224
     225                        tmp += sprintf(tmp, "--compression-level-%d ", flacparms.compressionLevel);
     226                        tmp += sprintf(tmp, "-b %d ", flacparms.blocksize);
     227                        tmp += sprintf(tmp, "-o \"%s\" ", outname);
     228                        tmp += sprintf(tmp, "\"%s\" ", inname);
     229
     230                        err = system(fbuf) != 0;
     231                       
     232                        if (err) {
     233                                printf("Got error from encoder. (check your parameters)\n");
     234                                printf("Encoder Commandline: %s\n", fbuf );
     235                                exit(-1);
     236                        } else {
     237                                return;
     238                        }
     239                }
     240#endif
    178241                if (rawInput) {
    179                         tmp += sprintf(tmp, "--force-raw-format ");
    180                         tmp += sprintf(tmp, "--sign=%s ", (rawAudioType.isUnsigned ? "unsigned" : "signed"));
    181                         tmp += sprintf(tmp, "--channels=%d ", (rawAudioType.isStereo ? 2 : 1));
    182                         tmp += sprintf(tmp, "--bps=%d ", rawAudioType.bitsPerSample);
    183                         tmp += sprintf(tmp, "--sample-rate=%d ", rawSamplerate);
    184                         tmp += sprintf(tmp, "--endian=%s ", (rawAudioType.isLittleEndian ? "little" : "big"));
     242                        FILE *inputRaw;
     243                        long length;
     244                        char *rawData;
     245
     246                        inputRaw = fopen(inname, "rb");
     247                        length = fileSize(inputRaw);
     248                        rawData = (char *)malloc(length);
     249                        fread(rawData, 1, length, inputRaw);
     250
     251                        printf(" - length = %d\n", length);
     252                        printf(" - channels = %d\n", (rawAudioType.isStereo ? 2 : 1));
     253                        printf(" - sample rate = %d\n", rawSamplerate);
     254                        printf(" - compression = %dbits\n", rawAudioType.bitsPerSample);
     255
     256                        encodeRaw(rawData, length, rawSamplerate, outname, compmode);
     257
     258                        fclose(inputRaw);
     259                        free(rawData);
     260                } else {
     261                        FILE *inputWav;
     262                        int fmtHeaderSize, length, numChannels, sampleRate, bitsPerSample;
     263                        char *wavData;
     264
     265                        inputWav = fopen(inname, "rb");
     266
     267                        /* Standard PCM fmt header is 16 bits, but at least Simon 1 and 2 use 18 bits */
     268                        fseek(inputWav, 16, SEEK_SET);
     269                        fmtHeaderSize = readUint32LE(inputWav);
     270
     271                        fseek(inputWav, 22, SEEK_SET);
     272                        numChannels = readUint16LE(inputWav);
     273                        sampleRate = readUint32LE(inputWav);
     274
     275                        fseek(inputWav, 34, SEEK_SET);
     276                        bitsPerSample = readUint16LE(inputWav);
     277
     278                        /* The size of the raw audio is after the RIFF chunk (12 bytes), fmt chunk (8 + fmtHeaderSize bytes), and data chunk id (4 bytes) */
     279                        fseek(inputWav, 24 + fmtHeaderSize, SEEK_SET);
     280                        length = readUint32LE(inputWav);
     281
     282                        wavData = (char *)malloc(length);
     283                        fread(wavData, 1, length, inputWav);
     284
     285                        printf(" - length = %d\n", length);
     286                        printf(" - channels = %d\n", numChannels);
     287                        printf(" - sample rate = %d\n", sampleRate);
     288                        printf(" - compression = %dbits\n", bitsPerSample);
     289
     290                        setRawAudioType(true, numChannels == 2, bitsPerSample);
     291                        encodeRaw(wavData, length, sampleRate, outname, compmode);
     292
     293                        fclose(inputWav);
     294                        free (wavData);
    185295                }
     296}
    186297
    187                 for (i = 0; i < flacparms.numArgs; i++) {
    188                         /* Append optional encoder arguments */
    189                         tmp += sprintf(tmp, "%s ", flacparms.argv[i]);
     298void encodeRaw(char *rawData, int length, int samplerate, const char *outname, CompressMode compmode) {
     299#ifndef DISABLE_OGG
     300        if (compmode == kVorbisMode) {
     301                FILE *outputOgg;
     302                char outputString[256] = "";
     303                int numChannels = (rawAudioType.isStereo ? 2 : 1);
     304                int totalSamples = length / ((rawAudioType.bitsPerSample / 8) * numChannels);
     305                int samplesLeft = totalSamples;
     306                int eos = 0;
     307                int totalBytes = 0;
     308
     309                vorbis_info vi;
     310                vorbis_comment vc;
     311                vorbis_dsp_state vd;
     312                vorbis_block vb;
     313
     314                ogg_stream_state os;
     315                ogg_page og;
     316                ogg_packet op;
     317
     318                ogg_packet header;
     319                ogg_packet header_comm;
     320                ogg_packet header_code;
     321
     322                outputOgg = fopen(outname,"wb");
     323
     324                vorbis_info_init(&vi);
     325
     326                if (oggparms.nominalBitr > 0) {
     327                        int result = 0;
     328
     329                        /* Input is in kbps, function takes bps */
     330                        result = vorbis_encode_setup_managed(&vi, numChannels, samplerate, (oggparms.maxBitr > 0 ? 1000 * oggparms.maxBitr : -1), (1000 * oggparms.nominalBitr), (oggparms.minBitr > 0 ? 1000 * oggparms.minBitr : -1));
     331
     332                        if (result == OV_EFAULT) {
     333                                printf("Error: Internal Logic Fault.\n\n");
     334                                vorbis_info_clear(&vi);
     335                                exit(-1);
     336                        } else if ((result == OV_EINVAL) || (result == OV_EIMPL)) {
     337                                printf("Error: Invalid bitrate parameters.\n\n");
     338                                vorbis_info_clear(&vi);
     339                                exit(-1);
     340                        }
     341
     342                        if (!oggparms.silent) {
     343                                sprintf(outputString, "Encoding to\n         \"%s\"\nat average bitrate %i kbps (", outname, oggparms.nominalBitr);
     344
     345                                if (oggparms.minBitr > 0) {
     346                                        sprintf(outputString + strlen(outputString), "min %i kbps, ", oggparms.minBitr);
     347                                } else {
     348                                        sprintf(outputString + strlen(outputString), "no min, ");
     349                                }
     350
     351                                if (oggparms.maxBitr > 0) {
     352                                        sprintf(outputString + strlen(outputString), "max %i kbps),\nusing full bitrate management engine\nSet optional hard quality restrictions\n", oggparms.maxBitr);
     353                                } else {
     354                                        sprintf(outputString + strlen(outputString), "no max),\nusing full bitrate management engine\nSet optional hard quality restrictions\n");
     355                                }
     356                        }
     357                } else {
     358                        int result = 0;
     359
     360                        /* Quality input is 1 - 10, function takes -0.1 through 1.0 */
     361                        result = vorbis_encode_setup_vbr(&vi, numChannels, samplerate, oggparms.quality * 0.1);
     362
     363                        if (result == OV_EFAULT) {
     364                                printf("Error: Internal Logic Fault.\n\n");
     365                                vorbis_info_clear(&vi);
     366                                exit(-1);
     367                        } else if ((result == OV_EINVAL) || (result == OV_EIMPL)) {
     368                                printf("Error: Invalid bitrate parameters.\n\n");
     369                                vorbis_info_clear(&vi);
     370                                exit(-1);
     371                        }
     372
     373                        if (!oggparms.silent) {
     374                                sprintf(outputString, "Encoding to\n         \"%s\"\nat quality %2.2f", outname, oggparms.quality);
     375                        }
     376
     377                        if ((oggparms.minBitr > 0) || (oggparms.maxBitr > 0)) {
     378                                struct ovectl_ratemanage_arg extraParam;
     379                                vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_GET, &extraParam);
     380
     381                                extraParam.bitrate_hard_min = (oggparms.minBitr > 0 ? (1000 * oggparms.minBitr) : -1);
     382                                extraParam.bitrate_hard_max = (oggparms.maxBitr > 0 ? (1000 * oggparms.maxBitr) : -1);
     383                                extraParam.management_active = 1;
     384
     385                                vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_SET, &extraParam);
     386
     387                                if (!oggparms.silent) {
     388                                        sprintf(outputString + strlen(outputString), " using constrained VBR (");
     389
     390                                        if (oggparms.minBitr != -1) {
     391                                                sprintf(outputString + strlen(outputString), "min %i kbps, ", oggparms.minBitr);
     392                                        } else {
     393                                                sprintf(outputString + strlen(outputString), "no min, ");
     394                                        }
     395
     396                                        if (oggparms.maxBitr != -1) {
     397                                                sprintf(outputString + strlen(outputString), "max %i kbps)\nSet optional hard quality restrictions\n", oggparms.maxBitr);
     398                                        } else {
     399                                                sprintf(outputString + strlen(outputString), "no max)\nSet optional hard quality restrictions\n");
     400                                        }
     401                                }
     402                        } else {
     403                                sprintf(outputString + strlen(outputString), "\n");
     404                        }
    190405                }
    191406
    192                 tmp += sprintf(tmp, "-o \"%s\" ", outname);
    193                 tmp += sprintf(tmp, "\"%s\" ", inname);
     407                printf(outputString);
    194408
    195                 err = system(fbuf) != 0;
    196                 break;
    197         }
     409                vorbis_encode_setup_init(&vi);
     410                vorbis_comment_init(&vc);
     411                vorbis_analysis_init(&vd, &vi);
     412                vorbis_block_init(&vd, &vb);
     413                ogg_stream_init(&os, 0);
     414                vorbis_analysis_headerout(&vd, &vc, &header, &header_comm, &header_code);
    198415
    199         if (err) {
    200                 printf("Got error from encoder. (check your parameters)\n");
    201                 printf("Encoder Commandline: %s\n", fbuf );
    202                 exit(-1);
     416                ogg_stream_packetin(&os, &header);
     417                ogg_stream_packetin(&os, &header_comm);
     418                ogg_stream_packetin(&os, &header_code);
     419
     420                while (!eos) {
     421                        int result = ogg_stream_flush(&os,&og);
     422
     423                        if (result == 0) {
     424                                break;
     425                        }
     426
     427                        fwrite(og.header, 1, og.header_len, outputOgg);
     428                        fwrite(og.body, 1, og.body_len, outputOgg);
     429                }
     430
     431                while (!eos) {
     432                        int i, j;
     433                        int numSamples = ((samplesLeft < 2048) ? samplesLeft : 2048);
     434                        float **buffer = vorbis_analysis_buffer(&vd, numSamples);
     435
     436                        /* We must tell the encoder that we have reached the end of the stream */
     437                        if (numSamples == 0) {
     438                                vorbis_analysis_wrote(&vd, 0);
     439                        } else {
     440                                /* Adapted from oggenc 1.1.1 */
     441                                if (rawAudioType.bitsPerSample == 8) {
     442                                        unsigned char *rawDataUnsigned = (unsigned char *)rawData;
     443                                        for (i = 0; i < numSamples; i++) {
     444                                                for (j = 0; j < numChannels; j++) {
     445                                                        buffer[j][i] = ((int)(rawDataUnsigned[i * numChannels + j]) - 128) / 128.0f;
     446                                                }
     447                                        }
     448                                } else if(rawAudioType.bitsPerSample == 16) {
     449                                        if(rawAudioType.isLittleEndian) {
     450                                                for(i = 0; i < numSamples; i++) {
     451                                                        for(j = 0; j < numChannels; j++) {
     452                                                                buffer[j][i] = ((rawData[(i * 2 * numChannels) + (2 * j) + 1] << 8) | (rawData[(i * 2 * numChannels) + (2 * j)] & 0xff)) / 32768.0f;
     453                                                        }
     454                                                }
     455                                        }
     456                                        else {
     457                                                for(i = 0; i < numSamples; i++) {
     458                                                        for(j = 0; j < numChannels; j++) {
     459                                                                buffer[j][i] = ((rawData[(i * 2 * numChannels) + (2 * j)] << 8) | (rawData[(i * 2 * numChannels) + (2 * j) + 1] & 0xff)) / 32768.0f;
     460                                                        }
     461                                                }
     462                                        }
     463                                }
     464
     465                                vorbis_analysis_wrote(&vd, numSamples);
     466                        }
     467
     468                        while (vorbis_analysis_blockout(&vd, &vb) == 1) {
     469                                vorbis_analysis(&vb, NULL);
     470                                vorbis_bitrate_addblock(&vb);
     471
     472                                while (vorbis_bitrate_flushpacket(&vd, &op)) {
     473                                        ogg_stream_packetin(&os, &op);
     474
     475                                        while (!eos) {
     476                                                int result = ogg_stream_pageout(&os, &og);
     477
     478                                                if(result == 0) {
     479                                                        break;
     480                                                }
     481
     482                                                totalBytes += fwrite(og.header, 1, og.header_len, outputOgg);
     483                                                totalBytes += fwrite(og.body, 1, og.body_len, outputOgg);
     484
     485                                                if(ogg_page_eos(&og)) {
     486                                                        eos = 1;
     487                                                }
     488                                        }
     489                                }
     490                        }
     491
     492                        rawData += 2048 * (rawAudioType.bitsPerSample / 8) * numChannels;
     493                        samplesLeft -= 2048;
     494                }
     495
     496                ogg_stream_clear(&os);
     497                vorbis_block_clear(&vb);
     498                vorbis_dsp_clear(&vd);
     499                vorbis_info_clear(&vi);
     500
     501                fclose(outputOgg);
     502
     503                if (!oggparms.silent) {
     504                        printf("\nDone encoding file \"%s\"\n", outname);
     505                        printf("\n\tFile length:  %dm %ds\n", (int)(totalSamples / samplerate / 60), (totalSamples / samplerate % 60));
     506                        printf("\tAverage bitrate: %.1f kb/s\n\n", (8.0 * (double)totalBytes / 1000.0) / ((double)totalSamples / (double)samplerate));
     507                }
     508        }
     509#endif
     510
     511#ifndef DISABLE_FLAC
     512        if (compmode == kFlacMode) {
     513                int i;
     514                int numChannels = (rawAudioType.isStereo ? 2 : 1);
     515                int samplesPerChannel = length / ((rawAudioType.bitsPerSample / 8) * numChannels);
     516                FLAC__StreamEncoder *encoder;
     517                FLAC__StreamEncoderInitStatus initStatus;
     518                FLAC__int32 *flacData;
     519
     520                flacData = (FLAC__int32 *)malloc(samplesPerChannel * numChannels * sizeof(FLAC__int32));
     521
     522                if (rawAudioType.bitsPerSample == 8) {
     523                        for (i = 0; i < samplesPerChannel * numChannels; i++) {
     524                                FLAC__uint8 *rawDataUnsigned;
     525                                rawDataUnsigned = (FLAC__uint8 *)rawData;
     526                                flacData[i] = (FLAC__int32)rawDataUnsigned[i] - 0x80;
     527                        }
     528                } else if (rawAudioType.bitsPerSample == 16) {
     529                        /* The rawData pointer is an 8-bit char so we must create a new pointer to access 16-bit samples */
     530                        FLAC__int16 *rawData16;
     531                        rawData16 = (FLAC__int16 *)rawData;
     532                        for (i = 0; i < samplesPerChannel * numChannels; i++) {
     533                                flacData[i] = (FLAC__int32)rawData16[i];
     534                        }
     535                }
     536
     537                if (!flacparms.silent) {
     538                        printf("Encoding to\n         \"%s\"\nat compression level %d using blocksize %d\n\n", outname, flacparms.compressionLevel, flacparms.blocksize);
     539                }
     540
     541                encoder = FLAC__stream_encoder_new();
     542
     543                FLAC__stream_encoder_set_bits_per_sample(encoder, rawAudioType.bitsPerSample);
     544                FLAC__stream_encoder_set_blocksize(encoder, flacparms.blocksize);
     545                FLAC__stream_encoder_set_channels(encoder, numChannels);
     546                FLAC__stream_encoder_set_compression_level(encoder, flacparms.compressionLevel);
     547                FLAC__stream_encoder_set_sample_rate(encoder, samplerate);
     548                FLAC__stream_encoder_set_streamable_subset(encoder, false);
     549                FLAC__stream_encoder_set_total_samples_estimate(encoder, samplesPerChannel);
     550                FLAC__stream_encoder_set_verify(encoder, flacparms.verify);
     551
     552                initStatus = FLAC__stream_encoder_init_file(encoder, outname, NULL, NULL);
     553
     554                if (initStatus != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
     555                        printf("Got error from encoder. (check your paramters)\n");
     556                        printf("FLAC error: %s\n\n", FLAC__StreamEncoderInitStatusString[initStatus]);
     557                        exit(-1);
     558                } else {
     559                        FLAC__stream_encoder_process_interleaved(encoder, flacData, samplesPerChannel);
     560                }
     561
     562                FLAC__stream_encoder_finish(encoder);
     563                FLAC__stream_encoder_delete(encoder);
     564
     565                free(flacData);
     566
     567                if (!flacparms.silent) {
     568                        printf("\nDone encoding file \"%s\"\n", outname);
     569                        printf("\n\tFile length:  %dm %ds\n\n", (int)(samplesPerChannel / samplerate / 60), (samplesPerChannel / samplerate % 60));
     570                }
    203571        }
     572#endif
    204573}
    205574
    206575void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode) {
     
    261630                length = fgetc(input);
    262631                length |= fgetc(input) << 8;
    263632                length |= fgetc(input) << 16;
     633
    264634                if (blocktype == 1) {
    265635                        length -= 2;
    266636                        sample_rate = fgetc(input);
     
    287657                                  (comp == 3 ? "2bits"   :
    288658                                                                "Multi")))), comp);
    289659
    290                 if (comp != 0)
     660                if (comp != 0) {
    291661                        error("Cannot handle compressed VOC data");
     662                }
    292663
    293664                /* Copy the raw data to a temporary file */
    294665                while (length > 0) {
    295666                        size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : (uint32)length, input);
    296                         if (size <= 0)
     667
     668                        if (size <= 0) {
    297669                                break;
     670                        }
     671
    298672                        length -= (int)size;
    299673                        fwrite(fbuf, 1, size, f);
    300674                }
     
    304678
    305679        assert(real_samplerate != -1);
    306680
    307         setRawAudioType(false, false, true, 8);
     681        setRawAudioType(false, false, 8);
    308682
    309683        /* Convert the raw temp file to OGG/MP3 */
    310684        encodeAudio(outName, true, real_samplerate, tempEncoded, compMode);
     
    318692                        encparms.abr=1;
    319693                } else if (strcmp(argv[i], "-b") == 0) {
    320694                        encparms.minBitr = atoi(argv[i + 1]);
    321                         if ((encparms.minBitr % 8) != 0)
     695
     696                        if ((encparms.minBitr % 8) != 0) {
    322697                                encparms.minBitr -= encparms.minBitr % 8;
    323                         if (encparms.minBitr >160)
     698                        }
     699
     700                        if (encparms.minBitr >160) {
    324701                                encparms.minBitr = 160;
    325                         if (encparms.minBitr < 8)
    326                                 encparms.minBitr=8;
     702                        }
     703
     704                        if (encparms.minBitr < 8) {
     705                                encparms.minBitr = 8;
     706                        }
     707
    327708                        i++;
    328709                } else if (strcmp(argv[i], "-B") == 0) {
    329710                        encparms.maxBitr = atoi(argv[i + 1]);
    330                         if ((encparms.maxBitr % 8) != 0)
     711
     712                        if ((encparms.maxBitr % 8) != 0) {
    331713                                encparms.maxBitr -= encparms.maxBitr % 8;
    332                         if (encparms.maxBitr > 160)
     714                        }
     715
     716                        if (encparms.maxBitr > 160) {
    333717                                encparms.maxBitr = 160;
    334                         if (encparms.maxBitr < 8)
     718                        }
     719
     720                        if (encparms.maxBitr < 8) {
    335721                                encparms.maxBitr = 8;
     722                        }
     723
    336724                        i++;
    337725                } else if (strcmp(argv[i], "-V") == 0) {
    338726                        encparms.vbrqual = atoi(argv[i + 1]);
    339                         if(encparms.vbrqual < 0)
     727
     728                        if(encparms.vbrqual < 0) {
    340729                                encparms.vbrqual = 0;
    341                         if(encparms.vbrqual > 9)
     730                        }
     731
     732                        if(encparms.vbrqual > 9) {
    342733                                encparms.vbrqual = 9;
     734                        }
     735
    343736                        i++;
    344737                } else if (strcmp(argv[i], "-q") == 0) {
    345738                        encparms.algqual = atoi(argv[i + 1]);
    346                         if (encparms.algqual < 0)
     739
     740                        if (encparms.algqual < 0) {
    347741                                encparms.algqual = 0;
    348                         if (encparms.algqual > 9)
     742                        }
     743
     744                        if (encparms.algqual > 9) {
    349745                                encparms.algqual = 9;
     746                        }
     747
    350748                        i++;
    351749                } else if (strcmp(argv[i], "--silent") == 0) {
    352750                        encparms.silent = 1;
     
    358756                        break;
    359757                }
    360758        }
     759
    361760        if (i != (argc - 1)) {
    362761                return 0;
    363762        }
     763
    364764        return 1;
    365765}
    366766
     
    368768        for (; i < argc; i++) {
    369769                if (strcmp(argv[i], "-b") == 0) {
    370770                        oggparms.nominalBitr = atoi(argv[i + 1]);
     771
     772                        if ((oggparms.nominalBitr % 8) != 0) {
     773                                oggparms.nominalBitr -= oggparms.nominalBitr % 8;
     774                        }
     775
     776                        if (oggparms.nominalBitr >160) {
     777                                oggparms.nominalBitr = 160;
     778                        }
     779
     780                        if (oggparms.nominalBitr < 8) {
     781                                oggparms.nominalBitr = 8;
     782                        }
     783
    371784                        i++;
    372                 }
    373                 else if (strcmp(argv[i], "-m") == 0) {
     785                } else if (strcmp(argv[i], "-m") == 0) {
    374786                        oggparms.minBitr = atoi(argv[i + 1]);
     787
     788                        if ((oggparms.minBitr % 8) != 0) {
     789                                oggparms.minBitr -= oggparms.minBitr % 8;
     790                        }
     791
     792                        if (oggparms.minBitr >160) {
     793                                oggparms.minBitr = 160;
     794                        }
     795
     796                        if (oggparms.minBitr < 8) {
     797                                oggparms.minBitr = 8;
     798                        }
     799
    375800                        i++;
    376801                }
    377802                else if (strcmp(argv[i], "-M") == 0) {
    378803                        oggparms.maxBitr = atoi(argv[i + 1]);
     804
     805                        if ((oggparms.maxBitr % 8) != 0) {
     806                                oggparms.maxBitr -= encparms.minBitr % 8;
     807                        }
     808
     809                        if (oggparms.maxBitr >160) {
     810                                oggparms.maxBitr = 160;
     811                        }
     812
     813                        if (oggparms.maxBitr < 8) {
     814                                oggparms.maxBitr = 8;
     815                        }
     816
    379817                        i++;
    380818                }
    381819                else if (strcmp(argv[i], "-q") == 0) {
     
    391829                else if (argv[i][0] == '-') {
    392830                        return 0;
    393831                }
    394                 else
     832                else {
    395833                        break;
     834                }
    396835        }
    397         if (i != argc - 1)
     836
     837        if (i != argc - 1) {
    398838                return 0;
     839        }
     840
    399841        return 1;
    400842}
    401843
    402844int process_flac_parms(int argc, char *argv[], int i){
    403         flacparms.argv = &argv[i];
    404         flacparms.numArgs = argc - 1 - i;
     845        for (; i < argc; i++) {
     846                if (strcmp(argv[i], "-b") == 0) {
     847                        flacparms.blocksize = atoi(argv[i + 1]);
     848                        i++;
     849                }
     850                else if (strcmp(argv[i], "--fast") == 0) {
     851                        flacparms.compressionLevel = 0;
     852                }
     853                else if (strcmp(argv[i], "--best") == 0) {
     854                        flacparms.compressionLevel = 8;
     855                }
     856                else if (strcmp(argv[i], "-0") == 0) {
     857                        flacparms.compressionLevel = 0;
     858                }
     859                else if (strcmp(argv[i], "-1") == 0) {
     860                        flacparms.compressionLevel = 1;
     861                }
     862                else if (strcmp(argv[i], "-2") == 0) {
     863                        flacparms.compressionLevel = 2;
     864                }
     865                else if (strcmp(argv[i], "-3") == 0) {
     866                        flacparms.compressionLevel = 3;
     867                }
     868                else if (strcmp(argv[i], "-4") == 0) {
     869                        flacparms.compressionLevel = 4;
     870                }
     871                else if (strcmp(argv[i], "-5") == 0) {
     872                        flacparms.compressionLevel = 5;
     873                }
     874                else if (strcmp(argv[i], "-6") == 0) {
     875                        flacparms.compressionLevel = 6;
     876                }
     877                else if (strcmp(argv[i], "-7") == 0) {
     878                        flacparms.compressionLevel = 7;
     879                }
     880                else if (strcmp(argv[i], "-8") == 0) {
     881                        flacparms.compressionLevel = 8;
     882                }
     883                else if (strcmp(argv[i], "--verify") == 0) {
     884                        flacparms.verify = true;
     885                }
     886                else if (strcmp(argv[i], "--silent") == 0) {
     887                        flacparms.silent = true;
     888                }
     889                else if (strcmp(argv[i], "--help") == 0) {
     890                        return 0;
     891                }
     892                else if (argv[i][0] == '-') {
     893                        return 0;
     894                }
     895                else {
     896                        break;
     897                }
     898        }
    405899
    406         if (i >= argc)
     900        if (i != argc - 1) {
    407901                return 0;
     902        }
     903
    408904        return 1;
    409905}
  • compress.h

     
    2424#define EXTRACT_H
    2525
    2626#include "util.h"
     27#include <vorbis/vorbisenc.h>
     28#include <FLAC/stream_encoder.h>
    2729
    2830#if defined(__cplusplus)
    2931extern "C" {
     
    3840/* The default for oggenc invocation is to use the --quality option only */
    3941#define oggqualDef 3
    4042
     43/* These are the default parameters for the FLAC invocation */
     44#define flacCompressDef 8
     45#define flacBlocksizeDef 1152
     46
    4147#define TEMP_WAV        "tempfile.wav"
    4248#define TEMP_RAW        "tempfile.raw"
    4349#define TEMP_MP3        "tempfile.mp3"
     
    6066extern void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode);
    6167
    6268extern void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, CompressMode compmode);
    63 extern void setRawAudioType(bool isLittleEndian, bool isStereo, bool isUnSigned, uint8 bitsPerSample);
     69extern void encodeRaw(char *rawData, int length, int samplerate, const char *outname, CompressMode compmode);
     70extern void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample);
    6471
    6572#if defined(__cplusplus)
    6673}
  • compress_agos.c

     
    7474        unlink(TEMP_RAW);
    7575        unlink(tempEncoded);
    7676        unlink(TEMP_WAV);
    77        
     77
    7878        exit(0);
    7979}
    8080
    81        
     81
    8282static int get_offsets(uint32 filenums[], uint32 offsets[])
    8383{
    8484        int i;
     
    173173        printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
    174174
    175175        printf("\nFlac mode params:\n");
    176         printf(" [params]     optional arguments passed directly to the encoder\n");
    177         printf("              recommended is: --best -b 1152\n");
     176        printf(" --fast       FLAC uses compresion level 0\n");
     177        printf(" --best       FLAC uses compresion level 8\n");
     178        printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
     179        printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
     180        printf(" --verify     files are encoded and then decoded to check accuracy\n");
     181        printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
    178182
    179183        printf("\n --help     this help message\n");
    180184
     
    253257        char tmp[256];
    254258        uint32 filenums[32768];
    255259        uint32 offsets[32768];
    256        
     260
    257261        sprintf(infile_base, "simon2");
    258262
    259263        input = fopen("voices.idx", "rb");
     
    295299                        sprintf(tmp, "voices%d.dat", filenums[i]);
    296300                        if (input)
    297301                                fclose(input);
    298                         input = fopen(tmp, "rb"); 
     302                        input = fopen(tmp, "rb");
    299303                        if (!input) {
    300304                                printf("Cannot open file: %s\n", tmp);
    301305                                exit(-1);
     
    311315int main(int argc, char *argv[])
    312316{
    313317        int i;
    314        
     318
    315319        if (argc < 2)
    316320                showhelp(argv[0]);
    317321
  • compress_kyra.cpp

     
    3939        if (argc < 3)
    4040                showhelp(argv[0]);
    4141
     42        char inputFile[256];
     43        char outputFile[256];
    4244        int i = 0;
     45
    4346        /* Compression mode */
    4447        gCompMode = kMP3Mode;
    4548        i = 1;
     49
    4650        if (strcmp(argv[1], "--mp3") == 0) {
    4751                gCompMode = kMP3Mode;
    4852                i++;
     
    6064        case kMP3Mode:
    6165                outputExt = OUTPUT_MP3;
    6266                tempEncoded = TEMP_MP3;
    63                 if (!process_mp3_parms(argc - 1, argv, i))
     67                if (!process_mp3_parms(argc - 2, argv, i))
    6468                        showhelp(argv[0]);
    6569                break;
    6670        case kVorbisMode:
    6771                outputExt = OUTPUT_OGG;
    6872                tempEncoded = TEMP_OGG;
    69                 if (!process_ogg_parms(argc - 1, argv, i))
     73                if (!process_ogg_parms(argc - 2, argv, i))
    7074                        showhelp(argv[0]);
    7175                break;
    7276        case kFlacMode:
    7377                outputExt = OUTPUT_FLAC;
    7478                tempEncoded = TEMP_FLAC;
    75                 if (!process_flac_parms(argc - 1, argv, i))
     79                if (!process_flac_parms(argc - 2, argv, i))
    7680                        showhelp(argv[0]);
    7781                break;
    7882        }
    79        
    80         if (scumm_stricmp(argv[argc - 2], argv[argc - 1]) == 0)
     83
     84        sprintf(inputFile, "%s/%s", argv[argc - 2], argv[argc - 3]);
     85        sprintf(outputFile, "%s/%s", argv[argc - 1], argv[argc - 3]);
     86
     87        if (scumm_stricmp(inputFile, outputFile) == 0)
    8188                error("infile and outfile are the same file");
    82         process(argv[argc - 2], argv[argc - 1]);
     89        process(inputFile, outputFile);
    8390        return 0;
    8491}
    8592
    8693static void showhelp(const char *exename) {
    87         printf("\nUsage: %s <params> infile outfile\n", exename);
     94        printf("\nUsage: %s [params] <inputfile> <inputdir> <outputdir>\n", exename);
    8895
    8996        printf("\nParams:\n");
    9097        printf(" --mp3        encode to MP3 format (default)\n");
     
    109116        printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
    110117
    111118        printf("\nFlac mode params:\n");
    112         printf(" [params]     optional arguments passed directly to the encoder\n");
    113         printf("              recommended is: --best -b 1152\n");
     119        printf(" --fast       FLAC uses compresion level 0\n");
     120        printf(" --best       FLAC uses compresion level 8\n");
     121        printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
     122        printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
     123        printf(" --verify     files are encoded and then decoded to check accuracy\n");
     124        printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
    114125
    115126        printf("\n --help     this help message\n");
    116127
     
    136147                return;
    137148        if (!output.loadFile(0, false))
    138149                return;
    139                
     150
    140151        PAKFile::cFileList *list = input.getFileList();
    141152        char outputName[32];
    142153        for (; list; list = list->next) {
     
    150161
    151162                input.outputFileAs(list->filename, TEMPFILE);
    152163                strncpy(outputName, list->filename, 32);
    153                
     164
    154165                FILE *tempFile = fopen(TEMPFILE, "rb");
    155166                fseek(tempFile, 26, SEEK_CUR);
    156167                extractAndEncodeVOC(TEMP_RAW, tempFile, gCompMode);
    157168                fclose(tempFile);
    158                
     169
    159170                char *vocStart = strstr(outputName, ".VOC");
    160171                for (unsigned int i = 0; i < strlen(outputExt); ++i)
    161172                        vocStart[i] = outputExt[i];
    162173                output.addFile(outputName, tempEncoded);
    163                
     174
    164175                unlink(TEMPFILE);
    165176                unlink(TEMP_RAW);
    166177                unlink(tempEncoded);
    167178        }
    168        
     179
    169180        if (output.getFileList()) {
    170181                output.saveFile(outfile);
    171182        } else {
  • compress_queen.c

     
    2020 *
    2121 */
    2222
    23 #include "util.h"
     23#include "compress.h"
    2424
    2525static const uint32 QTBL = 'QTBL';
     26static CompressMode gCompMode = kMP3Mode;
    2627
    2728#define INPUT_TBL       "queen.tbl"
    2829#define FINAL_OUT       "queen.1c"
     
    3132#define TEMP_TBL        "tempfile.tbl"
    3233#define TEMP_SB         "tempfile.sb"
    3334
    34 #define TEMP_MP3        "tempfile.mp3"
    35 #define TEMP_OGG        "tempfile.ogg"
    36 #define TEMP_FLAC       "tempfile.fla"
    37 
    38 const char *tempEncoded;
    39 
    4035#define CURRENT_TBL_VERSION     2
    4136#define EXTRA_TBL_HEADER 8
    4237#define SB_HEADER_SIZE_V104 110
     
    126121
    127122void showhelp(char *exename)
    128123{
    129         printf("\nUsage: %s [--mp3/--vorbis/--flac <args>] queen.1\n", exename);
     124        printf("\nUsage: %s <params> queen.1\n", exename);
     125
    130126        printf("\nParams:\n");
    131         printf(" --mp3 <args>         encode to MP3 format\n");
    132         printf(" --vorbis <args>      encode to Ogg Vorbis Format\n");
    133         printf(" --flac <args>        encode to Flac Format\n");
    134         printf("                      (Optional: <args> are passed on to the encoder)\n");
    135         printf("\nExample: %s --mp3 -q 5 queen.1\n", exename);
     127
     128        printf(" --mp3        encode to MP3 format (default)\n");
     129        printf(" --vorbis     encode to Ogg Vorbis format\n");
     130        printf(" --flac       encode to Flac format\n");
     131        printf("(If one of these is specified, it must be the first parameter.)\n");
     132
     133        printf("\nMP3 mode params:\n");
     134        printf(" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%d)\n", minBitrDef);
     135        printf(" -B <rate>    <rate> is the maximum VBR/ABR bitrate (default:%d)\n", maxBitrDef);
     136        printf(" --vbr        LAME uses the VBR mode (default)\n");
     137        printf(" --abr        LAME uses the ABR mode\n");
     138        printf(" -V <value>   specifies the value (0 - 9) of VBR quality (0=best) (default:%d)\n", vbrqualDef);
     139        printf(" -q <value>   specifies the MPEG algorithm quality (0-9; 0=best) (default:%d)\n", algqualDef);
     140        printf(" --silent     the output of LAME is hidden (default:disabled)\n");
     141
     142        printf("\nVorbis mode params:\n");
     143        printf(" -b <rate>    <rate> is the nominal bitrate (default:unset)\n");
     144        printf(" -m <rate>    <rate> is the minimum bitrate (default:unset)\n");
     145        printf(" -M <rate>    <rate> is the maximum bitrate (default:unset)\n");
     146        printf(" -q <value>   specifies the value (0 - 10) of VBR quality (10=best) (default:%d)\n", oggqualDef);
     147        printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
     148
     149        printf("\nFlac mode params:\n");
     150        printf(" --fast       FLAC uses compresion level 0\n");
     151        printf(" --best       FLAC uses compresion level 8\n");
     152        printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
     153        printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
     154        printf(" --verify     files are encoded and then decoded to check accuracy\n");
     155        printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
     156
     157        printf("\n --help     this help message\n");
     158
     159        printf("\n\nIf a parameter is not given the default value is used\n");
     160        printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
    136161        exit(2);
    137162}
    138163
     
    219244        FILE *inputData, *inputTbl, *outputTbl, *outputData, *tmpFile, *compFile;
    220245        uint8 compressionType = COMPRESSION_NONE;
    221246        char tmp[5];
    222         char sysBuf[1024];
    223         char *ptr = sysBuf;
    224247        int size, i = 1;
    225248        uint32 prevOffset;
    226249
     
    228251        if (argc < 2)
    229252                showhelp(argv[0]);
    230253
     254        /* compression mode */
     255        compressionType = COMPRESSION_MP3;
     256        gCompMode = kMP3Mode;
     257
    231258        if (strcmp(argv[1], "--mp3") == 0) {
    232259                compressionType = COMPRESSION_MP3;
    233                 tempEncoded = TEMP_MP3;
     260                gCompMode = kMP3Mode;
    234261                i++;
    235                 ptr += sprintf(ptr, "lame -r -h -s 11 --bitwidth 8 -m m ");
    236                 for (; i < (argc - 1); i++) {
    237                         /* Append optional encoder arguments */
    238                         ptr += sprintf(ptr, "%s ", argv[i]);
    239                 }
    240                 ptr += sprintf(ptr, "%s %s", TEMP_SB, tempEncoded);
    241262        } else if (strcmp(argv[1], "--vorbis") == 0) {
    242263                compressionType = COMPRESSION_OGG;
    243                 tempEncoded = TEMP_OGG;
     264                gCompMode = kVorbisMode;
    244265                i++;
    245                 ptr += sprintf(ptr, "oggenc -r -B 8 -C 1 -R 11025 %s -o %s ", TEMP_SB, tempEncoded);
    246                 for (; i < (argc - 1); i++) {
    247                         /* Append optional encoder arguments */
    248                         ptr += sprintf(ptr, "%s ", argv[i]);
    249                 }
    250266        } else if (strcmp(argv[1], "--flac") == 0) {
    251267                compressionType = COMPRESSION_FLAC;
    252                 tempEncoded = TEMP_FLAC;
     268                gCompMode = kFlacMode;
    253269                i++;
    254                 ptr += sprintf(ptr, "flac --force-raw-format --endian=little --sign=unsigned --bps=8 --channels=1 --sample-rate=11025 " );
    255                 ptr += sprintf(ptr, "--no-padding --lax --no-seektable --no-ogg " );
    256                 for (; i < (argc - 1); i++) {
    257                         /* Append optional encoder arguments */
    258                         ptr += sprintf(ptr, "%s ", argv[i]);
    259                 }
     270        }
    260271
    261                 ptr += sprintf(ptr, "-o %s %s", tempEncoded, TEMP_SB );
    262         } else {
    263                 showhelp(argv[0]);
     272        switch (gCompMode) {
     273        case kMP3Mode:
     274                tempEncoded = TEMP_MP3;
     275                if (!process_mp3_parms(argc, argv, i))
     276                        showhelp(argv[0]);
     277                break;
     278        case kVorbisMode:
     279                tempEncoded = TEMP_OGG;
     280                if (!process_ogg_parms(argc, argv, i))
     281                        showhelp(argv[0]);
     282                break;
     283        case kFlacMode:
     284                tempEncoded = TEMP_FLAC;
     285                if (!process_flac_parms(argc, argv, i))
     286                        showhelp(argv[0]);
     287                break;
    264288        }
    265289
    266290        /* Open input file (QUEEN.1) */
     
    342366                        fclose(tmpFile);
    343367
    344368                        /* Invoke encoder */
    345                         if (system(sysBuf)) {
    346                                 printf("Got error from encoder. (check your parameters)\n");
    347                                 unlink(TEMP_SB);
    348                                 exit(-1);
    349                         }
     369                        setRawAudioType(false, false, 8);
     370                        encodeAudio(TEMP_SB, true, 11025, tempEncoded, gCompMode);
    350371
    351372                        /* Append MP3/OGG to data file */
    352373                        compFile = fopen(tempEncoded, "rb");
  • compress_saga.cpp

     
    1919 *
    2020 * $URL$
    2121 * $Id$
    22  * 
     22 *
    2323 */
    2424
    2525#include "compress.h"
     
    194194        uint32 size;
    195195        char fbuf[2048];
    196196        FILE * tempf;
    197        
     197
    198198        tempf = fopen(fromFileName, "rb");
    199199        if (tempf == NULL)
    200200                error("Unable to open %s", fromFileName);
     
    211211        uint32 size;
    212212        char fbuf[2048];
    213213        FILE * tempf;
    214        
     214
    215215        tempf = fopen(toFileName, "wb");
    216216        if (tempf == NULL)
    217217                error("Unable to open %s", toFileName);
     
    228228
    229229void writeBufferToFile(uint8* data, uint32 inputSize, const char* toFileName) {
    230230        FILE * tempf;
    231        
     231
    232232        tempf = fopen(toFileName, "wb");
    233233        if (tempf == NULL)
    234234                error("Unable to open %s", toFileName);
     
    248248        Common::File inputFileStream(inputFile);
    249249        int rate, size;
    250250        byte flags;
    251        
     251
    252252        if (currentFileDescription->resourceType == kSoundVOC) {
    253253                inputData = Audio::loadVOCFromStream(inputFileStream, size, rate);
    254254                sampleSize = size;
     
    259259                free(inputData);
    260260                writeHeader(outputFile);
    261261
    262                 setRawAudioType( true, false, !isSigned, 8);
     262                setRawAudioType( true, false, 8);
    263263                encodeAudio(TEMP_RAW, true, sampleRate, tempEncoded, gCompMode);
    264264                return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
    265265        }
     
    271271                sampleStereo = currentFileDescription->stereo;
    272272                writeHeader(outputFile);
    273273
    274                 setRawAudioType( !currentFileDescription->swapEndian, currentFileDescription->stereo, !isSigned, sampleBits);
     274                setRawAudioType( !currentFileDescription->swapEndian, currentFileDescription->stereo, sampleBits);
    275275                encodeAudio(TEMP_RAW, true, currentFileDescription->frequency, tempEncoded, gCompMode);
    276276                return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
    277277        }
     
    287287
    288288                copyFile(inputFile, size, TEMP_RAW);
    289289
    290                 setRawAudioType( true, sampleStereo != 0, !isSigned, sampleBits);
     290                setRawAudioType( true, sampleStereo != 0, sampleBits);
    291291                encodeAudio(TEMP_RAW, true, sampleRate, tempEncoded, gCompMode);
    292292                return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
    293293        }
     
    302302                sampleStereo = currentFileDescription->stereo;
    303303                writeHeader(outputFile);
    304304
    305                 setRawAudioType( !currentFileDescription->swapEndian, currentFileDescription->stereo, !isSigned, sampleBits);
     305                setRawAudioType( !currentFileDescription->swapEndian, currentFileDescription->stereo, sampleBits);
    306306                encodeAudio(TEMP_RAW, true, currentFileDescription->frequency, tempEncoded, gCompMode);
    307307                return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
    308308                */
     
    348348                error("Something's wrong with your resource file");
    349349        }
    350350
    351         // Go to beginning of the table 
     351        // Go to beginning of the table
    352352        fseek(inputFile, resTableOffset, SEEK_SET);
    353353
    354354        inputTable = (Record*)malloc(resTableCount * sizeof(Record));
    355355
    356         // Put offsets of all the records in a table 
     356        // Put offsets of all the records in a table
    357357        for (i = 0; i < resTableCount; i++) {
    358358
    359359        if (!currentFileDescription->swapEndian) {
     
    365365        }
    366366
    367367                 printf("Record: %ul, offset: %ul, size: %ul\n", i, inputTable[i].offset, inputTable[i].size);
    368        
     368
    369369                if ((inputTable[i].offset > inputFileSize) ||
    370370                    (inputTable[i].offset + inputTable[i].size > inputFileSize)) {
    371371                        error("The offset points outside the file");
     
    374374        }
    375375        outputTable = (Record*)malloc(resTableCount * sizeof(Record));
    376376
    377         sprintf(outputFileNameWithExt, "%s.cmp", inputFileName);       
     377        sprintf(outputFileNameWithExt, "%s.cmp", inputFileName);
    378378        outputFile = fopen(outputFileNameWithExt, "wb");
    379379
    380380        for (i = 0; i < resTableCount; i++) {
    381381                fseek(inputFile, inputTable[i].offset, SEEK_SET);
    382382                outputTable[i].offset = ftell(outputFile);
    383                
     383
    384384                outputTable[i].size = encodeEntry(inputFile, inputTable[i].size, outputFile);
    385385        }
    386386        fclose(inputFile);
     
    391391                writeUint32LE(outputFile, outputTable[i].size);
    392392        }
    393393        writeUint32LE(outputFile, resTableOffset);
    394         writeUint32LE(outputFile, resTableCount);       // Should be the same number of entries 
     394        writeUint32LE(outputFile, resTableCount);       // Should be the same number of entries
    395395
    396396        fclose(outputFile);
    397397
    398398        free(inputTable);
    399399        free(outputTable);
    400        
     400
    401401        // Cleanup
    402402        unlink(TEMP_RAW);
    403403        unlink(tempEncoded);
     
    406406}
    407407
    408408void showhelp(char *exename) {
    409         printf("\nUsage: %s <params> [<file> | mac]\n", exename);
     409        printf("\nUsage: %s [params] <file>\n", exename);
    410410
    411411        printf("\nParams:\n");
    412412
     
    432432        printf("--silent     the output of oggenc is hidden (default:disabled)\n");
    433433
    434434        printf("\nFlac mode params:\n");
    435         printf("[params]     optional Arguments passed to the Encoder\n");
    436         printf("             recommended is: --best -b 1152\n");
     435        printf(" --fast       FLAC uses compresion level 0\n");
     436        printf(" --best       FLAC uses compresion level 8\n");
     437        printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
     438        printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
     439        printf(" --verify     files are encoded and then decoded to check accuracy\n");
     440        printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
    437441
    438442        printf("\n--help     this help message\n");
    439443
  • compress_scumm_bun.cpp

     
    614614}
    615615
    616616void showhelp(char *exename) {
    617         printf("\nUsage: %s <inputfile> <inputdir> <outputdir> [--ogg] [encoder params]\n", exename);
     617        printf("\nUsage: %s [--vorbis] [params] <inputfile> <inputdir> <outputdir>\n", exename);
    618618        printf("\nMP3 mode params:\n");
    619619        printf(" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%d)\n", minBitrDef);
    620620        printf(" -B <rate>    <rate> is the maximum VBR/ABR bitrate (default:%d)\n", maxBitrDef);
     
    10641064        uint32 tag;
    10651065        int32 numFiles, offset, i;
    10661066
    1067         strcpy(inputFilename, argv[1]);
    1068         strcpy(inputDir, argv[2]);
    1069         strcpy(outputDir, argv[3]);
     1067        strcpy(inputFilename, argv[argc - 3]);
     1068        strcpy(inputDir, argv[argc - 2]);
     1069        strcpy(outputDir, argv[argc - 1]);
    10701070
    10711071        if (argc > 4) {
    1072                 i = 4;
     1072                int result;
     1073                i = 1;
    10731074
    1074                 if (strcmp(argv[i], "--ogg") == 0) {
     1075                if (strcmp(argv[i], "--vorbis") == 0) {
    10751076                        _oggMode = true;
    10761077                        i++;
    10771078                }
    10781079
    1079                 if (argc > i) {
    1080                         // HACK: The functions in compress.c expect the last
    1081                         // argument to be a filename. As we don't expect one,
    1082                         // we simply add a dummy argument to the list.
    1083                         char **args = (char **)malloc((argc + 1) * sizeof(char *));
    1084                         char dummyName[] = "dummy";
    1085                         int j;
     1080                if (_oggMode)
     1081                        result = process_ogg_parms(argc - 2, argv, i);
     1082                else
     1083                        result = process_mp3_parms(argc - 2, argv, i);
    10861084
    1087                         for (j = 0; j < argc; j++)
    1088                                 args[j] = argv[j];
    1089                         args[j] = dummyName;
    1090                
    1091                         int result;
    1092 
    1093                         if (_oggMode)
    1094                                 result = process_ogg_parms(argc + 1, args, i);
    1095                         else
    1096                                 result = process_mp3_parms(argc + 1, args, i);
    1097 
    1098                         if (!result)
    1099                                 showhelp(argv[0]);
    1100 
    1101                         free(args);
    1102                 }
     1085                if (!result)
     1086                        showhelp(argv[0]);
    11031087        }
    11041088
    11051089        char *index = strrchr(inputFilename, '.');
     
    11411125                char filename[13], c;
    11421126                int z = 0;
    11431127                int z2;
    1144                        
     1128
    11451129                for (z2 = 0; z2 < 8; z2++)
    11461130                        if ((c = readByte(input)) != 0)
    11471131                                filename[z++] = c;
     
    11811165        fclose(input);
    11821166
    11831167        printf("compression done.\n");
    1184                
     1168
    11851169        return 0;
    11861170}
  • compress_scumm_san.cpp

     
    2424#include "zlib.h"
    2525
    2626void showhelp(char *exename) {
    27         printf("\nUsage: %s <inputfile> <inputdir> <outputdir> [--ogg] [encoder params]\n", exename);
     27        printf("\nUsage: %s [--vorbis] [encoder params] <inputfile> <inputdir> <outputdir>\n", exename);
    2828        printf("\nMP3 mode params:\n");
    2929        printf(" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%d)\n", minBitrDef);
    3030        printf(" -B <rate>    <rate> is the maximum VBR/ABR bitrate (default:%d)\n", maxBitrDef);
     
    643643        char inputFilename[200];
    644644        char tmpPath[200];
    645645
    646         strcpy(inputFilename, argv[1]);
    647         strcpy(inputDir, argv[2]);
    648         strcpy(outputDir, argv[3]);
     646        strcpy(inputFilename, argv[argc - 3]);
     647        strcpy(inputDir, argv[argc - 2]);
     648        strcpy(outputDir, argv[argc - 1]);
    649649
    650650        if (argc > 4) {
    651                 int i = 4;
     651                int i = 1;
    652652
    653                 if (strcmp(argv[i], "--ogg") == 0) {
     653                if (strcmp(argv[1], "--vorbis") == 0) {
    654654                        _oggMode = true;
    655655                        i++;
    656656                }
    657657
    658                 if (argc > i) {
    659                         // HACK: The functions in compress.c expect the last
    660                         // argument to be a filename. As we don't expect one,
    661                         // we simply add a dummy argument to the list.
    662                         char **args = (char **)malloc((argc + 1) * sizeof(char *));
    663                         char dummyName[] = "dummy";
    664                         int j;
     658                int result;
    665659
    666                         for (j = 0; j < argc; j++)
    667                                 args[j] = argv[j];
    668                         args[j] = dummyName;
    669                
    670                         int result;
     660                if (_oggMode)
     661                        result = process_ogg_parms(argc - 2, argv, i);
     662                else
     663                        result = process_mp3_parms(argc - 2, argv, i);
    671664
    672                         if (_oggMode)
    673                                 result = process_ogg_parms(argc + 1, args, i);
    674                         else
    675                                 result = process_mp3_parms(argc + 1, args, i);
    676 
    677                         if (!result)
    678                                 showhelp(argv[0]);
    679 
    680                         free(args);
    681                 }
     665                if (!result)
     666                        showhelp(argv[0]);
    682667        }
    683668
    684669        char *index = strrchr(inputFilename, '.');
     
    903888        }
    904889
    905890        free(frameInfo);
    906        
     891
    907892        fclose(output);
    908893
    909894        printf("compression done.\n");
    910                
     895
    911896        return 0;
    912897}
  • compress_scumm_sou.c

     
    7272        unlink(TEMP_DAT);
    7373        unlink(TEMP_RAW);
    7474        unlink(tempEncoded);
    75        
     75
    7676        exit(-1);
    7777}
    7878
     
    130130
    131131        /* Conver the VOC data */
    132132        extractAndEncodeVOC(TEMP_RAW, input, gCompMode);
    133        
     133
    134134        /* Append the converted data to the master output file */
    135135        sprintf(outname, tempEncoded);
    136136        f = fopen(outname, "rb");
     
    171171        printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
    172172
    173173        printf("\nFlac mode params:\n");
    174         printf(" [params]     optional arguments passed directly to the encoder\n");
    175         printf("              recommended is: --best -b 1152\n");
     174        printf(" --fast       FLAC uses compresion level 0\n");
     175        printf(" --best       FLAC uses compresion level 8\n");
     176        printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
     177        printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
     178        printf(" --verify     files are encoded and then decoded to check accuracy\n");
     179        printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
    176180
    177181        printf("\n --help     this help message\n");
    178182
     
    242246                printf("Can't open file " TEMP_DAT " for write!\n");
    243247                exit(-1);
    244248        }
    245        
     249
    246250        /* Get the 'SOU ....' header */
    247251        fread(buf, 1, 8, input);
    248252        if (strncmp(buf, f_hdr, 8)) {
  • compress_sword1.c

     
    116116        { "2M26", false },
    117117        { "3M7", false },
    118118        { "3M8", false },
    119         { "3M9", true }, 
     119        { "3M9", true },
    120120        { "3M10", false },
    121121        { "2M13", false },
    122122        { "3M12", false },
     
    163163        { "4M31", false },
    164164        { "4M32", false },
    165165        { "5M1", false },
    166         { "5M2", true }, 
     166        { "5M2", true },
    167167        { "5M3", false },
    168168        { "5M4", false },
    169169        { "5M5", false },
     
    275275        { "11M4", false },
    276276        { "11M7", false },
    277277        { "11M8", false },
    278         { "11M9", true }, 
     278        { "11M9", true },
    279279        { "12M1", false },
    280280        { "11M2", false },
    281281        { "SPM2", false },
     
    308308};
    309309
    310310void showhelp(char *exename) {
    311         printf("\nUsage: %s <params>\n", exename);
     311        printf("\nUsage: %s [params]\n", exename);
    312312
    313313        printf("\nParams:\n");
    314314        printf(" --mp3          encode to MP3 format (default)\n");
     
    337337        printf("                (default:%d)\n", oggqualDef);
    338338        printf(" --silent       the output of oggenc is hidden (default:disabled)\n");
    339339
     340        printf("\nFlac mode params:\n");
     341        printf(" --fast       FLAC uses compresion level 0\n");
     342        printf(" --best       FLAC uses compresion level 8\n");
     343        printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
     344        printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
     345        printf(" --verify     files are encoded and then decoded to check accuracy\n");
     346        printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
     347
    340348        printf("\n --help         this help message\n");
    341349
    342350        printf("\nIf a parameter is not given the default value is used\n");
     
    438446        }
    439447        cl3Index = (uint32*)malloc(numSamples * 8);
    440448        memset(cl3Index, 0, numSamples * 8);
    441        
     449
    442450        sampleIndex = cowHeader + numRooms + 1;
    443451        /* This points to the sample index table. 8 bytes each (4 bytes size and then 4 bytes file index) */
    444452
     
    446454
    447455        for (cnt = 0; cnt < numSamples; cnt++) {
    448456                if (sampleIndex[cnt << 1] | sampleIndex[(cnt << 1) | 1]) {
    449                         printf("sample %5d: ", cnt);
     457                        printf("sample %5d: \n", cnt);
    450458                        smpData = (uint8*)uncompressSpeech(clu, sampleIndex[cnt << 1] + headerSize, sampleIndex[(cnt << 1) | 1], &smpSize);
    451459                        if ((!smpData) || (!smpSize))
    452460                                error("unable to handle speech sample %d!\n", cnt);
     
    475483        int i;
    476484        char cluName[256], outName[256];
    477485
    478         setRawAudioType(true, false, false, 16);
     486        setRawAudioType(true, false, 16);
    479487        for (i = 1; i <= 2; i++) {
    480488                sprintf(cluName, "SPEECH/SPEECH%d.CLU", i);
    481489                clu = fopen(cluName, "rb");
     
    670678                compressSpeech(compMode);
    671679        if (compMusic)
    672680                compressMusic(compMode);
    673        
     681
    674682        return EXIT_SUCCESS;
    675683}
    676684
  • compress_sword2.c

     
    3131
    3232void showhelp(char *exename)
    3333{
    34         printf("\nUsage: %s <params> file.clu\n", exename);
     34        printf("\nUsage: %s [params] <file>\n", exename);
    3535
    3636        printf("\nParams:\n");
    3737        printf(" --mp3        encode to MP3 format (default)\n");
     
    5656        printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
    5757
    5858        printf("\nFlac mode params:\n");
    59         printf(" [params]     optional arguments passed directly to the encoder\n");
    60         printf("              recommended is: --best -b 1152\n");
     59        printf(" --fast       FLAC uses compresion level 0\n");
     60        printf(" --best       FLAC uses compresion level 8\n");
     61        printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
     62        printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
     63        printf(" --verify     files are encoded and then decoded to check accuracy\n");
     64        printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
    6165
    6266        printf("\n --help     this help message\n");
    6367
     
    104108        uint32 indexSize;
    105109        uint32 totalSize;
    106110        uint32 length;
    107        
     111
    108112        if (argc < 2)
    109113                showhelp(argv[0]);
    110114        i = 1;
  • compress_touche.c

     
    158158}
    159159
    160160static void showhelp(const char *exename) {
    161         printf("\nUsage: %s <params> input_directory\n", exename);
     161        printf("\nUsage: %s [params] <inputdir>\n", exename);
    162162
    163163        printf("\nParams:\n");
     164
    164165        printf(" --mp3        encode to MP3 format (default)\n");
    165166        printf(" --vorbis     encode to Vorbis format\n");
    166167        printf(" --flac       encode to Flac format\n");
     
    183184        printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
    184185
    185186        printf("\nFlac mode params:\n");
    186         printf(" [params]     optional arguments passed directly to the encoder\n");
    187         printf("              recommended is: --best -b 1152\n");
     187        printf(" --fast       FLAC uses compresion level 0\n");
     188        printf(" --best       FLAC uses compresion level 8\n");
     189        printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
     190        printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
     191        printf(" --verify     files are encoded and then decoded to check accuracy\n");
     192        printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
    188193
    189194        printf("\n --help     this help message\n");
    190195
  • encode_dxa.cpp

     
    699699}
    700700
    701701void showhelp(char *exename) {
    702         printf("\nUsage: %s <inputfile> \n", exename);
     702        printf("\nUsage: %s <params> <file>\n", exename);
    703703
    704704        printf("\nParams:\n");
    705705        printf(" --mp3        encode to MP3 format (default)\n");
     
    724724        printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
    725725
    726726        printf("\nFlac mode params:\n");
    727         printf(" [params]     optional arguments passed directly to the encoder\n");
    728         printf("              recommended is: --best -b 1152\n");
     727        printf(" --fast       FLAC uses compresion level 0\n");
     728        printf(" --best       FLAC uses compresion level 8\n");
     729        printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
     730        printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
     731        printf(" --verify     files are encoded and then decoded to check accuracy\n");
     732        printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
    729733
    730734        printf("\n --help     this help message\n");
    731735
    732736        printf("\n\nIf a parameter is not given the default value is used\n");
    733737        printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
    734         printf("Use the `mac' option instead of a filename if converting simon2mac sounds\n");
    735738        exit(2);
    736739}
    737740
  • kyra_pak.h

     
    2424#define KYRA_PAK_H
    2525
    2626#include "util.h"
    27 #include <string.h>
    2827
    2928class PAKFile {
    3029public:
     
    3433        bool loadFile(const char *file, const bool isAmiga);
    3534        bool saveFile(const char *file);
    3635        void clearFile() { delete _fileList; _fileList = 0; }
    37        
     36
    3837        const uint32 getFileSize() const { return _fileList->getTableSize()+5+4+_fileList->getFileSize(); }
    3938
    4039        void drawFileList();
     
    4746
    4847        bool addFile(const char *name, const char *file);
    4948        bool addFile(const char *name, uint8 *data, uint32 size);
    50        
     49
    5150        bool removeFile(const char *name);
    5251public:
    5352        struct FileList {
     
    5756                        delete [] data;
    5857                        delete next;
    5958                }
    60                
     59
    6160                FileList *findEntry(const char *f) {
    6261                        for (FileList *cur = this; cur; cur = cur->next) {
    6362                                if (scumm_stricmp(cur->filename, f) != 0)
     
    6665                        }
    6766                        return 0;
    6867                }
    69                
     68
    7069                const FileList *findEntry(const char *f) const {
    7170                        for (const FileList *cur = this; cur; cur = cur->next) {
    7271                                if (scumm_stricmp(cur->filename, f) != 0)
     
    9291                char *filename;
    9392                uint32 size;
    9493                uint8 *data;
    95                
     94
    9695                FileList *next;
    9796        };
    9897
    9998        typedef const FileList cFileList;
    100        
     99
    101100        cFileList *getFileList() const { return _fileList; }
    102101private:
    103102        FileList *_fileList;
  • Makefile

     
    5151all: $(TARGETS)
    5252
    5353compress_agos$(EXEEXT): compress_agos.o compress.o util.o
    54         $(CC) $(LDFLAGS) -o $@ $+
     54        $(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
    5555
    5656compress_kyra$(EXEEXT): compress_kyra.o kyra_pak.o compress.o util.o
    57         $(CXX) $(LDFLAGS) -o $@ $+
     57        $(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
    5858
    59 compress_queen$(EXEEXT): compress_queen.o util.o
    60         $(CC) $(LDFLAGS) -o $@ $+
     59compress_queen$(EXEEXT): compress_queen.o compress.o util.o
     60        $(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
    6161
    6262compress_saga$(EXEEXT): compress_saga.o compress.o util.o $(UTILS)
    63         $(CXX) $(LDFLAGS) -o $@ $+
     63        $(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
    6464
    6565compress_scumm_bun$(EXEEXT): compress_scumm_bun.o compress.o util.o
    66         $(CXX) $(LDFLAGS) -o $@ $+
     66        $(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
    6767
    6868compress_scumm_san$(EXEEXT): compress_scumm_san.o compress.o util.o
    69         $(CXX) $(LDFLAGS) -o $@ $+ -lz
     69        $(CXX) $(LDFLAGS) -o $@ $+ -lz -lvorbis -logg -lvorbisenc -lFLAC
    7070
    7171compress_scumm_sou$(EXEEXT): compress_scumm_sou.o compress.o util.o
    72         $(CC) $(LDFLAGS) -o $@ $+
     72        $(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
    7373
    7474compress_sword1$(EXEEXT): compress_sword1.o compress.o util.o
    75         $(CC) $(LDFLAGS) -o $@ $+
     75        $(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
    7676
    7777compress_sword2$(EXEEXT): compress_sword2.o compress.o util.o
    78         $(CC) $(LDFLAGS) -o $@ $+
     78        $(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
    7979
    8080compress_touche$(EXEEXT): compress_touche.o compress.o util.o
    81         $(CC) $(LDFLAGS) -o $@ $+
     81        $(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
    8282
    8383dekyra$(EXEEXT): dekyra.o dekyra_v1.o util.o
    8484        $(CXX) $(LDFLAGS) -o $@ $+
     
    9090        $(CXX) $(LDFLAGS) -o $@ $+
    9191
    9292encode_dxa$(EXEEXT): encode_dxa.o compress.o util.o
    93         $(CXX) $(LDFLAGS) -o $@ $+ -lpng -lz
     93        $(CXX) $(LDFLAGS) -o $@ $+ -lpng -lz -lvorbis -logg -lvorbisenc -lFLAC
    9494
    9595extract_agos$(EXEEXT): extract_agos.o
    9696        $(CC) $(LDFLAGS) -o $@ $+
     
    122122
    123123descumm.o descumm6.o descumm-common.o descumm-tool.o: descumm.h
    124124
    125 # Most compress_* tools (except for compress_queen) use compress.h
     125# All compress_* tools use compress.h
    126126compress_agos.o compress_saga.o compress_scumm_sou.o \
    127127compress_scumm_bun.o compress_sword1.o compress_sword2.o \
    128 compress_kyra.o compress.o encode_dxa.o: compress.h
     128compress_kyra.o compress_queen.o compress.o encode_dxa.o: compress.h
    129129
    130130# extract_parallaction.h
    131131extract_parallaction.o: extract_parallaction.h
  • README

     
    77example.
    88
    99Extraction Tools:
    10         extract_agos
    11                 Extracts the packed files used in the Amiga and AtariST
    12                 versions of Elvira 1/2, Waxworks and Simon the Sorcerer 1.
     10        extract_agos
     11                Extracts the packed files used in the Amiga and AtariST
     12                versions of Elvira 1/2, Waxworks and Simon the Sorcerer 1.
    1313
    14         extract_kyra
    15                 Unpacks .PAK files from Kyrandia games.
     14        extract_kyra
     15                Unpacks .PAK files from Kyrandia games.
    1616
    17         extract_scumm_mac
    18                 Extracts Macintosh "single file" SCUMM games into their
    19                 component parts, for use with ScummVM.
    20                 This is required for ScummVM up to version 0.6.x; all
    21                 later versions directly support reading this file
    22                 format.
     17        extract_scumm_mac
     18                Extracts Macintosh "single file" SCUMM games into their
     19                component parts, for use with ScummVM.
     20                This is required for ScummVM up to version 0.6.x; all
     21                later versions directly support reading this file
     22                format.
    2323
    24         extract_loom_tg16
    25                 Extracts data files from the PC-Engine version of Loom.
    26                 Use the dumpcd utility at http://www.zeograd.com/misc_download.php
    27                 to dump the code tracks on the CD.
     24        extract_loom_tg16
     25                Extracts data files from the PC-Engine version of Loom.
     26                Use the dumpcd utility at http://www.zeograd.com/misc_download.php
     27                to dump the code tracks on the CD.
    2828
    29         extract_mm_apple
    30                 Extracts data files from the Apple II version of Maniac
    31                 Mansion.
     29        extract_mm_apple
     30                Extracts data files from the Apple II version of Maniac
     31                Mansion.
    3232
    33         extract_mm_c64
    34                 Extracts data files from the Commodore 64 version of Maniac
    35                 Mansion.
     33        extract_mm_c64
     34                Extracts data files from the Commodore 64 version of Maniac
     35                Mansion.
    3636
    37         extract_mm_nes
    38                 Extracts data files from the NES version of Maniac Mansion.
     37        extract_mm_nes
     38                Extracts data files from the NES version of Maniac Mansion.
    3939
    40         extract_parallaction
    41                 Extracts the contents of archives used by Nippon Safes
     40        extract_parallaction
     41                Extracts the contents of archives used by Nippon Safes
    4242
    43         extract_zak_c64
    44                 Extracts data files from the Commodore 64 version of Zak
    45                 McKracken.
     43        extract_zak_c64
     44                Extracts data files from the Commodore 64 version of Zak
     45                McKracken.
    4646
    4747Compression Tools:
    48         compress_scumm_sou
    49                 Used to compress .sou files to .so3 (MP3), .sog (Vorbis),
    50                 or .sof (FLAC).
     48        compress_scumm_sou
     49                Used to compress .sou files to .so3 (MP3), .sog (Vorbis),
     50                or .sof (FLAC).
    5151
    52         compress_agos
    53                 Used to compress the Feeble Files or Simon 1/2 voc/wav files
    54                 to MP3, Vorbis or FLAC.
     52                Example of usage:
     53                compress_scumm_sou [params] monster.sou
    5554
    56         compress_queen
    57                 Used to rebuild the datafile of Flight of the Amazon Queen,
    58                 and allow optional MP3, Vorbis or FLAC compression.
     55        compress_agos
     56                Used to compress the Feeble Files or Simon 1/2 voc/wav files
     57                to MP3, Vorbis or FLAC.
    5958
    60         compress_saga
    61                 Used to compress SAGA engine digital sound files to MP3, Vorbis
    62                 or FLAC.
     59                Example of usage:
     60                compress_agos [params] [<file> | mac]
    6361
    64                 Example of usage:
    65                 compress_saga <flags here> <file>
     62        compress_queen
     63                Used to rebuild the datafile of Flight of the Amazon Queen,
     64                and allow optional MP3, Vorbis or FLAC compression.
    6665
    67                 Where <file> is the sound file you with to compress, without the
    68                 extension.
     66                Example of usage:
     67                compress_queen <params> queen.1
    6968
    70                 For Inherit the Earth, the digital music (music.rsc), speech
    71                 (voices.rsc or "inherit the earth voices") and sound effects
    72                 (sounds.rsc) files can be compressed. For I have no mouth, the
    73                 speech (voices*.res) and sound effects (sfx.res) files can be
    74                 compressed.
    75                
    76                 The compressed files have the ".cmp" extension. Once compressed,
    77                 you only need the respective .cmp files.
    78                
    79                 Only the files of the full game versions can be compressed, the
    80                 demo versions are not supported.
    81                
    82                 The MacBinary files (*.bin) of the Mac CD Guild version of Inherit
    83                 the Earth are not currently supported. Finally, there is no support
    84                 for compressed sounds in I have no mouth yet.
     69        compress_saga
     70                Used to compress SAGA engine digital sound files to MP3, Vorbis
     71                or FLAC.
    8572
    86         compress_sword1
    87                 Used to compress Broken Sword 1's music and speech files to
    88                 MP3 or Vorbis or FLAC.
     73                Example of usage:
     74                compress_saga [params] <file>
    8975
    90         compress_sword2
    91                 Used to compress Broken Sword 2's music and speech .clu
    92                 files to .cl3 (MP3), .clg (Vorbis) or .clf (FLAC).
     76                Where <file> is the sound file you with to compress, without the
     77                extension.
    9378
    94                 Please note that FLAC compression will produce a larger file
    95                 than the original! This is because the original files already
    96                 use lossy compression.
     79                For Inherit the Earth, the digital music (music.rsc), speech
     80                (voices.rsc or "inherit the earth voices") and sound effects
     81                (sounds.rsc) files can be compressed. For I have no mouth, the
     82                speech (voices*.res) and sound effects (sfx.res) files can be
     83                compressed.
    9784
    98         compress_touche
    99                 Used to compress and pack Touche speech files ('Vxxx' and
    100                 'OBJ') to MP3, Vorbis or FLAC to a single file named
    101                 TOUCHE.SO3/.SOG/.SOF depending on the sound compression. Once
    102                 compressed, only TOUCHE.DAT and TOUCHE.SOx files are required
    103                 to play the game under ScummVM.
     85                The compressed files have the ".cmp" extension. Once compressed,
     86                you only need the respective .cmp files.
    10487
    105         compress_scumm_san <inputfile> <inputdir> <outputdir> [--ogg]
    106                 Compresses '.san' smush animation files. It uses lossless
    107                 zlib for compressing FOBJ gfx chunks inside a san file.
    108                 It also can create a separate Ogg file with the audio track.
     88                Only the files of the full game versions can be compressed, the
     89                demo versions are not supported.
    10990
    110                 Example of usage:
    111                 compress_scumm_san opening.san uncomp comp
     91                The MacBinary files (*.bin) of the Mac CD Guild version of Inherit
     92                the Earth are not currently supported. Finally, there is no support
     93                for compressed sounds in I have no mouth yet.
    11294
    113                 In order to use such compressed files, your ScummVM binary
    114                 must have been built with zlib support enabled (you can find
    115                 out whether that's the case by looking at the About dialog).
    116                 For the Ogg or MP3 compression feature, your ScummVM binary
    117                 naturally must have been built with Ogg or MP3 support enabled.
     95        compress_sword1
     96                Used to compress Broken Sword 1's music and speech .clu
     97                files to .cl3 (MP3), .clg (Vorbis) or .clf (FLAC).
    11898
    119                 NOTE: For some '.san' files there is a corresponding '.flu'
    120                 file, which contains offsets into the '.san' file. Hence, the
    121                 compress_scumm_san has to modify the '.flu' file. This happens
    122                 automatically, if the '.san' and '.flu' files are in the
    123                 same directory (which is normally the case). If you want to
    124                 move the '.san' files before compressing them, make sure to
    125                 move the '.flu' files, too!
     99                Example of usage:
     100                compress_sword1 [params]
    126101
    127         compress_scumm_bun <inputfile> <inputdir> <outputdir> [--ogg]
     102       compress_sword2
     103                Used to compress Broken Sword 2's music and speech .clu
     104                files to .cl3 (MP3), .clg (Vorbis) or .clf (FLAC).
    128105
    129                 Compresses '.bun' music/voice files.
     106                Please note that FLAC compression will produce a larger file
     107                than the original! This is because the original files already
     108                use lossy compression.
    130109
    131                 Example of usage:
    132                 compress_scumm.bun digmusic.bun uncomp comp
     110                Example of usage:
     111                compress_sword2 [params] <file>
    133112
    134                 For the Ogg or MP3 compression feature, your ScummVM binary
    135                 naturally must have been built with Ogg or MP3 support enabled.
     113        compress_touche
     114                Used to compress and pack Touche speech files ('Vxxx' and
     115                'OBJ') to MP3, Vorbis or FLAC to a single file named
     116                TOUCHE.SO3 (MP3), TOUCHE.SOG (Vorbis), or TOUCHE.SOF (FLAC).
    136117
    137         compress_kyra
    138                 Used to compress The Legend of Kyrandia's speech files with
    139                 MP3, Vorbis or FLAC.
     118                Once compressed, only TOUCHE.DAT and TOUCHE.SOx files are
    140119
    141                 Example of usage:
    142                 compress_kyra <flags here> input/GEMCUT.VRM output/GEMCUT.VRM
     120                Example of usage:
     121                comrpess_touche [params] <inputdir>
    143122
    144                 Note: You have to keep the VRM extension, else it will NOT work.
    145                 Use it like shown above, copy all *.VRM files to a directory
    146                 and let the tool put the output file in another directory.
     123        compress_scumm_san
     124                Compresses '.san' smush animation files. It uses lossless
     125                zlib for compressing FOBJ gfx chunks inside a san file.
     126                It also can create a separate Ogg file with the audio track.
    147127
     128                In order to use such compressed files, your ScummVM binary
     129                must have been built with zlib support enabled (you can find
     130                out whether that's the case by looking at the About dialog).
     131                For the Ogg or MP3 compression feature, your ScummVM binary
     132                naturally must have been built with Ogg or MP3 support enabled.
     133
     134                NOTE: For some '.san' files there is a corresponding '.flu'
     135                file, which contains offsets into the '.san' file. Hence, the
     136                compress_scumm_san has to modify the '.flu' file. This happens
     137                automatically, if the '.san' and '.flu' files are in the
     138                same directory (which is normally the case). If you want to
     139                move the '.san' files before compressing them, make sure to
     140                move the '.flu' files, too!
     141
     142                Example of usage:
     143                compress_scumm_bun [--vorbis] [params] <inputfile> <inputdir> <outputdir>
     144
     145        compress_scumm_bun
     146                Compresses '.bun' music/voice files.
     147
     148                For the Ogg or MP3 compression feature, your ScummVM binary
     149                naturally must have been built with Ogg or MP3 support enabled.
     150
     151                Example of usage:
     152                compress_scumm_bun [--vorbis] [params] <inputfile> <inputdir> <outputdir>
     153
     154        compress_kyra
     155                Used to compress The Legend of Kyrandia's speech files with
     156                MP3, Vorbis or FLAC.
     157
     158                Example of usage:
     159                compress_kyra [params] <inputfile> <inputdir> <outputdir>
     160
    148161Script Tools:
    149         descumm
    150                 Decompiles SCUMM scripts
     162        descumm
     163                Decompiles SCUMM scripts
    151164
    152         desword2
    153                 Disassembles Broken Sword II scripts
     165        desword2
     166                Disassembles Broken Sword II scripts
    154167
    155         dekyra
    156                 Basic script disassembler for Legend of Kyrandia games
     168        dekyra
     169                Basic script disassembler for Legend of Kyrandia games
    157170
    158171Encoder Tools:
    159         encode_dxa <filename>
     172        encode_dxa <filename>
    160173
    161                 Creates DXA file out of extracted Smacker video.
     174                Creates DXA file out of extracted Smacker video.
    162175
    163                 To extract a video use RAD Game Tools and perform 2 passes
    164                 on it. For example, if your video is called 'intro.smk'.
     176                To extract a video use RAD Game Tools and perform 2 passes
     177                on it. For example, if your video is called 'intro.smk'.
    165178
    166                 1. Extract the video to PNG, 256 colors (choose PNG format
    167                 and tick the checkbox). It will create bunch of files named
    168                 'introXXX.png', where XXX is frame number. Make sure you have
    169                 extracted 256 colors PNGs, otherwise encode_dxa will complain.
     179                1. Extract the video to PNG, 256 colors (choose PNG format
     180                and tick the checkbox). It will create bunch of files named
     181                'introXXX.png', where XXX is frame number. Make sure you have
     182                extracted 256 colors PNGs, otherwise encode_dxa will complain.
    170183
    171                 2. Extract the audio to WAV format, you will get an
    172                 'intro.wav' file.
     184                2. Extract the audio to WAV format, you will get an
     185                'intro.wav' file.
    173186
    174                 3. Put files 'intro.smk', 'intro.wav' and 'intro*.png' into a
    175                 single directory.
     187                3. Put files 'intro.smk', 'intro.wav' and 'intro*.png' into a
     188                single directory.
    176189
    177                 4. Run `encode_dxa intro.smk` in that directory
     190                4. Run `encode_dxa intro.smk` in that directory
    178191
    179                 5. You will get an intro.dxa file and intro.flac/mp3/ogg file
    180                 in result.
     192                5. You will get an intro.dxa file and intro.flac/mp3/ogg file
     193                in result.
    181194
    182                 Additionally you may use batch processing mode of SMK files in
    183                 RAD Game Tools. Just select more than one file and push the
    184                 'Convert' button. It will ask you either you want them
    185                 processed in batch mode and will do this for you. All buttons
    186                 and conversion options work the same.
     195                Additionally you may use batch processing mode of SMK files in
     196                RAD Game Tools. Just select more than one file and push the
     197                'Convert' button. It will ask you either you want them
     198                processed in batch mode and will do this for you. All buttons
     199                and conversion options work the same.
    187200
    188         convert_dxa.bat
    189         convert_dxa_one.bat
     201        convert_dxa.bat
     202        convert_dxa_one.bat
    190203
    191                 To ease your life we also provide batch files to autoconvert
    192                 all files. It should work with any game version.
     204                To ease your life we also provide batch files to autoconvert
     205                all files. It should work with any game version.
    193206
    194                 1. Copy *.smk files from all CDs to some directory
     207                1. Copy *.smk files from all CDs to some directory
    195208
    196                 2. Edit paths in convert_dxa.bat file.
     209                2. Edit paths in convert_dxa.bat file.
    197210
    198                 3. Run the batch. If you set everything correct, it will be
    199                 almost unattended conversion, just for several files there
    200                 are no audio, and RAD Game Tools converter will ask you to
    201                 press OK
     211                3. Run the batch. If you set everything correct, it will be
     212                almost unattended conversion, just for several files there
     213                are no audio, and RAD Game Tools converter will ask you to
     214                press OK
    202215
    203         convert_dxa.sh
     216        convert_dxa.sh
    204217
    205                 Same as above convert_dxa.bat, just for *nix-based systems.
    206                 It uses Wine to run RAD Game Tools.
     218                Same as above convert_dxa.bat, just for *nix-based systems.
     219                It uses Wine to run RAD Game Tools.