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: joy (joy_AT_pingfm.org)
Date: Thu Jul 18 2002 - 20:58:16 EEST


On Wed, Jul 17, 2002 at 06:23:08PM -0400, Paul Davis wrote:
> >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".
>
aha, i slowly understand the things :).

> >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 ...

yes!, you are right. it was just another mistake by me calculating frames_len.

> >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.

i tought _mmap_commit() does only updating some sw-pointers for
alsa and has no real effect in the sense of commiting frames or
whatever. cause it's also only the only process (thread) which is
writing to the sounddevice it seems to be no problem to put it after
_mmap_commit(). but you are right that it's somehow cleaner and more
logical to put it before.

thanx for your comments, it helped me a lot, at least understanding
this mechanism.

-- 
regards

____- joy

________/\---------%%%___________----------- webcast every sunday 2000 cest at pingfm.org

pgp key at: x-hkp://wwwkeys.de.pgp.net


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 - 20:45:09 EEST