[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Alsa/Pulseaudio conflicts
From: |
Gilles Casse |
Subject: |
Alsa/Pulseaudio conflicts |
Date: |
Mon, 21 Apr 2008 20:46:42 +0200 |
Hynek Hanke wrote:
> The current implementation of Pulse Audio in Speech Dispatcher
> is slow because the implementation of it contains a problem.
> For each sound output, it opens and closes the whole connection,
> so there is a big overhead which is completely unnecessary.
Hello Hynek, all,
From pulseaudio 0.9.8, pa_stream_update_sample_rate has been added for
updating the rate. But if the format of the sound icon is different from
the speech samples, I guess that the stream must be still closed and
reopened.
I have updated the code consequently but unfortunately can't go further
at the moment. A patch is copied below as is (but code is not yet
operational).
Two remaining issues:
- on a Hardy based environment (beta release), the sound icons remain
mute (tested using sd from cvs (or from package Hardy) + espeak 1.36 (or
1.32), the sound-icon package has been installed, but no sound using
run_test or speechd-el).
- If I add the PA_STREAM_VARIABLE_RATE flag to
pa_stream_connect_playback (for adding the "update rate" capability),
spd-say does not play any sound. Perhaps a conflict with the other flag.
Copied below is the current patch.
Best regards,
Gilles
--- pulse.c.old 2008-04-20 21:51:21.000000000 +0200
+++ pulse.c 2008-04-21 18:41:55.000000000 +0200
@@ -723,7 +723,8 @@
SHOW_TIME("pa_connect_playback");
- if (pa_stream_connect_playback(id->pulse_stream, NULL, &a_attr,
(pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE),
&id->pulse_volume, NULL) < 0) {
+ // if (pa_stream_connect_playback(id->pulse_stream, NULL, &a_attr,
(pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE),
&id->pulse_volume, NULL) < 0) {
+ if (pa_stream_connect_playback(id->pulse_stream, NULL, &a_attr,
(pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_VARIABLE_RATE),
&id->pulse_volume, NULL) < 0) {
ERR("Failed to connect stream: %s",
pa_strerror(pa_context_errno(id->pulse_context)));
goto unlock_and_fail;
}
@@ -1268,6 +1052,7 @@
int ret = PULSE_OK;
size_t a_total_free_mem;
pa_sample_spec ss;
+ pa_operation *o = NULL;
if (id == NULL){
ERR("Invalid device passed to %s()\n",__FUNCTION__);
@@ -1303,9 +1088,31 @@
/* if the sample spec changes, the stream will be rebuilt. */
const pa_sample_spec *ss2 = pa_stream_get_sample_spec
(id->pulse_stream);
- if (!pa_sample_spec_equal (&ss, ss2)) {
+ // if (!pa_sample_spec_equal (&ss, ss2)) {
+ if ((ss.format != ss2->format) || (ss.channels != ss2->channels)) {
_pulse_close(id);
}
+ else if (ss.rate != ss2->rate) {
+ // just update rate (no need to reopen the stream).
+ // require pulseaudio >= 0.9.8
+ id->pulse_success = 0;
+
+ if (!(o=pa_stream_update_sample_rate(id->pulse_stream,
track.sample_rate, _stream_success_cb, id))){
+ ERR("pa_stream_update_sample_rate error (%s)\n",__FUNCTION__);
+ ret = PULSE_ERROR;
+ goto terminate;
+ }
+ SHOW("pulse_play: %s (call)\n", "pa_stream_update_sample_rate");
+ while (pa_operation_get_state(o) != PA_OPERATION_DONE) {
+ // CHECK_DEAD_GOTO(id, fail, 1);
+ pa_threaded_mainloop_wait(id->pulse_mainloop);
+ }
+ SHOW("pulse_play: %s (ret)\n", "pa_threaded_main_loop");
+
+ if (id->pulse_success == 0)
+ ERR("pa_stream_trigger() failed: %s",
pa_strerror(pa_context_errno(id->pulse_context)));
+
+ }
}
if (!id->pulse_mainloop) {