Normalize Audio File obj-c

僤鯓⒐⒋嵵緔 提交于 2019-12-12 09:46:17

问题


Is there a library function to normalize a sound file? I have searched around but could not find any.

I would like to be able to normalize a sound file and setting that into the sound file so it only needs to be done once rather than on the fly.

Can this be done with Core-Audio?


回答1:


Yes it can be done, but not with a single function call.

The functionality you want is not in fact CoreAudio, but rather in ExtendedAudioFile.h - part of the AudioToolbox framework. This is available for both iOS and MacOSX. I can attest for this being rather hard to find.

Functions of interest in this header are ExtAudioFileOpenURL(), ExtAudioFileRead() and ExtAudioFileWrite().

In outline what you do:

  1. Use ExtAudioFileOpenURL() to open the input file
  2. Use ExtAudioFileGetProperty() with propertyId kExtAudioFileProperty_FileDataFormat to obtain an AudioStreamBasicDescription describing the file.

  3. Possibly set the ASBD to get the format you want. AudioToolBox on MacOSX seems rather more amenable to this than on iOS.

  4. Calculate an allocate a buffer large enough to hold the entire audio file

  5. Read the entire file with ExtAudioFileRead() - NB: this call might not read it all in one go - operating in much the same was as POSIX read()

  6. Perform normalisation

  7. Use ExtAudioFileCreateWithURL() to create the output file
  8. Use ExtAudioFileWrite() to write the normalised samples out.
  9. Dispose of both audio files.

The documentation links to several example projects that can act as donors of working code. You'll find doing normalisation much easier with the samples as floats, but in iOS, I could never get the conversion to work automatically, so you might have to format convert yourself.



来源:https://stackoverflow.com/questions/14327091/normalize-audio-file-obj-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!