* Starting the device manually
@ 2006-07-24 9:37 Eric Peters
2006-07-24 11:05 ` Clemens Ladisch
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Eric Peters @ 2006-07-24 9:37 UTC (permalink / raw)
To: alsa-devel
Dear all,
I'm a bit confused by the alsa documentation. I want to fill up a buffer
of a alsa device with snd_pcm_writei and then if the buffer is full, I
want to be able to start the playback manually. By looking to the
documentation, I found the method snd_pcm_sw_params_set_start_threshold.
In some other messages on this list there was the hint to set this
threshhold larger than the max_buffer_size and then the device shouldn't
start automatically. So I've done. But unfortunately the playback starts
again automatically. Here are the lines of code, I'm setting the
buffer_size and period_size and the start threshhold:
/* determine the buffer size */
if (buffer_time == 0 && buffer_frames == 0) {
if( snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time, 0)
< 0) {
return -1;
}
if (buffer_time > 500000) {
buffer_time = 500000;
}
}
/* calculating the period size depending on the buffer size */
if (period_time == 0 && period_frames == 0) {
if (buffer_time > 0) {
period_time = buffer_time / 4;
} else {
period_frames = buffer_frames / 4;
}
}
/* setting the period size according to the buffer size */
if (period_time > 0) {
if (snd_pcm_hw_params_set_period_time_near(pcm_handle, hwparams,
&period_time, 0) < 0) {
return -1;
}
} else {
if ( snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams,
&period_frames, 0) < 0) {
return -1;
}
}
/* setting the buffer size */
if (buffer_time > 0) {
if (snd_pcm_hw_params_set_buffer_time_near(pcm_handle, hwparams,
&buffer_time, 0) < 0) {
return -1;
}
} else {
if ( snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams,
&buffer_frames) < 0) {
return -1;
}
}
/* calculating the number of frames of a buffer and a period */
buffer_frames = buffer_time * sample_rate;
period_frames = period_time * sample_rate;
/* setting the start threshhold in frames */
int err = 0;
/*Init swparams */
if ((err = snd_pcm_sw_params_malloc (&swparams)) < 0) {
return -1;
}
if ((err = snd_pcm_sw_params_current(pcm_handle, swparams)) < 0) {
return -1;
}
if ((err = snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams,
2*buffer_frames)) < 0) {
return FAILURE;
}
err = snd_pcm_sw_params(pcm_handle, swparams);
if (err < 0) {
return -1;
}
Here are some specifications of the system I'm using:
- SuSE 9.3 with all updates and patches
- ALSA version 1.0.9a
- sound board Audigy 4 PRO [SB0380]
- chip SigmaTel STAC9750,51
Now some questions:
- Where is the failure in my implementation?
- I think, if I don't call snd_pcm_start there should be no output if
the start threshold is larger than the max_buffer_size. Is this correct?
- Is it possible that the starting behaviour depends on the hardware I'm
using?
- Do you have other hints so I can start my playback manually on a
timepoint I want?
Best regards,
Eric
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Starting the device manually
2006-07-24 9:37 Starting the device manually Eric Peters
@ 2006-07-24 11:05 ` Clemens Ladisch
2006-07-24 11:40 ` Eric Peters
2006-07-24 15:35 ` James Courtier-Dutton
2006-07-24 15:37 ` James Courtier-Dutton
2 siblings, 1 reply; 7+ messages in thread
From: Clemens Ladisch @ 2006-07-24 11:05 UTC (permalink / raw)
To: Eric Peters; +Cc: alsa-devel
Eric Peters wrote:
> I'm a bit confused by the alsa documentation. I want to fill up a buffer
> of a alsa device with snd_pcm_writei and then if the buffer is full, I
> want to be able to start the playback manually. By looking to the
> documentation, I found the method snd_pcm_sw_params_set_start_threshold.
> In some other messages on this list there was the hint to set this
> threshhold larger than the max_buffer_size and then the device shouldn't
> start automatically. So I've done. But unfortunately the playback starts
> again automatically.
What are the contents of /proc/asound/card?/pcm0p/sub0/sw_params during
playback?
> /* calculating the number of frames of a buffer and a period */
> buffer_frames = buffer_time * sample_rate;
> period_frames = period_time * sample_rate;
Is this correct? Aren't the xxx_time variables in microseconds?
> snd_pcm_sw_params_set_start_threshold(..., 2*buffer_frames)
This is OK, but it is common to use just the boundary value instead of
some explicitly calculated value.
> - I think, if I don't call snd_pcm_start there should be no output if
> the start threshold is larger than the max_buffer_size. Is this correct?
... if the start threshold is larger than the current buffer size, in
frames. Yes.
> - Is it possible that the starting behaviour depends on the hardware I'm
> using?
No, the software parameters are hardware independent.
Regards,
Clemens
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Starting the device manually
2006-07-24 11:05 ` Clemens Ladisch
@ 2006-07-24 11:40 ` Eric Peters
2006-08-04 16:44 ` Clemens Ladisch
0 siblings, 1 reply; 7+ messages in thread
From: Eric Peters @ 2006-07-24 11:40 UTC (permalink / raw)
To: Clemens Ladisch; +Cc: alsa-devel
Clemens Ladisch wrote:
> Eric Peters wrote:
>>I'm a bit confused by the alsa documentation. I want to fill up a buffer
>>of a alsa device with snd_pcm_writei and then if the buffer is full, I
>>want to be able to start the playback manually. By looking to the
>>documentation, I found the method snd_pcm_sw_params_set_start_threshold.
>>In some other messages on this list there was the hint to set this
>>threshhold larger than the max_buffer_size and then the device shouldn't
>>start automatically. So I've done. But unfortunately the playback starts
>>again automatically.
>
> What are the contents of /proc/asound/card?/pcm0p/sub0/sw_params during
> playback?
tstamp_mode: NONE
period_step: 1
sleep_min: 0
avail_min: 1
xfer_align: 4096
start_threshold: 2703204728
stop_threshold: 16384
silence_threshold: 0
silence_size: 0
boundary: 1073741824
Can you explain me these values and what they're for? I think, I know
the sense of start and stop threshold. But the other values...
>
>>/* calculating the number of frames of a buffer and a period */
>>buffer_frames = buffer_time * sample_rate;
>>period_frames = period_time * sample_rate;
>
> Is this correct? Aren't the xxx_time variables in microseconds?
I don't know. ;-)
How is a frame defined?
>
>>snd_pcm_sw_params_set_start_threshold(..., 2*buffer_frames)
>
> This is OK, but it is common to use just the boundary value instead of
> some explicitly calculated value.
The boundary value in the output above? How can I determine this value
in my application?
>
>>- I think, if I don't call snd_pcm_start there should be no output if
>>the start threshold is larger than the max_buffer_size. Is this correct?
>
> ... if the start threshold is larger than the current buffer size, in
> frames. Yes.
>
>>- Is it possible that the starting behaviour depends on the hardware I'm
>>using?
>
> No, the software parameters are hardware independent.
>
>
> Regards,
> Clemens
Thanks Clemens for your fast answer.
Best regards,
Eric
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Starting the device manually
2006-07-24 9:37 Starting the device manually Eric Peters
2006-07-24 11:05 ` Clemens Ladisch
@ 2006-07-24 15:35 ` James Courtier-Dutton
2006-07-25 6:20 ` Eric Peters
2006-07-24 15:37 ` James Courtier-Dutton
2 siblings, 1 reply; 7+ messages in thread
From: James Courtier-Dutton @ 2006-07-24 15:35 UTC (permalink / raw)
To: Eric Peters; +Cc: alsa-devel
Eric Peters wrote:
> Dear all,
>
> I'm a bit confused by the alsa documentation. I want to fill up a buffer
> of a alsa device with snd_pcm_writei and then if the buffer is full, I
> want to be able to start the playback manually. By looking to the
> documentation, I found the method snd_pcm_sw_params_set_start_threshold.
> In some other messages on this list there was the hint to set this
> threshhold larger than the max_buffer_size and then the device shouldn't
> start automatically. So I've done. But unfortunately the playback starts
> again automatically. Here are the lines of code, I'm setting the
> buffer_size and period_size and the start threshhold:
>
>
Why would you actually want to do what you describe. (You certainly can
do it with ALSA, but as to why you would want to, is another thing entirely)
It is normally better to get the buffers running, sending silence
samples to the buffer, and then introduce your sound when you want to.
One can accurately determine the delay or latency of the buffer, so
accurately timing samples is not a problem.
One uses a callback approach to send sound to the card. A good example
of this callback approach is an application called jackd.
http://jackaudio.org/
James
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Starting the device manually
2006-07-24 9:37 Starting the device manually Eric Peters
2006-07-24 11:05 ` Clemens Ladisch
2006-07-24 15:35 ` James Courtier-Dutton
@ 2006-07-24 15:37 ` James Courtier-Dutton
2 siblings, 0 replies; 7+ messages in thread
From: James Courtier-Dutton @ 2006-07-24 15:37 UTC (permalink / raw)
To: Eric Peters; +Cc: alsa-devel
Eric Peters wrote:
> Dear all,
>
> I'm a bit confused by the alsa documentation. I want to fill up a buffer
> of a alsa device with snd_pcm_writei and then if the buffer is full, I
> want to be able to start the playback manually. By looking to the
> documentation, I found the method snd_pcm_sw_params_set_start_threshold.
> In some other messages on this list there was the hint to set this
> threshhold larger than the max_buffer_size and then the device shouldn't
> start automatically. So I've done. But unfortunately the playback starts
> again automatically. Here are the lines of code, I'm setting the
> buffer_size and period_size and the start threshhold:
>
>
Why would you actually want to do what you describe. (You certainly can
do it with ALSA, but as to why you would want to, is another thing entirely)
It is normally better to get the buffers running, sending silence
samples to the buffer, and then introduce your sound when you want to.
One can accurately determine the delay or latency of the buffer, so
accurately timing samples is not a problem.
One uses a callback approach to send sound to the card. A good example
of this callback approach is an application called jackd.
http://jackaudio.org/
James
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Starting the device manually
2006-07-24 15:35 ` James Courtier-Dutton
@ 2006-07-25 6:20 ` Eric Peters
0 siblings, 0 replies; 7+ messages in thread
From: Eric Peters @ 2006-07-25 6:20 UTC (permalink / raw)
To: James Courtier-Dutton; +Cc: alsa-devel
James Courtier-Dutton wrote:
> Eric Peters wrote:
>> Dear all,
>>
>> I'm a bit confused by the alsa documentation. I want to fill up a buffer
>> of a alsa device with snd_pcm_writei and then if the buffer is full, I
>> want to be able to start the playback manually. By looking to the
>> documentation, I found the method snd_pcm_sw_params_set_start_threshold.
>> In some other messages on this list there was the hint to set this
>> threshhold larger than the max_buffer_size and then the device shouldn't
>> start automatically. So I've done. But unfortunately the playback starts
>> again automatically. Here are the lines of code, I'm setting the
>> buffer_size and period_size and the start threshhold:
>>
>>
> Why would you actually want to do what you describe. (You certainly can
> do it with ALSA, but as to why you would want to, is another thing
> entirely)
> It is normally better to get the buffers running, sending silence
> samples to the buffer, and then introduce your sound when you want to.
> One can accurately determine the delay or latency of the buffer, so
> accurately timing samples is not a problem.
> One uses a callback approach to send sound to the card. A good example
> of this callback approach is an application called jackd.
> http://jackaudio.org/
>
> James
>
Thank you James for your answer,
but unfortunately it isn't a real simple application. So it wouldn't be
possible to start the device with silence samples. But I will take this
approach into account to make it better. :-)
Best regards,
Eric
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Starting the device manually
2006-07-24 11:40 ` Eric Peters
@ 2006-08-04 16:44 ` Clemens Ladisch
0 siblings, 0 replies; 7+ messages in thread
From: Clemens Ladisch @ 2006-08-04 16:44 UTC (permalink / raw)
To: Eric Peters; +Cc: alsa-devel
Eric Peters wrote:
> Clemens Ladisch wrote:
> > Eric Peters wrote:
> >>In some other messages on this list there was the hint to set this
> >>threshhold larger than the max_buffer_size and then the device shouldn't
> >>start automatically. So I've done. But unfortunately the playback starts
> >>again automatically.
> >
> > What are the contents of /proc/asound/card?/pcm0p/sub0/sw_params during
> > playback?
>
> start_threshold: 2703204728
This is way too large. In fact, it's so large that, as a signed value,
it's negative.
Just use the boundary value, which is appropriate for 'almost infinity'
values like this.
> >>/* calculating the number of frames of a buffer and a period */
> >>buffer_frames = buffer_time * sample_rate;
> >>period_frames = period_time * sample_rate;
> >
> > Is this correct? Aren't the xxx_time variables in microseconds?
>
> I don't know. ;-)
> How is a frame defined?
It's the amount of data that is transferred in one sample period. It's
more than one sample when there is more than one channel.
The buffer_time/period_time variables are in microseconds, while the
sample_rate uses seconds (Hz = 1/s), so you would have to divide by
1000000 for the calculation to make sense.
> > ..., but it is common to use just the boundary value instead of
> > some explicitly calculated value.
>
> The boundary value in the output above? How can I determine this value
> in my application?
snd_pcm_sw_params_get_boundary()
HTH
Clemens
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-08-04 16:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-24 9:37 Starting the device manually Eric Peters
2006-07-24 11:05 ` Clemens Ladisch
2006-07-24 11:40 ` Eric Peters
2006-08-04 16:44 ` Clemens Ladisch
2006-07-24 15:35 ` James Courtier-Dutton
2006-07-25 6:20 ` Eric Peters
2006-07-24 15:37 ` James Courtier-Dutton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.