Change it to ctx->bufferWrite %= ctx->mp3BufSize;