Changeset 315 for libmpc/trunk/mpcdec


Ignore:
Timestamp:
05/10/07 00:01:35 (18 years ago)
Author:
r2d
Message:

Added -i flag to print file information

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libmpc/trunk/mpcdec/mpcdec.c

    r299 r315  
    3737#include <mpc/mpcdec.h>
    3838#include <libwaveformat.h>
     39#include <unistd.h>
    3940
    4041#ifdef WIN32
     
    5455}
    5556
     57static void print_info(mpc_streaminfo * info, char * filename)
     58{
     59        int time = (int) mpc_streaminfo_get_length(info);
     60        int minutes = time / 60;
     61        int seconds = time % 60;
     62
     63        printf("file: %s\n", filename);
     64        printf("stream version %d\n", info->stream_version);
     65        printf("encoder: \%s\n", info->encoder);
     66        printf("profile: \%s (q=%0.2f)\n", info->profile_name, info->profile - 5);
     67        printf("PNS: \%s\n", info->pns == 0xFF ? "unknow" : info->pns ? "on" : "off");
     68        printf("mid/side stereo: %s\n", info->ms ? "on" : "off");
     69        printf("gapless: \%s\n", info->is_true_gapless ? "on" : "off");
     70        printf("average bitrate: \%6.1f kbps\n", info->average_bitrate * 1.e-3);
     71        printf("samplerate: \%d Hz\n", info->sample_freq);
     72        printf("channels: \%d\n", info->channels);
     73        printf("length: \%d:\%.2d (%u samples)\n", minutes, seconds, (mpc_uint32_t)mpc_streaminfo_get_length_samples(info));
     74        printf("file size: \%d Bytes\n", info->total_file_length);
     75        printf("track peak: \%2.2f dB\n", info->peak_title / 256.);
     76        printf("track gain: \%2.2f dB\n", info->gain_title / 256.);
     77        printf("album peak: \%2.2f dB\n", info->peak_album / 256.);
     78        printf("album gain: \%2.2f dB\n", info->gain_album / 256.);
     79        printf("\n");
     80
     81}
     82
    5683static void
    5784usage(const char *exename)
    5885{
    59     printf("Usage: %s <infile.mpc> [<outfile.wav>]\n", exename);
     86    printf("Usage: %s [-i] [-h] <infile.mpc> [<outfile.wav>]\n"
     87                        "-i : print file information on stdout\n"
     88                        "-h : print this help\n", exename);
    6089}
    6190
     
    6796        mpc_streaminfo si;
    6897        mpc_status err;
     98        mpc_bool_t info = MPC_FALSE;
    6999    MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH];
    70100    clock_t begin, end, sum; int total_samples; t_wav_output_file wav_output;
    71     mpc_bool_t is_wav_output;
     101        mpc_bool_t is_wav_output;
     102        int c;
     103        extern char * optarg;
     104        extern int optind;
    72105
    73106    printf("mpcdec - musepack (mpc) decoder sample application\n");
    74     if(3 < argc && argc < 2)
     107
     108        while ((c = getopt(argc , argv, "ih")) != -1) {
     109                switch (c) {
     110                        case 'i':
     111                                info = MPC_TRUE;
     112                                break;
     113                        case 'h':
     114                                usage(argv[0]);
     115                                return 0;
     116                }
     117        }
     118
     119        if(2 < argc - optind && argc - optind < 1)
    75120    {
    76121        usage(argv[0]);
     
    78123    }
    79124
    80     err = mpc_reader_init_stdio(&reader, argv[1]);
     125        err = mpc_reader_init_stdio(&reader, argv[optind]);
    81126    if(err < 0) return !MPC_STATUS_OK;
    82127
     
    85130    mpc_demux_get_info(demux,  &si);
    86131
    87     is_wav_output = argc > 2;
     132        if (info == MPC_TRUE) {
     133                print_info(&si, argv[optind]);
     134                mpc_demux_exit(demux);
     135                mpc_reader_exit_stdio(&reader);
     136                return 0;
     137        }
     138
     139        is_wav_output = argc - optind > 1;
    88140    if(is_wav_output)
    89141    {
     
    92144        wavo_fc.m_seek      = mpc_wav_output_seek;
    93145        wavo_fc.m_write     = mpc_wav_output_write;
    94         wavo_fc.m_user_data = fopen(argv[2], "wb");
     146                wavo_fc.m_user_data = fopen(argv[optind + 1], "wb");
    95147        if(!wavo_fc.m_user_data) return !MPC_STATUS_OK;
    96148        err = waveformat_output_open(&wav_output, wavo_fc, si.channels, 16, 0, si.sample_freq, (t_wav_uint32) si.samples * 2);
Note: See TracChangeset for help on using the changeset viewer.