使用JavaScript检测音频输入的bpm? [英] Detecting bpm of audio input using javascript?

查看:80
本文介绍了使用JavaScript检测音频输入的bpm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将音频输入+ beatdetektor示例放在一起,以便可以计算通过线路(甚至是麦克风输入)播放的曲目的BPM.

不幸的是,我不完全了解应该如何使用"process"方法中的"time"参数(特别是在那种情况下,我不一定知道轨迹何时改变,等等)./p>

以下是我使用可爱的p5.js库试图解决此难题的一些代码,请让我知道如何进行调整以达到所需的效果.

 < script src ="js/p5-zip/p5.js"></script>< script src ="js/p5-zip/addons/p5.sound.js"></script>< script src ="js/beatdetektor-master/beatdetektor.js"></script>< script>//beatdetektor的东西bd_med =新的BeatDetektor(85,169);vu =新的BeatDetektor.modules.vis.VU();kick_det =新的BeatDetektor.modules.vis.BassKick();//p5的东西mic = new p5.AudioIn();mic.start();fft =新的p5.FFT();fft.setInput(mic);funk = function(){频谱= fft.analyze();bd_med.process((新日期).getTime(),频谱)}//分析60帧,我们可以在此处使用requestAnimationFramesetInterval(funk,1000/60)</script> 

解决方案

根据此处是使用 process()函数来模拟一首歌曲的30秒.

看起来您将不得不跟踪歌曲的开始时间,然后计算调用 process()函数时经过了多少时间.处理中有一个方便的 millis() 函数,可能对您有帮助

I'm trying to put together an audio input + beatdetektor example so I could calculate the BPM of a track playing through my line in ( or even microphone input ).

Unfortunately, I didn't understand exactly how the "time" parameter from the "process" method is supposed to be used ( specially in that case, where I don't necessarily know when the track changes, etc ).

Here is some code I put together trying to solve this puzzle using the lovely p5.js library, please let me know how I could tweak this to achieve the desired effect.

<script src="js/p5-zip/p5.js"></script>
<script src="js/p5-zip/addons/p5.sound.js"></script>

<script src="js/beatdetektor-master/beatdetektor.js"></script>

<script>

  // beatdetektor stuff

  bd_med = new BeatDetektor(85,169);

  vu = new BeatDetektor.modules.vis.VU();
  kick_det = new BeatDetektor.modules.vis.BassKick();

  // p5 stuff
  mic = new p5.AudioIn();
  mic.start();
  fft = new p5.FFT();
  fft.setInput(mic);

  funk = function(){
    spectrum = fft.analyze();

    bd_med.process( (new Date).getTime(), spectrum)
  }

  // analyse with 60 frames, we could maybe use requestAnimationFrame here
  setInterval( funk, 1000/60 )

</script>

解决方案

According to the documentation on the BeatDetektor library, the process() function takes an argument in seconds.

My guess would be that the argument is the seconds since the start of the song, not an absolute date. Right now you're passing in the number of milliseconds since 1970. I don't know of any songs that are that long.

Here is an example of using the process() function to simulate 30 seconds of a song.

It looks like you're going to have to keep track of the start time of the song, then calculate how much time has passed when calling the process() function. Processing has a handy millis() function that might help you out.

这篇关于使用JavaScript检测音频输入的bpm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆