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;
}
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)
"master",
"slaves",
"adjust_time",
+ "resample_method",
NULL
};
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);
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;
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;
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;
}
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;
}
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;
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;
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;
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;
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));
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));
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;
}
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;
#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;
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));
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);
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;
#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;
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));
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);
#include <sys/resource.h>
#include <limits.h>
+#include <samplerate.h>
+
#include "util.h"
#include "xmalloc.h"
#include "log.h"
}
}
+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;
+}
const char *pa_strsignal(int sig);
+int pa_parse_resample_method(const char *string);
+
#endif