/* Opted against the header printout from old mp3lib, too much * irrelevant info. This is modelled after the mpg123 app's * standard output line. * If more verbosity is demanded, one can add more detail and * also throw in ID3v2 info which libmpg123 collects anyway. */ static void print_header_compact(struct mpg123_frameinfo *i) { static const char *smodes[5] = { "stereo", "joint-stereo", "dual-channel", "mono", "invalid" }; static const char *layers[4] = { "Unknown", "I", "II", "III" }; static const char *versions[4] = { "1.0", "2.0", "2.5", "x.x" }; mp_msg(MSGT_DECAUDIO, MSGL_V, "MPEG %s layer %s, ", versions[i->version], layers[i->layer]); switch (i->vbr) { case MPG123_CBR: if (i->bitrate) mp_msg(MSGT_DECAUDIO, MSGL_V, "%d kbit/s", i->bitrate); else mp_msg(MSGT_DECAUDIO, MSGL_V, "%d kbit/s (free format)", compute_bitrate(i)); break; case MPG123_VBR: mp_msg(MSGT_DECAUDIO, MSGL_V, "VBR"); break; case MPG123_ABR: mp_msg(MSGT_DECAUDIO, MSGL_V, "%d kbit/s ABR", i->abr_rate); break; default: mp_msg(MSGT_DECAUDIO, MSGL_V, "???"); } mp_msg(MSGT_DECAUDIO, MSGL_V, ", %ld Hz %s\n", i->rate, smodes[i->mode]); }
/* Update mean bitrate. This could be dropped if accurate time display * on audio file playback is not desired. */ static void update_info(struct dec_audio *da) { struct ad_mpg123_context *con = da->priv; struct mpg123_frameinfo finfo; if (mpg123_info(con->handle, &finfo) != MPG123_OK) return; /* finfo.bitrate is expressed in kilobits */ const int bitrate = finfo.bitrate * 1000; if (finfo.vbr != MPG123_CBR) { if (--con->delay < 1) { if (++con->mean_count > ((unsigned int) -1) / 2) con->mean_count = ((unsigned int) -1) / 4; /* Might not be numerically optimal, but works fine enough. */ con->mean_rate = ((con->mean_count - 1) * con->mean_rate + bitrate) / con->mean_count; da->bitrate = (int) (con->mean_rate + 0.5); con->delay = 10; } } else { da->bitrate = bitrate ? bitrate : compute_bitrate(&finfo); con->delay = 1; con->mean_rate = 0.; con->mean_count = 0; } }