L4. LAB 4: IPHONE AUDIO SIGNAL SAMPLIN 73
e code that is executed is called from the main.m file. It returns the app main in an
autoreleasepool, i.e., it handles the auto releasing of memory variables.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "IosAudioController.h"
int main(int argc, char * argv[]) {
iosAudio = [[IosAudioController alloc] init];
@autoreleasepool {
return UIApplicationMain(
argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
It calls on AppDelegate first to handle the app.
L4.3 RECORDING
e API that supplies the audio recording capability is part of the AudioToolbox. It can be
included within a file using the instruction #import. To specify the audio format to be used by
the app, an instance of AudioStreamBasicDescription needs to be created. is specifies the
audio data to be processed.
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = 44100.0;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags =( kAudioFormatFlagIsSignedInteger |
kAudioFormatFlagIsPacked);
audioFormat.mFramesPerPacket = 1;
audioFormat.mChannelsPerFrame = 1;
audioFormat.mBitsPerChannel = 16;
audioFormat.mBytesPerPacket = 2;
audioFormat.mBytesPerFrame = 2;
e above specifications indicate to the device that the audio data being handled has a sampling
rate of 44.1 KHz, is linear PCM, and is packed in the form of 16 bit integers. e audio is mono
with only one frame per packet. e frame size is not determined here because the hardware
determines the size of the frame at runtime.
is description is used to initialize the Audio Unit that will handle the audio i/o. e
audio data is handled by a separate C function called a callback which is shown as follows.