[pulseaudio-discuss] spurious underflows?
Andrew Kelley
superjoe30 at gmail.com
Wed Jun 3 18:06:10 PDT 2015
I open the audio playback device like this:
pa_threaded_mainloop_lock(audio_hardware->main_loop);
pa_sample_spec sample_spec;
sample_spec.format = to_pulseaudio_sample_format(sample_format);
sample_spec.rate = audio_device->default_sample_rate;
sample_spec.channels = audio_device->channel_layout.channel_count;
pa_channel_map channel_map =
to_pulseaudio_channel_map(&audio_device->channel_layout);
open_playback_device->stream =
pa_stream_new(audio_hardware->pulse_context,
"Genesis", &sample_spec, &channel_map);
// error handling omitted
pa_stream_set_state_callback(open_playback_device->stream,
playback_stream_state_callback,
open_playback_device);
pa_stream_set_write_callback(open_playback_device->stream,
playback_stream_write_callback,
open_playback_device);
pa_stream_set_underflow_callback(open_playback_device->stream,
playback_stream_underflow_callback,
open_playback_device);
open_playback_device->bytes_per_frame =
genesis_get_bytes_per_frame(sample_format,
audio_device->channel_layout.channel_count);
int bytes_per_second = open_playback_device->bytes_per_frame *
audio_device->default_sample_rate;
int buffer_length = open_playback_device->bytes_per_frame *
ceil(latency * bytes_per_second /
(double)open_playback_device->bytes_per_frame);
open_playback_device->buffer_attr.maxlength = buffer_length;
open_playback_device->buffer_attr.tlength = buffer_length;
open_playback_device->buffer_attr.prebuf = 0;
open_playback_device->buffer_attr.minreq = UINT32_MAX;
open_playback_device->buffer_attr.fragsize = UINT32_MAX;
pa_stream_connect_playback(open_playback_device->stream,
open_playback_device->audio_device->name,
&open_playback_device->buffer_attr,
PA_STREAM_ADJUST_LATENCY, nullptr, nullptr);
// error handling omitted
while (!open_playback_device->stream_ready)
pa_threaded_mainloop_wait(audio_hardware->main_loop);
pa_threaded_mainloop_unlock(audio_hardware->main_loop);
Here is some output from my program. When it prints UNDERRUN that means the
underflow callback was called. The number is the number of seconds that the
write callback took to fill the playback buffer. In this example the audio
device is opened with latency set to 10ms, e.g. 0.01 seconds. The percent
is how long the callback took out of how long the buffer size is. So that
first UNDERRUN makes sense, because the callback took 2x as long as it was
supposed to. When an underrun occurs, the playback buffer is filled
completely with silence. So why am I getting all these other underflow
callbacks when the callback was well within the range of time which should
have been fine? Any ideas of things I can do to troubleshoot?
callback took 0.02038 (203%)
UNDERRUN
callback took 0.00395 (39%)
callback took 0.00397 (39%)
callback took 0.00282 (28%)
UNDERRUN
UNDERRUN
callback took 0.00236 (23%)
UNDERRUN
callback took 0.00347 (34%)
UNDERRUN
callback took 0.00282 (28%)
callback took 0.00371 (37%)
UNDERRUN
UNDERRUN
callback took 0.00140 (13%)
UNDERRUN
callback took 0.00355 (35%)
callback took 0.00450 (44%)
UNDERRUN
callback took 0.00273 (27%)
callback took 0.00379 (37%)
callback took 0.00207 (20%)
UNDERRUN
callback took 0.00120 (11%)
callback took 0.00397 (39%)
UNDERRUN
callback took 0.00197 (19%)
callback took 0.00121 (12%)
callback took 0.00394 (39%)
UNDERRUN
callback took 0.00217 (21%)
callback took 0.00503 (50%)
UNDERRUN
callback took 0.00276 (27%)
callback took 0.00381 (38%)
callback took 0.00218 (21%)
UNDERRUN
callback took 0.00121 (12%)
callback took 0.00395 (39%)
callback took 0.00218 (21%)
callback took 0.00402 (40%)
UNDERRUN
callback took 0.00199 (19%)
callback took 0.00509 (50%)
UNDERRUN
callback took 0.00257 (25%)
callback took 0.00405 (40%)
UNDERRUN
callback took 0.00239 (23%)
callback took 0.00516 (51%)
UNDERRUN
callback took 0.00242 (24%)
callback took 0.00438 (43%)
callback took 0.00229 (22%)
callback took 0.00406 (40%)
callback took 0.00220 (21%)
callback took 0.00397 (39%)
callback took 0.00221 (22%)
callback took 0.00404 (40%)
UNDERRUN
callback took 0.00202 (20%)
callback took 0.00521 (52%)
UNDERRUN
callback took 0.00298 (29%)
callback took 0.00400 (39%)
UNDERRUN
callback took 0.00222 (22%)
callback took 0.00619 (61%)
UNDERRUN
callback took 0.00470 (46%)
callback took 0.00271 (27%)
UNDERRUN
callback took 0.00154 (15%)
callback took 0.00422 (42%)
callback took 0.00224 (22%)
callback took 0.00465 (46%)
UNDERRUN
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20150603/954fffb9/attachment.html>
More information about the pulseaudio-discuss
mailing list