]> code.delx.au - pulseaudio/commitdiff
add resample_method option module-combine
authorLennart Poettering <lennart@poettering.net>
Fri, 17 Sep 2004 21:10:05 +0000 (21:10 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 17 Sep 2004 21:10:05 +0000 (21:10 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@215 fefdeb5f-60dc-0310-8127-8f9354f1896f

14 files changed:
polyp/daemon-conf.c
polyp/module-combine.c
polyp/module-sine.c
polyp/play-memchunk.c
polyp/protocol-esound.c
polyp/protocol-native.c
polyp/protocol-simple.c
polyp/sink-input.c
polyp/sink-input.h
polyp/sound-file-stream.c
polyp/source-output.c
polyp/source-output.h
polyp/util.c
polyp/util.h

index 6dcd540d9c8e5643ac5ae15cdf6297fc901f5d9e..befb9602c983b0c32396dd960e81e6e72fc0c885 100644 (file)
@@ -125,25 +125,16 @@ int pa_daemon_conf_set_log_target(struct pa_daemon_conf *c, const char *string)
         return -1;
 
     return 0;
-
 }
 
 int pa_daemon_conf_set_resample_method(struct pa_daemon_conf *c, const char *string) {
+    int m;
     assert(c && string);
 
-    if (!strcmp(string, "sinc-best-quality"))
-        c->resample_method = SRC_SINC_BEST_QUALITY;
-    else if (!strcmp(string, "sinc-medium-quality"))
-        c->resample_method = SRC_SINC_MEDIUM_QUALITY;
-    else if (!strcmp(string, "sinc-fastest"))
-        c->resample_method = SRC_SINC_FASTEST;
-    else if (!strcmp(string, "zero-order-hold"))
-        c->resample_method = SRC_ZERO_ORDER_HOLD;
-    else if (!strcmp(string, "linear"))
-        c->resample_method = SRC_LINEAR;
-    else
+    if ((m = pa_parse_resample_method(string)) < 0)
         return -1;
 
+    c->resample_method = m;
     return 0;
 }
 
index 177d7d18d3d1064a37373569e576decf6712dd13..f6d596bc7375e4dce4f267d5b321a6263ae1bee3 100644 (file)
@@ -40,7 +40,7 @@
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("Combine multiple sinks to one")
 PA_MODULE_VERSION(PACKAGE_VERSION)
-PA_MODULE_USAGE("sink_name=<name for the sink> master=<master sink> slave=<slave sinks> adjust_time=<seconds>")
+PA_MODULE_USAGE("sink_name=<name for the sink> master=<master sink> slave=<slave sinks> adjust_time=<seconds> resample_method=<method>")
 
 #define DEFAULT_SINK_NAME "combined"
 #define MEMBLOCKQ_MAXLENGTH (1024*170)
@@ -53,6 +53,7 @@ static const char* const valid_modargs[] = {
     "master",
     "slaves",
     "adjust_time",
+    "resample_method",
     NULL
 };
 
@@ -200,7 +201,7 @@ static pa_usec_t sink_get_latency_cb(struct pa_sink *s) {
     return pa_sink_input_get_latency(u->master->sink_input);
 }
 
-static struct output *output_new(struct userdata *u, struct pa_sink *sink) {
+static struct output *output_new(struct userdata *u, struct pa_sink *sink, int resample_method) {
     struct output *o = NULL;
     char t[256];
     assert(u && sink && u->sink);
@@ -212,7 +213,7 @@ static struct output *output_new(struct userdata *u, struct pa_sink *sink) {
     o->memblockq = pa_memblockq_new(MEMBLOCKQ_MAXLENGTH, MEMBLOCKQ_MAXLENGTH, pa_frame_size(&u->sink->sample_spec), 0, 0, sink->core->memblock_stat);
 
     snprintf(t, sizeof(t), "%s: output #%u", u->sink->name, u->n_outputs+1);
-    if (!(o->sink_input = pa_sink_input_new(sink, t, &u->sink->sample_spec, 1)))
+    if (!(o->sink_input = pa_sink_input_new(sink, t, &u->sink->sample_spec, 1, resample_method)))
         goto fail;
 
     o->sink_input->get_latency = sink_input_get_latency_cb;
@@ -277,17 +278,25 @@ static void clear_up(struct userdata *u) {
 int pa__init(struct pa_core *c, struct pa_module*m) {
     struct userdata *u;
     struct pa_modargs *ma = NULL;
-    const char *master_name, *slaves;
+    const char *master_name, *slaves, *rm;
     struct pa_sink *master_sink;
     char *n = NULL;
     const char*split_state;
     struct timeval tv;
+    int resample_method = -1;
     assert(c && m);
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
         pa_log(__FILE__": failed to parse module arguments\n");
         goto fail;
     }
+
+    if ((rm = pa_modargs_get_value(ma, "resample_method", NULL))) {
+        if ((resample_method = pa_parse_resample_method(rm)) < 0) {
+            pa_log(__FILE__": invalid resample method '%s'\n", rm);
+            goto fail;
+        }
+    }
     
     u = pa_xmalloc(sizeof(struct userdata));
     m->userdata = u;
@@ -325,7 +334,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
     u->sink->get_latency = sink_get_latency_cb;
     u->sink->userdata = u;
     
-    if (!(u->master = output_new(u, master_sink))) {
+    if (!(u->master = output_new(u, master_sink, resample_method))) {
         pa_log(__FILE__": failed to create master sink input on sink '%s'.\n", u->sink->name);
         goto fail;
     }
@@ -341,7 +350,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
 
         pa_xfree(n);
 
-        if (!output_new(u, slave_sink)) {
+        if (!output_new(u, slave_sink, resample_method)) {
             pa_log(__FILE__": failed to create slave sink input on sink '%s'.\n", slave_sink->name);
             goto fail;
         }
index 2fa7759c9c1d1a41e9557095f738bae4600732f7..458b87883258ae50b08a9284ebc9bca53ce6a7c4 100644 (file)
@@ -139,7 +139,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
     calc_sine(u->memblock->data, u->memblock->length, frequency);
 
     snprintf(t, sizeof(t), "Sine Generator at %u Hz", frequency);
-    if (!(u->sink_input = pa_sink_input_new(sink, t, &ss, 0)))
+    if (!(u->sink_input = pa_sink_input_new(sink, t, &ss, 0, -1)))
         goto fail;
 
     u->sink_input->peek = sink_input_peek;
index 6490547eb7a1691fd40066f687152d20bacc85fb..aa6d30e99751f6ccecc42f3c2987c6e63bb1140f 100644 (file)
@@ -88,7 +88,7 @@ int pa_play_memchunk(struct pa_sink *sink, const char *name, const struct pa_sam
     if (volume <= 0)
         return 0;
 
-    if (!(si = pa_sink_input_new(sink, name, ss, 0)))
+    if (!(si = pa_sink_input_new(sink, name, ss, 0, -1)))
         return -1;
 
     si->volume = volume;
index aff45099227e4f6bff2d3e17c72e5ef47359d2a8..293d123a30df1e075f235c54f360a9b7509b1500 100644 (file)
@@ -305,7 +305,7 @@ static int esd_proto_stream_play(struct connection *c, esd_proto_t request, cons
     c->playback.fragment_size = l/10;
     
     assert(!c->sink_input);
-    c->sink_input = pa_sink_input_new(sink, name, &ss, 0);
+    c->sink_input = pa_sink_input_new(sink, name, &ss, 0, -1);
     assert(c->sink_input);
 
     c->sink_input->owner = c->protocol->module;
@@ -368,7 +368,7 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co
     pa_iochannel_socket_set_sndbuf(c->io, l/RECORD_BUFFER_FRAGMENTS*2);
     
     assert(!c->source_output);
-    c->source_output = pa_source_output_new(source, name, &ss);
+    c->source_output = pa_source_output_new(source, name, &ss, -1);
     assert(c->source_output);
     
     c->source_output->owner = c->protocol->module;
index e197d1e2bdeff35f567b8df17d39264f5cdb9f47..021c1a60627844a71c2bb64f0f671cc739aca5ed 100644 (file)
@@ -251,7 +251,7 @@ static struct record_stream* record_stream_new(struct connection *c, struct pa_s
     size_t base;
     assert(c && source && ss && name && maxlength);
 
-    if (!(source_output = pa_source_output_new(source, name, ss)))
+    if (!(source_output = pa_source_output_new(source, name, ss, -1)))
         return NULL;
 
     s = pa_xmalloc(sizeof(struct record_stream));
@@ -295,7 +295,7 @@ static struct playback_stream* playback_stream_new(struct connection *c, struct
     struct pa_sink_input *sink_input;
     assert(c && sink && ss && name && maxlength);
 
-    if (!(sink_input = pa_sink_input_new(sink, name, ss, 0)))
+    if (!(sink_input = pa_sink_input_new(sink, name, ss, 0, -1)))
         return NULL;
     
     s = pa_xmalloc(sizeof(struct playback_stream));
index a7bd76fbd7b958c2f0d30f320eec7ed1c0dbe8c2..ee3bf9d330ba373b8e7f12417c86f87d89de5daf 100644 (file)
@@ -314,7 +314,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
             goto fail;
         }
 
-        if (!(c->sink_input = pa_sink_input_new(sink, c->client->name, &p->sample_spec, 0))) {
+        if (!(c->sink_input = pa_sink_input_new(sink, c->client->name, &p->sample_spec, 0, -1))) {
             pa_log(__FILE__": Failed to create sink input.\n");
             goto fail;
         }
@@ -344,7 +344,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
             goto fail;
         }
 
-        c->source_output = pa_source_output_new(source, c->client->name, &p->sample_spec);
+        c->source_output = pa_source_output_new(source, c->client->name, &p->sample_spec, -1);
         if (!c->source_output) {
             pa_log(__FILE__": Failed to create source output.\n");
             goto fail;
index 486a204439689ad848b9dd36a77f04e431b070f1..9493023141026d332457a2b9dbdee28e8632b582 100644 (file)
@@ -36,7 +36,7 @@
 
 #define CONVERT_BUFFER_LENGTH 4096
 
-struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, const struct pa_sample_spec *spec, int variable_rate) {
+struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, const struct pa_sample_spec *spec, int variable_rate, int resample_method) {
     struct pa_sink_input *i;
     struct pa_resampler *resampler = NULL;
     int r;
@@ -47,9 +47,12 @@ struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, con
         pa_log(__FILE__": Failed to create sink input: too many inputs per sink.\n");
         return NULL;
     }
+
+    if (resample_method < 0)
+        resample_method = s->core->resample_method;
     
     if (variable_rate || !pa_sample_spec_equal(spec, &s->sample_spec))
-        if (!(resampler = pa_resampler_new(spec, &s->sample_spec, s->core->memblock_stat, s->core->resample_method)))
+        if (!(resampler = pa_resampler_new(spec, &s->sample_spec, s->core->memblock_stat, resample_method)))
             return NULL;
     
     i = pa_xmalloc(sizeof(struct pa_sink_input));
index 3767830043e8e59cc2c214c803eb9b8078707513..7c648ac129be4062328102d4766472bb19acd7ad 100644 (file)
@@ -62,7 +62,7 @@ struct pa_sink_input {
     struct pa_resampler *resampler;
 };
 
-struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, const struct pa_sample_spec *spec, int variable_rate);
+struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, const struct pa_sample_spec *spec, int variable_rate, int resample_method);
 void pa_sink_input_unref(struct pa_sink_input* i);
 struct pa_sink_input* pa_sink_input_ref(struct pa_sink_input* i);
 
index 60a58f47324c757afcc3c5445a8252768f982e02..b77d6d615ecd23b531b663794d3e86b32714477a 100644 (file)
@@ -145,7 +145,7 @@ int pa_play_file(struct pa_sink *sink, const char *fname, pa_volume_t volume) {
         goto fail;
     }
     
-    if (!(u->sink_input = pa_sink_input_new(sink, fname, &ss, 0)))
+    if (!(u->sink_input = pa_sink_input_new(sink, fname, &ss, 0, -1)))
         goto fail;
 
     u->sink_input->volume = volume;
index 252c155cf9069d72008987d2b944748a60e513dd..13b396582d43cd0f1d5e3bd0193e0bae155cf205 100644 (file)
@@ -33,7 +33,7 @@
 #include "subscribe.h"
 #include "log.h"
 
-struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec) {
+struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec, int resample_method) {
     struct pa_source_output *o;
     struct pa_resampler *resampler = NULL;
     int r;
@@ -44,8 +44,11 @@ struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *n
         return NULL;
     }
 
+    if (resample_method < 0)
+        resample_method = s->core->resample_method;
+
     if (!pa_sample_spec_equal(&s->sample_spec, spec))
-        if (!(resampler = pa_resampler_new(&s->sample_spec, spec, s->core->memblock_stat, s->core->resample_method)))
+        if (!(resampler = pa_resampler_new(&s->sample_spec, spec, s->core->memblock_stat, resample_method)))
             return NULL;
     
     o = pa_xmalloc(sizeof(struct pa_source_output));
index ed09b53706b1575be4e18370dbf8aa2fa832a870..51d5936b400b1db18632f94d46d0de415e3890b0 100644 (file)
@@ -57,7 +57,7 @@ struct pa_source_output {
     void *userdata;
 };
 
-struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec);
+struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec, int resample_method);
 void pa_source_output_unref(struct pa_source_output* o);
 struct pa_source_output* pa_source_output_ref(struct pa_source_output *o);
 
index e4dcd1c9ca9d1f3f2f41e097e9df3a854a1f20d5..b9bf9f829b32cdb96583d2defd61a6f78798d674 100644 (file)
@@ -41,6 +41,8 @@
 #include <sys/resource.h>
 #include <limits.h>
 
+#include <samplerate.h>
+
 #include "util.h"
 #include "xmalloc.h"
 #include "log.h"
@@ -420,3 +422,19 @@ const char *pa_strsignal(int sig) {
     }
 }
 
+int pa_parse_resample_method(const char *string) {
+    assert(string);
+
+    if (!strcmp(string, "sinc-best-quality"))
+        return SRC_SINC_BEST_QUALITY;
+    else if (!strcmp(string, "sinc-medium-quality"))
+        return SRC_SINC_MEDIUM_QUALITY;
+    else if (!strcmp(string, "sinc-fastest"))
+        return SRC_SINC_FASTEST;
+    else if (!strcmp(string, "zero-order-hold"))
+        return SRC_ZERO_ORDER_HOLD;
+    else if (!strcmp(string, "linear"))
+        return SRC_LINEAR;
+    else
+        return -1;
+}
index 07072df6f799e85de2040403596c1c05119d357f..c842a1c38fa2be22c701e3a0734bf1129cd6a902 100644 (file)
@@ -64,4 +64,6 @@ char *pa_split_spaces(const char *c, const char **state);
 
 const char *pa_strsignal(int sig);
 
+int pa_parse_resample_method(const char *string);
+
 #endif