summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-02-06 19:00:22 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-02-06 19:00:22 +0100
commit71e984c6302eb35baa061fd245b762e716cf863b (patch)
treec816058f67795cabaf68c3829df422ba35340534
parent3d1020e60a09ec87209abd2852d2293415dd135c (diff)
adapt streaming speed to output samplerate
-rw-r--r--streamer.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/streamer.c b/streamer.c
index d8aceb64..e07dd499 100644
--- a/streamer.c
+++ b/streamer.c
@@ -480,16 +480,26 @@ streamer_thread (void *ctx) {
}
}
- // read ahead at 384K per second
- // that means 10ms per 4k block, or 40ms per 16k block
- int alloc_time = 1000 / (96000 * 4 / 4096);
+ // read ahead at 2x speed of output samplerate, in 4k blocks
+ int rate = p_get_rate ();
+ if (!rate) {
+ trace ("str: got 0 output samplerate\n");
+ usleep(20000);
+ continue;
+ }
+ int channels = 2; // FIXME: needs to be queried from output plugin
+ int bytes_in_one_second = rate * sizeof (int16_t) * channels;
+ const int blocksize = 4096;
+ int alloc_time = 1000 / (bytes_in_one_second * 2 / blocksize);
streamer_lock ();
- if (streambuffer_fill < (STREAM_BUFFER_SIZE-4096)/* && bytes_until_next_song == 0*/) {
+ if (streambuffer_fill < (STREAM_BUFFER_SIZE-blocksize)) {
int sz = STREAM_BUFFER_SIZE - streambuffer_fill;
- int minsize = 4096;
+ int minsize = blocksize;
+
+ // speed up buffering when empty
if (streambuffer_fill < 16384) {
- minsize = 16384;
+ minsize *= 4;
alloc_time *= 4;
}
sz = min (minsize, sz);