Skip to contentSkip to conversation

How to transfer data to the endpoint (e.g. .wav file) in alsa external I/O plugin

DISCUSSION Hermes Zhang 2 participants 2 messages Nov 8, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

I'm a new in alsa plugin develop. Now I'm try to implement an I/O plugin for my platform in alsa. I can config the alsa plugin and start it, but when I'm deal with the data in the transfer api, I could not flush the data to the endpoint, e.g. .wav file.

I run below command to test my plugin:

arecord -D my_plug -c 1 -f S16_LE raw

I want to save the audio data to a wav file by my plugin. Then in my code, I try to write the data to the area structure like this:

static snd_pcm_sframes_t
my_read (snd_pcm_ioplug_t * io,
const snd_pcm_channel_area_t * areas, snd_pcm_uframes_t offset, snd_pcm_uframes_t size)

{
     /* I got the audio data from other api here */

memcpy(areas->addr + areas->first + areas->step * offset, my_data, size);

}

But I could not get a correct wav file, there will be a file named "raw" but only with some wav file head, not real data include. Does anyone know anything I'm wrong? Is this the right way to handle the transfer data? Thanks.

Best Regards,
Hermes

#1 lore raw
Quoted 11 lines · Hermes Zhang

Hi,

I'm a new in alsa plugin develop. Now I'm try to implement an I/O plugin for my platform in alsa. I can config the alsa plugin and start it, but when I'm deal with the data in the transfer api, I could not flush the data to the endpoint, e.g. .wav file.

I run below command to test my plugin:

arecord -D my_plug -c 1 -f S16_LE raw

I want to save the audio data to a wav file by my plugin. Then in my code, I try to write the data to the area structure like this:

Quoted 8 lines

static snd_pcm_sframes_t
my_read (snd_pcm_ioplug_t * io,
const snd_pcm_channel_area_t * areas, snd_pcm_uframes_t offset, snd_pcm_uframes_t size)

{
     /* I got the audio data from other api here */

memcpy(areas->addr + areas->first + areas->step * offset, my_data, size);

Both the first and the step fields are in bits, not in bytes. You need to divide by 8:

	areas->addr + (areas->first + areas->step * offset) / 8

Takashi