[alsa-devel] audio samples data flow from user mode to kernel mode
Hello All,
I’m trying to understand how audio samples transferred between user mode to kernel mode during playback and capture. I’m using aplay & arecord alsa utilities for playback and capture.
Let us take a PCM wav file of sample rate 48000 and it has a total number of samples 480000 (Approx.Duration in seconds=10). Size of each sample is 8 bytes(two channels). After invocation of aplay from user mode, how does these audio samples gets copied to kernel mode? Can someone explain me on this?
Is it possible to capture the timestamps for the first and last audio samples that arrive at the driver level?
Can I consider the .trigger(for playback & capture) callback in SNDRV_PCM_TRIGGER_START case is timestamp for the first audio sample?
Similarly does .trigger callbacks SNDRV_PCM_TRIGGER_STOP gives the last audio sample timestamp?
Thanks,
23.06.2018, 14:52, "Subhashini Rao Beerisetty" subhashbeerisetty@gmail.com:
Hello All,
Hello,
I’m trying to understand how audio samples transferred between user mode to kernel mode during playback and capture. I’m using aplay & arecord alsa utilities for playback and capture.
Let us take a PCM wav file of sample rate 48000 and it has a total number of samples 480000 (Approx.Duration in seconds=10). Size of each sample is 8 bytes(two channels). After invocation of aplay from user mode, how does these audio samples gets copied to kernel mode? Can someone explain me on this?
Is it possible to capture the timestamps for the first and last audio samples that arrive at the driver level?
Can I consider the .trigger(for playback & capture) callback in SNDRV_PCM_TRIGGER_START case is timestamp for the first audio sample?
Similarly does .trigger callbacks SNDRV_PCM_TRIGGER_STOP gives the last audio sample timestamp?
I think no, because the SNDRV_PCM_TRIGGER_START and SNDRV_PCM_TRIGGER_STOP functions only system call to the PCM transmitted. So, will want two different functions as playback / capture and the method depends on you use alsa or pulse.
I think you want to:
snd_mychip_playback_open snd_mychip_playback_close
snd_mychip_capture_open snd_mychip_capture_close
Trigger funcs times are not real playback or capture time-stamps.
Regards
Ozgur
Thanks,
On Sat, Jun 23, 2018 at 4:41 PM, o@goosey.org wrote:
23.06.2018, 14:52, "Subhashini Rao Beerisetty" < subhashbeerisetty@gmail.com>:
Hello All,
Hello,
I’m trying to understand how audio samples transferred between user mode
to kernel mode during playback and capture. I’m using aplay & arecord alsa utilities for playback and capture.
Let us take a PCM wav file of sample rate 48000 and it has a total
number of samples 480000 (Approx.Duration in seconds=10). Size of each sample is 8 bytes(two channels). After invocation of aplay from user mode, how does these audio samples gets copied to kernel mode? Can someone explain me on this?
Is it possible to capture the timestamps for the first and last audio
samples that arrive at the driver level?
Can I consider the .trigger(for playback & capture) callback in
SNDRV_PCM_TRIGGER_START case is timestamp for the first audio sample?
Similarly does .trigger callbacks SNDRV_PCM_TRIGGER_STOP gives the last
audio sample timestamp?
I think no, because the SNDRV_PCM_TRIGGER_START and SNDRV_PCM_TRIGGER_STOP functions only system call to the PCM transmitted. So, will want two different functions as playback / capture and the method depends on you use alsa or pulse.
I think you want to:
snd_mychip_playback_open snd_mychip_playback_close
snd_mychip_capture_open snd_mychip_capture_close
Are these part of "struct snd_pcm_ops" .open & .close? If so timestamps captured at these API's gives the first and last audio sample timestamps?
Trigger funcs times are not real playback or capture time-stamps.
Regards
Ozgur
Thanks,
Hi Subhashini,
On Sat, Jun 23, 2018 at 4:22 PM, Subhashini Rao Beerisetty subhashbeerisetty@gmail.com wrote:
Hello All,
I’m trying to understand how audio samples transferred between user mode to kernel mode during playback and capture. I’m using aplay & arecord alsa utilities for playback and capture.
Let us take a PCM wav file of sample rate 48000 and it has a total number of samples 480000 (Approx.Duration in seconds=10). Size of each sample is 8 bytes(two channels). After invocation of aplay from user mode, how does these audio samples gets copied to kernel mode? Can someone explain me on this?
Usually this is done in corresponding sound/alsa device driver. The alsa driver should populate the following structure :-
struct snd_pcm_substream { struct snd_pcm *pcm; struct snd_pcm_str *pstr; void *private_data; /* copied from pcm->private_data */ int number; char name[32]; /* substream name */ int stream; /* stream (direction) */ struct pm_qos_request latency_pm_qos_req; /* pm_qos request */ size_t buffer_bytes_max; /* limit ring buffer size */ struct snd_dma_buffer dma_buffer; size_t dma_max; /* -- hardware operations -- */ const struct snd_pcm_ops *ops;
Here, you can find the dma_buffer where you have to populate the destination(kernel buffer) I would suggest please have a look at Alsa driver documentation for further details. There are lot of important parameters which defines how the copy will happen from user-space to kernel space - like period size, period count etc. Also look at important functions - snd_pcm_period_elapsed etc
Is it possible to capture the timestamps for the first and last audio samples that arrive at the driver level?
Can I consider the .trigger(for playback & capture) callback in SNDRV_PCM_TRIGGER_START case is timestamp for the first audio sample?
Similarly does .trigger callbacks SNDRV_PCM_TRIGGER_STOP gives the last audio sample timestamp?
Thanks,
Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (3)
-
o@goosey.org
-
priyaranjan
-
Subhashini Rao Beerisetty