So far we've covered creating and processing audio, but what if you want to do something with the microphone/device audio input, or take the audio coming from your app and do something with it?
The Amazing Audio Engine supports receiving audio from a number of sources:
To begin receiving audio, you can either create an Objective-C class that implements the AEAudioReceiver protocol:
...or you can use the AEBlockAudioReceiver class to specify a block to receive audio:
In both cases, your callback or block will be passed:
Then, add the receiver to the source of your choice:
For some applications it might be necessary to provide audio monitoring, where the audio coming in through the microphone or other device audio input is played out of the speaker.
The AEPlaythroughChannel located within the "Modules" directory takes care of this. This class implements both the AEAudioPlayable and the AEAudioReceiver protocols, so that it acts as both an audio receiver and an audio source.
To use it, initialize it then add it as an input receiver using AEAudioController's addInputReceiver: and add it as a channel using addChannels: .
Included within the "Modules" directory is the AERecorder class, which implements the AEAudioReceiver protocol and provides simple but sophisticated audio recording.
To use AERecorder, initialize it using initWithAudioController: .
Then, when you're ready to begin recording, use beginRecordingToFileAtPath:fileType:error: , passing in the path to the file you'd like to record to, and the file type to use. Common file types include kAudioFileAIFFType
, kAudioFileWAVEType
, kAudioFileM4AType
(using AAC audio encoding), and kAudioFileCAFType
.
Finally, add the AERecorder instance as a receiver using the methods listed above.
Note that you can add the instance as a receiver of more than one source, and these will be mixed together automatically.
For example, you might have a karaoke app with a record function, and you want to record both the backing music and the microphone audio at the same time:
To complete the recording, call finishRecording.
The Amazing Audio Engine provides the ability to select a set of input channels when a multi-channel input device is connected.
You can assign an array of NSIntegers to the inputChannelSelection property of AEAudioController in order to select which channels of the input device should be used.
For example, for a four-channel input device, the following will select the last two channels as a stereo stream:
You can also assign audio input receivers or filters for different selections of channels. For example, you can have one AEAudioReceiver object receiving from the first channel of a stereo input device, and a different object receiving from the second channel.
Use the addInputReceiver:forChannels: and addInputFilter:forChannels: methods to do this:
Note that the numberOfInputChannels property is key-value observable, so you can use this to be notified when to display appopriate UI, etc.
Next, read on to find out how to interact with other audio apps, sending, receiving or filtering audio with Audiobus.