audio_ios.h
Audio in and out on iOS and iPadOS, through RemoteIO.
#include <sonore/audio_ios.h>- 3types
- 17other declarations
- Guides: Platforms and formats
On this page
Design notes
iOS has one audio unit that is the hardware: RemoteIO, whose bus 0 plays and whose bus 1 records. It runs under the app's AVAudioSession, which says what kind of audio app this is (playback, or play-and-record), asks for a rate and a buffer, and is where the system says the route changed or a phone call took the audio away. The two classes here are the standalone's PlatformAudio and PlatformAudioInput on iOS, the same surface every other backend offers (scripts/backend-surface.mjs checks it), over ONE RemoteIO unit both share (RemoteIo below) -- an app with two would have two clocks.
What iOS does differently:
- No device list. The route is the system's: the speaker, headphones, a USB or Lightning interface, AirPods. RemoteIO follows it by itself.
- The rate is the session's. 48 kHz is asked for and usually given; the DSP is prepared at whatever came. The buffer asked for is 5 ms.
- Recording needs the user's permission and a usage string in the app's Info.plist (NSMicrophoneUsageDescription; sonore_add_standalone writes one). The input opens only when RemoteIo was opened with it, which the app does once the permission is granted.
- An interruption -- a call, an alarm, Siri -- stops the unit. When it ends the session is made active again and the unit restarted. Media services being reset (rare, and drastic) is reported as a lost device, so the app reopens everything.
Written against the Objective-C runtime for the session and the C AudioComponent API for the unit, like every Apple file here.
Types 3
The one RemoteIO unit, its render callback, and the session around it. Opened by IosAudioOutput; IosAudioInput reads what its bus 1 records.
The system output on iOS: RemoteIO's bus 0.
The system input on iOS: what RemoteIO's bus 1 records, into a ring.
Functions 11
- fn
template <typename Ret, typename... Args> inline Ret send(id target, const char* selector, Args... args)standalone::iosaudio::send · audio_ios.h:59 - fn
inline id session()The AVAudioSession, or nil where AVFAudio is not loaded.standalone::iosaudio::session · audio_ios.h:65 - fn
inline id constant(const char* symbol)One of AVFAudio's NSString constants, by its symbol.standalone::iosaudio::constant · audio_ios.h:71 - fn
inline std::string utf8(id s)standalone::iosaudio::utf8 · audio_ios.h:76 - fn
inline bool configure(bool record, std::string* error)The session as this app wants it: play, or play and record; 48 kHz and a 5 ms buffer if the hardware will; active.standalone::iosaudio::configure · audio_ios.h:93 - fn
inline double sampleRate()standalone::iosaudio::sampleRate · audio_ios.h:120 - fn
inline Permission recordPermission()standalone::iosaudio::recordPermission · audio_ios.h:129 - fn
inline std::atomic<int>& permissionAnswer()The user's answer, from the system dialog: written by the block, read on the main thread's next look.standalone::iosaudio::permissionAnswer · audio_ios.h:140 - fn
inline void permissionAnswered(void*, BOOL granted)standalone::iosaudio::permissionAnswered · audio_ios.h:146 - fn
inline void requestRecordPermission()Ask for the microphone. The dialog shows once per install; the answer arrives on another thread, in permissionAnswer().standalone::iosaudio::requestRecordPermission · audio_ios.h:150 - fn
inline bool outputIsPrivate()Whether the sound goes where only the user hears it -- headphones, wired or Bluetooth, an interface's outputs -- rather than the built-in speaker, where the microphone would hear it too. AVAudioSessionPortDescription.portType.standalone::iosaudio::outputIsPrivate · audio_ios.h:162
Aliases 1
Enums 1
- enum
enum class PermissionAVAudioSessionRecordPermission: undetermined, denied, granted.standalone::iosaudio::Permission · audio_ios.h:127
Constants 4
- const
kOptionMixWithOthers = 0x1AVAudioSessionCategoryOptions.standalone::iosaudio::kOptionMixWithOthers · audio_ios.h:85 - const
kOptionDefaultToSpeaker = 0x8AVAudioSessionCategoryOptions.standalone::iosaudio::kOptionDefaultToSpeaker · audio_ios.h:86 - const
kOptionAllowBluetoothA2DP = 0x20AVAudioSessionCategoryOptions.standalone::iosaudio::kOptionAllowBluetoothA2DP · audio_ios.h:87 - const
kOptionAllowAirPlay = 0x40AVAudioSessionCategoryOptions.standalone::iosaudio::kOptionAllowAirPlay · audio_ios.h:88