Changeset 75 for libmpcdec/branches/zorg/mpcdec/mpcdec.c
- Timestamp:
- 10/12/06 23:34:50 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpcdec/branches/zorg/mpcdec/mpcdec.c
r70 r75 36 36 #include <time.h> 37 37 #include <mpcdec/mpcdec.h> 38 #include <libwaveformat.h> 38 39 39 40 #ifdef WIN32 … … 41 42 #endif 42 43 44 t_wav_uint32 mpc_wav_output_write(void* p_user_data, void const* p_buffer, t_wav_uint32 p_bytes) 45 { 46 FILE* p_handle = (FILE*) p_user_data; 47 return (t_wav_uint32) fwrite(p_buffer, 1, p_bytes, p_handle); 48 } 49 50 t_wav_uint32 mpc_wav_output_seek(void* p_user_data, t_wav_uint32 p_position) 51 { 52 FILE* p_handle = (FILE*) p_user_data; 53 return (t_wav_uint32) !fseek(p_handle, p_position, SEEK_SET); 54 } 55 43 56 static void 44 57 usage(const char *exename) 45 58 { 46 printf("Usage: %s <infile.mpc> \n", exename);59 printf("Usage: %s <infile.mpc> [<outfile.wav>]\n", exename); 47 60 } 48 61 … … 52 65 mpc_reader reader; mpc_streaminfo si; mpc_decoder* decoder; mpc_status err; 53 66 MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH]; 54 clock_t begin, end, sum; int total_samples; 67 clock_t begin, end, sum; int total_samples; t_wav_output_file wav_output; 68 mpc_bool_t is_wav_output; 55 69 56 if( argc !=2)70 if(3 < argc && argc < 2) 57 71 { 58 72 usage(argv[0]); … … 69 83 if(err < 0) return !MPC_STATUS_OK; 70 84 85 is_wav_output = argc > 2; 86 if(is_wav_output) 87 { 88 t_wav_output_file_callback wavo_fc; 89 memset(&wav_output, 0, sizeof wav_output); 90 wavo_fc.m_seek = mpc_wav_output_seek; 91 wavo_fc.m_write = mpc_wav_output_write; 92 wavo_fc.m_user_data = fopen(argv[2], "wb"); 93 if(!wavo_fc.m_user_data) return !MPC_STATUS_OK; 94 err = waveformat_output_open(&wav_output, wavo_fc, si.channels, 16, 0, si.sample_freq, (t_wav_uint32) si.pcm_samples * 2); 95 if(!err) return !MPC_STATUS_OK; 96 } 97 71 98 sum = total_samples = 0; 72 99 while(TRUE) 73 100 { 74 101 mpc_uint32_t samples; 75 begin = clock(); 102 103 begin = clock(); 76 104 samples = mpc_decoder_decode(decoder, sample_buffer, 0, 0); 77 end = clock(); 105 end = clock(); 106 78 107 if(samples <= 0) break; 79 if(!samples) break;108 if(!samples) break; 80 109 total_samples += samples; 81 110 sum += end - begin; 111 112 if(is_wav_output) 113 if(waveformat_output_process_float32(&wav_output, sample_buffer, samples*2) < 0) 114 break; 82 115 } 83 116 … … 92 125 mpc_decoder_exit(decoder); 93 126 mpc_reader_exit_stdio(&reader); 127 if(is_wav_output) 128 { 129 waveformat_output_close(&wav_output); 130 fclose(wav_output.m_callback.m_user_data); 131 } 94 132 95 133 #ifdef WIN32
Note: See TracChangeset
for help on using the changeset viewer.