examples/fpcalc.c invalid buffer length?

Issue #14 invalid
Johan Ström created an issue

Hi,

I'm playing around with your fpcalc example code, and I noticed something which I think is a bug: At fpcalc.c line 173 (https://bitbucket.org/acoustid/chromaprint/src/51c46effb3beac17345b7920ec6eda68077dc612/examples/fpcalc.c?at=master#cl-173) the number of bytes in the data buffer is calculated:

length = MIN(remaining, frame->nb_samples * codec_ctx->channels);

This however assumes that each sample is 1 byte. Since it always converts to AV_SAMPLE_FMT_S16, every sample is 2 bytes? The proper(?) code would instead be:

length = MIN(remaining, frame->nb_samples * codec_ctx->channels * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16));

"remaining" would also need to be adjusted accordingly.

If I'm correct here, this means we feed only the first 50% of the samples in each frame into the fingerprinting algorithm.

Am I misunderstanding something, or is this a valid bug? Thanks

Comments (4)

  1. Johan Ström reporter

    Never mind, my bad. chromaprint_feed takes nr of 16bit samples... not bytes..

    /**
     * Send audio data to the fingerprint calculator.
     *
     * Parameters:
     *  - ctx: Chromaprint context pointer
     *  - data: raw audio data, should point to an array of 16-bit signed
     *          integers in native byte-order
     *  - size: size of the data buffer (in samples)
     *
     * Returns:
     *  - 0 on error, 1 on success
     */
    CHROMAPRINT_API int chromaprint_feed(ChromaprintContext *ctx, void *data, int size);
    

    It was just me confusing myself when doing some debugging.

  2. Lukáš Lalinský

    Yeah, taking the number of 16 bit samples rather than bytes was an arbitrary decision. Let me know if the docs could be clearer.

  3. Log in to comment