TVOAudioFormat
Objective-C
@interface TVOAudioFormat : NSObject
Swift
class TVOAudioFormat : NSObject
TVOAudioFormat describes audio that is captured or rendered via a TVOAudioDevice. The class also offers
convenience methods to help interoperate with CoreAudio and size your audio buffers appropriately.
-
@brief The number of channels in the audio stream.
@discussion Valid values for this property are either 1 or 2. Only mono and stereo LPCM audio are supported.
Declaration
Objective-C
@property (nonatomic, readonly) size_t numberOfChannels;Swift
var numberOfChannels: Int { get } -
@brief The sample rate of the audio stream in units of frequency (Hz), i.e. the number of audio samples per second.
@discussion Valid values for this property are 8000, 16000, 24000, 32000, 44100 and 48000 Hz.
Declaration
Objective-C
@property (nonatomic, readonly) uint32_t sampleRate;Swift
var sampleRate: UInt32 { get } -
@brief The maximum number of frames contained in a single audio buffer.
@discussion The underlying media engine operates on 20 millisecond slices of LPCM audio. Ideally, your audio device should capture and render in exactly 10 millisecond buffers. However, in many cases this is not possible on iOS. If you’re using AudioUnits to produce or consume audio you should use
AVAudioSession.preferredIOBufferDurationto request appropriately sized buffers.Declaration
Objective-C
@property (nonatomic, readonly) size_t framesPerBuffer;Swift
var framesPerBuffer: Int { get } -
Unavailable
TVOAudioFormat can not be created with init
@brief Developers shouldn’t use init to create
TVOAudioFormat.@discussion Use
initWithChannels:sampleRate:framesPerBuffer:instead.Declaration
Objective-C
- (null_unspecified instancetype)init; -
@brief Initializes an instance of
TVOAudioFormat.@discussion
TVOAudioFormatdescribes signed 16-bit LPCM audio. This is the working format used to interoperate betweenTVOAudioDeviceand the underlying media engine. Please note that the media engine may be forced to perform a format conversion depending on the codecs used for sending and receiving audio. For example, ISAC accepts mono 32 kHz audio while OPUS accepts mono or stereo at 48 kHz.See
TVOAudioCodecDeclaration
Objective-C
- (nullable instancetype)initWithChannels:(size_t)channels sampleRate:(uint32_t)sampleRate framesPerBuffer:(size_t)framesPerBuffer;Swift
init?(channels: Int, sampleRate: UInt32, framesPerBuffer: Int)Parameters
channelsThe number of channels in the audio stream.
sampleRateThe sample rate of the audio stream.
framesPerBufferThe maximum number of frames contained in a single audio stream buffer.
Return Value
An instance of
TVOAudioFormat, which is immutable once created. Returnsnilif one or more parameters passed to the initializer are not supported by the SDK. -
@brief Computes the required buffer size for a given audio format.
@discussion This helper method can be used to size audio buffers appropriately.
Declaration
Objective-C
- (size_t)bufferSize;Swift
func bufferSize() -> IntReturn Value
The required buffer size, in bytes, to work with a given
TVOAudioFormat. -
@brief Generates an audio stream description which can be used with CoreAudio.
@discussion
AudioStreamBasicDescriptioncan be used to describe many different constant bitrate audio formats. SinceTVOAudioFormatdefines only signed 16-bit LPCM audio there is a well known transformation between the two.Declaration
Objective-C
- (AudioStreamBasicDescription)streamDescription;Swift
func streamDescription() -> AudioStreamBasicDescriptionReturn Value
An
AudioStreamBasicDescriptionwhich reflects the properties of theTVOAudioFormatbeing queried.