Audio Queue: 适合stream…支持多路回放
To prepare for recording using an audio recorder:
-
Specify a sound file URL.
-
Set up the audio session.
-
Configure the audio recorder’s initial state.
storage.
Audio unit |
Description |
iPod Equalizer unit |
The iPod EQ unit, of type kAudioUnitSubType_AUiPodEQ, provides a simple, |
3D Mixer unit |
The 3D Mixer unit, of type kAudioUnitSubType_AU3DMixerEmbedded, lets |
Multichannel Mixer unit |
The Multichannel Mixer unit, of type kAudioUnitSubType_- MultiChannelMixer, lets |
Remote I/O unit |
The Remote I/O unit, of type kAudioUnitSubType_RemoteIO, connects to |
Voice Processing I/O unit |
The Voice Processing I/O unit, of type kAudioUnitSubType_- VoiceProcessingIO, has |
Generic Output unit |
The Generic Output unit, of type kAudioUnitSubType_- GenericOutput, supports |
Converter unit |
The Converter unit, of type kAudioUnitSubType_AUConverter, lets you |
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 |
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 |
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 |
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 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 |
Code for low latency
|
For the lowest possible playback latency, use OpenAL or use the I/O unit directly.
|
四. Audio Session
of a playback application. This sample also demonstrates coordination between application audio and iPod audio.
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.
happen when a competing audio session from a built-in application activates and that session is not categorized by the system to mix with yours.
- 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.
other words, a change in audio session category is considered by the system—in this context—to be a route change, and will invoke a route change property listener callback.
along with the kAudioSessionProperty_PreferredHardwareSampleRate kAudioSessionProperty_PreferredHardwareIOBufferDuration
you establish hardware preferences, activate the audio session and then query it to obtain the actual values. This final step is important because the system may not be able to provide what you ask for.
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.
value to NO
If you have configured a movie player to use its own audio session, there’s some cleanup to perform. After a movie finishes, or the user dismisses it, do these two steps, in sequence, to regain the ability
to play audio:
-
Dispose of the movie player—even if you intend to play the same movie again later.
-
Reactivate your audio session.
#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