[alsa-devel] basic workflow when playing some sounddata
Dear Alsa-Developers,
I am very new to Alsa driver development and have some problems to get a clue how the process of playing sounddata works. Let me explain my point of view and it would be nice if anybody could give some clarifications and corrections on it.
Suppose I want to play a *.wav file from userspace with "aplay". After triggering all the configuration functions for PCM and the DAI at some point the chip_pcm_trigger() function get's called. As per "Writing Alsa Drivers" the TRIGGER_START command should now do something for "enabling the PCM engine". As per my understanding this could be for example to enable the interrupts of my DAI, which is (I2S over GSI) in my case. The interrupt handler by itself should call snd_pcm_period_elapsed() whenever a period of sounddata is copied to the device. Furthermore the so called "hw_pointer" should be updated in the interrupt handler, right? To make it easy I don't want to use DMA in the beginning. I simply want to copy the data to the hardware buffer of my DAI (I2S via GSI) and from there it is copied automatically to my codec. The question is now, at which place in the alsa framework I have to put the copy process of the sounddata. It should not be done in the interrupt handler because this would take to much time. But whereelse could this be done?
Also I don't know the meaning of chip_pcm_pointer() callback. As far as I could figure out from the source, this function is called whenever snd_pcm_period_elapsed() is called, right? But what should be done exactly in this callback. Again I want to say that I don't want to use DMA at all by now.
I've read already "Writing Alsa Drivers" but the questions above still remain for me and I am quite confused as you maybe noticed already from my questions above. ;-) It would be nice if anybody can give me a basic workflow which functions/callbacks are necessary for the playing part of an Alsa driver.
Thanks in advance for any help,
Regards, Markus
Markus Franke wrote:
Suppose I want to play a *.wav file from userspace with "aplay". After triggering all the configuration functions for PCM and the DAI at some point the chip_pcm_trigger() function get's called. As per "Writing Alsa Drivers" the TRIGGER_START command should now do something for "enabling the PCM engine". As per my understanding this could be for example to enable the interrupts of my DAI, which is (I2S over GSI) in my case.
Yes. For most devices, this is where DMA is started.
The interrupt handler by itself should call snd_pcm_period_elapsed() whenever a period of sounddata is copied to the device. Furthermore the so called "hw_pointer" should be updated in the interrupt handler, right?
Most devices (or DMA controllers) have a register that indicates the current position in the DMA buffer. If, however, this information is not made available by the hardware (or if DMA is not used), the interrupt handler has to save the current position so that the 'pointer' callback can return it.
To make it easy I don't want to use DMA in the beginning.
The driver API was designed so that writing drivers for the most common sound card architecture, i.e., DMA, is made easy.
I simply want to copy the data to the hardware buffer of my DAI (I2S via GSI) and from there it is copied automatically to my codec. The question is now, at which place in the alsa framework I have to put the copy process of the sounddata.
If you really don't want to use DMA, you have to implement the copy and silence callbacks. See the section "External Hardware Buffers" in "Writing an ALSA Driver".
Also I don't know the meaning of chip_pcm_pointer() callback.
It returns the current position in the DMA buffer.
As far as I could figure out from the source, this function is called whenever snd_pcm_period_elapsed() is called, right?
It's also called when an application wants to know the current position. For example, mplayer calls it quite often to be able to synchronize the video output to the sound.
Regards, Clemens
participants (2)
-
Clemens Ladisch
-
Markus Franke