Audio recording

Hi all!
I need to capture audio with the Dragonboard. I have read the guide Stereo connector and audio routing application note and it has helped a lot to me to understanding the hardware set up. The guide explains how to record and play back audio using the Amixer commands in the terminal.

I would like to record audio “programatically”, I mean, create a user-space device driver, like the solution purposed in this post.

I’ve searched the document in the kernel documentation page but I couldn’t find it on a such large list which I’m not familiar with.

Thank you all guys!

I’m trying to find a delicate way to respond to this!

I2C is something of a special case regarding user vs. kernel drivers. However you almost certainly shouldn’t create a user-space device driver for an audio device. Its not really the “right thing to do” and there are not suitable user/kernel interfaces that you could use to construct one so it wouldn’t be particularly easy.

Much easier to use the existing kernel driver and, if you want to interact with audio from the command line, use a tool like arecord.

Thank you for your response @danielt, I’ve only been working with Linux for a few weeks, so I don’t have many of the necessary concepts needed.

Where I can find the documentation for use the kernel audio driver for recording audio?

There lots of info available about using arecord:
https://www.google.com/search?q=arecord

However a quick getting started would be to install hexdump (to allow you to take a peek at the audio as text):

apt update && apt install bsdmaintools

Then run a simple pipeline to convert the incoming audio into text:

arecord -Dhw:DB410c,2 -f S16_LE -c 1 -r 48000 | hexdump | head 

The result for me (with no audio routings set up because I have nothing attached to my board) is a bunch of values that settle close to 0 (i.e. quiet white noise) which is what I would expect:

....
0004820 0003 0006 fffc 0002 0004 ffff 0003 0006
....

Note that the numbers starting ff are actually close to zero (this is how small negative numbers are represented).

You’ll know when you get the audio routing correct because the numbers will start to get much more variable!

But, as I can see, this way of recording audio needs to use the command line. I want to create an executable file that captures audio and generates a .wav file.

My idea is to execute the program, that runs in background with a routine that captures audio and saves it as .wav, this routine would be triggered when microphone detects some audio.

If you want to write this code as a learning exercise then you’re probably best off looking at one of the ALSA tutorials. One example is: A tutorial on using the ALSA Audio API . You can augment that with the alsa documentation to get additional details: http://www.alsa-project.org/alsa-doc/alsa-lib/

Of course if you just have an idea for an appliance you want to build and the recorder is merely a component then there are plenty of tools that can already do this sort of thing. Some examples are here (sox’s rec tool looks particularly good for this):
http://mocha.freeshell.org/audio.html#vox