Skip to content

LE Audio: Add bt_audio_get_chan_count #69617

@Thalley

Description

@Thalley

Is your enhancement proposal related to a problem? Please describe.
In LE audio, the channel or location values (enum bt_audio_location) are bitfields.
When decoding an SDU, which may have multiple frames per frame block, it's a good idea for the receiver to verify the frame block to see if it matches the number of channels for the stream.

Describe the solution you'd like
Implement a function bt_audio_get_chan_count that takes an enum bt_audio_location and returns the number of channels in that value.

The implementation would be something like

uint8_t bt_audio_get_chan_count(enum bt_audio_location chan_allocation)
{
	uint8_t cnt = 0U;

	if (chan_allocation == BT_AUDIO_LOCATION_MONO_AUDIO) {
		return 1;
	}

	while (chan_allocation != 0) {
		cnt += chan_allocation & 1U;
		chan_allocation >>= 1;
	}

	return cnt;
}

Describe alternatives you've considered
N/A

Additional context
N/A

Metadata

Metadata

Assignees

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions