Skip to content

BeatDetect problems #309

@labkey-matthewb

Description

@labkey-matthewb

Hi all, I copied out a few files (PCM, BeatDetect, and fftsg) to put together a little sound reactive project. In reading through the code, I came to the conclusion that the code in BeatDetect is really broken. I hope I'm wrong, but here's what I'm seeing.

  1. Whenever audio data is added to the PCM buffer, we compute an FFT on the last 512 samples and put the result in PCM->vdataL and PCM->vdataR.

getPCM(vdataL,512,0,1,0,0);
getPCM(vdataR,512,1,1,0,0);

  1. BeatDetect::detectFromSamples() ignores the FFT data in vdataL/R and passes pcmdataL/R into BeatDetect::getBeatVals(). This is the first disconnect, as I believe getBeatVals() thinks it is operating on FFT data not PCM data.

getBeatVals(pcm->pcmdataL,pcm->pcmdataR);

  1. Even if getBeatVals() were handed FFT data, I think it is not quite right. Looking at the documentation for rdft() in https://github.com/projectM-visualizer/projectm/blob/master/src/libprojectM/fftsg.cpp, it looks like the real components of the fft are stored in the even indexes of the output array. I think we should be skipping the imaginary coefficients in the odd slots and also the value at [0] (that's just the mean of the input data).

  2. I'm not sure the ranges for bass,mid,treb make sense. For instance, the code sums up the first 16 coefficients (indexes 0-15) to compute beat_instant[0], but if I understand this correctly, I don't think coefficient 15 would be considered bass. Assuming sample rate of 44100/sec I think it would represent something like 15*44100/512 = 1291hz?

But this does seem to work today? I think what's going on is that bass/mid/treb are all basically just proxies for volume (with some additional randomness), and this probably works fine for most presets. It's definitely possible I've got this all wrong, but I couldn't make sense of the BeatDetect output using generated sine wave data input, until I really reworked all this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions