Changeset 205 for libmpc/branches/r2d/mpc2sv8/mpc2sv8.c
- Timestamp:
- 02/09/07 12:31:52 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/mpc2sv8/mpc2sv8.c
r204 r205 34 34 #include <stdio.h> 35 35 #include <mpc/mpcdec.h> 36 #include <mpc/minimax.h> 36 37 37 38 #include "../libmpcdec/decoder.h" 38 39 #include "../libmpcdec/internal.h" 39 40 #include "../libmpcenc/libmpcenc.h" 41 42 #define TMP_BUF_SIZE 128 40 43 41 44 static void datacpy(mpc_decoder * d, mpc_encoder_t * e) … … 81 84 mpc_encoder_t e; 82 85 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]; 83 90 84 91 printf("mpc2sv8 - musepack (mpc) sv7 to sv8 converter\n"); … … 99 106 e.MS_Channelmode = si.ms; 100 107 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 } 102 120 103 // conversion stream121 // stream conversion 104 122 e.seek_ref = ftell(e.outputFile); 105 123 writeMagic(&e); … … 107 125 si.channels); // FIXME : convert replay gain info 108 126 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); 110 129 writeBlock(&e, "EI", MPC_FALSE, 0); 111 130 e.seek_ptr = ftell(e.outputFile); … … 127 146 } 128 147 // 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); 132 155 } 133 writeBlock(&e, "AD", MPC_FALSE, 0);134 156 writeSeekTable(&e); 135 157 writeBlock(&e, "ST", MPC_FALSE, 0); // write seek table block … … 143 165 } 144 166 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 } 147 176 148 177 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); 151 181 152 return 0;182 return MPC_STATUS_OK; 153 183 }
Note: See TracChangeset
for help on using the changeset viewer.