Changeset 356


Ignore:
Timestamp:
09/27/07 12:54:04 (17 years ago)
Author:
r2d
Message:

added pipe input and output for mpcdec

File:
1 edited

Legend:

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

    r353 r356  
    4747#define MPCDEC_MAJOR 0
    4848#define MPCDEC_MINOR 9
    49 #define MPCDEC_BUILD 0
     49#define MPCDEC_BUILD 1
    5050
    5151#define _cat(a,b,c) #a"."#b"."#c
     
    7474        int seconds = time % 60;
    7575
    76         printf("file: %s\n", filename);
    77         printf("stream version %d\n", info->stream_version);
    78         printf("encoder: %s\n", info->encoder);
    79         printf("profile: %s (q=%0.2f)\n", info->profile_name, info->profile - 5);
    80         printf("PNS: %s\n", info->pns == 0xFF ? "unknow" : info->pns ? "on" : "off");
    81         printf("mid/side stereo: %s\n", info->ms ? "on" : "off");
    82         printf("gapless: %s\n", info->is_true_gapless ? "on" : "off");
    83         printf("average bitrate: %6.1f kbps\n", info->average_bitrate * 1.e-3);
    84         printf("samplerate: %d Hz\n", info->sample_freq);
    85         printf("channels: %d\n", info->channels);
    86         printf("length: %d:%.2d (%u samples)\n", minutes, seconds, (mpc_uint32_t)mpc_streaminfo_get_length_samples(info));
    87         printf("file size: %d Bytes\n", info->total_file_length);
    88         printf("track peak: %2.2f dB\n", info->peak_title / 256.f);
    89         printf("track gain: %2.2f dB / %2.2f dB\n", info->gain_title / 256.f, info->gain_title == 0 ? 0 : 64.82f - info->gain_title / 256.f);
    90         printf("album peak: %2.2f dB\n", info->peak_album / 256.f);
    91         printf("album gain: %2.2f dB / %2.2f dB\n", info->gain_album / 256.f, info->gain_album == 0 ? 0 : 64.82f - info->gain_album / 256.f);
    92         printf("\n");
     76        fprintf(stderr, "file: %s\n", filename);
     77        fprintf(stderr, "stream version %d\n", info->stream_version);
     78        fprintf(stderr, "encoder: %s\n", info->encoder);
     79        fprintf(stderr, "profile: %s (q=%0.2f)\n", info->profile_name, info->profile - 5);
     80        fprintf(stderr, "PNS: %s\n", info->pns == 0xFF ? "unknow" : info->pns ? "on" : "off");
     81        fprintf(stderr, "mid/side stereo: %s\n", info->ms ? "on" : "off");
     82        fprintf(stderr, "gapless: %s\n", info->is_true_gapless ? "on" : "off");
     83        fprintf(stderr, "average bitrate: %6.1f kbps\n", info->average_bitrate * 1.e-3);
     84        fprintf(stderr, "samplerate: %d Hz\n", info->sample_freq);
     85        fprintf(stderr, "channels: %d\n", info->channels);
     86        fprintf(stderr, "length: %d:%.2d (%u samples)\n", minutes, seconds, (mpc_uint32_t)mpc_streaminfo_get_length_samples(info));
     87        fprintf(stderr, "file size: %d Bytes\n", info->total_file_length);
     88        fprintf(stderr, "track peak: %2.2f dB\n", info->peak_title / 256.f);
     89        fprintf(stderr, "track gain: %2.2f dB / %2.2f dB\n", info->gain_title / 256.f, info->gain_title == 0 ? 0 : 64.82f - info->gain_title / 256.f);
     90        fprintf(stderr, "album peak: %2.2f dB\n", info->peak_album / 256.f);
     91        fprintf(stderr, "album gain: %2.2f dB / %2.2f dB\n", info->gain_album / 256.f, info->gain_album == 0 ? 0 : 64.82f - info->gain_album / 256.f);
     92        fprintf(stderr, "\n");
    9393
    9494}
     
    9797usage(const char *exename)
    9898{
    99     printf("Usage: %s [-i] [-h] <infile.mpc> [<outfile.wav>]\n"
     99    fprintf(stderr, "Usage: %s [-i] [-h] <infile.mpc> [<outfile.wav>]\n"
    100100                        "-i : print file information on stdout\n"
    101101                        "-c : check the file for stream errors\n"
    102102                        "     (doesn't fully decode, outfile will be ignored)\n"
    103                         "-h : print this help\n", exename);
     103                        "-h : print this help\n"
     104            "you can use stdin and stdout as resp. <infile.mpc> and\n"
     105            "<outfile.wav> replacing the file name by \"-\"\n", exename);
    104106}
    105107
     
    116118        int c;
    117119
    118     printf(About);
     120    fprintf(stderr, About);
    119121
    120122        while ((c = getopt(argc , argv, "ihc")) != -1) {
     
    138140    }
    139141
    140         err = mpc_reader_init_stdio(&reader, argv[optind]);
     142        if (strcmp(argv[optind], "-") == 0)
     143                err = mpc_reader_init_stdio_stream(& reader, stdin);
     144        else
     145                err = mpc_reader_init_stdio(&reader, argv[optind]);
    141146    if(err < 0) return !MPC_STATUS_OK;
    142147
     
    160165        wavo_fc.m_seek      = mpc_wav_output_seek;
    161166        wavo_fc.m_write     = mpc_wav_output_write;
    162                 wavo_fc.m_user_data = fopen(argv[optind + 1], "wb");
     167            if (strcmp(argv[optind + 1], "-") == 0)
     168                    wavo_fc.m_user_data = stdout;
     169            else
     170                        wavo_fc.m_user_data = fopen(argv[optind + 1], "wb");
    163171        if(!wavo_fc.m_user_data) return !MPC_STATUS_OK;
    164172        err = waveformat_output_open(&wav_output, wavo_fc, si.channels, 16, 0, si.sample_freq, (t_wav_uint32) si.samples * 2);
     
    201209
    202210        if (err != MPC_STATUS_OK)
    203                 printf("An error occured while decoding\n");
     211                fprintf(stderr, "An error occured while decoding\n");
    204212        else if (check)
    205                 printf("No error found\n");
     213                fprintf(stderr, "No error found\n");
    206214
    207215        if (!check) {
    208                 printf("%u samples ", total_samples);
     216                fprintf(stderr, "%u samples ", total_samples);
    209217                if (sum <= 0) sum = 1;
    210218                total_samples = (mpc_uint32_t) ((mpc_uint64_t) total_samples * CLOCKS_PER_SEC * 100 / ((mpc_uint64_t)si.sample_freq * sum));
    211                 printf("decoded in %u ms (%u.%02ux)\n",
     219                fprintf(stderr, "decoded in %u ms (%u.%02ux)\n",
    212220                        (unsigned int) (sum * 1000 / CLOCKS_PER_SEC),
    213221                        total_samples / 100,
Note: See TracChangeset for help on using the changeset viewer.