4

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 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.