Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Help to find BPM #55

Closed
SM227465 opened this issue Jun 11, 2023 · 8 comments
Closed

Need Help to find BPM #55

SM227465 opened this issue Jun 11, 2023 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@SM227465
Copy link

SM227465 commented Jun 11, 2023

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);
  }
};
@gfargo
Copy link

gfargo commented Jun 21, 2023

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

@dlepaux
Copy link
Owner

dlepaux commented Jun 21, 2023

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.

@dlepaux
Copy link
Owner

dlepaux commented Jun 21, 2023

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

@dlepaux dlepaux changed the title Need Help to find BMP Need Help to find BPM Jun 21, 2023
@dlepaux dlepaux added the help wanted Extra attention is needed label Jun 21, 2023
@gfargo
Copy link

gfargo commented Jun 21, 2023

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?

@dlepaux
Copy link
Owner

dlepaux commented Jun 21, 2023

@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.

@dlepaux
Copy link
Owner

dlepaux commented Jun 22, 2023

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. :)

@gfargo
Copy link

gfargo commented Jun 22, 2023

Bravo @dlepaux 👏 looking forward to it!!

@dlepaux
Copy link
Owner

dlepaux commented Jun 24, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants