From d1590b298b8e68d9855b75e77bc22d96a5d6b9c9 Mon Sep 17 00:00:00 2001 From: Simon Budig Date: Fri, 20 Aug 2010 02:14:08 +0200 Subject: [PATCH] implement argc for the compiler/code. --- lyd/lyd-compiler.c | 5 ++++- lyd/lyd-private.h | 2 ++ lyd/lyd-voice.c | 19 +++++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lyd/lyd-compiler.c b/lyd/lyd-compiler.c index 012b6dc..94d100a 100644 --- a/lyd/lyd-compiler.c +++ b/lyd/lyd-compiler.c @@ -627,7 +627,10 @@ static void compile (LydParser *parser, program->commands[POS(t)].op = str2opcode (t->first->str); for (i=0;i< LYD_MAX_ARGS;i++) if (t->args[i]) - compile (parser, t->args[i], program, totcmds, POS(t), i); + { + program->commands[POS(t)].argc++; + compile (parser, t->args[i], program, totcmds, POS(t), i); + } } break; case unary: diff --git a/lyd/lyd-private.h b/lyd/lyd-private.h index 984f0d6..02f0df8 100644 --- a/lyd/lyd-private.h +++ b/lyd/lyd-private.h @@ -56,6 +56,7 @@ typedef enum struct _LydCommand { LydOpCode op; /* The operation to execute */ + int argc; float arg[LYD_MAX_ARGS]; /* arguments to operation */ }; @@ -68,6 +69,7 @@ struct _LydProgram typedef struct _LydCommandState { LydOpCode op; LydSample out; + int argc; LydSample *arg[LYD_MAX_ARGS]; LydSample literal[LYD_MAX_ARGS]; void *data; diff --git a/lyd/lyd-voice.c b/lyd/lyd-voice.c index c082351..592510b 100644 --- a/lyd/lyd-voice.c +++ b/lyd/lyd-voice.c @@ -31,6 +31,7 @@ static LydVoice * lyd_voice_create (Lyd *lyd, LydProgram *program) for (i = 0; program->commands[i].op; i++) { voice->state[i].op = program->commands[i].op; + voice->state[i].argc = program->commands[i].argc; for (j = 0; j < LYD_MAX_ARGS; j++) { int offset = program->commands[i].arg[j]; @@ -57,7 +58,7 @@ static LydVoice * lyd_voice_create (Lyd *lyd, LydProgram *program) return voice; } -static LydSample adsr (LydVoice *voice, LydSample **args, void **data) +static LydSample adsr (LydVoice *voice, int argc, LydSample **args, void **data) { LydSample a = *args[0], d = *args[1], s = *args[2], r = *args[3]; if (voice->released) @@ -95,6 +96,7 @@ typedef struct _ReverbData } ReverbData; static inline LydSample voice_reverb (LydVoice *voice, + int argc, LydSample **args, void **edata) { @@ -126,17 +128,21 @@ static inline LydSample voice_reverb (LydVoice *voice, } static inline LydSample voice_cycle (LydVoice *voice, + int argc, LydSample **args, void **data) { LydSample freq = *args[0]; - int count, pos; + int pos; - for (count = LYD_MAX_ARGS - 1; count > 1 && *args[count] == 0.0; count --); + if (argc < 2) + return 0; + + argc--; - pos = fmod (freq * count * voice->sample / voice->sample_rate, count); + pos = fmod (freq * argc * voice->sample / voice->sample_rate, argc); - return *args[1 + (pos+count) % count]; + return *args[1 + (pos + argc) % argc]; } @@ -208,7 +214,8 @@ static inline float phaseit(float oldphase, float hz, int sample_rate) #define OP(op) OP_END() OP_START(op) #define OP_FUN(op, fun_name) OP_END() OP_START(op) OUT = fun_name (voice, \ - &voice->state[i].arg[0], &DATA); + voice->state[i].argc, &voice->state[i].arg[0], \ + &DATA); static inline LydSample lyd_voice_compute (LydVoice *voice) { -- 1.7.0.4