1
votes

I'm new in alsa sound programming. I'm developing an application to record the audio in to a wav file in c language. I did some research on net but still not very clear about many topics. Please help. This is the configuration I'm setting.

access : SND_PCM_ACCESS_RW_INTERLEAVED

format: S16_LE

rate: 16000

channel: 1

I have few doubts:

  1. I'm highly confused between the period size and period time settings. What is the difference between snd_pcm_hw_params_set_period_time_near() and snd_pcm_hw_params_set_period_size_near(). Which API should be called for capture? Similarly there is snd_pcm_hw_params_set_buffer_time_near() and snd_pcm_hw_params_set_buffer_size_near(). How to decide between these two APIs?

  2. How to decide the period size value? I believe the same value is used in snd_pcm_sw_params_set_avail_min() call.

  3. What value should be used for number of frames to be read in snd_pcm_readi()?

  4. What is the importance of snd_pcm_sw_params_set_avail_min() and snd_pcm_start_threshold() APIs? Is it a must to call those

I'm referring the arecord implementation and another example code for capture.

Thanks in advance.

1

1 Answers

1
votes

The period time describes the same parameter as the period size. It might be useful if the rate is not yet known.

You get interrupts (i.e., the opportunity to get woken up if you're waiting for data) at the end of each period. If you know how much data you want to read each time, try to use that as period size.

Read as many frames as you want to process.

The avail_min parameter specifies how many frames must be available before an interrupt results in you application actually being waken up.

The start threshold specifies that the device starts automatically when you try to read that many frames.