---
title: "channelData(_:)"
framework: avfaudio
role: symbol
role_heading: Instance Method
path: "avfaudio/avaudiopcmbuffer/channeldata(_:)"
---

# channelData(_:)

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

## Declaration

```swift
func channelData(_ index: Int) -> AVAudioPCMBuffer.ChannelData
```

## Parameters

- `index`: The zero-based channel index.

## Return Value

Return Value A ChannelData enum containing the channel’s sample data.

## Discussion

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: warning: This function cannot enforce exclusivity at compile time because AVAudioPCMBuffer is an Objective-C class. The caller must ensure proper synchronization when accessing the buffer concurrently or when the buffer might be modified. note: Provides access to valid data only (up to frameLength). 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

- [mutableChannelData(_:)](avfaudio/avaudiopcmbuffer/mutablechanneldata(_:).md)
- [withUnsafeAudioBufferList(_:)](avfaudio/avaudiopcmbuffer/withunsafeaudiobufferlist(_:).md)
- [floatChannelData](avfaudio/avaudiopcmbuffer/floatchanneldata.md)
- [frameCapacity](avfaudio/avaudiopcmbuffer/framecapacity.md)
- [int16ChannelData](avfaudio/avaudiopcmbuffer/int16channeldata.md)
- [int32ChannelData](avfaudio/avaudiopcmbuffer/int32channeldata.md)
- [stride](avfaudio/avaudiopcmbuffer/stride.md)
- [AVAudioPCMBuffer.ChannelData](avfaudio/avaudiopcmbuffer/channeldata.md)
- [AVAudioPCMBuffer.MutableChannelData](avfaudio/avaudiopcmbuffer/mutablechanneldata.md)
