dlepaux / realtime-bpm-analyzer

Library using WebAudioAPI to analyse BPM from files, audionodes. It's also able to compute BPM from streams as well as realtime using a microphone. This tool might be useful for music producers and DJs or anybody that wants to get BPM from any music source.

Home Page:https://www.realtime-bpm-analyzer.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need Help to find BPM

SM227465 opened this issue · comments

I was trying to find the bpm of a local audio file, but I cannot figure out from where I can get the actual value as shown here. Here is a demo

I also tried to calculate the bpm of audio in real time but still could not figure it out, as shown here

import { createRealTimeBpmProcessor, getBiquadFilters } from 'realtime-bpm-analyzer';

let audioCtx;
let mediaElementSource;

const { type, node } = detectVideo();

if (!node) {
  return;
}

if (!audioCtx) {
  audioCtx = new AudioContext();
}

const realtimeAnalyzerNode = await createRealTimeBpmProcessor(audioCtx);

if (!mediaElementSource) {
  mediaElementSource = audioCtx.createMediaElementSource(node); // node is a YouTube video tag
}

const { lowpass, highpass } = getBiquadFilters(audioCtx);

mediaElementSource.connect(lowpass).connect(highpass).connect(realtimeAnalyzerNode);
mediaElementSource.connect(audioCtx.destination);

realtimeAnalyzerNode.port.postMessage({
  message: 'ASYNC_CONFIGURATION',
  parameters: {
    continuousAnalysis: true,
    stabilizationTime: 5_000,
   },
});

realtimeAnalyzerNode.port.onmessage = (event) => {
  if (event.data.message === 'BPM') {
    console.log('BPM', event.data.result);
  }
  if (event.data.message === 'BPM_STABLE') {
    console.log('BPM_STABLE', event.data.result);
  }
};

I too have been having issues trying to get real-time & local BPM working, however, all attempts result in what appears to be a default return

https://github.com/dlepaux/realtime-bpm-analyzer/blob/main/src/analyzer.ts#L269-L272

Hi @SM227465 ! I think you create the AudioContext at the wrong moment. You must create it after a user gesture. Meaning that you need to set a button an listen the click event to create it. Otherwise the process is right :)
The same mistake appear to be done with the realtime example you provided.

Hi @gfargo and @SM227465,
Actually there is an issue with the realtime analysis. I'm currently figuring out why the library can't handle properly the input.
It's like there is a difference between ScriptProcessor and AudioWorklet that makes the new process computing BPM a different way (and it should not)... I will keep you updated when the new release is out. Thanks

Thanks for the response @dlepaux!

If I have some time today I'd be happy to lend a set of eyes to help figure out what's going on, if it would be helpful.

Would you recommend using the older version with ScriptProcessor in the meantime?

@gfargo If you can, it would be awesome ! Let me know if you have time or if you have an idea about how to solve that and feel free to make a Pull Request. We can also chat on discord or something if you have questions.
Well if you need to achieve realtime analysis, yes, but scriptProcessor is deprecated as you might know.

Guys I have a good news, I've done a bunch of tests and succeed to get the same results from the v1 and v3. I'm going to update some stuff and I'll let you know when it's updated. :)

Bravo @dlepaux 👏 looking forward to it!!

Hey guys, the release is out with a freshly updated doc. Let me know if you encounter an issue :)
Have a good day