Priming buffer
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Clemens Ladisch
Quoted 1 line · Arve Knudsen
What's the purpose of
set_start_threshold?The stream will automatically start when the buffer has been filled up to the amount specified by
start_threshold.
Ok, obviously there's something I don't understand (no surprise). I did a little test where I set start threshold to buffer size, acquire memory using snd_pcm_mmap_begin (number of returned frames equals buffer size), fill the buffer and do a snd_pcm_mmap_commit. After the commit I check the state of the card, which is SND_PCM_STATE_PREPARED (a started pcm would be in the running state?). Or do you mean actual transfer of data, by start of stream?
Back to my original goal: I did an explicit start of the pcm after filling the buffer, but the output still sounds muted for some reason. If I start the pcm *before* writing to the buffer however (like I normally would), the output is like expected. Any idea what causes this initial muting of the output?
Thanks
Arve Knudsen
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Quoted 6 lines · Arve Knudsen
I did a little test where I set start threshold to buffer size, acquire memory using
snd_pcm_mmap_begin(number of returned frames equals buffer size), fill the buffer and do asnd_pcm_mmap_commit. After the commit I check the state of the card, which isSND_PCM_STATE_PREPARED(a started pcm would be in the running state?).
In theory, what you do sounds correct. (I assume you've used frames, not bytes, for the start threshold.)
Maybe you want to compare your code with aplay.c, which uses start threshold, too. (It calls snd_pcm_mmap_writei, which calls snd_pcm_write_areas, which calls snd_pcm_mmap_write_areas (defined in alsa-lib/src/pcm/pcm_mmap.c), which calls snd_pcm_mmap_begin and snd_pcm_mmap_commit.
Quoted 5 lines
Back to my original goal: I did an explicit start of the pcm after filling the buffer, but the output still sounds muted for some reason. If I start the pcm *before* writing to the buffer however (like I normally would), the output is like expected. Any idea what causes this initial muting of the output?
In theory, starting the pcm with an empty buffer causes an underrun to occur immediately.
If I understand you correctly, the first buffer of audio data is replaced by silence. Maybe you've set a silence threshold?
Regards,
Clemens
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Quoted 23 lines · Clemens Ladisch
Quoted 6 lines · Arve Knudsen
I did a little test where I set start threshold to buffer size, acquire memory using
snd_pcm_mmap_begin(number of returned frames equals buffer size), fill the buffer and do asnd_pcm_mmap_commit. After the commit I check the state of the card, which isSND_PCM_STATE_PREPARED(a started pcm would be in the running state?).In theory, what you do sounds correct. (I assume you've used frames, not bytes, for the start threshold.)
Maybe you want to compare your code with
aplay.c, which uses start threshold, too. (It callssnd_pcm_mmap_writei, which callssnd_pcm_write_areas, which callssnd_pcm_mmap_write_areas(defined inalsa-lib/src/pcm/pcm_mmap.c), which callssnd_pcm_mmap_beginandsnd_pcm_mmap_commit.Quoted 5 lines
Back to my original goal: I did an explicit start of the pcm after filling the buffer, but the output still sounds muted for some reason. If I start the pcm *before* writing to the buffer however (like I normally would), the output is like expected. Any idea what causes this initial muting of the output?
Quoted 5 lines
In theory, starting the pcm with an empty buffer causes an underrun to occur immediately.
If I understand you correctly, the first buffer of audio data is replaced by silence. Maybe you've set a silence threshold?
Maybe I should rephrase my question, now that I've got some time to think about it. Exactly what gets started when the start threshold is reached, the transfer of frames to the audio card (assuming we're writing frames)? Obviously it doesn't affect the state of the pcm, like snd_pcm_start does (SND_PCM_STATE_RUNNING). Basically, before I've just used 0 as the start threshold and filled the buffer with zeros prior to starting the pcm. It seems to me a start threshold equal to buffer size would mean no transfer of data goes on before the buffer is filled? If this is correct, what would it mean in the case of capture (reading frames from the card).
Again thanks
Arve Knudsen
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Quoted 7 lines · Arve Knudsen
On Fri, 12 Sep 2003 16:51:26 +0200 (METDST), Clemens Ladisch <[email protected]> wrote:
Maybe I should rephrase my question, now that I've got some time to think about it. Exactly what gets started when the start threshold is reached, the transfer of frames to the audio card (assuming we're writing frames)? Obviously it doesn't affect the state of the pcm, likesnd_pcm_startdoes (SND_PCM_STATE_RUNNING).
When at least start_threshold frames have been written to the buffer, the pcm will be started. This _will_ affect the pcm's state.
To quote alsa-kernel/core/pcm_lib.c (in snd_pcm_lib_write1):
if (runtime->status->state == SNDRV_PCM_STATE_PREPARED &&
snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) {
err = snd_pcm_start(substream);Quoted 2 lines
It seems to me a start threshold equal to buffer size would mean no transfer of data goes on before the buffer is filled?
Yes.
Quoted 2 lines
If this is correct, what would it mean in the case of capture (reading frames from the card).
When, in the prepared state, you want to read at least start_threshold frames in one call to xxx_read, the pcm will be started.
HTH
Clemens
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf