提前分析声音 - Actionscript

发布于 2024-12-09 11:30:52 字数 113 浏览 0 评论 0原文

我想创建一个游戏,可以在现场播放之前几秒钟分析 mp3。基本想法类似于吉他英雄,你可以看到“音品”到来并做好准备,然后他们敲击并与歌曲实时同步。

有没有办法提前分析声音文件,或分析静音的声音文件?

I would like to create a game that would analyze an mp3 a few seconds ahead of where it is playing live. A basic idea would be similar to guitar hero, the 'frets' you can see coming and prepare, then they hit and sync with the song in real time.

Is there a way to analyze a Sound file ahead of time, or analyze a muted Sound file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您可以使用 Sound.extract() 访问底层音频数据。您还可以通过向 Sound 对象添加 SampleDataEvent 侦听器来动态地将样本提供给 Sound 对象,并在不为其提供 mp3 的情况下播放它。

所以基本上这个过程通常是这样的:

  1. 将 mp3 加载到 Sound 对象中。
  2. 将其部分或全部示例数据提取到 ByteArray 中,以便您可以分析/修改它。根据您需要执行的操作,您可以一次提取足够的内容,以保持输出超出您想要的数量。
  3. 创建第二个 Sound 对象用于输出 - 不要为该对象提供 mp3。为 SampleDataEvents 添加一个侦听器,然后播放它。由于需要更多音频,它将定期调度 SampleDataEvents(一次需要 2048、4096 或 8192 个样本,44100 相当于一秒)。每次获取 SampleDataEvent 时,都可以使用您希望接下来播放的样本填充其数据 ByteArray 属性。

虽然我不明白你到底想做什么,但听起来你会让你的提取过程在播放过程之前进行几秒钟 - 提取到缓冲区 ByteArray,进行分析,然后复制每次输出 Sound 请求更多样本时,都会从缓冲区 BA 的开头开始采样。

You can get access to the underlying audio data with Sound.extract(). You can also feed samples to a Sound object dynamically by adding a SampleDataEvent listener to it and playing it without providing it with an mp3.

So essentially the process usually looks like this:

  1. Load an mp3 into a Sound object.
  2. Extract some or all of its sample data into a ByteArray so that you can analyze/modify it. Depending on what you need to do, you may just extract enough at a time to keep ahead of the output by the amount you want.
  3. Create a second Sound object for output - don't provide this one with an mp3. Add a listener to it for SampleDataEvents and then play it. It will dispatch SampleDataEvents regularly as it needs more audio (it takes 2048, 4096, or 8192 samples at a time, 44100 being one second's worth). Each time you get a SampleDataEvent, you populate its data ByteArray property with the samples you want it to play next.

While I don't understand exactly what it is you're trying to do, it sounds like you'd keep your extraction process going a couple seconds ahead of your playback process - extracting to a buffer ByteArray, doing your analysis, and then copying samples from the beginning of that buffer BA every time the output Sound requests more samples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文