[alsa-devel] PCM Plugin Channel question

Brandon Yates Brandon.Yates at adaptivedigital.com
Wed Jul 2 15:57:08 CEST 2014


Excellent. The fact that the areas are arrays in the case of multiple channels certainly was the one piece I was missing.  Thanks for the great explanation, you just made my day easier!

-----Original Message-----
From: Alexander E. Patrakov [mailto:patrakov at gmail.com] 
Sent: Wednesday, July 02, 2014 9:51 AM
To: Brandon Yates
Cc: alsa-devel at alsa-project.org
Subject: Re: [alsa-devel] PCM Plugin Channel question

02.07.2014 19:25, Brandon Yates пишет:
> Alex -  thanks. That was helpful. One follow up question.
>
>> if you use the areas-related parameters correctly, the plugin will
> also work with planar or complex layouts.
>
>
> I am not sure if I'm using snd_pcm_channel_area_t correctly. I don't 
> really understand all the fields.  For 1 channel setup I stole the 
> following function from the speex plugin
>
> static inline void *area_addr(const snd_pcm_channel_area_t *area,
> 			      snd_pcm_uframes_t offset)
> {
> 	unsigned int bitofs = area->first + area->step * offset;
> 	return (char *) area->addr + bitofs / 8; }
>
> This works for 1 channel but I don't understand how I would use area 
> for interleaved data.  My thoughts are just take the returned address from
> area_addr then use a for loop separating out odd and even shorts.   Is
> there a better way?

For stereo data, the key thought that you are missing is that there will be in fact _two_ areas for stereo data: area[0] and area[1]. Similarly for 4-channel data: 4 areas. One area per channel.

So, assuming interleaved stereo S16 audio, you will get the following two areas:

In area[0], addr points to the 0th left sample, first == 0, step == 32.
In area[1], either addr points to the 0th left sample and first == 16, or addr points to 0th right sample and first == 0. In both cases, step == 32.

Step == 32 means that you have to move right by 32 bits (4 bytes) to go to the next sample in this channel.

For non-interleaved audio, for each area, addr points to the beginning of the 0th sample in the corresponding channel, first == 0 and step == 16.

You just have to pass the area corresponding to the correct channel, and the sample index to the function you quoted, and get the address of that sample.

So the things are in fact very simple :)

--
Alexander E. Patrakov


More information about the Alsa-devel mailing list