Author Topic: Help to get exact bpm count and beatgrid  (Read 2939 times)

djjoy

  • Newbie
  • *
  • Posts: 3
    • View Profile
Help to get exact bpm count and beatgrid
« on: September 21, 2016, 17:56:10 »
Hello everybody,
I'm newbie in vamp and also in c++.
I have a DJ application that uses bass.dll, but the bpm counter of bass.dll is not very precise, and I want proccess the song throught vapm plugins to get the exact bpm.

If I use fixedtempo:0 with output = 0 (tempo), modifing your vamp-simple-host example to use with bass:
I get this:
0.002902494, 59.998911565: 51.3587 51.4 bpm
when the real bpm ( in traktor and virtual dj ) is 93.232

I use bass decode to send data to process:
BASS_Init(-1,44100,BASS_DEVICE_MONO,0,NULL);  //only one channel
stream = BASS_StreamCreateFile(FALSE,filename,0,0, BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT);  //open the song in decode float samples mode


//loop to fill data in the plugin

    // Here we iterate over the frames, avoiding asking the numframes in case it's streaming input.
    do {

        int count;

        if ((blockSize==stepSize) || (currentStep==0)) {
            // read a full fresh block
         count = BASS_ChannelGetData(stream, filebuf, blockSize );
            if (count  < 0)
         {
                cerr << "ERROR: sf_readf_float failed: "  << endl;
                break;
            }
            if (count != blockSize) --finalStepsRemaining;
        } else {
            //  otherwise shunt the existing data down and read the remainder.
            memmove(filebuf, filebuf + (stepSize * channels), overlapSize * channels * sizeof(float));
         count = BASS_ChannelGetData(stream, filebuf + (overlapSize * channels ), stepSize );
            if (count < 0) {
                cerr << "ERROR: sf_readf_float failed: " <<  endl;
                break;
            }
            if (count != stepSize) --finalStepsRemaining;
            count += overlapSize;
        }

        for (int c = 0; c < channels; ++c) {
            int j = 0;
            while (j < count) {
                plugbuf[c][j] = filebuf[j * info.chans + c];
                ++j;
            }
            while (j < blockSize) {
                plugbuf[c][j] = 0.0f;
                ++j;
            }
        }

        rt = RealTime::frame2RealTime(currentStep * stepSize, info.freq);

        printFeatures
            (RealTime::realTime2Frame(rt + adjustment, info.freq),
             info.freq, outputNo, plugin->process(plugbuf, rt),
             out, useFrames);
      int frames;
      frames = BASS_ChannelGetLength(stream, BASS_POS_BYTE);
        if (frames > 0){
            int pp = progress;
            progress = (int)((float(currentStep * stepSize) / frames) * 100.f + 0.5f);
            if (progress != pp && out) {
                cerr << "\r" << progress << "%";
            }
        }

        ++currentStep;

    } while (finalStepsRemaining > 0);


Can you helpme about this? What's wrong?

Best Regards,

DJ Joy









cannam

  • Administrator
  • Sr. Member
  • *****
  • Posts: 273
    • View Profile
Re: Help to get exact bpm count and beatgrid
« Reply #1 on: September 21, 2016, 18:03:05 »
Hello! Before I read on very far, can I check -- have you tried saving out this audio into a file and running the same plugin using vamp-simple-host, and if so, can you confirm whether it produced the results you expect (i.e. the right ones) or not?

The fixedtempo plugin is not the best tempo estimator we have, and I expect it's not as good as whatever is in traktor. Something like the QM Vamp Plugins tempo estimator will generally work better. But for all its flaws, it probably should not return a result like 51.4 bpm for something that is actually at 93.


Chris

djjoy

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Help to get exact bpm count and beatgrid
« Reply #2 on: September 24, 2016, 08:12:18 »
Hi again,
I have many hours testing and I have no goods results.

I try with qm-tempotrack and I get something like this:
Using block size = 1024, step size = 512
Plugin accepts 1 -> 1 channel(s)
Sound file has 1 (will mix/augment if necessary)
Output is: "tempo"
Note: nonZeroCount was 61771, is now 61771
 0.011609977: 99.384 99.38 bpm
 1.497687074: 93.9631 93.96 bpm
 4.469841269: 92.2852 92.29 bpm
 7.441995464: 93.9631 93.96 bpm
 8.928072562: 92.2852 92.29 bpm
 13.386303854: 95.7031 95.70 bpm
 14.872380952: 89.1029 89.10 bpm
 17.844535147: 90.6661 90.67 bpm
 19.330612244: 95.7031 95.70 bpm
 20.816689342: 92.2852 92.29 bpm
 22.302766439: 99.384 99.38 bpm
 25.274920634: 97.5088 97.51 bpm
 26.760997732: 95.7031 95.70 bpm
 28.247074829: 90.6661 90.67 bpm
 31.219229024: 86.1328 86.13 bpm
 32.705306122: 99.384 99.38 bpm
 35.677460317: 93.9631 93.96 bpm
 38.649614512: 92.2852 92.29 bpm
 40.135691609: 97.5088 97.51 bpm
 44.593922902: 117.454 117.45 bpm
 46.079999999: 132.512 132.51 bpm
 47.566077097: 129.199 129.20 bpm
 53.510385487: 132.512 132.51 bpm
 56.482539682: 139.675 139.67 bpm
 60.940770974: 135.999 136.00 bpm
 66.885079364: 143.555 143.55 bpm
......

Is this correct?
If the original song has a 93.232bpm (testing in VirtualDJ and Tracktor)... I have to process the received data to get this bpm?
I have to change some parameters ?

Waiting for your reply

Best Regards,

DJ JOY

djjoy

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Help to get exact bpm count and beatgrid
« Reply #3 on: September 29, 2016, 10:06:18 »
Some help or comments with this question?

Best Regards,

DJ Joy

cannam

  • Administrator
  • Sr. Member
  • *****
  • Posts: 273
    • View Profile
Re: Help to get exact bpm count and beatgrid
« Reply #4 on: September 30, 2016, 17:12:35 »
And if you use the vamp-simple-host with the vamp-example-plugins:fixedtempo plugin, does that give you the same 51.4 result as you had with your code?

I can't see anything obviously wrong with your code snippet, assuming that the audio is single channel throughout.

The QM tempo tracker works slightly differently -- it emits a new tempo every time its sense of the underlying tempo changes. This means in theory it works for tracks which vary in tempo as well, but it can mean you sometimes get a series of very close estimates which would be more useful if they had been merged together. To get a single tempo per track, one might typically pick the estimate that spans the greatest time range within the results.