オーディオレコーダーを使用して記録するために準備するには:
-
サウンドファイルのURLを指定してください。
-
オーディオセッションを設定します。
-
オーディオレコーダーの初期状態を設定します。
オーディオユニット |
説明 |
iPodのイコライザーユニット |
タイプのiPodのEQユニット、 kAudioUnitSubType_AUiPodEQは、 アプリケーションで使用できる簡単な、プリセットベースのイコライザーが用意されています。このオーディオユニットを使用する方法のデモでは、サンプルコードプロジェクトを参照 iPhoneMixerEQGraphTestを 。 |
3Dミキサーユニット |
タイプの3Dミキサーユニット、 kAudioUnitSubType_AU3DMixerEmbeddedは、 あなたが、複数のオーディオストリームをミックスステレオ出力パンを指定して、再生速度を操作して、より多くのことができます。OpenALのは、このオーディオユニットの上に構築され、ゲームアプリケーションに適してより高いレベルのAPIを提供しています。 |
マルチチャンネルミキサーユニット |
The Multichannel Mixer unit, of type kAudioUnitSubType_- MultiChannelMixer, lets you mix multiple mono or stereo audio streams to a single stereo stream. It also supports left/right panning for each input. For a demonstration of how to use this audio unit, see the sample code project Audio Mixer (MixerHost) . |
Remote I/O unit |
The Remote I/O unit, of type kAudioUnitSubType_RemoteIO, connects to audio input and output hardware and supports realtime I/O. For demonstrations of how to use this audio unit, see the sample code project aurioTouch . |
Voice Processing I/O unit |
The Voice Processing I/O unit, of type kAudioUnitSubType_- VoiceProcessingIO, has the characteristics of the I/O unit and adds echo suppression and other features for two-way communication. |
Generic Output unit |
The Generic Output unit, of type kAudioUnitSubType_- GenericOutput, supports converting to and from linear PCM format; can be used to start and stop a graph. |
Converter unit |
The Converter unit, of type kAudioUnitSubType_AUConverter, lets you convert audio data from one format to another. You typically obtain the features of this audio unit by using the Remote I/O unit, which incorporates a Converter unit. |
Tip |
Action |
Use compressed audio appropriately |
For AAC, MP3, and ALAC (Apple Lossless) audio, decoding can take place using hardware-assisted codecs. While efficient, this is limited to one audio stream at a time. If you need to play multiple sounds simultaneously, store those sounds using the IMA4 (compressed) or linear PCM (uncompressed) format. |
Convert to the data format and file format you need |
The afconvert tool in Mac OS X lets you convert to a wide range of audio data formats and file types. See “Preferred Audio Formats in iOS” (page 28) and the afconvert man page. |
Evaluate audio memory issues |
When playing sound with Audio Queue Services, you write a callback that sends short segments of audio data to audio queue buffers. In some cases, loading an entire sound file to memory for playback, which minimizes disk access, is best. In other cases, loading just enough data at a time to keep the buffers full is best. Test and evaluate which strategy works best for your application. |
Reduce audio file sizes by limiting sample rates, bit depths, and channels |
Sample rate and the number of bits per sample have a direct impact on the size of your audio files. If you need to play many such sounds, or long-duration sounds, consider reducing these values to reduce the memory footprint of the audio data. For example, rather than use 44.1 kHz sampling rate for sound effects, you could use a 32 kHz (or possibly lower) sample rate and still provide reasonable quality. Using monophonic (single-channel) audio instead of stereo (two channel) reduces file size. For each sound asset, consider whether mono could suit your needs. |
Pick the appropriate technology |
Use OpenAL when you want a convenient, high-level interface for positioning sounds in a stereo field or when you need low latency playback. To parse audio packets from a file or a network stream, use Audio File Stream Services. For simple playback of single or multiple sounds, use the AVAudioPlayer class. For recording to a file, use the AVAudioRecorder class. For audio chat, use the Voice Processing I/O unit. To play audio resources synced from a user’s iTunes library, use iPod Library Access. When your sole audio need is to play alerts and user-interface sound effects, use Core Audio’s System Sound Services. For other audio applications, including playback of streamed audio, precise synchronization, and access to packets of incoming audio, use Audio Queue Services. |
Code for low latency
|
For the lowest possible playback latency, use OpenAL or use the I/O unit directly.
|
An audio session comes with some default behavior. Specifically:
- Playback is enabled and recording is disabled.
- When the user moves the Silent switch (or Ring/Silent switch on iPhone) to the “silent” position, your audio is silenced.
- When the user presses the Sleep/Wake button to lock the screen, or when the Auto-Lock period expires, your audio is silenced.
- When your audio starts, other audio on the device—such as iPod audio that was already playing—is silenced.
- A VoIP app, which spends most of its time running in the background, should ensure that its audio session is active only while the app is handling a call. In the background, standing ready to receive a call, a VoIP app’s audio session should not be active.
- An app using the “recording” category should ensure that its audio session is active only while recording. Before recording starts and when recording stops, ensure your session is inactive to allow other sounds, such as incoming message alerts, to play. Alternatively, if your recording app also provides playback, you could switch to a playback category when not recording. This also allows alert sounds to play.
- Three for playback
- One for recording
- One that supports playback and recording—that need not occur simultaneously
- One for offline audio processing
- AV Foundation framework : The system automatically pauses playback or recording upon interruption, and reactivates your audio session when you resume playback or recording.
- Audio Queue Services, I/O audio unit : You are responsible for saving playback or recording position and reactivating your audio session after interruption ends
- OpenAL: implement the AVAudioSession interruption delegate methods or write an interruption listener callback function—as when using Audio Queue Services. However, the delegate or callback must additionally manage the OpenAL context.
To obtain meaningful values for hardware characteristics, ensure that the audio session is initialized and active before you issue queries.
kAudioSessionProperty_AudioInputAvailable
Whether audio input is available on the device. Use this property to determine if audio recording is possible.
あなたは、独自のオーディオセッションを使用するには、ムービープレーヤーを設定している場合は、実行するためのいくつかのクリーンアップがあります。映画が終了、またはユーザーがそれを退けた後、オーディオを再生する能力を取り戻すために、順番に、これらの2つの手順を実行します。
-
後でもう一度同じムービーを再生する場合は、ムービーでもプレイヤー-廃棄してください。
-
お使いのオーディオセッションをアクティブにします。
#if TARGET_IPHONE_SIMULATOR
#warning *** Simulator mode: audio session code works only on a device
// Execute subset of code that works in the Simulator
#else
// Execute device-only code as well as the other code
ます。https://my.oschina.net/dake/blog/196792で再現