From: Takashi Iwai Subject: Re: Understanding _snd_pcm_channel_area Struct (PCM Interface)! Date: Tue, 23 Jun 2009 13:14:15 +0200 Message-ID: References: <4A3DEAF9.80508@free.fr> <4A406AD3.2050002@gmail.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 266E524697 for ; Tue, 23 Jun 2009 13:14:16 +0200 (CEST) In-Reply-To: <4A406AD3.2050002@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Guilherme Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Tue, 23 Jun 2009 02:40:35 -0300, Guilherme wrote: > > Hi all. > > I am a bit confused on what I get with this function. > I finished my first project but I did not understand what exactly the > > _snd_pcm_channel_area at > > http://www.alsa-project.org/alsa-doc/alsa-lib/struct__snd__pcm__channel__area.html > > does. > > There are 3 fields in the documentation. > > addr, first and step. > > It seems that addr is the memory address of the channel samples... so > far so good. The "step" is the distance between 2 sample (but I am not > sure) and the least, "first", I could not figure out what does it means. This information is needed to understand how the multi-channel samples are assigned in a stream. The first is the offset of the channel position to the given addr. The step is the bytes to the next sample of that channel. For example, suppose you have a 2-channel stereo interleaved stream with 16bit samples. Then you'll have an array of snd_pcm_channel_area with two elements, for left and right channels, containing like area[0].addr = base_address; addr[0].first = 0; addr[0].step = 4; addr[1].addr = base_address; addr[1].first = 2; addr[1].step = 4; Both channels share the same base address but have the different "first" offset bytes. The step size is 4 = #chanel * sample-size. For a non-interleaved stereo stream, it'll look like addr[0].addr = base_addr_0; addr[0].first = 0; addr[0].step = 2; addr[1].addr = base_addr_1; addr[1].first = 0; addr[1].step = 2; Thus it looks like two mono streams with 16bit samples. HTH, Takashi