From fc3d3c0a4f110a23335398c327ac0a4fc949d5cb Mon Sep 17 00:00:00 2001 From: Guenter Geiger Date: Mon, 17 Jun 2002 10:13:57 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r12, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/ggee/; revision=13 --- other/Makefile | 44 ++++++++ other/ls_setup | 29 ++++++ other/ls_setup16 | 29 ++++++ other/messages.c | 40 ++++++++ other/vbap.c | 298 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ other/vbap.pd | 51 ++++++++++ 6 files changed, 491 insertions(+) create mode 100755 other/Makefile create mode 100755 other/ls_setup create mode 100755 other/ls_setup16 create mode 100755 other/messages.c create mode 100755 other/vbap.c create mode 100755 other/vbap.pd (limited to 'other') diff --git a/other/Makefile b/other/Makefile new file mode 100755 index 0000000..acd7225 --- /dev/null +++ b/other/Makefile @@ -0,0 +1,44 @@ +current: nt + + +# TARGETS += stk + +VERSION = \"0.24\" + +.SUFFIXES: .dll .obj +# ----------------------- NT ---------------------------- + +NTOBJECTS = *.obj +NTDLLS = *.dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo + +PDNTINCLUDE = /I. /I..\..\pd\src +ProgramFiles = C:\Program Files +PDNTLDIR = "$(ProgramFiles)\Microsoft Visual Studio\Vc98\lib" +#PDNTLDIR = "C:\Programme\Msdev\Vc98\lib" + +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\wsock32.lib \ + $(PDNTLDIR)\kernel32.lib \ + $(PDNTLDIR)\uuid.lib \ + ..\..\pd\bin\pd.lib + +nt: $(NTOBJECTS) + -link /dll $(PDNTLIB) vbap.obj /export:vbap_setup + + +clean: + del *.obj + del *.dll + + +.c.obj: + -cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + +.obj.dll: + + + + diff --git a/other/ls_setup b/other/ls_setup new file mode 100755 index 0000000..9fc3266 --- /dev/null +++ b/other/ls_setup @@ -0,0 +1,29 @@ +File: loudspeaker_hdm_3D Configured 28 sets in 3 dimensions: +Triplet 0 Loudspeakers: 1 5 6 Matrix 4.456940 0.000000 -3.755852 -2.228470 -0.923062 2.655788 -2.228470 0.923062 2.655788 +Triplet 1 Loudspeakers: 1 5 9 Matrix 0.652704 1.575766 0.777862 0.000000 -1.846125 -0.000000 0.652704 -0.270359 -0.777862 +Triplet 2 Loudspeakers: 1 6 9 Matrix 0.652704 -1.575766 0.777862 -0.000000 1.846125 0.000000 0.652704 0.270359 -0.777862 +Triplet 3 Loudspeakers: 2 6 8 Matrix 0.000002 4.456941 -3.755853 0.923062 -2.228471 2.655789 -0.923063 -2.228470 2.655789 +Triplet 4 Loudspeakers: 2 6 10 Matrix -1.575766 0.652704 0.777862 1.846125 -0.000001 -0.000000 0.270359 0.652703 -0.777862 +Triplet 5 Loudspeakers: 2 8 10 Matrix 1.575766 0.652703 0.777862 -1.846125 0.000001 0.000000 -0.270358 0.652704 -0.777862 +Triplet 6 Loudspeakers: 3 5 7 Matrix 0.000002 -4.456941 -3.755853 0.923062 2.228471 2.655789 -0.923063 2.228470 2.655789 +Triplet 7 Loudspeakers: 3 5 11 Matrix -1.575766 -0.652704 0.777862 1.846125 0.000001 0.000000 0.270359 -0.652703 -0.777862 +Triplet 8 Loudspeakers: 3 7 11 Matrix 1.575766 -0.652703 0.777862 -1.846125 -0.000001 -0.000000 -0.270358 -0.652704 -0.777862 +Triplet 9 Loudspeakers: 4 7 8 Matrix -4.456932 -0.000000 -3.755843 2.228464 -0.923062 2.655782 2.228468 0.923062 2.655785 +Triplet 10 Loudspeakers: 4 7 12 Matrix -0.652703 1.575764 0.777862 -0.000001 -1.846122 0.000000 -0.652704 -0.270359 -0.777862 +Triplet 11 Loudspeakers: 4 8 12 Matrix -0.652705 -1.575766 0.777862 0.000001 1.846125 -0.000000 -0.652703 0.270359 -0.777862 +Triplet 12 Loudspeakers: 5 6 7 Matrix 0.923063 -0.923062 -0.000001 -0.000000 0.923062 0.777862 -0.923062 -0.000000 0.777862 +Triplet 13 Loudspeakers: 5 9 13 Matrix 0.652704 -0.270359 0.777862 1.305407 1.305407 0.000000 -0.652704 -1.575766 -0.777862 +Triplet 14 Loudspeakers: 5 11 13 Matrix 0.270359 -0.652703 0.777862 -1.305407 -1.305407 -0.000000 1.575766 0.652704 -0.777862 +Triplet 15 Loudspeakers: 6 7 8 Matrix 0.923062 0.000000 0.777862 -0.000000 -0.923062 0.777862 -0.923062 0.923062 0.000001 +Triplet 16 Loudspeakers: 6 9 14 Matrix 0.652704 0.270359 0.777862 1.305407 -1.305407 -0.000000 -0.652704 1.575766 -0.777862 +Triplet 17 Loudspeakers: 6 10 14 Matrix 0.270359 0.652703 0.777862 -1.305407 1.305407 0.000000 1.575766 -0.652704 -0.777862 +Triplet 18 Loudspeakers: 7 11 15 Matrix -0.270358 -0.652704 0.777862 1.305408 -1.305407 0.000000 -1.575766 0.652703 -0.777862 +Triplet 19 Loudspeakers: 7 12 15 Matrix -0.652704 -0.270359 0.777862 -1.305406 1.305405 -0.000000 0.652703 -1.575764 -0.777862 +Triplet 20 Loudspeakers: 8 10 16 Matrix -0.270358 0.652704 0.777862 1.305408 1.305407 -0.000000 -1.575766 -0.652703 -0.777862 +Triplet 21 Loudspeakers: 8 12 16 Matrix -0.652703 0.270359 0.777862 -1.305408 -1.305407 0.000000 0.652705 1.575766 -0.777862 +Triplet 22 Loudspeakers: 9 13 14 Matrix 4.456940 -0.000000 3.755852 -2.228470 -0.923062 -2.655788 -2.228470 0.923062 -2.655788 +Triplet 23 Loudspeakers: 10 14 16 Matrix 0.000002 4.456941 3.755853 0.923062 -2.228471 -2.655789 -0.923063 -2.228470 -2.655789 +Triplet 24 Loudspeakers: 11 13 15 Matrix 0.000002 -4.456941 3.755853 0.923062 2.228471 -2.655789 -0.923063 2.228470 -2.655789 +Triplet 25 Loudspeakers: 12 15 16 Matrix -4.456932 0.000000 3.755843 2.228464 -0.923062 -2.655782 2.228468 0.923062 -2.655785 +Triplet 26 Loudspeakers: 13 14 15 Matrix 0.923063 -0.923062 0.000001 -0.000000 0.923062 -0.777862 -0.923062 0.000000 -0.777862 +Triplet 27 Loudspeakers: 14 15 16 Matrix 0.923062 -0.000000 -0.777862 -0.000000 -0.923062 -0.777862 -0.923062 0.923062 -0.000001 diff --git a/other/ls_setup16 b/other/ls_setup16 new file mode 100755 index 0000000..9fc3266 --- /dev/null +++ b/other/ls_setup16 @@ -0,0 +1,29 @@ +File: loudspeaker_hdm_3D Configured 28 sets in 3 dimensions: +Triplet 0 Loudspeakers: 1 5 6 Matrix 4.456940 0.000000 -3.755852 -2.228470 -0.923062 2.655788 -2.228470 0.923062 2.655788 +Triplet 1 Loudspeakers: 1 5 9 Matrix 0.652704 1.575766 0.777862 0.000000 -1.846125 -0.000000 0.652704 -0.270359 -0.777862 +Triplet 2 Loudspeakers: 1 6 9 Matrix 0.652704 -1.575766 0.777862 -0.000000 1.846125 0.000000 0.652704 0.270359 -0.777862 +Triplet 3 Loudspeakers: 2 6 8 Matrix 0.000002 4.456941 -3.755853 0.923062 -2.228471 2.655789 -0.923063 -2.228470 2.655789 +Triplet 4 Loudspeakers: 2 6 10 Matrix -1.575766 0.652704 0.777862 1.846125 -0.000001 -0.000000 0.270359 0.652703 -0.777862 +Triplet 5 Loudspeakers: 2 8 10 Matrix 1.575766 0.652703 0.777862 -1.846125 0.000001 0.000000 -0.270358 0.652704 -0.777862 +Triplet 6 Loudspeakers: 3 5 7 Matrix 0.000002 -4.456941 -3.755853 0.923062 2.228471 2.655789 -0.923063 2.228470 2.655789 +Triplet 7 Loudspeakers: 3 5 11 Matrix -1.575766 -0.652704 0.777862 1.846125 0.000001 0.000000 0.270359 -0.652703 -0.777862 +Triplet 8 Loudspeakers: 3 7 11 Matrix 1.575766 -0.652703 0.777862 -1.846125 -0.000001 -0.000000 -0.270358 -0.652704 -0.777862 +Triplet 9 Loudspeakers: 4 7 8 Matrix -4.456932 -0.000000 -3.755843 2.228464 -0.923062 2.655782 2.228468 0.923062 2.655785 +Triplet 10 Loudspeakers: 4 7 12 Matrix -0.652703 1.575764 0.777862 -0.000001 -1.846122 0.000000 -0.652704 -0.270359 -0.777862 +Triplet 11 Loudspeakers: 4 8 12 Matrix -0.652705 -1.575766 0.777862 0.000001 1.846125 -0.000000 -0.652703 0.270359 -0.777862 +Triplet 12 Loudspeakers: 5 6 7 Matrix 0.923063 -0.923062 -0.000001 -0.000000 0.923062 0.777862 -0.923062 -0.000000 0.777862 +Triplet 13 Loudspeakers: 5 9 13 Matrix 0.652704 -0.270359 0.777862 1.305407 1.305407 0.000000 -0.652704 -1.575766 -0.777862 +Triplet 14 Loudspeakers: 5 11 13 Matrix 0.270359 -0.652703 0.777862 -1.305407 -1.305407 -0.000000 1.575766 0.652704 -0.777862 +Triplet 15 Loudspeakers: 6 7 8 Matrix 0.923062 0.000000 0.777862 -0.000000 -0.923062 0.777862 -0.923062 0.923062 0.000001 +Triplet 16 Loudspeakers: 6 9 14 Matrix 0.652704 0.270359 0.777862 1.305407 -1.305407 -0.000000 -0.652704 1.575766 -0.777862 +Triplet 17 Loudspeakers: 6 10 14 Matrix 0.270359 0.652703 0.777862 -1.305407 1.305407 0.000000 1.575766 -0.652704 -0.777862 +Triplet 18 Loudspeakers: 7 11 15 Matrix -0.270358 -0.652704 0.777862 1.305408 -1.305407 0.000000 -1.575766 0.652703 -0.777862 +Triplet 19 Loudspeakers: 7 12 15 Matrix -0.652704 -0.270359 0.777862 -1.305406 1.305405 -0.000000 0.652703 -1.575764 -0.777862 +Triplet 20 Loudspeakers: 8 10 16 Matrix -0.270358 0.652704 0.777862 1.305408 1.305407 -0.000000 -1.575766 -0.652703 -0.777862 +Triplet 21 Loudspeakers: 8 12 16 Matrix -0.652703 0.270359 0.777862 -1.305408 -1.305407 0.000000 0.652705 1.575766 -0.777862 +Triplet 22 Loudspeakers: 9 13 14 Matrix 4.456940 -0.000000 3.755852 -2.228470 -0.923062 -2.655788 -2.228470 0.923062 -2.655788 +Triplet 23 Loudspeakers: 10 14 16 Matrix 0.000002 4.456941 3.755853 0.923062 -2.228471 -2.655789 -0.923063 -2.228470 -2.655789 +Triplet 24 Loudspeakers: 11 13 15 Matrix 0.000002 -4.456941 3.755853 0.923062 2.228471 -2.655789 -0.923063 2.228470 -2.655789 +Triplet 25 Loudspeakers: 12 15 16 Matrix -4.456932 0.000000 3.755843 2.228464 -0.923062 -2.655782 2.228468 0.923062 -2.655785 +Triplet 26 Loudspeakers: 13 14 15 Matrix 0.923063 -0.923062 0.000001 -0.000000 0.923062 -0.777862 -0.923062 0.000000 -0.777862 +Triplet 27 Loudspeakers: 14 15 16 Matrix 0.923062 -0.000000 -0.777862 -0.000000 -0.923062 -0.777862 -0.923062 0.923062 -0.000001 diff --git a/other/messages.c b/other/messages.c new file mode 100755 index 0000000..f25f49e --- /dev/null +++ b/other/messages.c @@ -0,0 +1,40 @@ +/* (C) Guenter Geiger */ + + +#include +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* ------------------------ messages ----------------------------- */ + +static t_class *messages_class; + + +typedef struct _messages +{ + t_object x_obj; +} t_messages; + + +void messages_bang(t_messages *x) +{ + post("bang"); +} + +static void *messages_new() +{ + t_messages *x = (t_messages *)pd_new(messages_class); + outlet_new(&x->x_obj, &s_float); + return (x); +} + +void messages_setup(void) +{ + messages_class = class_new(gensym("messages"), (t_newmethod)messages_new, 0, + sizeof(t_messages), 0,0); + class_addbang(messages_class,messages_bang); +} + + diff --git a/other/vbap.c b/other/vbap.c new file mode 100755 index 0000000..db36993 --- /dev/null +++ b/other/vbap.c @@ -0,0 +1,298 @@ +/* (C) Guenter Geiger */ + + +/* +(C) Guenter Geiger + + +based on code by: +(c) Ville Pulkki 2.2.1999 +Helsinki University of Technology +Laboratory of Acoustics and Audio Signal Processing +*/ + +#include +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + + +#include +#include +#include +#include /* strtok */ + +#define MAX_TRIPLET_AMOUNT 64 + +/* this is related to the number of ls .. + + and shoud be 3**(MAX_LS_AMOUNT / 4) + +*/ + +#define MAX_LS_AMOUNT 16 +#define MAX_DIM_SQUARE 9 + + +/* ------------------------ vbap ----------------------------- */ + +static t_class *vbap_class; + + +typedef struct _vbap +{ + t_object x_ob; + t_outlet* x_out2; + t_outlet* x_out3; + t_float lsm[MAX_TRIPLET_AMOUNT][MAX_LS_AMOUNT+1]; /* loudspeaker triplet matrices */ + int lstripl[MAX_TRIPLET_AMOUNT][3]; /* loudspeaker triplet ldspeaker numbers */ + int lasttrip[3]; + int triplet_amount; + int dimension; + int opened; +} t_vbap; + + + + +t_float *angle_to_cart(t_float azi, t_float ele); +void vbap(t_vbap* x,t_float g[3], int ls[3], t_float azi, t_float ele) ; +int read_ls_conf(t_vbap* x,FILE *fp ); + + +void vbap_list(t_vbap *x,t_symbol* s,t_int argc,t_atom* argv) +{ + t_float azi,ele; + t_float g[3]; + int ls[3]; + t_atom a[2]; + + if (argc != 2) + post("vbap: list message required %d",argc); + else { + int i; + azi = atom_getfloat(argv++); + ele = atom_getfloat(argv++); + + vbap(x,g,ls,azi,ele); + + for (i=0;idimension;i++) { + if (x->lasttrip[i] != ls[i]) { + SETFLOAT(a,(t_float)x->lasttrip[i]); + SETFLOAT(a+1,0.0f); + outlet_list(x->x_ob.ob_outlet, &s_list,2 ,(t_atom*)&a); + x->lasttrip[i] = ls[i]; + } + } + + for (i=0;idimension;i++) { + SETFLOAT(a,(t_float)ls[i]); + SETFLOAT(a+1,g[i]); + outlet_list(x->x_ob.ob_outlet, &s_list,2 ,(t_atom*)&a); + + } + } + +} + + +void vbap_bang(t_vbap *x) +{ + post("vbap: bang"); +} + + + +static void *vbap_new(t_symbol* s) +{ + FILE *fp; + t_vbap *x = (t_vbap *)pd_new(vbap_class); + char fname[MAXPDSTRING]; + + if (s == &s_) { + post("vbap: Using default loudspeaker setup"); + s = gensym("ls_setup"); + } + + /* opening the loudspeaker matrix file*/ + + canvas_makefilename(canvas_getcurrent(),s->s_name, + fname,MAXPDSTRING); + + if((fp=fopen(fname,"r"))==NULL){ + post("vbap: Could not open loudspeaker data file %s\n",fname); + x->opened = 0; + } + else { + if (!read_ls_conf(x,fp)) + return NULL; + x->opened = 1; + fclose(fp); + } + + x->lasttrip[0] = 0; + x->lasttrip[1] = 1; + x->lasttrip[2] = 2; + + outlet_new(&x->x_ob, &s_list); + + return (x); +} + +void vbap_setup(void) +{ + vbap_class = class_new(gensym("vbap"), (t_newmethod)vbap_new, 0, + sizeof(t_vbap), 0,A_DEFSYM,0); +/* class_addbang(vbap_class,vbap_bang);*/ + class_addlist(vbap_class,vbap_list); +} + + + + +t_float *angle_to_cart(t_float azi, t_float ele) +{ + t_float *res; + t_float atorad = (2 * 3.1415927 / 360) ; + res = (t_float *) malloc(3*sizeof(t_float)); + res[0] = (float) (cos((t_float) (azi * atorad)) * cos((t_float) (ele * atorad))); + res[1] = (float) (sin((t_float) (azi * atorad)) * cos((t_float) (ele * atorad))); + res[2] = (float) (sin((t_float) (ele * atorad))); + return res; +} + + +void vbap(t_vbap* x,t_float g[3], int ls[3], float azi, float ele) +{ + /* calculates gain factors using loudspeaker setup and given direction */ + t_float *cartdir; + t_float power; + int i,j,k; + t_float small_g; + t_float big_sm_g, gtmp[3]; + int winner_triplet; + + cartdir=angle_to_cart(azi,ele); + big_sm_g = -100000.0; + for(i=0;itriplet_amount;i++){ + small_g = 10000000.0; + for(j=0;jdimension;j++){ + gtmp[j]=0.0; + for(k=0;kdimension;k++) + gtmp[j]+=cartdir[k]*x->lsm[i][k+j*x->dimension]; + if(gtmp[j] < small_g) + small_g = gtmp[j]; + } + if(small_g > big_sm_g){ + big_sm_g = small_g; + winner_triplet=i; + g[0]=gtmp[0]; g[1]=gtmp[1]; + ls[0]=x->lstripl[i][0]; ls[1]=x->lstripl[i][1]; + if(x->dimension==3){ + g[2]=gtmp[2]; + ls[2]=x->lstripl[i][2]; + } else { + g[2]=0.0; + ls[2]=0; + } + } + } + + /* this should probably be optimized somehow */ + + power=sqrt(g[0]*g[0] + g[1]*g[1] + g[2]*g[2]); + /* power=g[0]+g[1];*/ + + g[0] /= power; + g[1] /= power; + g[2] /= power; + + + free(cartdir); +} + +int read_ls_conf(t_vbap* x,FILE *fp ){ + /* reads from specified file the loudspeaker triplet setup */ + int amount,i,j,a,b,d=0; + char *toke; + char c[1000]; + t_float mx[MAX_DIM_SQUARE]; + fgets(c,1000,fp); + toke = (char *) strtok(c, " "); + toke = (char *) strtok(NULL, " "); + toke = (char *) strtok(NULL, " "); + if((toke = (char *) strtok(NULL, " "))==NULL){ + fprintf(stderr,"Wrong ls matrix file?\n"); + return 0; + } + sscanf(toke, "%d",&amount); + toke = (char *) strtok(NULL, " "); + toke = (char *) strtok(NULL, " "); + if((toke = (char *) strtok(NULL, " "))==NULL){ + fprintf(stderr,"Wrong ls matrix file?\n"); + return 0; + } + sscanf(toke, "%d",&x->dimension); + + x->triplet_amount = amount; + + for(i=0;idimension==3){ + fprintf(stderr,"Something wrong in ls matrix file\n"); + return 0; + } + if(strncmp(toke,"Pair",4)!=0 && x->dimension==2){ + fprintf(stderr,"Something wrong in ls matrix file\n"); + return 0; + } + toke = (char *) strtok(NULL, " "); + toke = (char *) strtok(NULL, " "); toke = (char *) strtok(NULL, " "); + sscanf(toke, "%d",&a); + x->lstripl[i][0]=a; + toke = (char *) strtok(NULL, " "); + sscanf(toke, "%d",&b); + x->lstripl[i][1]=b; + if (x->dimension==3){ + toke = (char *) strtok(NULL, " "); + sscanf(toke, "%d",&d); + x->lstripl[i][2]=d; + } + + + toke = (char *) strtok(NULL, " "); + for(j=0;j<(x->dimension*x->dimension);j++){ + toke = (char *) strtok(NULL, " "); + sscanf(toke, "%f",&(mx[j])); + x->lsm[i][j]=mx[j]; + } + + } + return 1; +} + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/other/vbap.pd b/other/vbap.pd new file mode 100755 index 0000000..d5047c0 --- /dev/null +++ b/other/vbap.pd @@ -0,0 +1,51 @@ +#N canvas 477 72 599 479 10; +#X msg 82 109 20 0; +#X obj 27 108 pack 1 2; +#X floatatom 27 87 0 0 0; +#X floatatom 70 88 0 0 0; +#X obj 62 176 route 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18; +#X floatatom 62 221 0 0 0; +#X floatatom 78 251 0 0 0; +#X floatatom 94 284 0 0 0; +#X floatatom 111 316 0 0 0; +#X floatatom 127 224 0 0 0; +#X floatatom 143 251 0 0 0; +#X floatatom 160 282 0 0 0; +#X floatatom 176 317 0 0 0; +#X floatatom 216 225 0 0 0; +#X floatatom 239 251 0 0 0; +#X floatatom 273 277 0 0 0; +#X floatatom 334 247 0 0 0; +#X floatatom 309 225 0 0 0; +#X floatatom 308 314 0 0 0; +#X floatatom 373 276 0 0 0; +#X floatatom 415 315 0 0 0; +#X floatatom 401 227 0 0 0; +#X floatatom 476 295 0 0 0; +#X floatatom 443 258 0 0 0; +#X text 31 15 A VBAP (Vector Base Amplitude Panning) external; +#X obj 82 144 vbap; +#X connect 0 0 25 0; +#X connect 1 0 25 0; +#X connect 2 0 1 0; +#X connect 3 0 1 1; +#X connect 4 0 5 0; +#X connect 4 1 6 0; +#X connect 4 2 7 0; +#X connect 4 3 8 0; +#X connect 4 4 9 0; +#X connect 4 5 10 0; +#X connect 4 6 11 0; +#X connect 4 7 12 0; +#X connect 4 8 13 0; +#X connect 4 9 14 0; +#X connect 4 10 15 0; +#X connect 4 11 16 0; +#X connect 4 12 17 0; +#X connect 4 13 18 0; +#X connect 4 14 19 0; +#X connect 4 15 20 0; +#X connect 4 16 21 0; +#X connect 4 17 22 0; +#X connect 4 18 23 0; +#X connect 25 0 4 0; -- cgit v1.2.1