Sunshine master
Self-hosted game stream host for Moonlight.
AVAudio Class Reference

Core Audio capture class for macOS audio input and system-wide audio tapping. Provides functionality for both microphone capture via AVFoundation and system-wide audio capture via Core Audio taps (requires macOS 14.0+). More...

#include <src/platform/macos/av_audio.h>

Inheritance diagram for AVAudio:
[legend]
Collaboration diagram for AVAudio:
[legend]

Instance Methods

(void) - cleanupAudioBuffer
 Cleans up and deallocates the audio buffer resources.
 
(void) - cleanupSystemTapContext:
 Cleans up system tap resources in a safe, ordered manner.
 
(OSStatus) - createAggregateDeviceWithTapDescription:sampleRate:frameSize:
 Creates an aggregate device with the specified tap description and audio parameters.
 
(nullable CATapDescription *) - createSystemTapDescriptionForChannels:
 Creates a Core Audio tap description for system audio capture.
 
(void) - initializeAudioBuffer:
 Initializes the circular audio buffer for the specified number of channels.
 
(int) - initializeSystemTapContext:frameSize:channels:
 Initializes the system tap context with specified audio parameters.
 
(int) - setupMicrophone:sampleRate:frameSize:channels:
 Sets up microphone capture using AVFoundation framework.
 
(int) - setupSystemTap:frameSize:channels:
 Sets up system-wide audio tap for capturing all system audio. Requires macOS 14.0+ and appropriate permissions.
 

Class Methods

(nullable AVCaptureDevice *) + findMicrophone:
 Find a specific microphone device by name.
 
(NSArray< NSString * > *) + microphoneNames
 Get names of all available microphone devices.
 
(NSArray< AVCaptureDevice * > *) + microphones
 Get all available microphone devices on the system.
 

Public Attributes

TPCircularBuffer audioSampleBuffer
 Shared circular buffer for both audio capture paths.
 
dispatch_semaphore_t audioSemaphore
 Real-time safe semaphore for signaling audio sample availability.
 

Properties

AVCaptureSession * audioCaptureSession
 AVFoundation capture session for microphone input.
 
AVCaptureConnection * audioConnection
 Audio connection within the capture session.
 
BOOL hostAudioEnabled
 Whether host audio playback should be enabled (affects tap mute behavior)
 

Detailed Description

Core Audio capture class for macOS audio input and system-wide audio tapping. Provides functionality for both microphone capture via AVFoundation and system-wide audio capture via Core Audio taps (requires macOS 14.0+).

Method Documentation

◆ cleanupSystemTapContext:

- (void) cleanupSystemTapContext: (nullable id) tapDescription

Cleans up system tap resources in a safe, ordered manner.

Parameters
tapDescriptionOptional tap description object to release (can be nil)

◆ createAggregateDeviceWithTapDescription:sampleRate:frameSize:

- (OSStatus) createAggregateDeviceWithTapDescription: (CATapDescription *) tapDescription
sampleRate: (UInt32) sampleRate
frameSize: (UInt32) frameSize 

Creates an aggregate device with the specified tap description and audio parameters.

Parameters
tapDescriptionCore Audio tap description for system audio capture
sampleRateTarget sample rate in Hz
frameSizeNumber of frames per buffer
Returns
OSStatus indicating success (noErr) or error code

◆ createSystemTapDescriptionForChannels:

- (CATapDescription *) createSystemTapDescriptionForChannels: (UInt8) channels

Creates a Core Audio tap description for system audio capture.

Parameters
channelsNumber of audio channels to configure the tap for
Returns
CATapDescription object on success, nil on failure

◆ findMicrophone:

+ (nullable AVCaptureDevice *) findMicrophone: (nullable NSString *) name

Find a specific microphone device by name.

Parameters
nameThe name of the microphone to find (nullable - will return nil if name is nil)
Returns
AVCaptureDevice object if found, nil otherwise

◆ initializeAudioBuffer:

- (void) initializeAudioBuffer: (UInt8) channels

Initializes the circular audio buffer for the specified number of channels.

Parameters
channelsNumber of audio channels to configure the buffer for

◆ initializeSystemTapContext:frameSize:channels:

- (int) initializeSystemTapContext: (UInt32) sampleRate
frameSize: (UInt32) frameSize
channels: (UInt8) channels 

Initializes the system tap context with specified audio parameters.

Parameters
sampleRateTarget sample rate in Hz
frameSizeNumber of frames per buffer
channelsNumber of audio channels
Returns
0 on success, -1 on failure

◆ microphoneNames

+ (NSArray< NSString * > *) microphoneNames

Get names of all available microphone devices.

Returns
Array of NSString objects with microphone device names

◆ microphones

+ (NSArray< AVCaptureDevice * > *) microphones

Get all available microphone devices on the system.

Returns
Array of AVCaptureDevice objects representing available microphones

◆ setupMicrophone:sampleRate:frameSize:channels:

- (int) setupMicrophone: (nullable AVCaptureDevice *) device
sampleRate: (UInt32) sampleRate
frameSize: (UInt32) frameSize
channels: (UInt8) channels 

Sets up microphone capture using AVFoundation framework.

Parameters
deviceThe AVCaptureDevice to use for audio input (nullable - will return error if nil)
sampleRateTarget sample rate in Hz
frameSizeNumber of frames per buffer
channelsNumber of audio channels (1=mono, 2=stereo)
Returns
0 on success, -1 on failure

◆ setupSystemTap:frameSize:channels:

- (int) setupSystemTap: (UInt32) sampleRate
frameSize: (UInt32) frameSize
channels: (UInt8) channels 

Sets up system-wide audio tap for capturing all system audio. Requires macOS 14.0+ and appropriate permissions.

Parameters
sampleRateTarget sample rate in Hz
frameSizeNumber of frames per buffer
channelsNumber of audio channels
Returns
0 on success, -1 on failure

The documentation for this class was generated from the following files: