Shairport bugs

To continue the previous post.
If you are getting a lot of nasty messages such as “missing frame”, “resending packet” and your sound is cracking sometimes – you’re welcome.

In the previous instruction the not-top version of shairport is fetched.
Go here to get the last version: https://github.com/albertz/shairport.

There were three bugs before (and two of them was fixed in github version). They all are related to hairtunes module.

1) (fixed on github) Function biquad_filt should be

static double biquad_filt(biquad_t *bq, double in) {
    double w = in – bq->a[0]*bq->hist[0] – bq->a[1]*bq->hist[1];
    double out = bq->b[1]*bq->hist[0] + bq->b[2]*bq->hist[1] + bq->b[0]*w;
    bq->hist[1] = bq->hist[0];
    bq->hist[0] = w;
    return out;
}
instead of

static double biquad_filt(biquad_t *bq, double in) {
    double w = in – bq->a[0]*bq->hist[0] – bq->a[1]*bq->hist[1];
    double out __attribute__((unused)) = bq->b[1]*bq->hist[0] + bq->b[2]*bq->hist[1] + bq->b[0]*w;
    bq->hist[1] = bq->hist[0];
    bq->hist[0] = w;
    return w;
}

2) (fixed on github) BUFFER_FRAME should be ^2 since sequence number is an unsigned short with overflowing. 512 works pretty well.

3) (not fixed on github) Nice bug in buffer_put_packet function:
Consider the following expression:
if (seqno == ab_write+1)
pretty simple piece of code, but there’s a bug here. Imagine the situation when seqno has overflowed already (eq 0) and ab_write is about to do it (eq 65535). In this case the expression above is NOT true.
ab_write+1 is automatically converted into int and so does seqno. So this expression actually looks like 0==65536, which is FALSE. The fix is quite fast:
if (seqno == (seq_t)(ab_write+1))
That’s all, have fun!

6 Replies to “Shairport bugs”

  1. However, I can still hear some cracks as if it were an old turn-table.
    I'm not sure if hpet timer settings can be trimmed in openwrt.
    Could you please share a compiled and improved version of shairport with brief instruction how to upgrade the existing version? All in all, it seems I'll have to start from scratch – after I receive a USB-hub and a card reader 😉

  2. urgh. me again. forgot to check my creative labs sound card, although I had a chance…

    i just upgraded my router to the 'barrier breaker', added extflash. i'm having the same problem with madplay. I believe, it's related to the sound subsystem (alsa/oss settings).
    now I've got another problem: how do I make shairport work on a clean router (without building my own firmware?). it seems it doesn't publish the service. do you know how do I debug it? which ports does it use (I'm having tcpdump running).

Leave a Reply

Your email address will not be published. Required fields are marked *