From ad06adccebe5834a1c5f185b60f8976ee55dc530 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Fri, 13 Mar 2009 12:36:14 +0100 Subject: mp3 playback prebuffering --- src/player.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/player.c b/src/player.c index 546936e..bbf815f 100644 --- a/src/player.c +++ b/src/player.c @@ -48,6 +48,9 @@ THE SOFTWARE. * a "nice" integer */ #define RG_SCALE_FACTOR 100 +/* FIXME: Hardcoded bitrate (kbit/s) */ +#define MP3_BITRATE 128 + /* compute replaygain scale factor * algo taken from here: http://www.dsprelated.com/showmessage/29246/1.php * mpd does the same @@ -314,15 +317,21 @@ size_t BarPlayerMp3CurlCb (void *ptr, size_t size, size_t nmemb, void *stream) { * _after_ a transfer finished */ curl_easy_getinfo (player->audioFd, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength); - player->songDuration = contentLength / (128.0 * 1000.0 / + player->songDuration = contentLength / ((float) MP3_BITRATE * 1024.0 / (float) BAR_PLAYER_MS_TO_S_FACTOR / 8.0); } + /* some "prebuffering" */ + if (player->mode < PLAYER_RECV_DATA && + player->bufferFilled < sizeof (player->buffer) / 10) { + return size*nmemb; + } + mad_stream_buffer (&player->mp3Stream, player->buffer, player->bufferFilled); player->mp3Stream.error = 0; do { - /* channels * max samples found in mad.h */ + /* channels * max samples, found in mad.h */ signed short int madDecoded[2*1152], *madPtr = madDecoded; if (mad_frame_decode (&player->mp3Frame, &player->mp3Stream) != 0) { -- cgit v1.2.3