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

# channelData(_:)

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

## Declaration

```swift
func channelData(_ index: Int) -> AVReadOnlyAudioPCMBuffer.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 access to the channel’s sample data. Example: 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):         // 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

- [withUnsafeAudioBufferList(_:)](avfaudio/avreadonlyaudiopcmbuffer/withunsafeaudiobufferlist(_:).md)
- [AVReadOnlyAudioPCMBuffer.ChannelData](avfaudio/avreadonlyaudiopcmbuffer/channeldata.md)
