* when playing back a sample from the sample cache, just take a pa_volume_t and not a pa_cvolume_t as argument for the volume. Usually it is not known to the player of theses samples how many channels it has, hence it doesn't make any sense to allow him to pass a by-channel volume structure here.

* fix volume calculation when playing samples from the sample cache


git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@784 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2006-04-23 19:49:01 +00:00
parent 4e61ebb981
commit 335e23473f
6 changed files with 16 additions and 18 deletions

View file

@ -66,7 +66,6 @@ static const char* const valid_modargs[] = {
static int ring_bell(struct userdata *u, int percent) {
pa_sink *s;
pa_cvolume cv;
assert(u);
if (!(s = pa_namereg_get(u->core, u->sink_name, PA_NAMEREG_SINK, 1))) {
@ -74,7 +73,7 @@ static int ring_bell(struct userdata *u, int percent) {
return -1;
}
pa_scache_play_item(u->core, u->scache_item, s, pa_cvolume_set(&cv, PA_CHANNELS_MAX, (percent*PA_VOLUME_NORM)/100));
pa_scache_play_item(u->core, u->scache_item, s, (percent*PA_VOLUME_NORM)/100);
return 0;
}

View file

@ -597,7 +597,7 @@ static int pa_cli_command_scache_play(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
return -1;
}
if (pa_scache_play_item(c, n, sink, NULL) < 0) {
if (pa_scache_play_item(c, n, sink, PA_VOLUME_NORM) < 0) {
pa_strbuf_puts(buf, "Failed to play sample.\n");
return -1;
}

View file

@ -122,7 +122,8 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
e->lazy = 0;
e->last_used_time = 0;
memset(&e->sample_spec, 0, sizeof(pa_sample_spec));
memset(&e->sample_spec, 0, sizeof(e->sample_spec));
pa_channel_map_init(&e->channel_map);
pa_cvolume_reset(&e->volume, PA_CHANNELS_MAX);
return e;
@ -240,7 +241,7 @@ void pa_scache_free(pa_core *c) {
c->mainloop->time_free(c->scache_auto_unload_event);
}
int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, const pa_cvolume *volume) {
int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t volume) {
pa_scache_entry *e;
char *t;
pa_cvolume r;
@ -257,7 +258,9 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, const pa_cv
return -1;
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index);
e->volume.channels = e->sample_spec.channels;
if (e->volume.channels > e->sample_spec.channels)
e->volume.channels = e->sample_spec.channels;
}
if (!e->memchunk.memblock)
@ -265,12 +268,8 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, const pa_cv
t = pa_sprintf_malloc("sample:%s", name);
if (volume) {
r = *volume;
r.channels = e->volume.channels;
pa_sw_cvolume_multiply(&r, &r, &e->volume);
} else
r = e->volume;
pa_cvolume_set(&r, e->volume.channels, volume);
pa_sw_cvolume_multiply(&r, &r, &e->volume);
if (pa_play_memchunk(sink, t, &e->sample_spec, &e->channel_map, &e->memchunk, &r) < 0) {
pa_xfree(t);

View file

@ -49,7 +49,7 @@ int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename,
int pa_scache_add_directory_lazy(pa_core *c, const char *pathname);
int pa_scache_remove_item(pa_core *c, const char *name);
int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, const pa_cvolume *cvolume);
int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t volume);
void pa_scache_free(pa_core *c);
const char *pa_scache_get_name_by_id(pa_core *c, uint32_t id);

View file

@ -742,7 +742,7 @@ static int esd_proto_sample_free_or_play(struct connection *c, esd_proto_t reque
pa_sink *sink;
if ((sink = pa_namereg_get(c->protocol->core, c->protocol->sink_name, PA_NAMEREG_SINK, 1)))
if (pa_scache_play_item(c->protocol->core, name, sink, NULL) >= 0)
if (pa_scache_play_item(c->protocol->core, name, sink, PA_VOLUME_NORM) >= 0)
ok = idx + 1;
} else {
assert(request == ESD_PROTO_SAMPLE_FREE);

View file

@ -57,7 +57,7 @@
#include "protocol-native.h"
/* Kick a client if it doesn't authenticate within this time */
#define AUTH_TIMEOUT 5
#define AUTH_TIMEOUT 60
/* Don't accept more connection than this */
#define MAX_CONNECTIONS 10
@ -1165,14 +1165,14 @@ static void command_finish_upload_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_
static void command_play_sample(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
struct connection *c = userdata;
uint32_t sink_index;
pa_cvolume volume;
pa_volume_t volume;
pa_sink *sink;
const char *name, *sink_name;
assert(c && t);
if (pa_tagstruct_getu32(t, &sink_index) < 0 ||
pa_tagstruct_gets(t, &sink_name) < 0 ||
pa_tagstruct_get_cvolume(t, &volume) < 0 ||
pa_tagstruct_getu32(t, &volume) < 0 ||
pa_tagstruct_gets(t, &name) < 0 ||
!pa_tagstruct_eof(t)) {
protocol_error(c);
@ -1190,7 +1190,7 @@ static void command_play_sample(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED ui
CHECK_VALIDITY(c->pstream, sink, tag, PA_ERR_NOENTITY);
if (pa_scache_play_item(c->protocol->core, name, sink, &volume) < 0) {
if (pa_scache_play_item(c->protocol->core, name, sink, volume) < 0) {
pa_pstream_send_error(c->pstream, tag, PA_ERR_NOENTITY);
return;
}