Contents

channelData(_:)

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

Declaration

func channelData(_ index: Int) -> AVAudioPCMBuffer.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 read-only 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):
        // Read Float32 data
        for frame in 0..<samples.count {
            let value = samples[frame]
        }
    case .int16(let samples):
        // Read Int16 data
    case .int32(let samples):
        // Read Int32 data
    }
}

See Also

Accessing PCM Buffer Data