Changeset 480
- Timestamp:
- 03/31/12 00:52:54 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/trunk/mpcdec/mpcdec.c
r444 r480 40 40 #include <libwaveformat.h> 41 41 #include <getopt.h> 42 #include <math.h> 43 #include <byteswap.h> 42 44 43 45 #ifdef _MSC_VER … … 75 77 return (t_wav_uint32) !fseek(p_handle, p_position, SEEK_SET); 76 78 } 79 80 #ifdef MPC_FIXED_POINT 81 82 static int raw_output_int16(FILE * file, short * buff, int cnt, mpc_bool_t reverse_endian) 83 { 84 int i; 85 for (i = 0; i < cnt; i++) { 86 short out = buff[i]; 87 if (reverse_endian) 88 out = bswap_16(out); 89 if (fwrite(&out, sizeof(out), 1, file) != 1) 90 return -1; 91 } 92 return 0; 93 } 94 95 #else 96 97 static int raw_output_float32(FILE * file, float * buff, int cnt, mpc_bool_t reverse_endian) 98 { 99 int i; 100 for (i = 0; i < cnt; i++) { 101 int tmp = nearbyintf(buff[i] * (1 << 15)); 102 short out; 103 if (tmp > ((1 << 15) - 1)) 104 tmp = ((1 << 15) - 1); 105 if (tmp < -(1 << 15)) 106 tmp = -(1 << 15); 107 if (reverse_endian) 108 tmp = bswap_16((short) tmp); 109 out = (short)tmp; 110 if (fwrite(&out, sizeof(out), 1, file) != 1) 111 return -1; 112 } 113 return 0; 114 } 115 116 #endif 77 117 78 118 static void print_info(mpc_streaminfo * info, char * filename) … … 109 149 "-c : check the file for stream errors\n" 110 150 " (doesn't fully decode, outfile will be ignored)\n" 151 "-r : output raw data (left/right) in machine native endian\n" 152 "-e : reverse raw data endianness\n" 111 153 "-h : print this help\n" 112 154 "you can use stdin and stdout as resp. <infile.mpc> and\n" … … 122 164 mpc_status err; 123 165 mpc_bool_t info = MPC_FALSE, is_wav_output = MPC_FALSE, check = MPC_FALSE; 166 mpc_bool_t is_raw_output = MPC_FALSE, reverse_endian = MPC_FALSE; 124 167 MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH]; 125 clock_t begin, end, sum; int total_samples; t_wav_output_file wav_output; 168 clock_t begin, end, sum; int total_samples; 169 t_wav_output_file wav_output; 170 t_wav_output_file_callback wavo_fc; 126 171 int c; 127 172 128 173 fprintf(stderr, About); 129 174 130 while ((c = getopt(argc , argv, "ihc ")) != -1) {175 while ((c = getopt(argc , argv, "ihcre")) != -1) { 131 176 switch (c) { 132 177 case 'i': … … 136 181 check = MPC_TRUE; 137 182 break; 183 case 'r': 184 is_raw_output = MPC_TRUE; 185 break; 186 case 'e': 187 reverse_endian = MPC_TRUE; 188 break; 138 189 case 'h': 139 190 usage(argv[0]); … … 166 217 } 167 218 168 if (!check) 169 is_wav_output = argc - optind > 1; 170 if(is_wav_output) 219 if (check) { 220 is_raw_output = MPC_FALSE; 221 } else if (argc - optind > 1 && is_raw_output == MPC_FALSE) { 222 is_wav_output = MPC_TRUE; 223 }; 224 225 if (is_wav_output || is_raw_output) 171 226 { 172 t_wav_output_file_callback wavo_fc;173 227 memset(&wav_output, 0, sizeof wav_output); 174 228 wavo_fc.m_seek = mpc_wav_output_seek; 175 229 wavo_fc.m_write = mpc_wav_output_write; 176 if (strcmp(argv[optind + 1], "-") == 0 ) {230 if (strcmp(argv[optind + 1], "-") == 0 || (is_raw_output && argc - optind <= 1)) { 177 231 SET_BINARY_MODE(stdout); 178 232 wavo_fc.m_user_data = stdout; 179 233 } else 180 234 wavo_fc.m_user_data = fopen(argv[optind + 1], "wb"); 181 if(!wavo_fc.m_user_data) return !MPC_STATUS_OK; 182 err = waveformat_output_open(&wav_output, wavo_fc, si.channels, 16, 0, si.sample_freq, (t_wav_uint32) si.samples * si.channels); 183 if(!err) return !MPC_STATUS_OK; 235 if(!wavo_fc.m_user_data) 236 return !MPC_STATUS_OK; 237 238 if (is_wav_output) { 239 if (!waveformat_output_open(&wav_output, wavo_fc, si.channels, 16, 0, si.sample_freq, (t_wav_uint32) si.samples * si.channels)) 240 return !MPC_STATUS_OK; 241 } 184 242 } 185 243 … … 200 258 sum += end - begin; 201 259 202 if (is_wav_output) {260 if (is_wav_output || is_raw_output) { 203 261 #ifdef MPC_FIXED_POINT 204 262 mpc_int16_t tmp_buff[MPC_DECODER_BUFFER_LENGTH]; … … 210 268 tmp_buff[i] = tmp; 211 269 } 212 if(waveformat_output_process_int16(&wav_output, tmp_buff, frame.samples * si.channels) < 0) 270 #endif 271 if (is_wav_output) { 272 #ifdef MPC_FIXED_POINT 273 if(waveformat_output_process_int16(&wav_output, tmp_buff, frame.samples * si.channels) < 0) 213 274 #else 214 if(waveformat_output_process_float32(&wav_output, sample_buffer, frame.samples * si.channels) < 0) 215 #endif 216 break; 275 if(waveformat_output_process_float32(&wav_output, sample_buffer, frame.samples * si.channels) < 0) 276 #endif 277 break; 278 } 279 if (is_raw_output) { 280 #ifdef MPC_FIXED_POINT 281 if (raw_output_int16(wavo_fc.m_user_data, tmp_buff, frame.samples * si.channels, reverse_endian) < 0) 282 #else 283 if (raw_output_float32(wavo_fc.m_user_data, sample_buffer, frame.samples * si.channels, reverse_endian) < 0) 284 #endif 285 break; 286 } 217 287 } 218 288 }
Note: See TracChangeset
for help on using the changeset viewer.