diff options
author | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2009-03-13 12:36:14 +0100 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2009-03-13 12:36:14 +0100 |
commit | ad06adccebe5834a1c5f185b60f8976ee55dc530 (patch) | |
tree | dc5fa3f44053a242beba46454a9a3ef077b425d8 | |
parent | 9d753bf7f9ee0e2b56be5b13b7e6f26f11938235 (diff) | |
download | pianobar-ad06adccebe5834a1c5f185b60f8976ee55dc530.tar.gz pianobar-ad06adccebe5834a1c5f185b60f8976ee55dc530.tar.bz2 pianobar-ad06adccebe5834a1c5f185b60f8976ee55dc530.zip |
mp3 playback prebuffering
-rw-r--r-- | src/player.c | 13 |
1 files 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) { |