将音乐文件分割成块
您将如何将音乐文件(最好是 mp3)分割成块?
我正在使用 SDL_mixer API。里面可能有一些有用的功能,但我找不到。
目的是对每个块使用 FFT 以获得可视化中使用的频率。
How would you go about splitting a music file (preferably mp3) into chunks?
I am using the SDL_mixer API. There may be some useful functions in there but I couldn't find any.
The purpose is to use FFT on each chunk to get the frequencies to use in visualization.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在发现 SDL_mixer 库不会给你你想要的东西。它对“音乐”(MP3) 的支持从混音器外部播放文件,因此除了 API 提供的音量和位置控制之外,您无法将自己插入到其音频流中。
如果您使用
Mix_Chunk
对象来利用通道混音器,则可以使用Mix_RegisterEffect
将自己添加为流式传输音乐的通道上的效果。如果您想可视化块的最终混合而不是单个通道或多个通道,您可以自己插入的另一个位置是在混合之后,使用Mix_SetPostMix
。然而,这些块最适合短声音,因为它们完全加载到内存中而不是流式传输 - 并且它们当前不支持 MP3。如果您决心使用 SDL,请考虑使用 SDL_sound 来完成此任务。这是 SDL 的另一个扩展,它只处理文件的解码。当您使用
Sound_Decode
时,它会一次向您提供一块数据。然后,您可以使用Mix_HookMusic
将解码后的数据传递到混音器,以保持类似流的方法。或者,如果您想利用混音器和效果函数,您甚至可以使用Sound_DecodeAll
加载整个文件,并直接填充Mix_Chunk
,但代价是流式传输。需要注意的事项:
Sound_SetBufferSize
来简化此问题。I see now that the SDL_mixer library isn't going to give you what you want. Its support for "music" (MP3) plays the file externally from the mixer, so apart from volume and position controls that the API provides, you can't insert yourself into its audio stream.
If you were using
Mix_Chunk
objects instead to take advantage of the channel mixer, you would be able to add yourself as an effect on the channel that's streaming the music, usingMix_RegisterEffect
. Another place you could insert yourself is after the mix, usingMix_SetPostMix
, if you wanted to visualize the final mix of chunks instead of an individual channel or channels. However, those chunks are best suited for short sounds, as they are loaded entirely into memory rather than streamed – and they don't currently support MP3.If you're committed to using SDL, consider using SDL_sound for this task. This is another extension to SDL, which handles just the decoding of files. It hands you data a chunk at a time when you use
Sound_Decode
. You can then take the decoded data and pass it to the mixer by usingMix_HookMusic
to keep a stream-like approach. Or, you could even load the whole file withSound_DecodeAll
, and fill in aMix_Chunk
directly, if you want to take advantage of the mixer and effect functions, at the expense of streaming.Things to watch out for:
Sound_SetBufferSize
to simplify this problem.