| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062 |
- /*
- * Copyright (c) 1983-2023 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- The CDP System 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 Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
- /*
- * Calculations for position as created as explained in text abutting the code (see param_preprocess).
- * either using angle-subtended to the listener, or position in apparent width of lspks at given distrance.
- *
- * However, panning was more effective when extended to an extra loudspeaker,
- * So what really happens is that the original panning procedures are followed,
- * but, with approaching motion, to the lspkr BEFORE the focus (goal) of the movement
- * (or, with receding motion, from the lspkr AFTER the focus (start) of the movement)
- * And then extended to the goal lspkr by steps equal to the largest step used in the calculated motion.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <structures.h>
- #include <tkglobals.h>
- #include <pnames.h>
- #include <filetype.h>
- #include <processno.h>
- #include <modeno.h>
- #include <logic.h>
- #include <globcon.h>
- #include <cdpmain.h>
- #include <math.h>
- #include <mixxcon.h>
- #include <osbind.h>
- #include <standalone.h>
- #include <ctype.h>
- #include <sfsys.h>
- #include <string.h>
- #include <srates.h>
- #define SIGNAL_TO_LEFT (0)
- #define SIGNAL_TO_RIGHT (1)
- #define ROOT2 (1.4142136)
- #define RECEDE 0
- #define LEFT 1
- #define EXTEND 2
- #define EXTENSION ringsize
- #ifdef unix
- #define round(x) lround((x))
- #endif
- char errstr[2400];
- int anal_infiles = 1;
- int sloom = 0;
- int sloombatch = 0;
- const char* cdp_version = "7.1.0";
- //CDP LIB REPLACEMENTS
- static int setup_tangent_application(dataptr dz);
- static int parse_sloom_data(int argc,char *argv[],char ***cmdline,int *cmdlinecnt,dataptr dz);
- static int parse_infile_and_check_type(char **cmdline,dataptr dz);
- static int setup_tangent_param_ranges_and_defaults(dataptr dz);
- static int handle_the_outfile(int *cmdlinecnt,char ***cmdline,dataptr dz);
- static int open_the_outfile(dataptr dz);
- static int setup_and_init_input_param_activity(dataptr dz,int tipc);
- static int setup_input_param_defaultval_stores(int tipc,aplptr ap);
- static int establish_application(dataptr dz);
- static int initialise_vflags(dataptr dz);
- static int setup_parameter_storage_and_constants(int storage_cnt,dataptr dz);
- static int initialise_is_int_and_no_brk_constants(int storage_cnt,dataptr dz);
- static int mark_parameter_types(dataptr dz,aplptr ap);
- static int assign_file_data_storage(int infilecnt,dataptr dz);
- static int get_tk_cmdline_word(int *cmdlinecnt,char ***cmdline,char *q);
- static int get_the_process_no(char *prog_identifier_from_cmdline,dataptr dz);
- static int get_the_mode_from_cmdline(char *str,dataptr dz);
- static int setup_and_init_input_brktable_constants(dataptr dz,int brkcnt);
- static int tangent(dataptr dz);
- static void pancalc(double position,double *leftgain,double *rightgain);
- static int tangent_param_preprocess(dataptr dz);
- static int store_the_filename(char *filename,dataptr dz);
- static int store_the_further_filename(int n,char *filename,dataptr dz);
- static int read_input_sndfiles_list(char *filename,dataptr dz);
- static int allocate_the_filespace(dataptr dz);
- /**************************************** MAIN *********************************************/
- int main(int argc,char *argv[])
- {
- int exit_status;
- dataptr dz = NULL;
- char **cmdline;
- int cmdlinecnt, n;
- //aplptr ap;
- int is_launched = FALSE;
- if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
- fprintf(stdout,"%s\n",cdp_version);
- fflush(stdout);
- return 0;
- }
- /* CHECK FOR SOUNDLOOM */
- if((sloom = sound_loom_in_use(&argc,&argv)) > 1) {
- sloom = 0;
- sloombatch = 1;
- }
- if(sflinit("cdp")){
- sfperror("cdp: initialisation\n");
- return(FAILED);
- }
- /* SET UP THE PRINCIPLE DATASTRUCTURE */
- if((exit_status = establish_datastructure(&dz))<0) { // CDP LIB
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- if(!sloom) {
- if(argc == 1) {
- usage1();
- return(FAILED);
- } else if(argc == 2) {
- usage2(argv[1]);
- return(FAILED);
- }
- }
- if(!sloom) {
- if((exit_status = make_initial_cmdline_check(&argc,&argv))<0) { // CDP LIB
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- cmdline = argv;
- cmdlinecnt = argc;
- if((get_the_process_no(argv[0],dz))<0)
- return(FAILED);
- cmdline++;
- cmdlinecnt--;
- dz->maxmode = 8;
- if((exit_status = get_the_mode_from_cmdline(cmdline[0],dz))<0) {
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(exit_status);
- }
- cmdline++;
- cmdlinecnt--;
- // setup_particular_application =
- if((exit_status = setup_tangent_application(dz))<0) {
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- if((exit_status = count_and_allocate_for_infiles(cmdlinecnt,cmdline,dz))<0) { // CDP LIB
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- } else {
- //parse_TK_data() =
- if((exit_status = parse_sloom_data(argc,argv,&cmdline,&cmdlinecnt,dz))<0) {
- exit_status = print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(exit_status);
- }
- }
- //ap = dz->application;
- // parse_infile_and_hone_type() =
- if((exit_status = parse_infile_and_check_type(cmdline,dz))<0) {
- exit_status = print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- // setup_param_ranges_and_defaults() =
- if((exit_status = setup_tangent_param_ranges_and_defaults(dz))<0) {
- exit_status = print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- dz->all_words = 0;
- dz->ifd[0] = -1;
- switch(dz->process) {
- case(TAN_ONE) :
- // open_first_infile CDP LIB
- if((exit_status = open_first_infile(cmdline[0],dz))<0) {
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- if((exit_status = store_the_filename(cmdline[0],dz))<0)
- return(exit_status);
- cmdlinecnt--;
- cmdline++;
- break;
- case(TAN_TWO) :
- case(TAN_SEQ) :
- if((exit_status = open_first_infile(cmdline[0],dz))<0) {
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- if((exit_status = store_the_filename(cmdline[0],dz))<0)
- return(exit_status);
- cmdlinecnt--;
- cmdline++;
- for(n=1;n<dz->infilecnt;n++) {
- if((exit_status = handle_other_infile(n,cmdline[0],dz))<0) {
- sprintf(errstr,"Possibly too many parameters on commandline.\n");
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- sndcloseEx(dz->ifd[n]);
- dz->ifd[n] = -1;
- if((exit_status = store_the_further_filename(dz->all_words,cmdline[0],dz))<0)
- return(exit_status);
- cmdlinecnt--;
- cmdline++;
- }
- break;
- case(TAN_LIST) :
- if((exit_status = read_input_sndfiles_list(cmdline[0],dz))<0) {
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- cmdlinecnt--;
- cmdline++;
- break;
- }
- if(dz->ifd[0] >= 0) {
- sndcloseEx(dz->ifd[0]);
- dz->ifd[0] = -1;
- }
- // handle_extra_infiles() : redundant
- // handle_outfile() =
- if((exit_status = handle_the_outfile(&cmdlinecnt,&cmdline,dz))<0) {
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- // handle_formants() redundant
- // handle_formant_quiksearch() redundant
- // handle_special_data() redundant
- if((exit_status = read_parameters_and_flags(&cmdline,&cmdlinecnt,dz))<0) { // CDP LIB
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- // check_param_validity_and_consistency() redundant
- is_launched = TRUE;
- // create_sndbufs()) redundant
- if((exit_status = tangent_param_preprocess(dz))<0) {
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- if((exit_status = open_the_outfile(dz))<0) {
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- //spec_process_file =
- if((exit_status = tangent(dz))<0) {
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- if((exit_status = complete_output(dz))<0) { // CDP LIB
- print_messages_and_close_sndfiles(exit_status,is_launched,dz);
- return(FAILED);
- }
- exit_status = print_messages_and_close_sndfiles(FINISHED,is_launched,dz); // CDP LIB
- free(dz);
- return(SUCCEEDED);
- }
- /**********************************************
- REPLACED CDP LIB FUNCTIONS
- **********************************************/
- /****************************** SET_PARAM_DATA *********************************/
- int set_param_data(aplptr ap, int special_data,int maxparamcnt,int paramcnt,char *paramlist)
- {
- ap->special_data = (char)special_data;
- ap->param_cnt = (char)paramcnt;
- ap->max_param_cnt = (char)maxparamcnt;
- if(ap->max_param_cnt>0) {
- if((ap->param_list = (char *)malloc((size_t)(ap->max_param_cnt+1)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY: for param_list\n");
- return(MEMORY_ERROR);
- }
- strcpy(ap->param_list,paramlist);
- }
- return(FINISHED);
- }
- /****************************** SET_VFLGS *********************************/
- int set_vflgs
- (aplptr ap,char *optflags,int optcnt,char *optlist,char *varflags,int vflagcnt, int vparamcnt,char *varlist)
- {
- ap->option_cnt = (char) optcnt; /*RWD added cast */
- if(optcnt) {
- if((ap->option_list = (char *)malloc((size_t)(optcnt+1)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY: for option_list\n");
- return(MEMORY_ERROR);
- }
- strcpy(ap->option_list,optlist);
- if((ap->option_flags = (char *)malloc((size_t)(optcnt+1)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY: for option_flags\n");
- return(MEMORY_ERROR);
- }
- strcpy(ap->option_flags,optflags);
- }
- ap->vflag_cnt = (char) vflagcnt;
- ap->variant_param_cnt = (char) vparamcnt;
- if(vflagcnt) {
- if((ap->variant_list = (char *)malloc((size_t)(vflagcnt+1)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY: for variant_list\n");
- return(MEMORY_ERROR);
- }
- strcpy(ap->variant_list,varlist);
- if((ap->variant_flags = (char *)malloc((size_t)(vflagcnt+1)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY: for variant_flags\n");
- return(MEMORY_ERROR);
- }
- strcpy(ap->variant_flags,varflags);
- }
- return(FINISHED);
- }
- /***************************** APPLICATION_INIT **************************/
- int application_init(dataptr dz)
- {
- int exit_status;
- int storage_cnt;
- int tipc, brkcnt;
- aplptr ap = dz->application;
- if(ap->vflag_cnt>0)
- initialise_vflags(dz);
- tipc = ap->max_param_cnt + ap->option_cnt + ap->variant_param_cnt;
- ap->total_input_param_cnt = (char)tipc;
- if(tipc>0) {
- if((exit_status = setup_input_param_range_stores(tipc,ap))<0)
- return(exit_status);
- if((exit_status = setup_input_param_defaultval_stores(tipc,ap))<0)
- return(exit_status);
- if((exit_status = setup_and_init_input_param_activity(dz,tipc))<0)
- return(exit_status);
- }
- brkcnt = tipc;
- //THERE ARE NO INPUTFILE brktables USED IN THIS PROCESS
- if(brkcnt>0) {
- if((exit_status = setup_and_init_input_brktable_constants(dz,brkcnt))<0)
- return(exit_status);
- }
- if((storage_cnt = tipc + ap->internal_param_cnt)>0) {
- if((exit_status = setup_parameter_storage_and_constants(storage_cnt,dz))<0)
- return(exit_status);
- if((exit_status = initialise_is_int_and_no_brk_constants(storage_cnt,dz))<0)
- return(exit_status);
- }
- if((exit_status = mark_parameter_types(dz,ap))<0)
- return(exit_status);
- // establish_infile_constants() replaced by
- dz->infilecnt = 1;
- //establish_bufptrs_and_extra_buffers():
- return(FINISHED);
- }
- /********************** SETUP_PARAMETER_STORAGE_AND_CONSTANTS ********************/
- /* RWD mallo changed to calloc; helps debug verison run as release! */
- int setup_parameter_storage_and_constants(int storage_cnt,dataptr dz)
- {
- if((dz->param = (double *)calloc(storage_cnt, sizeof(double)))==NULL) {
- sprintf(errstr,"setup_parameter_storage_and_constants(): 1\n");
- return(MEMORY_ERROR);
- }
- if((dz->iparam = (int *)calloc(storage_cnt, sizeof(int) ))==NULL) {
- sprintf(errstr,"setup_parameter_storage_and_constants(): 2\n");
- return(MEMORY_ERROR);
- }
- if((dz->is_int = (char *)calloc(storage_cnt, sizeof(char)))==NULL) {
- sprintf(errstr,"setup_parameter_storage_and_constants(): 3\n");
- return(MEMORY_ERROR);
- }
- if((dz->no_brk = (char *)calloc(storage_cnt, sizeof(char)))==NULL) {
- sprintf(errstr,"setup_parameter_storage_and_constants(): 5\n");
- return(MEMORY_ERROR);
- }
- return(FINISHED);
- }
- /************** INITIALISE_IS_INT_AND_NO_BRK_CONSTANTS *****************/
- int initialise_is_int_and_no_brk_constants(int storage_cnt,dataptr dz)
- {
- int n;
- for(n=0;n<storage_cnt;n++) {
- dz->is_int[n] = (char)0;
- dz->no_brk[n] = (char)0;
- }
- return(FINISHED);
- }
- /***************************** MARK_PARAMETER_TYPES **************************/
- int mark_parameter_types(dataptr dz,aplptr ap)
- {
- int n, m; /* PARAMS */
- for(n=0;n<ap->max_param_cnt;n++) {
- switch(ap->param_list[n]) {
- case('0'): break; /* dz->is_active[n] = 0 is default */
- case('i'): dz->is_active[n] = (char)1; dz->is_int[n] = (char)1;dz->no_brk[n] = (char)1; break;
- case('I'): dz->is_active[n] = (char)1; dz->is_int[n] = (char)1; break;
- case('d'): dz->is_active[n] = (char)1; dz->no_brk[n] = (char)1; break;
- case('D'): dz->is_active[n] = (char)1; /* normal case: double val or brkpnt file */ break;
- default:
- sprintf(errstr,"Programming error: invalid parameter type in mark_parameter_types()\n");
- return(PROGRAM_ERROR);
- }
- } /* OPTIONS */
- for(n=0,m=ap->max_param_cnt;n<ap->option_cnt;n++,m++) {
- switch(ap->option_list[n]) {
- case('i'): dz->is_active[m] = (char)1; dz->is_int[m] = (char)1; dz->no_brk[m] = (char)1; break;
- case('I'): dz->is_active[m] = (char)1; dz->is_int[m] = (char)1; break;
- case('d'): dz->is_active[m] = (char)1; dz->no_brk[m] = (char)1; break;
- case('D'): dz->is_active[m] = (char)1; /* normal case: double val or brkpnt file */ break;
- default:
- sprintf(errstr,"Programming error: invalid option type in mark_parameter_types()\n");
- return(PROGRAM_ERROR);
- }
- } /* VARIANTS */
- for(n=0,m=ap->max_param_cnt + ap->option_cnt;n < ap->variant_param_cnt; n++, m++) {
- switch(ap->variant_list[n]) {
- case('0'): break;
- case('i'): dz->is_active[m] = (char)1; dz->is_int[m] = (char)1; dz->no_brk[m] = (char)1; break;
- case('I'): dz->is_active[m] = (char)1; dz->is_int[m] = (char)1; break;
- case('d'): dz->is_active[m] = (char)1; dz->no_brk[m] = (char)1; break;
- case('D'): dz->is_active[m] = (char)1; /* normal case: double val or brkpnt file */ break;
- default:
- sprintf(errstr,"Programming error: invalid variant type in mark_parameter_types()\n");
- return(PROGRAM_ERROR);
- }
- } /* INTERNAL */
- for(n=0,
- m=ap->max_param_cnt + ap->option_cnt + ap->variant_param_cnt; n<ap->internal_param_cnt; n++,m++) {
- switch(ap->internal_param_list[n]) {
- case('0'): break; /* dummy variables: variables not used: but important for internal paream numbering!! */
- case('i'): dz->is_int[m] = (char)1; dz->no_brk[m] = (char)1; break;
- case('d'): dz->no_brk[m] = (char)1; break;
- default:
- sprintf(errstr,"Programming error: invalid internal param type in mark_parameter_types()\n");
- return(PROGRAM_ERROR);
- }
- }
- return(FINISHED);
- }
- /************************ HANDLE_THE_OUTFILE *********************/
- int handle_the_outfile(int *cmdlinecnt,char ***cmdline,dataptr dz)
- {
- char *filename = (*cmdline)[0], *p;
- if(filename[0]=='-' && filename[1]=='f') {
- dz->floatsam_output = 1;
- dz->true_outfile_stype = SAMP_FLOAT;
- filename+= 2;
- }
- if(!sloom) {
- if(file_has_invalid_startchar(filename) || value_is_numeric(filename)) {
- sprintf(errstr,"Outfile name %s has invalid start character(s) or looks too much like a number.\n",filename);
- return(DATA_ERROR);
- }
- }
- strcpy(dz->outfilename,filename);
- p = dz->outfilename;
- while(*p != ENDOFSTR) {
- if(*p == '.') {
- *p = ENDOFSTR;
- break;
- }
- p++;
- }
- strcat(dz->outfilename,".mmx");
- (*cmdline)++;
- (*cmdlinecnt)--;
- return(FINISHED);
- }
- /************************ OPEN_THE_OUTFILE *********************/
- int open_the_outfile(dataptr dz)
- {
- int exit_status;
- dz->infile->channels = 8;
- if((exit_status = create_sized_outfile(dz->outfilename,dz))<0)
- return(exit_status);
- dz->infile->channels = 1;
- return(FINISHED);
- }
- /***************************** ESTABLISH_APPLICATION **************************/
- int establish_application(dataptr dz)
- {
- aplptr ap;
- if((dz->application = (aplptr)malloc(sizeof (struct applic)))==NULL) {
- sprintf(errstr,"establish_application()\n");
- return(MEMORY_ERROR);
- }
- ap = dz->application;
- memset((char *)ap,0,sizeof(struct applic));
- return(FINISHED);
- }
- /************************* INITIALISE_VFLAGS *************************/
- int initialise_vflags(dataptr dz)
- {
- int n;
- if((dz->vflag = (char *)malloc(dz->application->vflag_cnt * sizeof(char)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY: vflag store,\n");
- return(MEMORY_ERROR);
- }
- for(n=0;n<dz->application->vflag_cnt;n++)
- dz->vflag[n] = FALSE;
- return FINISHED;
- }
- /************************* SETUP_INPUT_PARAM_DEFAULTVALS *************************/
- int setup_input_param_defaultval_stores(int tipc,aplptr ap)
- {
- int n;
- if((ap->default_val = (double *)malloc(tipc * sizeof(double)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY for application default values store\n");
- return(MEMORY_ERROR);
- }
- for(n=0;n<tipc;n++)
- ap->default_val[n] = 0.0;
- return(FINISHED);
- }
- /***************************** SETUP_AND_INIT_INPUT_PARAM_ACTIVITY **************************/
- int setup_and_init_input_param_activity(dataptr dz,int tipc)
- {
- int n;
- if((dz->is_active = (char *)malloc((size_t)tipc))==NULL) {
- sprintf(errstr,"setup_and_init_input_param_activity()\n");
- return(MEMORY_ERROR);
- }
- for(n=0;n<tipc;n++)
- dz->is_active[n] = (char)0;
- return(FINISHED);
- }
- /************************* SETUP_TANGENT_APPLICATION *******************/
- int setup_tangent_application(dataptr dz)
- {
- int exit_status;
- aplptr ap;
- if((exit_status = establish_application(dz))<0) // GLOBAL
- return(FAILED);
- ap = dz->application;
- // SEE parstruct FOR EXPLANATION of next 2 functions
- switch(dz->process) {
- case(TAN_ONE):
- exit_status = set_param_data(ap,0 ,5,4,"didd0");
- break;
- case(TAN_TWO):
- exit_status = set_param_data(ap,0 ,5,5,"diddd");
- break;
- case(TAN_SEQ):
- case(TAN_LIST):
- exit_status = set_param_data(ap,0 ,5,3,"d0dd0");
- break;
- }
- if(exit_status < 0)
- return(exit_status);
- switch(dz->mode) {
- case(0):
- exit_status = set_vflgs(ap,"fjs",3,"iDd","rl",2,0,"00");
- break;
- case(1):
- exit_status = set_vflgs(ap,"fj",2,"iD","rl",2,0,"00");
- break;
- }
- if(exit_status < 0)
- return(exit_status);
- // set_legal_infile_structure -->
- dz->has_otherfile = FALSE;
- // assign_process_logic -->
- switch(dz->process) {
- case(TAN_ONE):
- dz->input_data_type = SNDFILES_ONLY;
- break;
- case(TAN_TWO):
- dz->input_data_type = TWO_SNDFILES;
- break;
- case(TAN_SEQ):
- dz->input_data_type = MANY_SNDFILES;
- break;
- case(TAN_LIST):
- dz->input_data_type = SNDLIST_ONLY;
- break;
- }
- dz->process_type = TO_TEXTFILE;
- dz->outfiletype = TEXTFILE_OUT;
- return application_init(dz); //GLOBAL
- }
- /************************* PARSE_INFILE_AND_CHECK_TYPE *******************/
- int parse_infile_and_check_type(char **cmdline,dataptr dz)
- {
- int exit_status;
- infileptr infile_info;
- if(!sloom) {
- if((infile_info = (infileptr)malloc(sizeof(struct filedata)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY for infile structure to test file data.");
- return(MEMORY_ERROR);
- } else if((exit_status = cdparse(cmdline[0],infile_info))<0) {
- sprintf(errstr,"Failed to parse input file %s\n",cmdline[0]);
- return(PROGRAM_ERROR);
- }
- if(dz->process == TAN_LIST) {
- if(!(infile_info->filetype & SNDLIST)) {
- sprintf(errstr,"File %s is not of correct type\n",cmdline[0]);
- return(DATA_ERROR);
- }
- } else {
- if(infile_info->filetype != SNDFILE) {
- sprintf(errstr,"File %s is not of correct type\n",cmdline[0]);
- return(DATA_ERROR);
- } else if(infile_info->channels != 1) {
- sprintf(errstr,"File %s is not of correct type (must be mono)\n",cmdline[0]);
- return(DATA_ERROR);
- } else if((exit_status = copy_parse_info_to_main_structure(infile_info,dz))<0) {
- sprintf(errstr,"Failed to copy file parsing information\n");
- return(PROGRAM_ERROR);
- }
- }
- free(infile_info);
- }
- return(FINISHED);
- }
- /************************* SETUP_TANGENT_PARAM_RANGES_AND_DEFAULTS *******************/
- int setup_tangent_param_ranges_and_defaults(dataptr dz)
- {
- int exit_status;
- aplptr ap = dz->application;
- // set_param_ranges()
- ap->total_input_param_cnt = (char)(ap->max_param_cnt + ap->option_cnt + ap->variant_param_cnt);
- // NB total_input_param_cnt is > 0 !!!
- if((exit_status = setup_input_param_range_stores(ap->total_input_param_cnt,ap))<0)
- return(FAILED);
- // get_param_ranges()
- ap->lo[TAN_DUR] = dz->duration * 2.0;
- ap->hi[TAN_DUR] = 32767;
- ap->default_val[TAN_DUR] = 8;
- if(dz->process == TAN_ONE || dz->process == TAN_TWO) {
- ap->lo[TAN_STEPS] = 2;
- ap->hi[TAN_STEPS] = 32767;
- ap->default_val[TAN_STEPS] = 24;
- }
- if(dz->mode == 0) {
- ap->lo[TAN_MANG] = 90;
- ap->hi[TAN_MANG] = 135;
- ap->default_val[TAN_MANG] = 130;
- } else {
- ap->lo[TAN_SKEW] = 0;
- ap->hi[TAN_SKEW] = 1;
- ap->default_val[TAN_SKEW] = .75;
- }
- ap->lo[TAN_DEC] = 0;
- ap->hi[TAN_DEC] = 1;
- ap->default_val[TAN_DEC] = .9;
- if(dz->process == TAN_TWO) {
- ap->lo[TAN_FBAL] = 0;
- ap->hi[TAN_FBAL] = 1;
- ap->default_val[TAN_FBAL] = .9;
- }
- ap->lo[TAN_FOCUS] = 1;
- ap->hi[TAN_FOCUS] = 8;
- ap->default_val[TAN_FOCUS] = 1;
- ap->lo[TAN_JITTER] = 0;
- ap->hi[TAN_JITTER] = 1;
- ap->default_val[TAN_JITTER] = 0;
- if(dz->mode == 0) {
- ap->lo[TAN_SLOW] = 0;
- ap->hi[TAN_SLOW] = 1;
- ap->default_val[TAN_SLOW] = 0.5;
- }
- dz->maxmode = 8;
- if(!sloom)
- put_default_vals_in_all_params(dz);
- return(FINISHED);
- }
- /********************************* PARSE_SLOOM_DATA *********************************/
- int parse_sloom_data(int argc,char *argv[],char ***cmdline,int *cmdlinecnt,dataptr dz)
- {
- int exit_status;
- int cnt = 1, infilecnt;
- int filesize, insams, inbrksize;
- double dummy;
- int true_cnt = 0;
- //aplptr ap;
- while(cnt<=PRE_CMDLINE_DATACNT) {
- if(cnt > argc) {
- sprintf(errstr,"Insufficient data sent from TK\n");
- return(DATA_ERROR);
- }
- switch(cnt) {
- case(1):
- if(sscanf(argv[cnt],"%d",&dz->process)!=1) {
- sprintf(errstr,"Cannot read process no. sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(2):
- if(sscanf(argv[cnt],"%d",&dz->mode)!=1) {
- sprintf(errstr,"Cannot read mode no. sent from TK\n");
- return(DATA_ERROR);
- }
- if(dz->mode > 0)
- dz->mode--;
- //setup_particular_application() =
- if((exit_status = setup_tangent_application(dz))<0)
- return(exit_status);
- //ap = dz->application;
- break;
- case(3):
- if(sscanf(argv[cnt],"%d",&infilecnt)!=1) {
- sprintf(errstr,"Cannot read infilecnt sent from TK\n");
- return(DATA_ERROR);
- }
- if(infilecnt < 1) {
- true_cnt = cnt + 1;
- cnt = PRE_CMDLINE_DATACNT; /* force exit from loop after assign_file_data_storage */
- }
- if((exit_status = assign_file_data_storage(infilecnt,dz))<0)
- return(exit_status);
- break;
- case(INPUT_FILETYPE+4):
- if(sscanf(argv[cnt],"%d",&dz->infile->filetype)!=1) {
- sprintf(errstr,"Cannot read filetype sent from TK (%s)\n",argv[cnt]);
- return(DATA_ERROR);
- }
- break;
- case(INPUT_FILESIZE+4):
- if(sscanf(argv[cnt],"%d",&filesize)!=1) {
- sprintf(errstr,"Cannot read infilesize sent from TK\n");
- return(DATA_ERROR);
- }
- dz->insams[0] = filesize;
- break;
- case(INPUT_INSAMS+4):
- if(sscanf(argv[cnt],"%d",&insams)!=1) {
- sprintf(errstr,"Cannot read insams sent from TK\n");
- return(DATA_ERROR);
- }
- dz->insams[0] = insams;
- break;
- case(INPUT_SRATE+4):
- if(sscanf(argv[cnt],"%d",&dz->infile->srate)!=1) {
- sprintf(errstr,"Cannot read srate sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_CHANNELS+4):
- if(sscanf(argv[cnt],"%d",&dz->infile->channels)!=1) {
- sprintf(errstr,"Cannot read channels sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_STYPE+4):
- if(sscanf(argv[cnt],"%d",&dz->infile->stype)!=1) {
- sprintf(errstr,"Cannot read stype sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_ORIGSTYPE+4):
- if(sscanf(argv[cnt],"%d",&dz->infile->origstype)!=1) {
- sprintf(errstr,"Cannot read origstype sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_ORIGRATE+4):
- if(sscanf(argv[cnt],"%d",&dz->infile->origrate)!=1) {
- sprintf(errstr,"Cannot read origrate sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_MLEN+4):
- if(sscanf(argv[cnt],"%d",&dz->infile->Mlen)!=1) {
- sprintf(errstr,"Cannot read Mlen sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_DFAC+4):
- if(sscanf(argv[cnt],"%d",&dz->infile->Dfac)!=1) {
- sprintf(errstr,"Cannot read Dfac sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_ORIGCHANS+4):
- if(sscanf(argv[cnt],"%d",&dz->infile->origchans)!=1) {
- sprintf(errstr,"Cannot read origchans sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_SPECENVCNT+4):
- if(sscanf(argv[cnt],"%d",&dz->infile->specenvcnt)!=1) {
- sprintf(errstr,"Cannot read specenvcnt sent from TK\n");
- return(DATA_ERROR);
- }
- dz->specenvcnt = dz->infile->specenvcnt;
- break;
- case(INPUT_WANTED+4):
- if(sscanf(argv[cnt],"%d",&dz->wanted)!=1) {
- sprintf(errstr,"Cannot read wanted sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_WLENGTH+4):
- if(sscanf(argv[cnt],"%d",&dz->wlength)!=1) {
- sprintf(errstr,"Cannot read wlength sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_OUT_CHANS+4):
- if(sscanf(argv[cnt],"%d",&dz->out_chans)!=1) {
- sprintf(errstr,"Cannot read out_chans sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- /* RWD these chanegs to samps - tk will have to deal with that! */
- case(INPUT_DESCRIPTOR_BYTES+4):
- if(sscanf(argv[cnt],"%d",&dz->descriptor_samps)!=1) {
- sprintf(errstr,"Cannot read descriptor_samps sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_IS_TRANSPOS+4):
- if(sscanf(argv[cnt],"%d",&dz->is_transpos)!=1) {
- sprintf(errstr,"Cannot read is_transpos sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_COULD_BE_TRANSPOS+4):
- if(sscanf(argv[cnt],"%d",&dz->could_be_transpos)!=1) {
- sprintf(errstr,"Cannot read could_be_transpos sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_COULD_BE_PITCH+4):
- if(sscanf(argv[cnt],"%d",&dz->could_be_pitch)!=1) {
- sprintf(errstr,"Cannot read could_be_pitch sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_DIFFERENT_SRATES+4):
- if(sscanf(argv[cnt],"%d",&dz->different_srates)!=1) {
- sprintf(errstr,"Cannot read different_srates sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_DUPLICATE_SNDS+4):
- if(sscanf(argv[cnt],"%d",&dz->duplicate_snds)!=1) {
- sprintf(errstr,"Cannot read duplicate_snds sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_BRKSIZE+4):
- if(sscanf(argv[cnt],"%d",&inbrksize)!=1) {
- sprintf(errstr,"Cannot read brksize sent from TK\n");
- return(DATA_ERROR);
- }
- if(inbrksize > 0) {
- switch(dz->input_data_type) {
- case(WORDLIST_ONLY):
- break;
- case(PITCH_AND_PITCH):
- case(PITCH_AND_TRANSPOS):
- case(TRANSPOS_AND_TRANSPOS):
- dz->tempsize = inbrksize;
- break;
- case(BRKFILES_ONLY):
- case(UNRANGED_BRKFILE_ONLY):
- case(DB_BRKFILES_ONLY):
- case(ALL_FILES):
- case(ANY_NUMBER_OF_ANY_FILES):
- if(dz->extrabrkno < 0) {
- sprintf(errstr,"Storage location number for brktable not established by CDP.\n");
- return(DATA_ERROR);
- }
- if(dz->brksize == NULL) {
- sprintf(errstr,"CDP has not established storage space for input brktable.\n");
- return(PROGRAM_ERROR);
- }
- dz->brksize[dz->extrabrkno] = inbrksize;
- break;
- default:
- sprintf(errstr,"TK sent brktablesize > 0 for input_data_type [%d] not using brktables.\n",
- dz->input_data_type);
- return(PROGRAM_ERROR);
- }
- break;
- }
- break;
- case(INPUT_NUMSIZE+4):
- if(sscanf(argv[cnt],"%d",&dz->numsize)!=1) {
- sprintf(errstr,"Cannot read numsize sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_LINECNT+4):
- if(sscanf(argv[cnt],"%d",&dz->linecnt)!=1) {
- sprintf(errstr,"Cannot read linecnt sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_ALL_WORDS+4):
- if(sscanf(argv[cnt],"%d",&dz->all_words)!=1) {
- sprintf(errstr,"Cannot read all_words sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_ARATE+4):
- if(sscanf(argv[cnt],"%f",&dz->infile->arate)!=1) {
- sprintf(errstr,"Cannot read arate sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_FRAMETIME+4):
- if(sscanf(argv[cnt],"%lf",&dummy)!=1) {
- sprintf(errstr,"Cannot read frametime sent from TK\n");
- return(DATA_ERROR);
- }
- dz->frametime = (float)dummy;
- break;
- case(INPUT_WINDOW_SIZE+4):
- if(sscanf(argv[cnt],"%f",&dz->infile->window_size)!=1) {
- sprintf(errstr,"Cannot read window_size sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_NYQUIST+4):
- if(sscanf(argv[cnt],"%lf",&dz->nyquist)!=1) {
- sprintf(errstr,"Cannot read nyquist sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_DURATION+4):
- if(sscanf(argv[cnt],"%lf",&dz->duration)!=1) {
- sprintf(errstr,"Cannot read duration sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_MINBRK+4):
- if(sscanf(argv[cnt],"%lf",&dz->minbrk)!=1) {
- sprintf(errstr,"Cannot read minbrk sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_MAXBRK+4):
- if(sscanf(argv[cnt],"%lf",&dz->maxbrk)!=1) {
- sprintf(errstr,"Cannot read maxbrk sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_MINNUM+4):
- if(sscanf(argv[cnt],"%lf",&dz->minnum)!=1) {
- sprintf(errstr,"Cannot read minnum sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- case(INPUT_MAXNUM+4):
- if(sscanf(argv[cnt],"%lf",&dz->maxnum)!=1) {
- sprintf(errstr,"Cannot read maxnum sent from TK\n");
- return(DATA_ERROR);
- }
- break;
- default:
- sprintf(errstr,"case switch item missing: parse_sloom_data()\n");
- return(PROGRAM_ERROR);
- }
- cnt++;
- }
- if(cnt!=PRE_CMDLINE_DATACNT+1) {
- sprintf(errstr,"Insufficient pre-cmdline params sent from TK\n");
- return(DATA_ERROR);
- }
- if(true_cnt)
- cnt = true_cnt;
- *cmdlinecnt = 0;
- while(cnt < argc) {
- if((exit_status = get_tk_cmdline_word(cmdlinecnt,cmdline,argv[cnt]))<0)
- return(exit_status);
- cnt++;
- }
- return(FINISHED);
- }
- /********************************* GET_TK_CMDLINE_WORD *********************************/
- int get_tk_cmdline_word(int *cmdlinecnt,char ***cmdline,char *q)
- {
- if(*cmdlinecnt==0) {
- if((*cmdline = (char **)malloc(sizeof(char *)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY for TK cmdline array.\n");
- return(MEMORY_ERROR);
- }
- } else {
- if((*cmdline = (char **)realloc(*cmdline,((*cmdlinecnt)+1) * sizeof(char *)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY for TK cmdline array.\n");
- return(MEMORY_ERROR);
- }
- }
- if(((*cmdline)[*cmdlinecnt] = (char *)malloc((strlen(q) + 1) * sizeof(char)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY for TK cmdline item %d.\n",(*cmdlinecnt)+1);
- return(MEMORY_ERROR);
- }
- strcpy((*cmdline)[*cmdlinecnt],q);
- (*cmdlinecnt)++;
- return(FINISHED);
- }
- /****************************** ASSIGN_FILE_DATA_STORAGE *********************************/
- int assign_file_data_storage(int infilecnt,dataptr dz)
- {
- int exit_status;
- int no_sndfile_system_files = FALSE;
- dz->infilecnt = infilecnt;
- if((exit_status = allocate_filespace(dz))<0)
- return(exit_status);
- if(no_sndfile_system_files)
- dz->infilecnt = 0;
- return(FINISHED);
- }
- /************************* redundant functions: to ensure libs compile OK *******************/
- int assign_process_logic(dataptr dz)
- {
- return(FINISHED);
- }
- void set_legal_infile_structure(dataptr dz)
- {}
- int set_legal_internalparam_structure(int process,int mode,aplptr ap)
- {
- return(FINISHED);
- }
- int setup_internal_arrays_and_array_pointers(dataptr dz)
- {
- return(FINISHED);
- }
- int establish_bufptrs_and_extra_buffers(dataptr dz)
- {
- return(FINISHED);
- }
- int read_special_data(char *str,dataptr dz)
- {
- return(FINISHED);
- }
- int inner_loop
- (int *peakscore,int *descnt,int *in_start_portion,int *least,int *pitchcnt,int windows_in_buf,dataptr dz)
- {
- return(FINISHED);
- }
- int get_process_no(char *prog_identifier_from_cmdline,dataptr dz)
- {
- return(FINISHED);
- }
- /******************************** USAGE1 ********************************/
- int usage1(void)
- {
- fprintf(stdout,
- "\nCREATE TANGENT MOTION TO OR FROM 8-CHANNEL RING\n\n"
- "USAGE: tangent NAME mode infile(s) outfile parameters: \n"
- "\n"
- "where NAME can be any one of\n"
- "\n"
- "onefile twofiles sequence list\n\n"
- "Type 'tangent onefile' for more info on tangent onefile..ETC.\n");
- return(USAGE_ONLY);
- }
- /************************************* TANGENT_PARAM_PREPROCESS *********************************/
- int tangent_param_preprocess(dataptr dz)
- {
- int stepcnt;
- double *lens, *angles;
- double rightangle = PI/2.0, maxangle = 0.0, tangentlen, linear_steplen, sum_of_angles, angle, newtotlen;
- int steps_betwixt_12, n, m;
- double direct_steplen, subtended_steplen;
- if(dz->mode==0) {
- dz->param[TAN_MANG] -= 45.0; // If motion starts at centre (lspkr 1)
- if(dz->param[TAN_MANG] < 46.0) // max angle value lies between lspkrs 3 & 4 (90 and 135)
- dz->param[TAN_MANG] = 46.0; // We do the calulation AS IF we're starting at lspkr 2
- if(dz->param[TAN_MANG] > 89.0) // So the maxangle is between 45 and 90
- dz->param[TAN_MANG] = 89.0; // Force end of motion to be between lspkrs 3 & 4
- }
- if(dz->process == TAN_SEQ || dz->process == TAN_LIST)
- stepcnt = dz->infilecnt;
- else
- stepcnt = dz->iparam[TAN_STEPS];
- dz->array_cnt = 1;
- if((dz->parray = (double **)malloc(dz->array_cnt * sizeof(double *)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY to create segment lengths arrays.\n");
- return(MEMORY_ERROR);
- }
- if((dz->parray[0] = (double *)malloc((stepcnt + 1) * sizeof(double)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY to store segment lengths.\n");
- return(MEMORY_ERROR);
- }
- lens = dz->parray[0];
- angles = lens; // Same object used: naming for code clarity.
- if(dz->mode == 0) {
- maxangle = dz->param[TAN_MANG] * PI/180.0;
- // assuming circle radius = 1 // __________tangentlen______________
- tangentlen = tan(maxangle); // | __/
- linear_steplen = tangentlen/stepcnt; // |\ _________/
- sum_of_angles = 0.0; // 1|maxangle _________/
- // | __\_____/
- // |/
- for(n=1;n<=stepcnt;n++) {
- angle = rightangle - sum_of_angles - atan(1/(linear_steplen * n));
- angles[n-1] = angle;
- sum_of_angles += angle;
- }
- if(!flteq(dz->param[TAN_SLOW],1.0)) {
- sum_of_angles = 0.0;
- for(n=0;n<stepcnt;n++) {
- angles[n] = pow(angles[n],dz->param[TAN_SLOW]);
- sum_of_angles += angles[n];
- }
- } // x x x
- // ------ ------|------
- // | . | . .
- // steps are now made equivalent to // | . | . .
- // subtended angles // | a . (s=0) | s . a .
- newtotlen = 0; // 1| . 1| . .
- for(n=0;n<stepcnt;n++) { // | . | . .
- lens[n] = angles[n]/sum_of_angles; // |. b |.. b
- newtotlen += lens[n]; // |______ |_____________
- } //
- // Find new lens as proportion of total // Angle a is left over after
- for(n=0;n<stepcnt;n++) // subtracting b, and sum of previous angles (s)
- lens[n] /= newtotlen; // from rightangle
- // b = arctan(1/Nx)
- // In plane of lspkrs,
- // total distance between lspkes 1 and 3 = 2
- for(n=0;n<stepcnt;n++) // Angular distance to lspkr 3 = rightangle
- lens[n] *= (maxangle/rightangle) * 2; // Distance to maxangle is = (maxangle/rightangle) * length 2
- } else {
- steps_betwixt_12 = (int)floor(stepcnt * (1.0 - dz->param[TAN_SKEW]));
- direct_steplen = 1.0/(double)steps_betwixt_12; // \___x_\__x__\/ /
- // \ \ / / At every step (y),
- // \ \ / / Width subtended by lspkrs
- for(n=0;n<steps_betwixt_12;n++) // Assume equal steps // \__x__\/ / increases by x.
- lens[n] = direct_steplen; // btwn lspkrs 1+2 // \ / / If inter-lskpr dist (z) = 1
- // \ /y / steps as proportion of interlspkr dist
- // \0______0/ are x(1+x), x(1+2x) etc.
- newtotlen = 0; // 0 = \ z=1 /
- subtended_steplen = (2 * direct_steplen) * sin(PI/8.0); // lspkrs at\ / L = listener
- for(m = 1; n < stepcnt; n++,m++) { // For remaining steps // 45degrees \ /
- lens[n] = subtended_steplen; // In diagram, x // \L
- lens[n] /= (1.0 + (m * lens[n])); // In diagram, x/(1+mx) // y = direct_steplen. Angle at lspkr (0) = 45 = PI/4
- newtotlen += lens[n]; // Bisecting angle, sin(PI/8) = (x/2)/y = x/2y
- } // so x = 2ysin(PI/8)
- // Finally scale to lie vetween lsprs
- for(n = steps_betwixt_12; n < stepcnt; n++)
- lens[n] /= newtotlen;
- }
- // Now extend the motion to the next lspkr
- dz->EXTENSION = max(1,(int)floor(1.0/lens[0])); // Makes steps in extension >= to maximum previous step
- if(dz->vflag[LEFT]) {
- dz->iparam[TAN_FOCUS]--;
- if(dz->iparam[TAN_FOCUS] < 1) // Move the focus of the movement calculated above to the previous lspkr
- dz->iparam[TAN_FOCUS] = 8; // Then add the extension,
- } else { // taking the complete path to the
- dz->iparam[TAN_FOCUS]++; // original FOCUS loudspeaker
- if(dz->iparam[TAN_FOCUS] > 8)
- dz->iparam[TAN_FOCUS] = 1;
- }
- return (FINISHED);
- }
- /************************************ PANCALC *******************************/
- void pancalc(double position,double *leftgain,double *rightgain)
- {
- int dirflag;
- double temp;
- double relpos;
- double reldist, invsquare;
- if(position < 0.0)
- dirflag = SIGNAL_TO_LEFT; /* signal on left */
- else
- dirflag = SIGNAL_TO_RIGHT;
- if(position < 0)
- relpos = -position;
- else
- relpos = position;
- if(relpos <= 1.0){ /* between the speakers */
- temp = 1.0 + (relpos * relpos);
- reldist = ROOT2 / sqrt(temp);
- temp = (position + 1.0) / 2.0;
- *rightgain = temp * reldist;
- *leftgain = (1.0 - temp ) * reldist;
- } else { /* outside the speakers */
- temp = (relpos * relpos) + 1.0;
- reldist = sqrt(temp) / ROOT2; /* relative distance to source */
- invsquare = 1.0 / (reldist * reldist);
- if(dirflag == SIGNAL_TO_LEFT){
- *leftgain = invsquare;
- *rightgain = 0.0;
- } else { /* SIGNAL_TO_RIGHT */
- *rightgain = invsquare;
- *leftgain = 0;
- }
- }
- }
- /********************************************************************************************/
- int get_the_process_no(char *prog_identifier_from_cmdline,dataptr dz)
- {
- if(!strcmp(prog_identifier_from_cmdline,"onefile")) dz->process = TAN_ONE;
- else if(!strcmp(prog_identifier_from_cmdline,"twofiles")) dz->process = TAN_TWO;
- else if(!strcmp(prog_identifier_from_cmdline,"sequence")) dz->process = TAN_SEQ;
- else if(!strcmp(prog_identifier_from_cmdline,"list")) dz->process = TAN_LIST;
- else {
- sprintf(errstr,"Unknown program identification string '%s'\n",prog_identifier_from_cmdline);
- return(USAGE_ONLY);
- }
- return(FINISHED);
- }
- /******************************** SETUP_AND_INIT_INPUT_BRKTABLE_CONSTANTS ********************************/
- int setup_and_init_input_brktable_constants(dataptr dz,int brkcnt)
- {
- int n;
- if((dz->brk = (double **)malloc(brkcnt * sizeof(double *)))==NULL) {
- sprintf(errstr,"setup_and_init_input_brktable_constants(): 1\n");
- return(MEMORY_ERROR);
- }
- if((dz->brkptr = (double **)malloc(brkcnt * sizeof(double *)))==NULL) {
- sprintf(errstr,"setup_and_init_input_brktable_constants(): 6\n");
- return(MEMORY_ERROR);
- }
- if((dz->brksize = (int *)malloc(brkcnt * sizeof(int)))==NULL) {
- sprintf(errstr,"setup_and_init_input_brktable_constants(): 2\n");
- return(MEMORY_ERROR);
- }
- if((dz->firstval = (double *)malloc(brkcnt * sizeof(double)))==NULL) {
- sprintf(errstr,"setup_and_init_input_brktable_constants(): 3\n");
- return(MEMORY_ERROR);
- }
- if((dz->lastind = (double *)malloc(brkcnt * sizeof(double)))==NULL) {
- sprintf(errstr,"setup_and_init_input_brktable_constants(): 4\n");
- return(MEMORY_ERROR);
- }
- if((dz->lastval = (double *)malloc(brkcnt * sizeof(double)))==NULL) {
- sprintf(errstr,"setup_and_init_input_brktable_constants(): 5\n");
- return(MEMORY_ERROR);
- }
- if((dz->brkinit = (int *)malloc(brkcnt * sizeof(int)))==NULL) {
- sprintf(errstr,"setup_and_init_input_brktable_constants(): 7\n");
- return(MEMORY_ERROR);
- }
- for(n=0;n<brkcnt;n++) {
- dz->brk[n] = NULL;
- dz->brkptr[n] = NULL;
- dz->brkinit[n] = 0;
- dz->brksize[n] = 0;
- }
- return(FINISHED);
- }
- /******************************** USAGE2 ********************************/
- int usage2(char *str)
- {
- if(!strcmp(str,"onefile")) {
- fprintf(stdout,
- "USAGE: tangent onefile\n"
- " 1 infile outf dur steps maxangle dec [-ffoc] [-jjitter] [-sslow] [-r] [-l]\n"
- " 2 infile outf dur steps skew dec [-ffoc] [-jjitter] [-r] [-l]\n"
- "\n"
- "Play repets of mono sound on tangent path to (or from) 8-channel, front-centred\n"
- "loudspeaker array. Lspkrs numbered clockwise, starting with \"1\" at front-centre.\n"
- "\n"
- "MODE 1 For focus at 1, tangent starts along line at right-angles to lspkr 2.\n"
- "MODE 2 For focus at 1 tangent starts along line formed by lspkrs 2 and 3.\n"
- "\n"
- "DUR Duration of output file.\n"
- "STEPS Count of events in tangent stream (Modes 1-4 only).\n"
- " Note that in ALL modes, in the part of the stream closest to the focus\n"
- " SAME initial (receding) or final (approaching) event is repeated,\n"
- " and these repeated events are ADDITIONAL to this step-count.\n"
- "MAXANGLE (Mode 1) Motion between 3 lspkr pairs (e.g. 1-2, 2-3, 3-4)\n"
- " Max angle of rotation of motion lies between 3rd pair ( 90 to 135 ).\n"
- " (lsprks 3-4 in the example)\n"
- "SKEW (Mode 2) Motion between 3 lspkr pairs (e.g. 1-2, 2-3, 3-4)\n"
- " Skew is ratio (0-1) of time spent between last pair & penultimate pair\n"
- " (lspkr pairs 3-4 and 2-3, in the example)\n"
- "DEC Loudness decimation on passing from one event to the next.\n"
- "FOC Focal lpskr to or from which motion takes place (default, front centre).\n"
- "JITTER Randomisation of event timings (0-1, default 0) Can vary over time.\n"
- "SLOW Slow (or speed up) the pan-motion acceleration (default 0.5).\n"
- " Smaller values make stream arrive more slowly at goal.\n"
- " For approaching motion, 0.5 makes arrival not too fast.\n"
- " For receding motion, 1.0, makes initial motion rapid.\n"
- "-r Sounds RECEDE (default, sound approaches)\n"
- "-l Motion to or from LEFT of focal lspkr (default: to or from right).\n");
- } else if(!strcmp(str,"twofiles")) {
- fprintf(stdout,
- "USAGE: tangent twofiles\n"
- " 1 inf1 inf2 outf dur steps maxangle dec bal [-ffoc] [-jjitter] [-sslow] [-r] [-l]\n"
- " 2 inf1 inf2 outf dur steps skew dec bal [-ffoc] [-jjitter] [-r] [-l]\n"
- "\n"
- "Play two syncd mono sounds on tangent path to (or from) 8-channel, front-centred\n"
- "loudspeaker array. Lspkrs numbered clockwise, starting with \"1\" at front-centre.\n"
- "Output begins with 1st input sound, then gradually mixes in second input sound.\n"
- "If one sound is a filtered version of the other, suggesting greater distance,\n"
- "For an approaching sequence, put filtered sound as sound 1\n"
- "but for a receding sequence, put filtered sound as sound 2.\n"
- "\n"
- "MODE 1 For focus at 1, tangent starts along line at right-angles to lspkr 2.\n"
- "MODE 2 For focus at 1 tangent starts along line formed by lspkrs 2 and 3.\n"
- "\n"
- "DUR Duration of output file.\n"
- "STEPS Count of events in tangent stream (Modes 1-4 only).\n"
- " Note that in ALL modes, in the part of the stream closest to the focus\n"
- " SAME initial (receding) or final (approaching) event is repeated,\n"
- " and these repeated events are ADDITIONAL to this step-count.\n"
- "MAXANGLE (Mode 1) Motion between 3 lspkr pairs (e.g. 1-2, 2-3, 3-4)\n"
- " Max angle of rotation of motion lies between 3rd pair ( 90 to 135 ).\n"
- " (lsprks 3-4 in the example)\n"
- "SKEW (Mode 2) Motion between 3 lspkr pairs (e.g. 1-2, 2-3, 3-4)\n"
- " Skew is ratio (0-1) of time spent between last pair & penultimate pair\n"
- " (lspkr pairs 3-4 and 2-3, in the example)\n"
- "DEC Loudness decimation on passing from one event to the next.\n"
- "BAL Progressive accumulation of 2nd sound in mix.\n"
- "FOC Focal lpskr to or from which motion takes place (default, front centre).\n"
- "JITTER Randomisation of event timings (0-1, default 0) Can vary over time.\n"
- "SLOW Slow (or speed up) the pan-motion acceleration (default 0.5).\n"
- " Smaller values make stream arrive more slowly at goal.\n"
- " For approaching motion, 0.5 makes arrival not too fast.\n"
- " For receding motion, 1.0, makes initial motion rapid.\n"
- "-r Sounds RECEDE (default, sound approaches)\n"
- "-l Motion to or from LEFT of focal lspkr (default: to or from right).\n");
- } else if(!strcmp(str,"sequence")) {
- fprintf(stdout,
- "USAGE: tangent sequence\n"
- " 1 file1 file2 [file3..] outf dur maxangle dec [-ffoc] [-jjitter] [-sslow] [-r] [-l]\n"
- " 2 file1 file2 [file3..] outf dur skew dec [-ffoc] [-jjitter] [-r] [-l]\n"
- "\n"
- "Play sequence of mono sounds on tangent path to (or from) 8-channel, front-centred\n"
- "loudspeaker array. Lspkrs numbered clockwise, starting with \"1\" at front-centre.\n"
- "\n"
- "MODE 1 For focus at 1, tangent starts along line at right-angles to lspkr 2.\n"
- "MODE 2 For focus at 1 tangent starts along line formed by lspkrs 2 and 3.\n"
- "\n"
- "DUR Duration of output file.\n"
- "MAXANGLE (Mode 1) Motion between 3 lspkr pairs (e.g. 1-2, 2-3, 3-4)\n"
- " Max angle of rotation of motion lies between 3rd pair ( 90 to 135 ).\n"
- " (lsprks 3-4 in the example)\n"
- "SKEW (Mode 2) Motion between 3 lspkr pairs (e.g. 1-2, 2-3, 3-4)\n"
- " Skew is ratio (0-1) of time spent between last pair & penultimate pair\n"
- " (lspkr pairs 3-4 and 2-3, in the example)\n"
- "DEC Loudness decimation on passing from one event to the next.\n"
- "FOC Focal lpskr to or from which motion takes place (default, front centre).\n"
- "JITTER Randomisation of event timings (0-1, default 0) Can vary over time.\n"
- "SLOW Slow (or speed up) the pan-motion acceleration (default 0.5).\n"
- " Smaller values make stream arrive more slowly at goal.\n"
- " For approaching motion, 0.5 makes arrival not too fast.\n"
- " For receding motion, 1.0, makes initial motion rapid.\n"
- "-r Sounds RECEDE (default, sound approaches)\n"
- "-l Motion to or from LEFT of focal lspkr (default: to or from right).\n");
- } else if(!strcmp(str,"list")) {
- fprintf(stdout,
- "USAGE: tangent list\n"
- " 1 textfile outf dur maxangle dec [-ffoc] [-jjitter] [-sslow] [-r] [-l]\n"
- " 2 textfile outf dur skew dec [-ffoc] [-jjitter] [-r] [-l]\n"
- "\n"
- "Play sequence of mono sounds (listed in the textfile) on tangent path to (or from)\n"
- "8-channel front-centred lspkr array, numbered clockwise, from \"1\" at front-centre.\n"
- "\n"
- "MODE 1 For focus at 1, tangent starts along line at right-angles to lspkr 2.\n"
- "MODE 2 For focus at 1 tangent starts along line formed by lspkrs 2 and 3.\n"
- "\n"
- "DUR Duration of output file.\n"
- "MAXANGLE (Mode 1) Motion between 3 lspkr pairs (e.g. 1-2, 2-3, 3-4)\n"
- " Max angle of rotation of motion lies between 3rd pair ( 90 to 135 ).\n"
- " (lsprks 3-4 in the example)\n"
- "SKEW (Mode 2) Motion between 3 lspkr pairs (e.g. 1-2, 2-3, 3-4)\n"
- " Skew is ratio (0-1) of time spent between last pair & penultimate pair\n"
- " (lspkr pairs 3-4 and 2-3, in the example)\n"
- "DEC Loudness decimation on passing from one event to the next.\n"
- "FOC Focal lpskr to or from which motion takes place (default, front centre).\n"
- "JITTER Randomisation of event timings (0-1, default 0) Can vary over time.\n"
- "SLOW Slow (or speed up) the pan-motion acceleration (default 0.5).\n"
- " Smaller values make stream arrive more slowly at goal.\n"
- " For approaching motion, 0.5 makes arrival not too fast.\n"
- " For receding motion, 1.0, makes initial motion rapid.\n"
- "-r Sounds RECEDE (default, sound approaches)\n"
- "-l Motion to or from LEFT of focal lspkr (default: to or from right).\n");
- } else
- fprintf(stdout,"Unknown option '%s'\n",str);
- return(USAGE_ONLY);
- }
- int usage3(char *str1,char *str2)
- {
- fprintf(stderr,"Insufficient parameters on command line.\n");
- return(USAGE_ONLY);
- }
- /******************************** TANGENT ********************************/
- int tangent(dataptr dz)
- {
- int exit_status;
- char temp[400], temp2[400], temp3[400], temp4[400];
- int stepcnt;
- int lspkr = 1, rspkr = 2, n, m, swapped = 0;
- double dur = dz->param[TAN_DUR], thistime, thispos = 0.0, pos, leftgain = 0.0, rightgain = 0.0;
- double timestep, extstep, maxangle = 0.0, gain = 1.0, fbal = 1.0, thisgain, rightangle = PI/2.0, time, jitter;
- double *lens = dz->parray[0];
- thistime = 0.0;
- if(dz->process == TAN_SEQ || dz->process == TAN_LIST)
- stepcnt = dz->infilecnt;
- else
- stepcnt = dz->iparam[TAN_STEPS];
- timestep = dur/(double)(stepcnt + dz->EXTENSION);
- sprintf(temp3,"%s",dz->wordstor[0]);
- sprintf(temp,"8\n");
- if(fputs(temp,dz->fp) < 0) {
- sprintf(errstr,"Error writing to output data file\n");
- return(PROGRAM_ERROR);
- }
- if(dz->process == TAN_TWO)
- sprintf(temp4,"%s",dz->wordstor[1]);
- if(dz->mode==0)
- maxangle = dz->param[TAN_MANG] * PI/180.0;
- if(dz->vflag[RECEDE]) { // If receeding
- thispos = 0.0; // Start at closest approach
- // Create PRE-extension to next lspkr at full level and equal steps
- if(dz->vflag[LEFT]) {
- lspkr = dz->iparam[TAN_FOCUS] + 1;
- if(lspkr > 8)
- lspkr = 1;
- rspkr = lspkr - 1;
- if(rspkr < 1)
- rspkr = 8;
- } else {
- lspkr = dz->iparam[TAN_FOCUS] - 1;
- if(lspkr < 1)
- lspkr = 8;
- rspkr = lspkr + 1;
- if(rspkr > 8)
- rspkr = 1;
- }
- extstep = 1.0/dz->EXTENSION;
- for(n = 0;n < dz->EXTENSION;n++) {
- time = thistime;
- if(time > 0.0) {
- if(dz->brksize[TAN_JITTER]) {
- if((exit_status = read_value_from_brktable(thistime,TAN_JITTER,dz))<0)
- return(exit_status);
- }
- if(dz->param[TAN_JITTER] > 0.0) {
- jitter = (drand48() * 2.0) - 1.0;
- jitter *= dz->param[TAN_JITTER];
- jitter *= timestep/2.0;
- time += jitter;
- }
- }
- pos = (thispos * 2.0) - 1.0; // Convert to -1 to 1 format
- pancalc(pos,&leftgain,&rightgain);
- strcpy(temp,temp3); // NB Modes 4 & 5 retain initial sound event during extension
- strcat(temp," ");
- sprintf(temp2,"%lf",time);
- strcat(temp,temp2);
- strcat(temp," 1 1:");
- sprintf(temp2,"%d",lspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",leftgain);
- strcat(temp,temp2);
- strcat(temp," 1:");
- sprintf(temp2,"%d",rspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",rightgain);
- strcat(temp,temp2);
- strcat(temp,"\n");
- if(fputs(temp,dz->fp) < 0) {
- sprintf(errstr,"Error writing to output data file\n");
- return(PROGRAM_ERROR);
- }
- thistime += timestep;
- thispos += extstep;
- }
- // Now do the tangent motion
- fbal = 1.0;
- gain = 1.0;
- thispos = 0.0; // Start at closest approach
- lspkr = dz->iparam[TAN_FOCUS]; // on closest lspkrs
- if(dz->vflag[LEFT]) {
- rspkr = lspkr - 1;
- if(rspkr < 1)
- rspkr = 8;
- } else {
- rspkr = lspkr + 1;
- if(rspkr > 8)
- rspkr = 1;
- }
- for(n=0;n<stepcnt;n++) {
- thispos += lens[n]; // Position of next segment
- if(thispos > 1) {
- if(!swapped) { // If JUST Reached lspkrs 1
- lspkr = rspkr; // Reposition between lskprs 1 & 2
- if(dz->vflag[LEFT]) {
- rspkr = lspkr - 1;
- if(rspkr < 1)
- rspkr = 8;
- } else {
- rspkr = lspkr + 1;
- if(rspkr > 8)
- rspkr = 1;
- }
- swapped = 1;
- }
- pos = ((thispos - 1) * 2.0) - 1.0; // Convert to -1 to 1 format
- } else
- pos = (thispos * 2.0) - 1.0; // Convert to -1 to 1 format
- time = thistime;
- if(time > 0.0) {
- if(dz->brksize[TAN_JITTER]) {
- if((exit_status = read_value_from_brktable(thistime,TAN_JITTER,dz))<0)
- return(exit_status);
- }
- if(dz->param[TAN_JITTER] > 0.0) {
- jitter = (drand48() * 2.0) - 1.0;
- jitter *= dz->param[TAN_JITTER];
- jitter *= timestep/2.0;
- time += jitter;
- }
- }
- thisgain = gain;
- if(dz->process == TAN_TWO)
- thisgain *= fbal;
- pancalc(pos,&leftgain,&rightgain);
- if(dz->process == TAN_SEQ || dz->process == TAN_LIST) // For multifile processes, change filename for each event
- sprintf(temp3,"%s",dz->wordstor[n]);
- strcpy(temp,temp3);
- strcat(temp," ");
- sprintf(temp2,"%lf",time);
- strcat(temp,temp2);
- strcat(temp," 1 1:");
- sprintf(temp2,"%d",lspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",leftgain * thisgain);
- strcat(temp,temp2);
- strcat(temp," 1:");
- sprintf(temp2,"%d",rspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",rightgain * thisgain);
- strcat(temp,temp2);
- strcat(temp,"\n");
- if(fputs(temp,dz->fp) < 0) {
- sprintf(errstr,"Error writing to output data file\n");
- return(PROGRAM_ERROR);
- }
- if(dz->process == TAN_TWO) {
- thisgain = gain;
- thisgain *= max(0.0,1.0 - fbal);
- strcpy(temp,temp4); // Mix in filtered version of file
- strcat(temp," ");
- sprintf(temp2,"%lf",time);
- strcat(temp,temp2);
- strcat(temp," 1 1:");
- sprintf(temp2,"%d",lspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",leftgain * thisgain);
- strcat(temp,temp2);
- strcat(temp," 1:");
- sprintf(temp2,"%d",rspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",rightgain * thisgain);
- strcat(temp,temp2);
- strcat(temp,"\n");
- if(fputs(temp,dz->fp) < 0) {
- sprintf(errstr,"Error writing to output data file\n");
- return(PROGRAM_ERROR);
- }
- }
- thistime += timestep; // Time of next segment
- gain *= dz->param[TAN_DEC];
- if(dz->process == TAN_TWO)
- fbal *= dz->param[TAN_FBAL];
- }
- } else { // If approaching
- if(dz->mode==1)
- thispos = 2.0;
- else // Start at max distance
- thispos = (maxangle/rightangle) * 2;
- if(dz->vflag[LEFT]) {
- lspkr = dz->iparam[TAN_FOCUS] - 1; // on furthest lspkrs
- if(lspkr < 1)
- lspkr = 8;
- rspkr = lspkr - 1;
- if(rspkr < 1)
- rspkr = 8;
- } else {
- lspkr = dz->iparam[TAN_FOCUS] + 1; // on furthest lspkrs
- if(lspkr > 8)
- lspkr = 1;
- rspkr = lspkr + 1;
- if(rspkr > 8)
- rspkr = 1;
- }
- gain = pow(dz->param[TAN_DEC],(stepcnt - 1));
- dz->param[TAN_DEC] = 1.0/dz->param[TAN_DEC];
- if(dz->process == TAN_TWO) {
- fbal = pow(dz->param[TAN_FBAL],(stepcnt - 1));
- dz->param[TAN_FBAL] = 1.0/dz->param[TAN_FBAL];
- }
- for(n=0,m = stepcnt - 1;n<stepcnt;n++,m--) {
- if(thispos < 1) {
- if(!swapped) { // If JUST Reach lspkrs 1
- if(dz->vflag[LEFT]) {
- lspkr++; // Reposition between lskprs 1 & 2
- if(lspkr > 8)
- lspkr = 1;
- rspkr++;
- if(rspkr > 8)
- rspkr = 1;
- } else {
- lspkr--; // Reposition between lskprs 1 & 2
- if(lspkr < 1)
- lspkr = 8;
- rspkr--;
- if(rspkr < 1)
- rspkr = 8;
- }
- swapped = 1;
- }
- pos = (thispos * 2.0) - 1.0; // Convert to -1 to 1 format
- } else
- pos = ((thispos - 1) * 2.0) - 1.0; // Convert to -1 to 1 format
- time = thistime;
- if(time > 0.0) {
- if(dz->brksize[TAN_JITTER]) {
- if((exit_status = read_value_from_brktable(thistime,TAN_JITTER,dz))<0)
- return(exit_status);
- }
- if(dz->param[TAN_JITTER] > 0.0) {
- jitter = (drand48() * 2.0) - 1.0;
- jitter *= dz->param[TAN_JITTER];
- jitter *= timestep/2.0;
- time += jitter;
- }
- }
- thisgain = gain;
- if(dz->process == TAN_TWO)
- thisgain *= fbal;
- pancalc(pos,&leftgain,&rightgain);
- if(dz->process == TAN_SEQ || dz->process == TAN_LIST) // For multifile processes, change filename for each event
- sprintf(temp3,"%s",dz->wordstor[n]);
- strcpy(temp,temp3);
- strcat(temp," ");
- sprintf(temp2,"%lf",time);
- strcat(temp,temp2);
- strcat(temp," 1 1:");
- sprintf(temp2,"%d",lspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",leftgain * gain);
- strcat(temp,temp2);
- strcat(temp," 1:");
- sprintf(temp2,"%d",rspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",rightgain * gain);
- strcat(temp,temp2);
- strcat(temp,"\n");
- if(fputs(temp,dz->fp) < 0) {
- sprintf(errstr,"Error writing to output data file\n");
- return(PROGRAM_ERROR);
- }
- if(dz->process == TAN_TWO) {
- thisgain = gain;
- thisgain *= max(1.0 - fbal,0.0);
- strcpy(temp,temp4); // Mix in filtered version of file
- strcat(temp," ");
- sprintf(temp2,"%lf",time);
- strcat(temp,temp2);
- strcat(temp," 1 1:");
- sprintf(temp2,"%d",lspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",leftgain * thisgain);
- strcat(temp,temp2);
- strcat(temp," 1:");
- sprintf(temp2,"%d",rspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",rightgain * thisgain);
- strcat(temp,temp2);
- strcat(temp,"\n");
- if(fputs(temp,dz->fp) < 0) {
- sprintf(errstr,"Error writing to output data file\n");
- return(PROGRAM_ERROR);
- }
- }
- thispos -= lens[m]; // Position of next segment
- thistime += timestep; // Time of next segment
- gain *= dz->param[TAN_DEC];
- if(dz->process == TAN_TWO)
- fbal *= dz->param[TAN_FBAL];
- }
- // Create POST-extension to next lspkr at full level and equal steps
- if(dz->EXTENSION) {
- if(dz->vflag[LEFT]) {
- lspkr = dz->iparam[TAN_FOCUS];
- rspkr = lspkr + 1;
- if(rspkr > 8)
- rspkr = 1;
- } else {
- lspkr = dz->iparam[TAN_FOCUS];
- rspkr = lspkr - 1;
- if(rspkr < 1)
- rspkr = 8;
- }
- extstep = 1.0/dz->EXTENSION;
- thispos = extstep;
- for(n = 0;n < dz->EXTENSION;n++) {
- time = thistime;
- if(time > 0.0) {
- if(dz->brksize[TAN_JITTER]) {
- if((exit_status = read_value_from_brktable(thistime,TAN_JITTER,dz))<0)
- return(exit_status);
- }
- if(dz->param[TAN_JITTER] > 0.0) {
- jitter = (drand48() * 2.0) - 1.0;
- jitter *= dz->param[TAN_JITTER];
- jitter *= timestep/2.0;
- time += jitter;
- }
- }
- pos = (thispos * 2.0) - 1.0; // Convert to -1 to 1 format
- pancalc(pos,&leftgain,&rightgain);
- strcpy(temp,temp3); // NB Modes 4 & 5 retain final sound event during extension
- strcat(temp," ");
- sprintf(temp2,"%lf",time);
- strcat(temp,temp2);
- strcat(temp," 1 1:");
- sprintf(temp2,"%d",lspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",leftgain);
- strcat(temp,temp2);
- strcat(temp," 1:");
- sprintf(temp2,"%d",rspkr);
- strcat(temp,temp2);
- strcat(temp," ");
- sprintf(temp2,"%lf",rightgain);
- strcat(temp,temp2);
- strcat(temp,"\n");
- if(fputs(temp,dz->fp) < 0) {
- sprintf(errstr,"Error writing to output data file\n");
- return(PROGRAM_ERROR);
- }
- thistime += timestep;
- thispos = min(thispos + extstep, 1.0);
- }
- }
- }
- return FINISHED;
- }
- /****************************** GET_MODE *********************************/
- int get_the_mode_from_cmdline(char *str,dataptr dz)
- {
- char temp[200], *p;
- if(sscanf(str,"%s",temp)!=1) {
- sprintf(errstr,"Cannot read mode of program.\n");
- return(USAGE_ONLY);
- }
- p = temp + strlen(temp) - 1;
- while(p >= temp) {
- if(!isdigit(*p)) {
- fprintf(stderr,"Invalid mode of program entered.\n");
- return(USAGE_ONLY);
- }
- p--;
- }
- if(sscanf(str,"%d",&dz->mode)!=1) {
- fprintf(stderr,"Cannot read mode of program.\n");
- return(USAGE_ONLY);
- }
- if(dz->mode <= 0 || dz->mode > dz->maxmode) {
- fprintf(stderr,"Program mode value [%d] is out of range [1 - %d].\n",dz->mode,dz->maxmode);
- return(USAGE_ONLY);
- }
- dz->mode--; /* CHANGE TO INTERNAL REPRESENTATION OF MODE NO */
- return(FINISHED);
- }
- /****************************** STORE_THE_FILENAME *********************************/
- int store_the_filename(char *filename,dataptr dz)
- {
- char *p;
- int k;
- if(dz->wordstor != NULL) {
- sprintf(errstr,"Cannot store filename: wordstor already allocated.\n");
- return(PROGRAM_ERROR);
- }
- if((dz->wordstor = (char **)malloc(dz->infilecnt * sizeof(char *)))==NULL) {
- sprintf(errstr,"Cannot store filename.\n");
- return(MEMORY_ERROR);
- }
- p = filename + strlen(filename);
- p--;
- while(p != filename) {
- if(*p == '.') {
- if(strcmp(p,".wav")) {
- sprintf(errstr,"Input file %s is not a soundfile.\n",filename);
- return(DATA_ERROR);
- }
- break;
- }
- p--;
- }
- if(p == filename)
- k = 5;
- else
- k = 1;
- if((dz->wordstor[0] = (char *)malloc((strlen(filename)+1) * sizeof(char)))==NULL) {
- sprintf(errstr,"Cannot store filename.\n");
- return(MEMORY_ERROR);
- }
- if((dz->wordstor[0] = (char *)malloc((strlen(filename)+k) * sizeof(char)))==NULL) {
- sprintf(errstr,"Cannot store further filename.\n");
- return(MEMORY_ERROR);
- }
- strcpy(dz->wordstor[0],filename);
- if(k==5)
- strcat(dz->wordstor[0],".wav");
- dz->all_words++;
- return(FINISHED);
- }
- /****************************** STORE_THE_FURTHER_FILENAME *********************************/
- int store_the_further_filename(int n,char *filename,dataptr dz)
- {
- char *p;
- int k;
- p = filename + strlen(filename);
- p--;
- while(p != filename) {
- if(*p == '.') {
- if(strcmp(p,".wav")) {
- sprintf(errstr,"Input file %s is not a soundfile.\n",filename);
- return(DATA_ERROR);
- }
- break;
- }
- p--;
- }
- if(p == filename)
- k = 5;
- else
- k = 1;
- if((dz->wordstor[n] = (char *)malloc((strlen(filename)+k) * sizeof(char)))==NULL) {
- sprintf(errstr,"Cannot store further filename.\n");
- return(MEMORY_ERROR);
- }
- strcpy(dz->wordstor[n],filename);
- if(k==5)
- strcat(dz->wordstor[n],".wav");
- dz->all_words++;
- return(FINISHED);
- }
- /****************************** READ_INPUT_SNDFILES_LIST *********************************
- *
- * Ensure Files are mono
- * Compare properties (srate and channel-count)
- * Store channel-cnt and the duration.
- *
- */
- int read_input_sndfiles_list(char *filename,dataptr dz)
- {
- int exit_status, n;
- char *p, fnam[400];
- infileptr infile_info;
- FILE *fp;
- if((fp = fopen(filename,"r"))==NULL) {
- sprintf(errstr,"Cannot open file %s to read sonudfile names.\n",filename);
- return(DATA_ERROR);
- }
- dz->infilecnt = 0;
- while(fgets(fnam,200,fp)!=NULL) {
- p = fnam;
- while(isspace(*p))
- p++;
- if(*p == ';') // Allow comments in file
- continue;
- dz->infilecnt++;
- }
- if(dz->infilecnt <= 0) {
- sprintf(errstr,"No data found in file %s\n",filename);
- return(DATA_ERROR);
- }
- dz->infile->filetype = SNDFILE;
- dz->input_data_type = MANY_SNDFILES;
- if((exit_status = allocate_the_filespace(dz))<0)
- return(exit_status);
- fseek(fp,0,0);
- n = 0;
- while(fgets(fnam,200,fp)!=NULL) {
- p = fnam;
- while(isspace(*p))
- p++;
- if(*p == ';') // Allow comments in file
- continue;
- p = fnam + strlen(fnam); // Remove newline character
- p--;
- while(p != fnam) {
- if(*p == '\n') {
- *p = ENDOFSTR;
- break;
- }
- p--;
- }
- if(n == 0) {
- if((exit_status = open_first_infile(fnam,dz))<0)
- return exit_status;
- if((infile_info = (infileptr)malloc(sizeof(struct filedata)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY for infile structure to test TK data.");
- return(MEMORY_ERROR);
- }
- if((exit_status = cdparse(fnam,infile_info))<0)
- return(exit_status);
- if(infile_info->channels != MONO) {
- sprintf(errstr,"Process only works with mono input files.");
- return(DATA_ERROR);
- }
- dz->infile->srate = infile_info->srate;
- dz->infile->channels = infile_info->channels;
- dz->duration = infile_info->duration;
- if((exit_status = store_the_filename(fnam,dz))<0)
- return(exit_status);
- } else {
- if((exit_status = handle_other_infile(n,fnam,dz))<0)
- return exit_status;
- sndcloseEx(dz->ifd[n]);
- dz->ifd[n] = -1;
- if((exit_status = store_the_further_filename(dz->all_words,fnam,dz))<0)
- return(exit_status);
- }
- n++;
- }
- fclose(fp);
- if(dz->ifd[0] >= 0) {
- sndcloseEx(dz->ifd[0]);
- dz->ifd[0] = -1;
- }
- return FINISHED;
- }
- /************************ ALLOCATE_THE_FILESPACE *********************/
- int allocate_the_filespace(dataptr dz)
- {
- int n;
- if((dz->ifd = (int *)malloc(dz->infilecnt * sizeof(int)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY for infile poniters array.\n");
- return(MEMORY_ERROR);
- }
- if((dz->insams = (int *)malloc(dz->infilecnt * sizeof(int)))==NULL) {
- sprintf(errstr,"INSUFFICIENT MEMORY for infile-sampsize array.\n");
- return(MEMORY_ERROR);
- }
- for(n=0;n<dz->infilecnt;n++) {
- dz->ifd[n] = -1;
- dz->insams[n] = 0L;
- }
- return(FINISHED);
- }
|