diff --git a/build/rtbuf/Makefile b/build/rtbuf/Makefile
index cb6a229..7c57a76 100644
--- a/build/rtbuf/Makefile
+++ b/build/rtbuf/Makefile
@@ -8,7 +8,7 @@ CFLAGS = -O0 -ggdb -W -Wall -Werror
LDFLAGS = -L${SRCDIR}/../cli/build/so
LIBS = -lcli -lpthread
HEADERS = rtbuf.h rtbuf_lib.h symbol.h
-OBJECTS = rtbuf.o rtbuf_lib.o rtbuf_cli.o symbol.o
+OBJECTS = rtbuf.o rtbuf_lib.o rtbuf_cli.o rtbuf_fun.o symbol.o
SRC = ${HEADERS} ${OBJECTS:%.o=%.c}
diff --git a/rtbuf.c b/rtbuf.c
index cec4ccc..f56e440 100644
--- a/rtbuf.c
+++ b/rtbuf.c
@@ -4,6 +4,8 @@
#include <stdlib.h>
#include <strings.h>
#include "rtbuf.h"
+#include "rtbuf_lib.h"
+#include "symbol.h"
s_rtbuf g_rtbuf[RTBUF_MAX];
unsigned int g_rtbuf_max = RTBUF_MAX;
@@ -14,6 +16,7 @@ int g_rtbuf_sorted[RTBUF_MAX];
unsigned int g_rtbuf_sorted_n = 0;
void print_rtbuf (unsigned int i);
+void print_rtbuf_fun (s_rtbuf_fun *fun);
int rtbuf_init ()
{
@@ -44,10 +47,10 @@ int rtbuf_new (s_rtbuf_fun *rf)
assert(rf);
if ((rtb = rtbuf_next()) < 0)
return -1;
- g_rtbuf[rtb].data = calloc(rf->spec.nmemb, rf->spec.size);
+ g_rtbuf[rtb].data = calloc(rf->nmemb, rf->size);
g_rtbuf[rtb].fun = rf;
- g_rtbuf[rtb].var = calloc(rf->spec.nvar, sizeof(int));
- while (j < rf->spec.nvar)
+ g_rtbuf[rtb].var = calloc(rf->var_n, sizeof(int));
+ while (j < rf->var_n)
g_rtbuf[rtb].var[j++] = -1;
g_rtbuf_sort = 1;
return rtb;
@@ -73,7 +76,7 @@ void rtbuf_var_bind (s_rtbuf *rtb, unsigned int i, int target)
void rtbuf_unbind (s_rtbuf *rtb)
{
- unsigned int i = rtb->fun->spec.nvar;
+ unsigned int i = rtb->fun->var_n;
while (i--)
rtbuf_var_unbind(rtb, i);
}
@@ -100,7 +103,7 @@ typedef struct rtbuf_var_stack {
void rtbuf_var_stack_init (s_rtbuf_var_stack *rvs)
{
- printf("rtbuf_var_stack_init\n");
+ //printf("rtbuf_var_stack_init\n");
bzero(rvs, sizeof(s_rtbuf_var_stack));
}
@@ -108,7 +111,7 @@ s_rtbuf_var_ptr * rtbuf_var_stack_push (s_rtbuf_var_stack *rvs,
unsigned int rtb,
unsigned int var)
{
- printf("rtbuf_var_stack_push %i %i\n", rtb, var);
+ //printf("rtbuf_var_stack_push %i %i\n", rtb, var);
s_rtbuf_var_ptr *top;
if (rvs->size >= RTBUF_MAX)
return 0;
@@ -121,7 +124,7 @@ s_rtbuf_var_ptr * rtbuf_var_stack_push (s_rtbuf_var_stack *rvs,
s_rtbuf_var_ptr * rtbuf_var_stack_pop (s_rtbuf_var_stack *rvs)
{
- printf("rtbuf_var_stack_pop\n");
+ //printf("rtbuf_var_stack_pop\n");
if (rvs->size <= 0)
return 0;
rvs->size--;
@@ -131,13 +134,13 @@ s_rtbuf_var_ptr * rtbuf_var_stack_pop (s_rtbuf_var_stack *rvs)
s_rtbuf_var_ptr * rtbuf_var_stack_top (s_rtbuf_var_stack *rvs)
{
s_rtbuf_var_ptr *top;
- printf("rtbuf_var_stack_top\n");
+ //printf("rtbuf_var_stack_top\n");
if (rvs->size <= 0) {
- printf(" rtbuf_var_stack_top => 0\n");
+ //printf(" rtbuf_var_stack_top => 0\n");
return 0;
}
top = &rvs->st[rvs->size - 1];
- printf(" rtbuf_var_stack_top => { %u, %u }\n", top->rtb, top->var);
+ //printf(" rtbuf_var_stack_top => { %u, %u }\n", top->rtb, top->var);
return top;
}
@@ -147,9 +150,9 @@ void rtbuf_find_roots (s_rtbuf_var_stack *rvs)
unsigned int i = 0;
unsigned int n = g_rtbuf_n;
unsigned int c = 0;
- printf("rtbuf_find_roots\n");
+ //printf("rtbuf_find_roots\n");
while (i < RTBUF_MAX && n > 0) {
- printf(" rtbuf_find_roots %u %u\n", i, n);
+ //printf(" rtbuf_find_roots %u %u\n", i, n);
if (rtb->data) {
if (rtb->flags & RTBUF_DELETE)
rtbuf_delete(rtb);
@@ -164,7 +167,7 @@ void rtbuf_find_roots (s_rtbuf_var_stack *rvs)
rtb++;
i++;
}
- printf(" rtbuf_find_roots => %u\n", c);
+ //printf(" rtbuf_find_roots => %u\n", c);
}
void rtbuf_sort_push_child (s_rtbuf_var_stack *rvs,
@@ -173,7 +176,7 @@ void rtbuf_sort_push_child (s_rtbuf_var_stack *rvs,
int rtb;
unsigned int i = 0;
int found = 0;
- printf("rtbuf_sort_push_child { %u, %u }\n", ptr->rtb, ptr->var);
+ //printf("rtbuf_sort_push_child { %u, %u }\n", ptr->rtb, ptr->var);
rtb = g_rtbuf[ptr->rtb].var[ptr->var];
ptr->var++;
if (rtb >= 0) {
@@ -216,7 +219,7 @@ void rtbuf_sort ()
rtbuf_find_roots(&rvs);
g_rtbuf_sorted_n = 0;
while ((ptr = rtbuf_var_stack_top(&rvs))) {
- if (ptr->var == g_rtbuf[ptr->rtb].fun->spec.nvar) {
+ if (ptr->var == g_rtbuf[ptr->rtb].fun->var_n) {
g_rtbuf_sorted[g_rtbuf_sorted_n++] = ptr->rtb;
rtbuf_var_stack_pop(&rvs);
} else
@@ -234,8 +237,14 @@ void rtbuf_start ()
rtbuf_sort();
while (i < g_rtbuf_sorted_n) {
s_rtbuf *rtb = &g_rtbuf[g_rtbuf_sorted[i]];
- if (rtb->fun->start)
+ if (rtb->fun->start) {
+ printf(" start ");
+ print_rtbuf(g_rtbuf_sorted[i]);
+ printf(" ");
+ print_rtbuf_fun(rtb->fun);
+ printf("\n");
rtb->fun->start(rtb);
+ }
i++;
}
}
diff --git a/rtbuf.h b/rtbuf.h
index 059c581..890fc9a 100644
--- a/rtbuf.h
+++ b/rtbuf.h
@@ -1,25 +1,34 @@
#ifndef RTBUF_H
#define RTBUF_H
-typedef struct rtbuf_spec
-{
- unsigned int nmemb; /* number of members in buffer data */
- unsigned int size; /* size of members in bytes in buffer data */
- unsigned int nvar; /* number of rtbuf variables */
-} s_rtbuf_spec;
-
typedef struct rtbuf s_rtbuf;
typedef int f_rtbuf_fun (s_rtbuf *rtbuf);
typedef struct rtbuf_fun
{
+ const char *name; /* symbol */
f_rtbuf_fun *f;
f_rtbuf_fun *start;
f_rtbuf_fun *stop;
- s_rtbuf_spec spec;
+ unsigned int nmemb; /* number of members in buffer data */
+ unsigned int size; /* size of members in bytes in buffer data */
+ const char **var;
+ unsigned int var_n; /* number of rtbuf variables */
+ struct rtbuf_lib *lib;
+ unsigned int lib_fun;
} s_rtbuf_fun;
+#define RTBUF_FUN_MAX 32768
+s_rtbuf_fun g_rtbuf_fun[RTBUF_FUN_MAX];
+unsigned int g_rtbuf_fun_n;
+
+typedef struct rtbuf_lib_fun s_rtbuf_lib_fun;
+
+s_rtbuf_fun * find_rtbuf_fun (const char *x);
+s_rtbuf_fun * new_rtbuf_fun (s_rtbuf_lib_fun *x);
+void delete_rtbuf_fun (s_rtbuf_fun *fun);
+
#define RTBUF_SORT 0x0001
#define RTBUF_DELETE 0x0002
diff --git a/rtbuf_cli.c b/rtbuf_cli.c
index db9e3dd..c8b45e3 100644
--- a/rtbuf_cli.c
+++ b/rtbuf_cli.c
@@ -5,13 +5,24 @@
#include <stdio.h>
#include <cli.h>
#include "rtbuf_lib.h"
+#include "symbol.h"
pthread_t g_rtbuf_cli_thread = 0;
void print_lib (unsigned int i)
{
assert(i < RTBUF_LIB_MAX);
- printf("#<lib %i \"%s\">\n", i, g_rtbuf_lib[i].path);
+ printf("#<lib %i %s>\n", i, g_rtbuf_lib[i].name);
+}
+
+void print_rtbuf_fun (s_rtbuf_fun *fun)
+{
+ printf("#<fun %i %s nmemb=%u size=%u var_n=%u>",
+ fun->lib_fun,
+ fun->name,
+ fun->nmemb,
+ fun->size,
+ fun->var_n);
}
void print_lib_long (unsigned int i)
@@ -20,14 +31,13 @@ void print_lib_long (unsigned int i)
unsigned int j = 0;
assert(i < RTBUF_LIB_MAX);
lib = &g_rtbuf_lib[i];
- printf("#<lib %i \"%s\"\n", i, lib->path);
+ printf("#<lib %i %s", i, lib->name);
while (j < lib->fun_n) {
- s_rtbuf_fun *fun = &lib->fun[j];
- printf(" #<fun %i %i %i %i>\n", j, fun->spec.nmemb, fun->spec.size,
- fun->spec.nvar);
+ printf("\n ");
+ print_rtbuf_fun(lib->fun[j]);
j++;
}
- printf(" >\n");
+ printf(">\n");
fflush(stdout);
}
@@ -50,9 +60,9 @@ void print_rtbuf_long (unsigned int i)
printf(" %x", rtb->flags);
printf(" %d", rtb->refc);
}
- while (j < rtb->fun->spec.nvar) {
+ while (j < rtb->fun->var_n) {
if (rtb->var[j] >= 0) {
- printf("\n var[%i] = ", j);
+ printf("\n %i %s = ", j, rtb->fun->var[j]);
print_rtbuf(rtb->var[j]);
}
j++;
@@ -80,15 +90,15 @@ int rtbuf_cli_libs (int argc, const char *argv[])
int rtbuf_cli_lib (int argc, const char *argv[])
{
- unsigned int i;
- assert(argc == 1);
- i = atoi(argv[1]);
- if (i >= RTBUF_LIB_MAX) {
- printf("library not found\n");
- return -1;
+ int i;
+ if (argc != 1)
+ return rtbuf_err("usage: lib LIBRARY");
+ i = rtbuf_lib_find(argv[1]);
+ if (0 <= i && i < RTBUF_LIB_MAX) {
+ print_lib_long(i);
+ return 0;
}
- print_lib_long(i);
- return 0;
+ return rtbuf_err("library not found");
}
int rtbuf_cli_load (int argc, const char *argv[])
@@ -146,7 +156,7 @@ int rtbuf_cli_new (int argc, const char *argv[])
return rtbuf_err("library not found");
if ((rf = rtbuf_lib_find_fun(&g_rtbuf_lib[rl], argv[2])) < 0)
return rtbuf_err("function not found");
- if ((rtb = rtbuf_new(&g_rtbuf_lib[rl].fun[rf])) < 0)
+ if ((rtb = rtbuf_new(g_rtbuf_lib[rl].fun[rf])) < 0)
return rtbuf_err("buffer not created");
print_rtbuf(rtb);
printf("\n");
@@ -177,7 +187,7 @@ int rtbuf_cli_bind (int argc, const char *argv[])
if ((rtb = rtbuf_find(argv[1])) < 0)
return rtbuf_err("buffer not found");
var = atoi(argv[2]);
- if (var < 0 || (unsigned int) var >= g_rtbuf[rtb].fun->spec.nvar)
+ if (var < 0 || (unsigned int) var >= g_rtbuf[rtb].fun->var_n)
return rtbuf_err("variable not found");
if ((target = rtbuf_find(argv[3])) < 0)
return rtbuf_err("target not found");
@@ -195,7 +205,7 @@ int rtbuf_cli_unbind (int argc, const char *argv[])
return rtbuf_err("buffer not found");
if (argc == 2) {
int var = atoi(argv[2]);
- if (var < 0 || (unsigned int) var >= g_rtbuf[rtb].fun->spec.nvar)
+ if (var < 0 || (unsigned int) var >= g_rtbuf[rtb].fun->var_n)
return rtbuf_err("variable not found");
rtbuf_var_unbind(&g_rtbuf[rtb], var);
}
@@ -327,11 +337,12 @@ int main (int argc, char *argv[])
{
(void) argc;
(void) argv;
+ init_symbols();
rtbuf_lib_init();
return repl();
}
-int rtbuf_err (const char *msg)
+extern int rtbuf_err (const char *msg)
{
fprintf(stderr, "%s\n", msg);
return -1;
diff --git a/rtbuf_fun.c b/rtbuf_fun.c
new file mode 100644
index 0000000..fcf2bc0
--- /dev/null
+++ b/rtbuf_fun.c
@@ -0,0 +1,82 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include "rtbuf.h"
+#include "rtbuf_lib.h"
+#include "symbol.h"
+
+s_rtbuf_fun g_rtbuf_fun[RTBUF_FUN_MAX];
+unsigned int g_rtbuf_fun_n = 0;
+
+int rtbuf_fun_p (s_rtbuf_fun *fun)
+{
+ return fun && fun->name;
+}
+
+s_rtbuf_fun * find_rtbuf_fun (const char *x)
+{
+ const char *sym = find_symbol(x);
+ if (sym) {
+ unsigned int i = 0;
+ unsigned int n = g_rtbuf_fun_n;
+ while (i < RTBUF_FUN_MAX && n > 0) {
+ if (rtbuf_fun_p(&g_rtbuf_fun[i]) &&
+ sym == g_rtbuf_fun[i].name)
+ return &g_rtbuf_fun[i];
+ i++;
+ }
+ }
+ return 0;
+}
+
+void init_rtbuf_fun (s_rtbuf_fun *fun, s_rtbuf_lib_fun *x)
+{
+ const char **var = x->var;
+ unsigned int j = 0;
+ fun->name = intern(x->name);
+ fun->f = x->f;
+ fun->start = x->start;
+ fun->stop = x->stop;
+ fun->nmemb = x->nmemb;
+ fun->size = x->size;
+ fun->var_n = 0;
+ if (var)
+ while (*var) {
+ fun->var_n++;
+ var++;
+ }
+ fun->var = malloc(sizeof(const char *) * (fun->var_n + 1));
+ if ((var = x->var))
+ while (*var)
+ fun->var[j++] = intern(*var++);
+ fun->var[j] = 0;
+}
+
+s_rtbuf_fun * new_rtbuf_fun (s_rtbuf_lib_fun *x)
+{
+ unsigned int i = 0;
+ if (g_rtbuf_fun_n == RTBUF_FUN_MAX) {
+ fprintf(stderr, "RTBUF_FUN_MAX exceeded\n");
+ return 0;
+ }
+ while (i < RTBUF_FUN_MAX) {
+ if (!rtbuf_fun_p(&g_rtbuf_fun[i])) {
+ init_rtbuf_fun(&g_rtbuf_fun[i], x);
+ g_rtbuf_fun_n++;
+ return &g_rtbuf_fun[i];
+ }
+ i++;
+ }
+ return 0;
+}
+
+void delete_rtbuf_fun (s_rtbuf_fun *fun)
+{
+ if (fun && fun->var) {
+ free(fun->var);
+ bzero(fun, sizeof(s_rtbuf_fun));
+ g_rtbuf_fun_n--;
+ }
+ fun->name = 0;
+}
diff --git a/rtbuf_lib.c b/rtbuf_lib.c
index 64feabc..4450118 100644
--- a/rtbuf_lib.c
+++ b/rtbuf_lib.c
@@ -6,6 +6,7 @@
#include <string.h>
#include <strings.h>
#include "rtbuf_lib.h"
+#include "symbol.h"
s_rtbuf_lib g_rtbuf_lib[RTBUF_LIB_MAX];
unsigned int g_rtbuf_lib_n = 0;
@@ -32,22 +33,50 @@ void rtbuf_lib_init ()
*out = 0;
}
+int rtbuf_lib_p (s_rtbuf_lib *lib)
+{
+ return lib->lib ? 1 : 0;
+}
+
int rtbuf_lib_find (const char *str)
{
- int i = atoi(str);
- if (0 <= i && i < RTBUF_LIB_MAX) {
- s_rtbuf_lib *lib = &g_rtbuf_lib[i];
- if (lib->path[0] && lib->lib && lib->fun)
+ const char *sym;
+ if ('0' <= str[0] && str[0] <= '9') {
+ int i = atoi(str);
+ if (0 <= i && i < RTBUF_LIB_MAX && rtbuf_lib_p(&g_rtbuf_lib[i]))
return i;
}
+ if ((sym = find_symbol(str))) {
+ unsigned int i = 0;
+ unsigned int n = g_rtbuf_lib_n;
+ while (i < RTBUF_LIB_MAX && n > 0) {
+ if (rtbuf_lib_p(&g_rtbuf_lib[i])) {
+ if (sym == g_rtbuf_lib[i].name)
+ return i;
+ n--;
+ }
+ i++;
+ }
+ }
return -1;
}
int rtbuf_lib_find_fun (s_rtbuf_lib *rl, const char *str)
{
- int i = atoi(str);
- if (0 <= i && (unsigned) i < rl->fun_n)
- return i;
+ const char *sym;
+ if ('0' <= str[0] && str[0] <= '9') {
+ int i = atoi(str);
+ if (0 <= i && (unsigned) i < rl->fun_n)
+ return i;
+ }
+ if ((sym = find_symbol(str))) {
+ unsigned int i = 0;
+ while (i < rl->fun_n) {
+ if (sym == rl->fun[i]->name)
+ return i;
+ i++;
+ }
+ }
return -1;
}
@@ -56,7 +85,7 @@ s_rtbuf_lib * rtbuf_lib_new ()
unsigned int i = 0;
s_rtbuf_lib *lib = g_rtbuf_lib;
while (i < RTBUF_LIB_MAX) {
- if (lib->path[0] == 0) {
+ if (lib->path == 0) {
g_rtbuf_lib_n++;
return lib;
}
@@ -79,31 +108,32 @@ void rtbuf_lib_load_path (s_rtbuf_lib *lib, const char *name)
lib->lib = 0;
while (*path && !lib->lib) {
const char *in = *path++;
- char *out = lib->path;
+ lib->path = &g_string[g_string_n];
while (*in)
- *out++ = *in++;
+ g_string[g_string_n++] = *in++;
in = name;
while (*in)
- *out++ = *in++;
+ g_string[g_string_n++] = *in++;
in = ".so";
while (*in)
- *out++ = *in++;
- *out = 0;
+ g_string[g_string_n++] = *in++;
+ g_string[g_string_n++] = 0;
printf("lib_load path \"%s\"\n", lib->path);
lib->lib = dlopen(lib->path, 0);
- printf("lib_load lib %p\n", lib->lib);
}
}
-int rtbuf_fun_p (s_rtbuf_fun *fun)
+int rtbuf_lib_fun_p (s_rtbuf_lib_fun *fun)
{
- return fun->f || fun->start || fun->stop;
+ return fun->name || fun->f || fun->start || fun->stop;
}
s_rtbuf_lib * rtbuf_lib_load (const char *name)
{
s_rtbuf_lib *lib = rtbuf_lib_new();
+ s_rtbuf_lib_fun *fun;
unsigned long *ver;
+ unsigned int i = 0;
if (!lib)
return 0;
rtbuf_lib_load_path(lib, name);
@@ -114,10 +144,26 @@ s_rtbuf_lib * rtbuf_lib_load (const char *name)
ver = dlsym(lib->lib, "rtbuf_lib_ver");
printf("lib_load ver %lu\n", *ver);
assert(*ver == RTBUF_LIB_VER);
- lib->fun = dlsym(lib->lib, "rtbuf_lib_fun");
+ lib->name = intern(name);
+ printf("lib_load name %s\n", lib->name);
+ fun = dlsym(lib->lib, "rtbuf_lib_fun");
lib->fun_n = 0;
while (lib->fun_n < RTBUF_LIB_MAX &&
- rtbuf_fun_p(&lib->fun[lib->fun_n]))
+ rtbuf_lib_fun_p(&fun[lib->fun_n])) {
+ if (fun[lib->fun_n].name == 0) {
+ Dl_info info;
+ dladdr(fun[lib->fun_n].f, &info);
+ fun[lib->fun_n].name = intern(info.dli_sname);
+ }
lib->fun_n++;
+ }
+ lib->fun = malloc(sizeof(s_rtbuf_fun*) * (lib->fun_n + 1));
+ while (i < lib->fun_n) {
+ lib->fun[i] = new_rtbuf_fun(&fun[i]);
+ lib->fun[i]->lib = lib;
+ lib->fun[i]->lib_fun = i;
+ i++;
+ }
+ lib->fun[i] = 0;
return lib;
}
diff --git a/rtbuf_lib.h b/rtbuf_lib.h
index 3a84869..8f89382 100644
--- a/rtbuf_lib.h
+++ b/rtbuf_lib.h
@@ -6,12 +6,22 @@
#define RTBUF_LIB_MAX 1000
#define RTBUF_LIB_VER 0x00010001
+typedef struct rtbuf_lib_fun {
+ const char *name;
+ f_rtbuf_fun *f;
+ f_rtbuf_fun *start;
+ f_rtbuf_fun *stop;
+ unsigned int nmemb; /* number of members in buffer data */
+ unsigned int size; /* size of members in bytes in buffer data */
+ const char **var; /* names of variables, end with NULL */
+} s_rtbuf_lib_fun;
+
typedef struct rtbuf_lib {
- s_rtbuf_fun *fun;
+ const char *name;
+ s_rtbuf_fun **fun;
unsigned int fun_n;
void *lib;
- char path[1024];
- char *name;
+ const char *path;
} s_rtbuf_lib;
extern s_rtbuf_lib g_rtbuf_lib[];
diff --git a/rtbuf_signal.c b/rtbuf_signal.c
index 4ffd8aa..3a56bd7 100644
--- a/rtbuf_signal.c
+++ b/rtbuf_signal.c
@@ -16,16 +16,18 @@ typedef struct sinus_data {
double phase;
} s_sinus_data;
-static int sinus (s_rtbuf *rtb);
-static int sinus_start (s_rtbuf *rtb);
-
-unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
-s_rtbuf_fun rtbuf_lib_fun[] = {
- { sinus, sinus_start, 0,
- { sizeof(s_sinus_data) / sizeof(double),
- sizeof(double),
- SINUS_ARITY } },
- { 0, 0, 0, { 0, 0, 0 } }
+extern int sinus (s_rtbuf *rtb);
+extern int sinus_start (s_rtbuf *rtb);
+
+const char *sinus_vars[] = { "frequency", "amplitude", 0 };
+
+const char *rtbuf_lib_name = "signal";
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
+s_rtbuf_lib_fun rtbuf_lib_fun[] = {
+ { "sinus", sinus, sinus_start, 0,
+ sizeof(s_sinus_data) / sizeof(double),
+ sizeof(double), sinus_vars },
+ { 0, 0, 0, 0, 0, 0, 0 }
};
int sinus (s_rtbuf *rtb)
@@ -37,7 +39,7 @@ int sinus (s_rtbuf *rtb)
double *freq_samples = freq < 0 ? 0 : (double*) g_rtbuf[freq].data;
phase = data->phase;
while (i < RTBUF_SIGNAL_SAMPLES) {
- double f = freq ? freq_samples[i] : 220;
+ double f = freq_samples ? freq_samples[i] : 220;
//printf(" i=%u freq=%f", i, f);
f /= (double) RTBUF_SIGNAL_SAMPLERATE;
phase = phase + 2.0 * M_PI * f;
diff --git a/rtbuf_sndio.c b/rtbuf_sndio.c
index 011fbbb..2f04fbf 100644
--- a/rtbuf_sndio.c
+++ b/rtbuf_sndio.c
@@ -31,15 +31,20 @@ typedef struct sndio_output_data {
static int sndio_output (s_rtbuf *rtb);
static int sndio_output_start (s_rtbuf *rtb);
static int sndio_output_stop (s_rtbuf *rtb);
-
-unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
-s_rtbuf_fun rtbuf_lib_fun[] = {
- { sndio_input, sndio_input_start, sndio_input_stop,
- { sizeof(s_sndio_input_data) / sizeof(double), sizeof(double),
- 0 } },
- { sndio_output, sndio_output_start, sndio_output_stop,
- { 1, sizeof(s_sndio_output_data), RTBUF_SNDIO_CHANNELS } },
- { 0, 0, 0, { 0, 0, 0 } }
+static const char *sndio_output_vars[] = { "left", "right", 0 };
+
+extern const char *rtbuf_lib_name;
+extern unsigned long rtbuf_lib_ver;
+extern s_rtbuf_lib_fun rtbuf_lib_fun[];
+
+const char *rtbuf_lib_name = "sndio";
+unsigned long rtbuf_lib_ver = RTBUF_LIB_VER;
+s_rtbuf_lib_fun rtbuf_lib_fun[] = {
+ { "input", sndio_input, sndio_input_start, sndio_input_stop,
+ sizeof(s_sndio_input_data) / sizeof(double), sizeof(double), 0 },
+ { "output", sndio_output, sndio_output_start, sndio_output_stop,
+ 1, sizeof(s_sndio_output_data), sndio_output_vars },
+ { 0, 0, 0, 0, 0, 0, 0 }
};
int sndio_input (s_rtbuf *rtb)
@@ -170,9 +175,10 @@ int sndio_output (s_rtbuf *rtb)
//printf("\n");
return 0;
}
-
+/*
int rtbuf_err (const char *msg)
{
fprintf(stderr, "%s\n", msg);
return -1;
}
+*/
diff --git a/symbol.c b/symbol.c
index 0f22667..d50b6fb 100644
--- a/symbol.c
+++ b/symbol.c
@@ -4,50 +4,63 @@
#include <strings.h>
#include "symbol.h"
-s_symbol g_symbols[SYMBOL_MAX];
+char g_string[STRING_MAX];
+unsigned int g_string_n = 0;
+
+const char *g_symbols[SYMBOL_MAX];
unsigned int g_symbols_n = 0;
void init_symbols () {
+ bzero(g_string, sizeof(g_string));
bzero(g_symbols, sizeof(g_symbols));
}
-int find_symbol (const char *name)
+symbol find_symbol (const char *name)
{
unsigned int i = 0;
unsigned int n = g_symbols_n;
while (i < SYMBOL_MAX && n > 0) {
- if (g_symbols[i].name) {
- if (strcmp(name, g_symbols[i].name) == 0)
- return i;
+ if (g_symbols[i]) {
+ if (name == g_symbols[i] ||
+ strcmp(name, g_symbols[i]) == 0)
+ return g_symbols[i];
n--;
}
i++;
}
- return -1;
+ return 0;
}
-int make_symbol (const char *name)
+symbol make_symbol (const char *name)
{
unsigned int i = 0;
if (g_symbols_n == SYMBOL_MAX) {
fprintf(stderr, "maximum number of symbols exceeded\n");
- return -1;
+ return 0;
}
while (i < SYMBOL_MAX) {
- if (g_symbols[i].name == 0) {
- g_symbols[i].name = name;
+ if (g_symbols[i] == 0) {
+ const char *in = name;
+ char *out = &g_string[g_string_n];
+ g_symbols[i] = out;
+ while (*in) {
+ *out++ = *in++;
+ g_string_n++;
+ }
+ *out = 0;
+ g_string_n++;
g_symbols_n++;
- return i;
+ return g_symbols[i];
}
i++;
}
- return -1;
+ return 0;
}
-int intern (const char *name)
+const char * intern (const char *name)
{
- int i = find_symbol(name);
- if (i < 0)
- i = make_symbol(name);
- return i;
+ const char *sym = find_symbol(name);
+ if (sym == 0)
+ sym = make_symbol(name);
+ return sym;
}
diff --git a/symbol.h b/symbol.h
index 98e16d7..f2bf1ae 100644
--- a/symbol.h
+++ b/symbol.h
@@ -1,17 +1,19 @@
#ifndef SYMBOL_H
#define SYMBOL_H
-typedef struct symbol
-{
- const char *name;
-} s_symbol;
+typedef const char *symbol;
+
+#define STRING_MAX 65536
+extern char g_string[STRING_MAX];
+extern unsigned int g_string_n;
#define SYMBOL_MAX 32768
-s_symbol g_symbols[SYMBOL_MAX];
-unsigned int g_symbols_n;
+extern symbol g_symbols[SYMBOL_MAX];
+extern unsigned int g_symbols_n;
-int find_symbol (const char *name);
-int make_symbol (const char *name);
-int intern (const char *name);
+void init_symbols ();
+symbol find_symbol (symbol name);
+symbol make_symbol (symbol name);
+symbol intern (symbol name);
#endif