Recording from Alsa - Understanding Memory Mapping

Recording from ALSA - understanding memory mapping

There is a known bug with the USB audio driver on ARM, where the kernel's and the application's maps of the same buffer might not be cache-coherent.

Using the ALSA memory mapping functions makes sense only if the code can handlle the samples directly without copying them to another buffer.
If you do copy them, you are doing exactly the same that snd_pcm_readi already does.
In other words, just don't use memory mapping.

When capturing, the buffer size has no effect on latency, so you should make it as large as possible to avoid possible overruns.

Smaller period sizes give you lower latency, but your program does not do anything real-time related, so you could use a larger period size to save a little bit of power.

Recording with ALSA

snd_pcm_readi writes the samples in the format that you have set with snd_pcm_hw_params_set_format, so you have to ensure that the buffer's type matches this.
The equivalent of double is SND_PCM_FORMAT_FLOAT64.

Furthermore, malloc wants a size in bytes, so you have to use

size = frames * sizeof(double);

When printing the samples, you have more bytes than samples, so size would be the wrong counter to use.
The number of returned samples is in rc:

for (z = 0; z < rc; z++)
fprintf(output, "%lf\n", buffer[z]);


Related Topics



Leave a reply



Submit