add resample_method option module-combine

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@215 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2004-09-17 21:10:05 +00:00
parent 08953564bb
commit 61ec86c90f
14 changed files with 59 additions and 33 deletions

View file

@ -125,25 +125,16 @@ int pa_daemon_conf_set_log_target(struct pa_daemon_conf *c, const char *string)
return -1; return -1;
return 0; return 0;
} }
int pa_daemon_conf_set_resample_method(struct pa_daemon_conf *c, const char *string) { int pa_daemon_conf_set_resample_method(struct pa_daemon_conf *c, const char *string) {
int m;
assert(c && string); assert(c && string);
if (!strcmp(string, "sinc-best-quality")) if ((m = pa_parse_resample_method(string)) < 0)
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
return -1; return -1;
c->resample_method = m;
return 0; return 0;
} }

View file

@ -40,7 +40,7 @@
PA_MODULE_AUTHOR("Lennart Poettering") PA_MODULE_AUTHOR("Lennart Poettering")
PA_MODULE_DESCRIPTION("Combine multiple sinks to one") PA_MODULE_DESCRIPTION("Combine multiple sinks to one")
PA_MODULE_VERSION(PACKAGE_VERSION) 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 DEFAULT_SINK_NAME "combined"
#define MEMBLOCKQ_MAXLENGTH (1024*170) #define MEMBLOCKQ_MAXLENGTH (1024*170)
@ -53,6 +53,7 @@ static const char* const valid_modargs[] = {
"master", "master",
"slaves", "slaves",
"adjust_time", "adjust_time",
"resample_method",
NULL 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); 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; struct output *o = NULL;
char t[256]; char t[256];
assert(u && sink && u->sink); 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); 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); 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; goto fail;
o->sink_input->get_latency = sink_input_get_latency_cb; 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) { int pa__init(struct pa_core *c, struct pa_module*m) {
struct userdata *u; struct userdata *u;
struct pa_modargs *ma = NULL; struct pa_modargs *ma = NULL;
const char *master_name, *slaves; const char *master_name, *slaves, *rm;
struct pa_sink *master_sink; struct pa_sink *master_sink;
char *n = NULL; char *n = NULL;
const char*split_state; const char*split_state;
struct timeval tv; struct timeval tv;
int resample_method = -1;
assert(c && m); assert(c && m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
pa_log(__FILE__": failed to parse module arguments\n"); pa_log(__FILE__": failed to parse module arguments\n");
goto fail; 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)); u = pa_xmalloc(sizeof(struct userdata));
m->userdata = u; 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->get_latency = sink_get_latency_cb;
u->sink->userdata = u; 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); pa_log(__FILE__": failed to create master sink input on sink '%s'.\n", u->sink->name);
goto fail; goto fail;
} }
@ -341,7 +350,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
pa_xfree(n); 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); pa_log(__FILE__": failed to create slave sink input on sink '%s'.\n", slave_sink->name);
goto fail; goto fail;
} }

View 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); calc_sine(u->memblock->data, u->memblock->length, frequency);
snprintf(t, sizeof(t), "Sine Generator at %u Hz", 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; goto fail;
u->sink_input->peek = sink_input_peek; u->sink_input->peek = sink_input_peek;

View file

@ -88,7 +88,7 @@ int pa_play_memchunk(struct pa_sink *sink, const char *name, const struct pa_sam
if (volume <= 0) if (volume <= 0)
return 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; return -1;
si->volume = volume; si->volume = volume;

View 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; c->playback.fragment_size = l/10;
assert(!c->sink_input); 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); assert(c->sink_input);
c->sink_input->owner = c->protocol->module; 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); pa_iochannel_socket_set_sndbuf(c->io, l/RECORD_BUFFER_FRAGMENTS*2);
assert(!c->source_output); 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); assert(c->source_output);
c->source_output->owner = c->protocol->module; c->source_output->owner = c->protocol->module;

View file

@ -251,7 +251,7 @@ static struct record_stream* record_stream_new(struct connection *c, struct pa_s
size_t base; size_t base;
assert(c && source && ss && name && maxlength); 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; return NULL;
s = pa_xmalloc(sizeof(struct record_stream)); 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; struct pa_sink_input *sink_input;
assert(c && sink && ss && name && maxlength); 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; return NULL;
s = pa_xmalloc(sizeof(struct playback_stream)); s = pa_xmalloc(sizeof(struct playback_stream));

View file

@ -314,7 +314,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
goto fail; 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"); pa_log(__FILE__": Failed to create sink input.\n");
goto fail; goto fail;
} }
@ -344,7 +344,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
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) { if (!c->source_output) {
pa_log(__FILE__": Failed to create source output.\n"); pa_log(__FILE__": Failed to create source output.\n");
goto fail; goto fail;

View file

@ -36,7 +36,7 @@
#define CONVERT_BUFFER_LENGTH 4096 #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_sink_input *i;
struct pa_resampler *resampler = NULL; struct pa_resampler *resampler = NULL;
int r; 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"); pa_log(__FILE__": Failed to create sink input: too many inputs per sink.\n");
return NULL; return NULL;
} }
if (resample_method < 0)
resample_method = s->core->resample_method;
if (variable_rate || !pa_sample_spec_equal(spec, &s->sample_spec)) 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; return NULL;
i = pa_xmalloc(sizeof(struct pa_sink_input)); i = pa_xmalloc(sizeof(struct pa_sink_input));

View file

@ -62,7 +62,7 @@ struct pa_sink_input {
struct pa_resampler *resampler; 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); void pa_sink_input_unref(struct pa_sink_input* i);
struct pa_sink_input* pa_sink_input_ref(struct pa_sink_input* i); struct pa_sink_input* pa_sink_input_ref(struct pa_sink_input* i);

View file

@ -145,7 +145,7 @@ int pa_play_file(struct pa_sink *sink, const char *fname, pa_volume_t volume) {
goto fail; 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; goto fail;
u->sink_input->volume = volume; u->sink_input->volume = volume;

View file

@ -33,7 +33,7 @@
#include "subscribe.h" #include "subscribe.h"
#include "log.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_source_output *o;
struct pa_resampler *resampler = NULL; struct pa_resampler *resampler = NULL;
int r; int r;
@ -44,8 +44,11 @@ struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *n
return NULL; return NULL;
} }
if (resample_method < 0)
resample_method = s->core->resample_method;
if (!pa_sample_spec_equal(&s->sample_spec, spec)) 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; return NULL;
o = pa_xmalloc(sizeof(struct pa_source_output)); o = pa_xmalloc(sizeof(struct pa_source_output));

View file

@ -57,7 +57,7 @@ struct pa_source_output {
void *userdata; 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); void pa_source_output_unref(struct pa_source_output* o);
struct pa_source_output* pa_source_output_ref(struct pa_source_output *o); struct pa_source_output* pa_source_output_ref(struct pa_source_output *o);

View file

@ -41,6 +41,8 @@
#include <sys/resource.h> #include <sys/resource.h>
#include <limits.h> #include <limits.h>
#include <samplerate.h>
#include "util.h" #include "util.h"
#include "xmalloc.h" #include "xmalloc.h"
#include "log.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;
}

View file

@ -64,4 +64,6 @@ char *pa_split_spaces(const char *c, const char **state);
const char *pa_strsignal(int sig); const char *pa_strsignal(int sig);
int pa_parse_resample_method(const char *string);
#endif #endif