开发者

How can I quickly loop through chunks of audio and determine their sample values (amplitude/power level/etc) in Core Audio?

What I'm trying to accomplish is basically as follows:

  1. Open up a file, determine how many 'samples' I will need based on its duration
  2. Dividing the file up into x samples; determine the (average) power level / amplitude for each sample.
  3. Using these sample values, proceed with drawing a waveform that represents the audio (following these guidelines, perhaps)

I have s开发者_StackOverflow社区pent 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜