implement missing scache_get_id_by_name

add some more consts to idxset
add module-sine, a sine generating sink_input module


git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@165 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2004-09-01 12:21:06 +00:00
parent 36550f4a66
commit fa19d6ab7e
7 changed files with 195 additions and 15 deletions

View file

@ -2,7 +2,7 @@
*** 0.4 ***
- make mcalign merge chunks
- use ref counting in more objects
- use ref counting in more objects (i.e. sink, source, sink_input, source_output)
- unix socket directories include user name
- native library/protocol:
module load/unload
@ -14,6 +14,7 @@
- remove all gcc warnings
- esd compatible startup script or personality
- limit number of concurrent streams
- decibel macros
** later ***
- xmlrpc/http
@ -28,4 +29,3 @@ backends for:
- sdl
- gstreamer
- portaudio
- python

View file

@ -79,7 +79,8 @@ pkglib_LTLIBRARIES=libiochannel.la \
module-esound-protocol-tcp.la \
module-esound-protocol-unix.la \
module-native-protocol-tcp.la \
module-native-protocol-unix.la
module-native-protocol-unix.la \
module-sine.la
if !X_DISPLAY_MISSING
pkglib_LTLIBRARIES+=module-x11-bell.la
@ -273,6 +274,10 @@ module_cli_la_SOURCES = module-cli.c
module_cli_la_LDFLAGS = -module -avoid-version
module_cli_la_LIBADD = $(AM_LIBADD) libcli.la libiochannel.la
module_sine_la_SOURCES = module-sine.c
module_sine_la_LDFLAGS = -module -avoid-version
module_sine_la_LIBADD = $(AM_LIBADD) -lm
if !X_DISPLAY_MISSING
module_x11_bell_la_SOURCES = module-x11-bell.c
module_x11_bell_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS)

View file

@ -107,7 +107,7 @@ void pa_idxset_free(struct pa_idxset *s, void (*free_func) (void *p, void *userd
pa_xfree(s);
}
static struct idxset_entry* hash_scan(struct pa_idxset *s, struct idxset_entry* e, void *p) {
static struct idxset_entry* hash_scan(struct pa_idxset *s, struct idxset_entry* e, const void *p) {
assert(p);
assert(s->compare_func);
@ -221,7 +221,7 @@ void* pa_idxset_get_by_index(struct pa_idxset*s, uint32_t index) {
return (*a)->data;
}
void* pa_idxset_get_by_data(struct pa_idxset*s, void *p, uint32_t *index) {
void* pa_idxset_get_by_data(struct pa_idxset*s, const void *p, uint32_t *index) {
unsigned h;
struct idxset_entry *e;
assert(s && p);
@ -289,9 +289,10 @@ void* pa_idxset_remove_by_index(struct pa_idxset*s, uint32_t index) {
return data;
}
void* pa_idxset_remove_by_data(struct pa_idxset*s, void *data, uint32_t *index) {
void* pa_idxset_remove_by_data(struct pa_idxset*s, const void *data, uint32_t *index) {
struct idxset_entry *e;
unsigned h;
void *r;
assert(s->hash_func);
h = s->hash_func(data) % s->hash_table_size;
@ -300,13 +301,13 @@ void* pa_idxset_remove_by_data(struct pa_idxset*s, void *data, uint32_t *index)
if (!(e = hash_scan(s, s->hash_table[h], data)))
return NULL;
data = e->data;
r = e->data;
if (index)
*index = e->index;
remove_entry(s, e);
return data;
return r;
}
void* pa_idxset_rrobin(struct pa_idxset *s, uint32_t *index) {

View file

@ -40,10 +40,10 @@ void pa_idxset_free(struct pa_idxset *s, void (*free_func) (void *p, void *userd
int pa_idxset_put(struct pa_idxset*s, void *p, uint32_t *index);
void* pa_idxset_get_by_index(struct pa_idxset*s, uint32_t index);
void* pa_idxset_get_by_data(struct pa_idxset*s, void *p, uint32_t *index);
void* pa_idxset_get_by_data(struct pa_idxset*s, const void *p, uint32_t *index);
void* pa_idxset_remove_by_index(struct pa_idxset*s, uint32_t index);
void* pa_idxset_remove_by_data(struct pa_idxset*s, void *p, uint32_t *index);
void* pa_idxset_remove_by_data(struct pa_idxset*s, const void *p, uint32_t *index);
/* This may be used to iterate through all entries. When called with
an invalid index value it returns the first entry, otherwise the

165
polyp/module-sine.c Normal file
View file

@ -0,0 +1,165 @@
/* $Id$ */
/***
This file is part of polypaudio.
polypaudio is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
polypaudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with polypaudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include "sink-input.h"
#include "module.h"
#include "modargs.h"
#include "xmalloc.h"
#include "namereg.h"
struct userdata {
struct pa_core *core;
struct pa_sink_input *sink_input;
struct pa_memblock *memblock;
size_t peek_index;
};
static const char* const valid_modargs[] = {
"sink",
"frequency",
NULL,
};
static int sink_input_peek(struct pa_sink_input *i, struct pa_memchunk *chunk) {
struct userdata *u;
assert(i && chunk && i->userdata);
u = i->userdata;
chunk->memblock = pa_memblock_ref(u->memblock);
chunk->index = u->peek_index;
chunk->length = u->memblock->length - u->peek_index;
return 0;
}
static void sink_input_drop(struct pa_sink_input *i, const struct pa_memchunk *chunk, size_t length) {
struct userdata *u;
assert(i && chunk && length && i->userdata);
u = i->userdata;
assert(chunk->memblock == u->memblock && length <= u->memblock->length-u->peek_index);
u->peek_index += length;
if (u->peek_index >= u->memblock->length)
u->peek_index = 0;
}
static void sink_input_kill(struct pa_sink_input *i) {
struct userdata *u;
assert(i && i->userdata);
u = i->userdata;
pa_sink_input_free(u->sink_input);
u->sink_input = NULL;
}
static void calc_sine(float *f, size_t l, float freq) {
size_t i;
l /= sizeof(float);
for (i = 0; i < l; i++)
f[i] = (float) sin((double) i/l*M_PI*2*freq)/2;
}
int pa_module_init(struct pa_core *c, struct pa_module*m) {
struct pa_modargs *ma = NULL;
struct userdata *u;
struct pa_sink *sink;
const char *sink_name;
struct pa_sample_spec ss;
uint32_t frequency;
char t[256];
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
fprintf(stderr, __FILE__": Failed to parse module arguments\n");
goto fail;
}
m->userdata = u = pa_xmalloc(sizeof(struct userdata));
u->core = c;
u->sink_input = NULL;
u->memblock = NULL;
sink_name = pa_modargs_get_value(ma, "sink", NULL);
if (!(sink = pa_namereg_get(c, sink_name, PA_NAMEREG_SINK, 1))) {
fprintf(stderr, __FILE__": No such sink\n");
goto fail;
}
ss.format = PA_SAMPLE_FLOAT32;
ss.rate = sink->sample_spec.rate;
ss.channels = 1;
frequency = 440;
if (pa_modargs_get_value_u32(ma, "frequency", &frequency) < 0 || frequency < 1 || frequency > ss.rate/2) {
fprintf(stderr, __FILE__": Invalid frequency specification\n");
goto fail;
}
u->memblock = pa_memblock_new(pa_bytes_per_second(&ss), c->memblock_stat);
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)))
goto fail;
u->sink_input->peek = sink_input_peek;
u->sink_input->drop = sink_input_drop;
u->sink_input->kill = sink_input_kill;
u->sink_input->userdata = u;
u->sink_input->owner = m;
u->peek_index = 0;
pa_modargs_free(ma);
return 0;
fail:
if (ma)
pa_modargs_free(ma);
pa_module_done(c, m);
return -1;
}
void pa_module_done(struct pa_core *c, struct pa_module*m) {
struct userdata *u = m->userdata;
assert(c && m);
if (!u)
return;
if (u->sink_input)
pa_sink_input_free(u->sink_input);
if (u->memblock)
pa_memblock_unref(u->memblock);
pa_xfree(u);
}

View file

@ -28,12 +28,12 @@
# Load audio drivers automatically on access
autoload_sink_add output module-oss device="/dev/adsp" sink_name=output source_name=input
autoload_source_add input module-oss device="/dev/adsp" sink_name=output source_name=input
#autoload_sink_add output module-oss device="/dev/adsp" sink_name=output source_name=input
#autoload_source_add input module-oss device="/dev/adsp" sink_name=output source_name=input
#autoload_sink_add output module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
#autoload_source_add input module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
#autoload_sink_add output module-alsa-sink sink_name=output
#autoload_source_add input module-alsa-source source_name=input
autoload_sink_add output module-alsa-sink sink_name=output
autoload_source_add input module-alsa-source source_name=input
# Load several protocols
#load module-esound-protocol-tcp

View file

@ -157,5 +157,14 @@ const char * pa_scache_get_name_by_id(struct pa_core *c, uint32_t id) {
return NULL;
return e->name;
}
uint32_t pa_scache_get_id_by_name(struct pa_core *c, const char *name) {
struct pa_scache_entry *e;
assert(c && name);
if (!c->scache || !(e = pa_idxset_get_by_data(c->scache, name, NULL)))
return PA_IDXSET_INVALID;
return e->index;
}