Re: [linux-audio-dev] Exact description of PCM system for ALSA

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Exact description of PCM system for ALSA
From: Paul Davis (pbd_AT_op.net)
Date: Thu Jul 18 2002 - 01:23:08 EEST


>frames_transmit = frames_available;
>snd_pcm_mmap_begin(alsa_handler, &area, &offset, &frames_transmit);
>prepare the areas and get back area, offset and frames_transmit.
>frames_transmit gives back the REAL value of available frames which
>could be written to in the mmaped-area. its sometimes for some unknown
>reasons < frames_available. this is what i did wrong all the time. i
>had the wrong idea that frames_transmit is always == frames_available.

the buffer is a ring buffer. since the mmap api assumes that you want
to deal with a contiguous buffer, if the end of the buffer is in the
middle of the current "frames available", then you will necessarily
want to deal with two separate contiguous areas. this is why the
return value of "frames_transmit" can be different from "frames_available".

>outbuffer = ((char *) area->addr + (area->first + area->step * offset)
>/ 8);
>this mysterious formula setup and calculates the mmaped-buffer which could be
>written to. it works only with '2 chn, Signed 16-bit'-streams for
>me. should be modified for 'usigned 8-bit'-streams', but i currently
>don't know how.

AFAIK, this works for all configurations. it certainly works for 26
and 18 channels of 24-in-32 noninterleaved ...

>result = snd_pcm_mmap_commit(alsa_handler, offset, frames_transmit);
>gives back the virtually written (writable) frames which should be
>always == frames_transmit.
>
>a simple
>memcpy(outbuffer, data, result);
>finally transfers the current data into the mmaped-buffer.

this is very dangerous. you must never call snd_pcm_mmap_commit()
*before* you have actually written the data.

--p


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Thu Jul 18 2002 - 01:26:36 EEST