Ignore:
Timestamp:
02/09/07 12:31:52 (17 years ago)
Author:
r2d
Message:
  • corrected a small bug
  • added copy of header and footer data (tags) of the input file
  • added encoder version conversion
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libmpc/branches/r2d/mpc2sv8/mpc2sv8.c

    r204 r205  
    3434#include <stdio.h>
    3535#include <mpc/mpcdec.h>
     36#include <mpc/minimax.h>
    3637
    3738#include "../libmpcdec/decoder.h"
    3839#include "../libmpcdec/internal.h"
    3940#include "../libmpcenc/libmpcenc.h"
     41
     42#define TMP_BUF_SIZE 128
    4043
    4144static void datacpy(mpc_decoder * d, mpc_encoder_t * e)
     
    8184        mpc_encoder_t e;
    8285        mpc_uint_t si_size;
     86        mpc_size_t stream_size;
     87        size_t r_size;
     88        FILE * in_file;
     89        char buf[TMP_BUF_SIZE];
    8390
    8491    printf("mpc2sv8 - musepack (mpc) sv7 to sv8 converter\n");
     
    99106        e.MS_Channelmode = si.ms;
    100107
    101         // copie début fichier
     108        // copy begining of file
     109        in_file = fopen(argv[1], "rb");
     110        if(in_file == 0) return !MPC_STATUS_OK;
     111        r_size = si.header_position;
     112        while(r_size) {
     113                size_t tmp_size = fread(buf, 1, mini(TMP_BUF_SIZE, r_size), in_file);
     114                if (fwrite(buf, 1, tmp_size, e.outputFile) != tmp_size) {
     115                        fprintf(stderr, "Error writing to target file");
     116                        exit(!MPC_STATUS_OK);
     117                }
     118                r_size -= tmp_size;
     119        }
    102120
    103         // conversion stream
     121        // stream conversion
    104122        e.seek_ref = ftell(e.outputFile);
    105123        writeMagic(&e);
     
    107125                                          si.channels); // FIXME : convert replay gain info
    108126        si_size = writeBlock(&e, "SI", MPC_TRUE, 0);
    109         writeEncoderInfo(&e, si.profile, si.pns, 0, 0, 0, 0); // FIXME : convert encoder information
     127        writeEncoderInfo(&e, si.profile, si.pns, si.encoder_version / 100,
     128                                          si.encoder_version % 100, 0, 0);
    110129        writeBlock(&e, "EI", MPC_FALSE, 0);
    111130        e.seek_ptr = ftell(e.outputFile);
     
    127146        }
    128147    // write the last incomplete block
    129         if ((e.block_cnt & ((1 << e.seek_pwr) - 1)) == 0) {
    130                 e.seek_table[e.seek_pos] = ftell(e.outputFile);
    131                 e.seek_pos++;
     148        if (e.framesInBlock != 0) {
     149                if ((e.block_cnt & ((1 << e.seek_pwr) - 1)) == 0) {
     150                        e.seek_table[e.seek_pos] = ftell(e.outputFile);
     151                        e.seek_pos++;
     152                }
     153                e.block_cnt++;
     154                writeBlock(&e, "AD", MPC_FALSE, 0);
    132155        }
    133         writeBlock(&e, "AD", MPC_FALSE, 0);
    134156        writeSeekTable(&e);
    135157        writeBlock(&e, "ST", MPC_FALSE, 0); // write seek table block
     
    143165        }
    144166
    145         // copie fin fichier
    146 
     167        // copy end of file
     168        stream_size = (((mpc_demux_pos(demux) + 7) >> 3) - si.header_position + 3) & ~3;
     169        fseek(in_file, si.header_position + stream_size, SEEK_SET);
     170        while((r_size = fread(buf, 1, TMP_BUF_SIZE, in_file))) {
     171                if (fwrite(buf, 1, r_size, e.outputFile) != r_size) {
     172                        fprintf(stderr, "Error writing to target file");
     173                        break;
     174                }
     175        }
    147176
    148177        fclose ( e.outputFile );
    149     mpc_demux_exit(demux);
    150     mpc_reader_exit_stdio(&reader);
     178        fclose ( in_file );
     179        mpc_demux_exit(demux);
     180        mpc_reader_exit_stdio(&reader);
    151181
    152     return 0;
     182        return MPC_STATUS_OK;
    153183}
Note: See TracChangeset for help on using the changeset viewer.