[alsa-devel] capturing data from the microphone

Jaroslav Kysela perex at perex.cz
Mon Jan 11 15:03:03 CET 2010

On Mon, 11 Jan 2010, Riccardo Magliocchetti wrote:

> Riccardo Magliocchetti ha scritto:
>> Raymond Yau ha scritto:
>>> 2010/1/6 Riccardo Magliocchetti <riccardo.magliocchetti at gmail.com>
>>>> Hi Pierre,
>>>> pl bossart ha scritto:
>>>>> You haven't specified the buffer/period size in the hw params. See
>>>>> alsa-lib/test/pcm.c
>>>>> - Pierre
>>>> They fail when opening default device so I had to remove them, work fine
>>>> when opening
>>>> plughw:0,0 though.
>>>>> On Mon, Jan 4, 2010 at 11:39 AM, Riccardo Magliocchetti
>>>>> <riccardo.magliocchetti at gmail.com> wrote:
>>>>>> [the same message is waiting in moderator queue, sorry if you
>>>>>> receive it
>>>> two times]
>>>>>> Hello,
>>>>>> i'm trying to capture audio data from the microphone, but i'm not able
>>>> to
>>>>>> read any frames.
>>>>>> The frames are always 0 and delay is fixed to 2730. I've tried calling
>>>>>> snd_pcm_avail_delay,  snd_pcm_avail_update but does not make a
>>>> difference.
>>>>>> The soundcard is driven by  snd_hda_intel. The code is more or less
>>>>>> the
>>>>>> same as Paul Davis' tutorial on using the alsa api.
>>> Even 4096 bytes is x86 DMA page size , seem to be a good choice for those
>>> PCI sound cards, however you cannot assume all sound cards/plugins
>>> support
>>> this buffer size
>>> If you did not set period_size, buffer_size or periods (period_time,
>>> buffer_time or periods)  , you should call
>>> snd_pcm_hw_params_get_buffer_size() and
>>> snd_pcm_hw_params_get_period_size()
>>> after snd_pcm_hw_params()
>> Thank you both Pierre and Raymond, using the get functions after
>> snd_pcm_hw_params() is working, now i have some concurrency issues to
>> resolve before i can say everything is working properly.
> The init works fine but snd_pcm_avail() always returns 0, full code is here
> http://pastebin.com/f687bf37a

The PCM stream must be triggered via snd_pcm_start() or using 
snd_pcm_read*() when sw_param->start_threshold is set appropriately.


Jaroslav Kysela <perex at perex.cz>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.

More information about the Alsa-devel mailing list