[alsa-devel] How to transfer data to the endpoint (e.g. .wav file) in alsa external I/O plugin
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
On Tue, 08 Nov 2016 07:45:07 +0100, Hermes Zhang wrote:
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);
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
participants (2)
-
Hermes Zhang
-
Takashi Iwai