You can use the default-sample-rate/alternate-sample-rate config values
as minimal sample rates.

So if you input a 8kHz audio stream, you resample it to 48kHz or 44.1kHz
rather than let it to go 8Khz.

I attached my patches.
They just remove the limitation that the desired sample rate should be
either default-sample-rate or alternate-sample-rate when the sink is
opened.
This was just a quick hack as I don't know pulseaudio source code at
all.
Feel free to discuss or modify them :)

The resulting behavior is the following:

New audio stream 88200Hz -> sink & source at 88200Hz
Adding a stream at 441000Hz -> sink & source don't change their sample
rate (still 88200Hz so). The additionnal stream is thus resampled to
88200Hz

Shutdown sink, New audio stream at 441000Hz -> sink & source at 44100Hz

Shutdown sink, New audio stream at 8000Hz -> sink & source at 44100Hz
because there seems to be a lower limit (maybe 8Khz is not in the
supported rates of the sound card :D ).

I can add to the patch a software limitation so the desired sample rate
can't be below default-sample-rate value for example.

Best regards,



Le dimanche 27 novembre 2016 à 17:16 +0200, Tanu Kaskinen a écrit :
> The dynamic rate switching was added to deal specifically with the most
> common case: switching between 44100 Hz and 48000 Hz. It's not that
> supporting a more flexible policy is necessarily undesirable, it's just
> that nobody has been interested enough to provide patches.
> 
> One reason why we don't simply try to switch to whatever rate streams
> happen to have is that we don't want to end up in a situation where one
> stream causes the sink to run at 8000 Hz and then an overlapping higher
> quality stream appears and suffers from the very low sink rate.
> 
> So, if we relax the rate restrictions, we need to add at least a limit
> for how low rates we accept. I don't remember if there were any other
> considerations when this feature was discussed. If you provide patches
> for improving the rate switching policy, at this point I don't see any
> reason why such feature would be rejected.
> 

--- /home/erwan/apps/pulseaudio/original/pulseaudio-7.1/src/pulsecore/sink.c	2015-10-19 05:16:31.000000000 +0200
+++ /home/erwan/apps/pulseaudio/pulseaudio-7.1/src/pulsecore/sink.c	2016-11-27 22:23:22.369700147 +0100
@@ -1385,24 +1385,15 @@
 int pa_sink_update_rate(pa_sink *s, uint32_t rate, bool passthrough) {
     int ret = -1;
     uint32_t desired_rate = rate;
-    uint32_t default_rate = s->default_sample_rate;
-    uint32_t alternate_rate = s->alternate_sample_rate;
     uint32_t idx;
     pa_sink_input *i;
-    bool default_rate_is_usable = false;
-    bool alternate_rate_is_usable = false;
 
-    if (rate == s->sample_spec.rate)
+    if (desired_rate == s->sample_spec.rate)
         return 0;
 
     if (!s->update_rate)
         return -1;
 
-    if (PA_UNLIKELY(default_rate == alternate_rate && !passthrough)) {
-        pa_log_debug("Default and alternate sample rates are the same, so there is no point in switching.");
-        return -1;
-    }
-
     if (PA_SINK_IS_RUNNING(s->state)) {
         pa_log_info("Cannot update rate, SINK_IS_RUNNING, will keep using %u Hz",
                     s->sample_spec.rate);
@@ -1419,25 +1410,6 @@
     if (PA_UNLIKELY(!pa_sample_rate_valid(desired_rate)))
         return -1;
 
-    if (!passthrough && default_rate != desired_rate && alternate_rate != desired_rate) {
-        if (default_rate % 11025 == 0 && desired_rate % 11025 == 0)
-            default_rate_is_usable = true;
-        if (default_rate % 4000 == 0 && desired_rate % 4000 == 0)
-            default_rate_is_usable = true;
-        if (alternate_rate && alternate_rate % 11025 == 0 && desired_rate % 11025 == 0)
-            alternate_rate_is_usable = true;
-        if (alternate_rate && alternate_rate % 4000 == 0 && desired_rate % 4000 == 0)
-            alternate_rate_is_usable = true;
-
-        if (alternate_rate_is_usable && !default_rate_is_usable)
-            desired_rate = alternate_rate;
-        else
-            desired_rate = default_rate;
-    }
-
-    if (desired_rate == s->sample_spec.rate)
-        return -1;
-
     if (!passthrough && pa_sink_used_by(s) > 0)
         return -1;
 
--- /home/erwan/apps/pulseaudio/original/pulseaudio-7.1/src/pulsecore/source.c	2015-09-25 14:09:43.000000000 +0200
+++ /home/erwan/apps/pulseaudio/pulseaudio-7.1/src/pulsecore/source.c	2016-11-27 22:11:26.000000000 +0100
@@ -975,22 +975,13 @@
 int pa_source_update_rate(pa_source *s, uint32_t rate, bool passthrough) {
     int ret;
     uint32_t desired_rate = rate;
-    uint32_t default_rate = s->default_sample_rate;
-    uint32_t alternate_rate = s->alternate_sample_rate;
-    bool default_rate_is_usable = false;
-    bool alternate_rate_is_usable = false;
 
-    if (rate == s->sample_spec.rate)
+    if (desired_rate == s->sample_spec.rate)
         return 0;
 
     if (!s->update_rate && !s->monitor_of)
         return -1;
 
-    if (PA_UNLIKELY(default_rate == alternate_rate && !passthrough)) {
-        pa_log_debug("Default and alternate sample rates are the same, so there is no point in switching.");
-        return -1;
-    }
-
     if (PA_SOURCE_IS_RUNNING(s->state)) {
         pa_log_info("Cannot update rate, SOURCE_IS_RUNNING, will keep using %u Hz",
                     s->sample_spec.rate);
@@ -1007,25 +998,6 @@
     if (PA_UNLIKELY(!pa_sample_rate_valid(desired_rate)))
         return -1;
 
-    if (!passthrough && default_rate != desired_rate && alternate_rate != desired_rate) {
-        if (default_rate % 11025 == 0 && desired_rate % 11025 == 0)
-            default_rate_is_usable = true;
-        if (default_rate % 4000 == 0 && desired_rate % 4000 == 0)
-            default_rate_is_usable = true;
-        if (alternate_rate && alternate_rate % 11025 == 0 && desired_rate % 11025 == 0)
-            alternate_rate_is_usable = true;
-        if (alternate_rate && alternate_rate % 4000 == 0 && desired_rate % 4000 == 0)
-            alternate_rate_is_usable = true;
-
-        if (alternate_rate_is_usable && !default_rate_is_usable)
-            desired_rate = alternate_rate;
-        else
-            desired_rate = default_rate;
-    }
-
-    if (desired_rate == s->sample_spec.rate)
-        return -1;
-
     if (!passthrough && pa_source_used_by(s) > 0)
         return -1;
 
_______________________________________________
pulseaudio-discuss mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss

Reply via email to