ralph-irving / squeezelite

Lightweight headless squeezebox player for Lyrion Media Server
https://sourceforge.net/projects/lmsclients/files/squeezelite/
Other
391 stars 98 forks source link

output threshold is incorrect #204

Closed philippe44 closed 9 months ago

philippe44 commented 10 months ago

This is something we discussed a while ago I think. In output.c, we have to wait till we have enough pcm samples

// start when threshold met
if (output.state == OUTPUT_BUFFER && (frames * BYTES_PER_FRAME) > output.threshold * output.next_sample_rate / 10 && frames > output.start_frames) {
    output.state = OUTPUT_RUNNING;
    LOG_INFO("start buffer frames: %u", frames);
    wake_controller();
}

But I don't think this is right and that bit me in the ogf fix I did: as frames is number of frames, it should not be multiplied by BYTES_PER_FRAMES. The threshold is in 1/10th of a second, and one count of sample_rate is one frame. So for 20 of threshold at 44100, we should have 2 sec = 88200 frames. But if we multiply the left member, current frames by BYTES_PER_FRAME, then we compare bytes and frames which is wrong and we end up starting way too early

ralph-irving commented 10 months ago

I do remember the discussion, I think it was related to commit 11700c41a86f0b1e69f53d4c975a5175c2d0ae45 ?

philippe44 commented 10 months ago

I do remember the discussion, I think it was related to commit 11700c41a86f0b1e69f53d4c975a5175c2d0ae45 ?

Yes and I obviously hit my head on that one but I think this time my comment is correct 😄. It's finally working correctly on my esp32 version, where it was stuttering before because it started too early before buffer had enough data (in ogf livestream)