Contents

channelData(_:)

Returns read-only access to a specific channel’s data.

Declaration

func channelData(_ index: Int) -> AVReadOnlyAudioPCMBuffer.ChannelData

Parameters

  • index:

    The zero-based channel index.

Return Value

A ChannelData enum containing the channel’s sample data.

Discussion

The returned ChannelData is tied to the lifetime of this buffer and provides type-safe access to the channel’s sample data.

  • Example:

for channelIndex in 0..<Int(buffer.format.channelCount) {
    let channelData = buffer.channelData(channelIndex)
    switch channelData {
    case .float(let samples):
        // Process Float32 data
        for frame in 0..<samples.count {
            let value = samples[frame]
        }
    case .int16(let samples):
        // Process Int16 data
    case .int32(let samples):
        // Process Int32 data
    }
}

See Also

Accessing channel data