All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexander E. Patrakov" <patrakov@gmail.com>
To: Brandon Yates <Brandon.Yates@adaptivedigital.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: PCM Plugin Channel question
Date: Wed, 02 Jul 2014 19:51:27 +0600	[thread overview]
Message-ID: <53B40E5F.7000104@gmail.com> (raw)
In-Reply-To: <B02206F4ACA2904A8270028316B8DAFF01149F05@mercury.corp.adaptivedigital.com>

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
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2014-07-02 13:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-01 22:59 PCM Plugin Channel question Brandon Yates
2014-07-02  3:45 ` Alexander E. Patrakov
2014-07-02 13:25   ` Brandon Yates
2014-07-02 13:51     ` Alexander E. Patrakov [this message]
2014-07-02 13:57       ` Brandon Yates

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53B40E5F.7000104@gmail.com \
    --to=patrakov@gmail.com \
    --cc=Brandon.Yates@adaptivedigital.com \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.