如何快速循环音频块并确定 Core Audio 中的样本值(幅度/功率级别/等)?
我想要完成的基本上如下:
- 打开一个文件,根据其持续时间确定我需要多少个“样本”
- 将文件分成x个样本;确定每个样本的(平均)功率水平/幅度。
- 使用这些样本值,继续绘制代表音频的波形(遵循这些指南,也许)
我花了大约三天的时间,仔细搜索在线论坛、书籍和API,但没有结果。我卡在最关键的一步了->确定音频块(缓冲区)的功率级别。
读完大部分即将出版的核心音频书后,我已经习惯了低AudioQueues、音频单元以及某种程度上的 OpenAL 级环境。然而,我看到的所有示例和解释(在本书和网络上的其他地方)都涉及在播放或录制音频文件时(即实时)确定功率电平值。
然而,我的目的是快速有效地确定磁盘上给定文件的这些值,而无需实时播放它。任何关于我需要查看哪些库、函数的指导将不胜感激。
谢谢。
What I'm trying to accomplish is basically as follows:
- Open up a file, determine how many 'samples' I will need based on its duration
- Dividing the file up into x samples; determine the (average) power level / amplitude for each sample.
- Using these sample values, proceed with drawing a waveform that represents the audio (following these guidelines, perhaps)
I have spent about three days, meticulously searching through online forums, books and APIs with no avail. I'm stuck at the most crucial step -> determining the power level for a chunk (buffer) of audio.
Having read through most of the upcoming Core Audio book, I've become comfortable with the low-level environment of AudioQueues, Audio Units, and to some extent - OpenAL. However, all of the examples and explanations I have seen (in this book and elsewhere on the web) all deal with determining power level values either while an audio file is being played or recorded (ie. in real time).
My purpose, however, is to quickly and efficiently determine these values of a given file on disk without having to play it back in real time. Any guidance towards which libraries, functions I need to be looking at would be greatly appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几种方法可以实现这一目标。您可以将整个文件读入内存,然后应用分析。或者读取文件的块并使用 AudioFile.h 中的 AudioFileReadPackets(...) 获取每个块的平均级别。
There are a few ways you can achieve this. You could read the whole file into memory and then apply the analysis. Or read chunks of the file and get the average level for each chunk using AudioFileReadPackets(...) in AudioFile.h.
你卡在哪一部分了?我还没有尝试过读取或写入文件,所以其他人可以在这方面帮助您。但就实际处理音频流而言,您将需要使用加速框架。其中包含用于获取所需数据的函数。为了获得功率电平,我不确定是否需要先对信号进行 FFT。
如果您这样做,我已经写了一个冗长的答案 使用 Apple FFT和加速框架,了解如何使用加速框架进行 FFT。
我记得查看了函数列表——其中有用于查找信号峰值功率和平均功率的函数。您可能希望将音频信号作为一堆浮点数读取,以便使用这些函数。
Which part are you stuck on? I haven't yet played around with reading or writing to file, so someone else can help you with that aspect. But in terms of actually processing the audio stream you will want to use accelerate framework. This contains functions for getting the data you need. For getting the power level, I'm not sure if you need to FFT the signal first.
If you do, I have written a lengthy answer Using the Apple FFT and Accelerate Framework on how to do FFT with the accelerate framework.
I remember looking through the list of functions -- there are functions for finding peak and average power in a signal. You would probably want to read in your audio signal as a bunch of floats in order to make use of these functions.