cdparse.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149
  1. /*
  2. * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
  3. * http://www.trevorwishart.co.uk
  4. * http://www.composersdesktop.com
  5. *
  6. This file is part of the CDP System.
  7. The CDP System is free software; you can redistribute it
  8. and/or modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The CDP System is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the CDP System; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA
  19. *
  20. */
  21. /* floats version */
  22. /* RECEIVES FROM TK
  23. *
  24. * Name of input file.
  25. *
  26. * SENDS TO TK
  27. *
  28. * (1) Various file constants, which TK needs to STORE, to pass back at subsequent stage.
  29. */
  30. /**** FEB 1999 MODS
  31. *
  32. * Force cdparams() output to be printed to stdout on a single line, with items separated by
  33. * single spaces, forming a valid TK list
  34. *
  35. * Recognise Float-sndfiles.
  36. */
  37. #include <stdio.h>
  38. #include <osbind.h>
  39. #include <math.h>
  40. #include <float.h>
  41. #include <structures.h>
  42. #include <sfsys.h>
  43. #include <cdpstate.h>
  44. #include <tkglobals.h>
  45. #include <filetype.h>
  46. #include <globcon.h>
  47. #include <headread.h>
  48. #include <speccon.h>
  49. #include <processno.h>
  50. #include <stdlib.h>
  51. #include <ctype.h>
  52. #include <limits.h>
  53. #include <string.h>
  54. //OCT 2005
  55. #include <standalone.h>
  56. /* NEW CODE June 1st 2000 */
  57. #ifndef CDP97
  58. #define CDP97 //RWD.6.98 need this!
  59. #endif
  60. #ifdef _DEBUG
  61. #include <assert.h>
  62. #endif
  63. void maxsamp(int ifd,double *maxamp,double *maxloc,int *maxrep);
  64. /* END OF NEW CODE */
  65. #define POSSIBLE (TRUE)
  66. #ifdef IS_CDPARSE
  67. char errstr[400]; /* only for app version, not for cdp2k library version */
  68. #endif
  69. //RWD debugging
  70. #define LOCALMEMBYTES (4000)
  71. #ifdef unix
  72. #define round(x) lround((x))
  73. #endif
  74. static void initialise_fileptr(infileptr inputfile);
  75. static int check_for_data_in_file(char *filename,infileptr inputfile);
  76. static int set_wlength_and_check_data(char *filename,int ifd,infileptr inputfile);
  77. static int check_pitch_or_transpos_binary_data(infileptr inputfile,char *filename,int ifd);
  78. static int megaparsec(char *filename,FILE *fp,infileptr inputfile);
  79. static int initial_parse_textfile(char *filename,FILE *fp,int *linelist,
  80. int *has_comments,int *dB_notation,int *total_wordcnt,
  81. int *numcnt,int *linecnt,int *max_line_word_cnt,int *min_line_word_cnt);
  82. static void initial_textfile_check(int dB_notation,int *sndlist,int *mixlist,int *brklist,int *numlist,
  83. int numcnt,int total_wordcnt,int max_line_word_cnt,int in_line_word_cnt);
  84. static int valid_start_of_mixfile_line(int k,int *chans,int lineno,char **wordstor,int *srate,
  85. int *mixlist,infileptr inputfile,char *filename,double *dur);
  86. #ifdef IS_CDPARSE
  87. static int is_valid_end_of_mixfile_line(int j,int chans,int lineno,char **wordstor,int *wordcnt);
  88. #else
  89. static int is_valid_end_of_mixfile_line(int j,int chans,int lineno,char **wordstor,int *wordcnt,char *filename);
  90. #endif
  91. static int confirm_true_stereo(int *chans,int *is_left,int *is_right,int *is_central,char *panword);
  92. static int is_a_possible_mixfile(char **wordstor,int *wordcnt,int linecnt,
  93. int *mixlist,int *srate,infileptr inputfile, char *filename,double *dur);
  94. static int OK_level(char *str);
  95. static int is_a_dB_value(char *str);
  96. static int get_leveldb_frame(char *str,double *val);
  97. static int is_a_valid_sndfile_for_mixfile(char *filename,char *sndfilename,int *srate,
  98. int chans,int linecnt,infileptr inputfile,double time,double *dur,int multichan);
  99. static int check_for_brklist_and_count_numbers(char **wordstor,int *wordcnt,
  100. int linecnt,int *brklist,infileptr inputfile,char *filename);
  101. static int check_for_a_linelist(int line_word_cnt,int *linelist,char **wordstor,infileptr inputfile);
  102. static int store_wordlist_without_comments
  103. (FILE *fp,char *temp,int total_wordcnt,char **wordstor,int *wordcnt,infileptr inputfile);
  104. /* NEW CODE */
  105. static int assign_type(int sndlist,int numlist,int brklist,int mixlist,int synclist,int linelist,
  106. int extended_brkfile,infileptr inputfile);
  107. /* NEW CODE */
  108. static int check_for_sndlist(char **wordstor,int *wordcnt,int linecnt,int *sndlist);
  109. static int check_for_a_synclist(int *synclist,char **wordstor,int *wordcnt,infileptr inputfile,char *filename);
  110. static int is_a_valid_sndfile_for_sync(char *filename,char *sndfilename,int *srate,int linecnt,infileptr inputfile);
  111. static int set_sndlist_flags(infileptr inputfile,char **wordstor);
  112. static int assign_brkfile_type(infileptr inputfile,int linelist);
  113. #ifdef NO_DUPLICATE_SNDFILES
  114. #ifdef IS_CDPARSE
  115. static int duplicated_filenames(int linecnt,char **wordstor,int *wordcnt);
  116. #else
  117. static int duplicated_filenames(int linecnt,char **wordstor,int *wordcnt,char *filename);
  118. #endif
  119. #endif
  120. static int check_for_an_extended_brkfile
  121. (int *extended_brkfile,char **wordstor,int *wordcnt,int linecnt,int total_words,infileptr inputfile);
  122. static int extract_value_pair
  123. (int *n,double *time, double *val,double *maxval,double *minval,double *lasttime, char **wordstor);
  124. static void utol(char *str);
  125. extern int smpflteq(double a,double b);
  126. int do_exit(int exit_status);
  127. /* RWD TODO: use sndsystem */
  128. #ifdef IS_CDPARSE
  129. //static int nuheadread(infileptr inputfile,int ifd,char *filename,double *maxamp,double *maxloc, int *maxrep,int getmax);
  130. #endif
  131. static int parse_a_textfile(char *filename,infileptr inputfile);
  132. static int get_multichan_mixdata_in_line(int wordcnt,char **wordstor,int total_words,double *time,int *chans,int maxoutchan);
  133. static int is_a_possible_multichannel_mixfile
  134. (int numlist,int brklist,int sndlist,int linecnt,char **wordstor,int *wordcnt,char *mixfilename,infileptr inputfile);
  135. static int IsNumeric(char *str);
  136. /***************************** MAIN **************************/
  137. #ifdef IS_CDPARSE
  138. int sloom = 1;
  139. int sloombatch = 0;
  140. const char* cdp_version = "7.1.0";
  141. int main(int argc,char *argv[])
  142. {
  143. char *filename;
  144. infileptr inputfile;
  145. char temp[/*2000*/LOCALMEMBYTES], *p; /*** Added FEB 1999 *****/
  146. int getmaxinfo = 1;
  147. #else
  148. int cdparse(char *filename,infileptr inputfile)
  149. {
  150. int getmaxinfo = 0;
  151. #endif
  152. int exit_status;
  153. int ifd;
  154. double maxamp = 0.0, maxloc = -1.0;
  155. int maxrep = 0;
  156. int getmax = 0;
  157. #ifdef IS_CDPARSE
  158. /* NEW CODE : June 1st 2000 */
  159. if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
  160. fprintf(stdout,"%s\n",cdp_version);
  161. fflush(stdout);
  162. return 0;
  163. }
  164. if(argc!=3) {
  165. sprintf(errstr,"Incorrect call to cdparse()\n");
  166. exit_status = FAILED;
  167. return do_exit(exit_status);
  168. }
  169. if(sscanf(argv[2],"%d",&getmax)!=1) {
  170. sprintf(errstr,"Incorrect call to cdparse()\n");
  171. exit_status = FAILED;
  172. return do_exit(exit_status);
  173. }
  174. filename = argv[1];
  175. if(file_has_invalid_startchar(filename)) {
  176. sprintf(errstr, "Filename %s has invalid starting character(s)\n",filename);
  177. exit_status = FAILED;
  178. return do_exit(exit_status);
  179. }
  180. if(file_has_invalid_extension(filename)) {
  181. sprintf(errstr, "Filename %s has invalid extension for CDP work\n",filename);
  182. exit_status = FAILED;
  183. return do_exit(exit_status);
  184. }
  185. if((inputfile = (infileptr)malloc(sizeof(struct filedata)))==NULL) {
  186. sprintf(errstr,"Insufficient memory for parsing file %s.\n",filename);
  187. exit_status = MEMORY_ERROR;
  188. return do_exit(exit_status);
  189. }
  190. #endif
  191. initialise_fileptr(inputfile);
  192. if((ifd = sndopenEx(filename,0,CDP_OPEN_RDONLY)) >= 0) {
  193. if((exit_status = readhead(inputfile,ifd,filename,&maxamp,&maxloc,&maxrep,getmax,getmaxinfo))<0) {
  194. if(sndcloseEx(ifd)<0) {
  195. sprintf(errstr, "Failed to close file %s\n",filename);
  196. exit_status = SYSTEM_ERROR;
  197. return do_exit(exit_status);
  198. }
  199. return do_exit(exit_status);
  200. }
  201. if(getmaxinfo && getmax && (maxrep < 0)) { /* if maxsamp required & not in header, get it by searching file */
  202. //TW only get maxsamp if it's a soundfile
  203. if(inputfile->filetype == SNDFILE) {
  204. maxsamp(ifd,&maxamp,&maxloc,&maxrep); /*RWD TODO */
  205. sndseekEx(ifd,0,0); /* RWD TODO */
  206. }
  207. }
  208. if((inputfile->insams = sndsizeEx(ifd))<0) {
  209. sprintf(errstr, "Can't read size of input file %s\n",filename);
  210. exit_status = DATA_ERROR;
  211. if(sndcloseEx(ifd)<0) {
  212. sprintf(errstr, "Failed to close file %s: %s\n",filename,sferrstr());
  213. exit_status = SYSTEM_ERROR;
  214. }
  215. return do_exit(exit_status);
  216. }
  217. if((exit_status = check_for_data_in_file(filename,inputfile))<0) {
  218. if(sndcloseEx(ifd)<0) {
  219. sprintf(errstr, "Failed to close file %s\n",filename);
  220. exit_status = SYSTEM_ERROR;
  221. }
  222. return do_exit(exit_status);
  223. }
  224. switch(inputfile->filetype) {
  225. case(ANALFILE):
  226. case(PITCHFILE):
  227. case(TRANSPOSFILE):
  228. case(FORMANTFILE):
  229. inputfile->nyquist = inputfile->origrate/2.0;
  230. inputfile->frametime = (float)(1.0/inputfile->arate);
  231. /*inputfile->insams = inputfile->infilesize/sizeof(float); */
  232. if((exit_status = set_wlength_and_check_data(filename,ifd,inputfile))<0) {
  233. if(sndcloseEx(ifd)<0) {
  234. sprintf(errstr, "Failed to close file %s\n",filename);
  235. exit_status = SYSTEM_ERROR;
  236. }
  237. return do_exit(exit_status);
  238. }
  239. inputfile->duration = inputfile->wlength * inputfile->frametime;
  240. if(inputfile->duration <= FLTERR) {
  241. sprintf(errstr, "file %s has ZERO duration : ignoring it\n",filename);
  242. exit_status = DATA_ERROR;
  243. return do_exit(exit_status);
  244. }
  245. break;
  246. case(ENVFILE):
  247. if(sndgetprop(ifd,"window size",(char *)&inputfile->window_size,sizeof(float)) < 0) {
  248. sprintf(errstr, "Cannot read window size for file %s\n",filename);
  249. exit_status = DATA_ERROR;
  250. return do_exit(exit_status);
  251. }
  252. inputfile->duration = inputfile->window_size * inputfile->insams * MS_TO_SECS;
  253. if(inputfile->duration <= FLTERR) {
  254. sprintf(errstr, "file %s has zero duration : ignoring it\n",filename);
  255. exit_status = DATA_ERROR;
  256. return do_exit(exit_status);
  257. }
  258. break;
  259. case(SNDFILE):
  260. case(FLT_SNDFILE): /*RWD 2001 added - needed? */
  261. /*inputfile->insams = inputfile->infilesize/sizeof(short); */
  262. inputfile->nyquist = (double)inputfile->srate/2.0;
  263. inputfile->duration = (double)(inputfile->insams/inputfile->channels)/(double)(inputfile->srate);
  264. if(inputfile->duration <= FLTERR) {
  265. sprintf(errstr, "file %s has zero duration : ignoring it\n",filename);
  266. exit_status = DATA_ERROR;
  267. return do_exit(exit_status);
  268. }
  269. //RWD.7.99 need to reset this to FLT_SNDFILE if stype==FLOAT ?
  270. break;
  271. default:
  272. exit_status = DATA_ERROR;
  273. sprintf(errstr,"Unknown type of file: file %s\n",filename);
  274. if(sndcloseEx(ifd)<0) {
  275. sprintf(errstr, "Failed to close file %s\n",filename);
  276. exit_status = SYSTEM_ERROR;
  277. }
  278. return do_exit(exit_status);
  279. }
  280. if(sndcloseEx(ifd)<0) {
  281. sprintf(errstr, "Failed to close file %s\n",filename);
  282. exit_status = SYSTEM_ERROR;
  283. return do_exit(exit_status);
  284. }
  285. } else {
  286. if((exit_status = parse_a_textfile(filename,inputfile)) < 0)
  287. return(exit_status);
  288. }
  289. #ifdef IS_CDPARSE
  290. p = temp;
  291. sprintf(p,"%d ",inputfile->filetype); /* 0 */
  292. p = temp + strlen(temp);
  293. //TW CORRECTED, FOR COMPATIBILITY WITH tkinput: first value OUTPUT is NOW in samples (it was, infilesize)
  294. // sprintf(p,"%d ", inputfile->infilesize /* 1 */ p = temp + strlen(temp);
  295. sprintf(p,"%d ", inputfile->insams); /* 1 */ p = temp + strlen(temp);
  296. sprintf(p,"%d ", inputfile->insams); /* 2 */ p = temp + strlen(temp);
  297. sprintf(p,"%d ", inputfile->srate); /* 3 */ p = temp + strlen(temp);
  298. sprintf(p,"%d ", inputfile->channels); /* 4 */ p = temp + strlen(temp);
  299. sprintf(p,"%d ", inputfile->wanted); /* 5 */ p = temp + strlen(temp);
  300. sprintf(p,"%d ", inputfile->wlength); /* 6 */ p = temp + strlen(temp);
  301. sprintf(p,"%d ", inputfile->linecnt); /* 7 */ p = temp + strlen(temp);
  302. sprintf(p,"%f ", inputfile->arate); /* 8 */ p = temp + strlen(temp);
  303. sprintf(p,"%.12f ",inputfile->frametime); /* 9 */ p = temp + strlen(temp);
  304. sprintf(p,"%lf ", inputfile->nyquist); /* 10 */ p = temp + strlen(temp);
  305. sprintf(p,"%lf ", inputfile->duration); /* 11 */ p = temp + strlen(temp);
  306. sprintf(p,"%d ", inputfile->stype); /* 12 */ p = temp + strlen(temp);
  307. sprintf(p,"%d ", inputfile->origstype); /* 13 */ p = temp + strlen(temp);
  308. sprintf(p,"%d ", inputfile->origrate); /* 14 */ p = temp + strlen(temp);
  309. sprintf(p,"%d ", inputfile->Mlen); /* 15 */ p = temp + strlen(temp);
  310. sprintf(p,"%d ", inputfile->Dfac); /* 16 */ p = temp + strlen(temp);
  311. sprintf(p,"%d ", inputfile->origchans); /* 17 */ p = temp + strlen(temp);
  312. sprintf(p,"%d ", inputfile->specenvcnt); /* 18 */ p = temp + strlen(temp);
  313. sprintf(p,"%d ", inputfile->out_chans); /* 19 */ p = temp + strlen(temp);
  314. //TW REVISED
  315. // sprintf(p,"%d ", inputfile->descriptor_bytes); /* 20 * p = temp + strlen(temp); /*RWD TODO : ??? */
  316. sprintf(p,"%d ", inputfile->descriptor_samps); /* 20 */ p = temp + strlen(temp);
  317. sprintf(p,"%d ", inputfile->is_transpos); /* 21 */ p = temp + strlen(temp);
  318. sprintf(p,"%d ", inputfile->could_be_transpos); /* 22 */ p = temp + strlen(temp);
  319. sprintf(p,"%d ", inputfile->could_be_pitch); /* 23 */ p = temp + strlen(temp);
  320. sprintf(p,"%d ", inputfile->different_srates); /* 24 */ p = temp + strlen(temp);
  321. sprintf(p,"%d ", inputfile->duplicate_snds); /* 25 */ p = temp + strlen(temp);
  322. sprintf(p,"%d ", inputfile->brksize); /* 26 */ p = temp + strlen(temp);
  323. sprintf(p,"%d ", inputfile->numsize); /* 27 */ p = temp + strlen(temp);
  324. sprintf(p,"%d ", inputfile->all_words); /* 28 */ p = temp + strlen(temp);
  325. sprintf(p,"%f ", inputfile->window_size); /* 29 */ p = temp + strlen(temp);
  326. sprintf(p,"%lf ", inputfile->minbrk); /* 30 */ p = temp + strlen(temp);
  327. sprintf(p,"%lf ", inputfile->maxbrk); /* 31 */ p = temp + strlen(temp);
  328. sprintf(p,"%lf ", inputfile->minnum); /* 32 */ p = temp + strlen(temp);
  329. sprintf(p,"%lf ", inputfile->maxnum); /* 33 */ p = temp + strlen(temp);
  330. //TW maxsamp is now float value
  331. sprintf(p,"%lf ", maxamp); /* 34 value of maxsamp */ p = temp + strlen(temp);
  332. sprintf(p,"%d ", (int)round(maxloc)); /* 35 location maxsamp */ p = temp + strlen(temp);
  333. sprintf(p,"%d\n", maxrep); /* 36 no of repets, [old usage, -1 flagged no maxval] */
  334. fprintf(stdout,"%s",temp);
  335. fprintf(stdout,"END\n");
  336. fflush(stdout);
  337. return(SUCCEEDED);
  338. #else
  339. return(FINISHED);
  340. #endif
  341. }
  342. /********************************** CHECK_FOR_DATA_IN_FILE ************************************/
  343. int check_for_data_in_file(char *filename,infileptr inputfile)
  344. {
  345. switch(inputfile->filetype) {
  346. case(FORMANTFILE):
  347. /*if(inputfile->infilesize <= (int)(DESCRIPTOR_DATA_BLOKS * inputfile->specenvcnt * sizeof(float))) */
  348. if(inputfile->insams <= (int)(DESCRIPTOR_DATA_BLOKS * inputfile->specenvcnt)) {
  349. sprintf(errstr, "FILE %s contains no data.\n",filename);
  350. return(DATA_ERROR);
  351. }
  352. break;
  353. default:
  354. if(inputfile->insams <= 0L) {
  355. sprintf(errstr, "FILE %s contains no data.\n",filename);
  356. return(DATA_ERROR);
  357. }
  358. break;
  359. }
  360. return(FINISHED);
  361. }
  362. /************************* INITIALISE_FILEPTR *************************/
  363. void initialise_fileptr(infileptr inputfile)
  364. {
  365. inputfile->filetype = 0;
  366. /*inputfile->infilesize = 0;*/
  367. inputfile->insams = 0;
  368. inputfile->srate = 0;
  369. inputfile->channels = 0;
  370. inputfile->stype = 0;
  371. inputfile->origstype = 0;
  372. inputfile->origrate = 0;
  373. inputfile->Mlen = 0;
  374. inputfile->Dfac = 0;
  375. inputfile->origchans = 0;
  376. inputfile->specenvcnt = 0;
  377. inputfile->wanted = 0;
  378. inputfile->wlength = 0;
  379. inputfile->out_chans = 0;
  380. inputfile->descriptor_samps = 0;
  381. inputfile->is_transpos = FALSE;
  382. inputfile->could_be_transpos = FALSE;
  383. inputfile->could_be_pitch = FALSE;
  384. inputfile->different_srates = FALSE;
  385. inputfile->duplicate_snds = FALSE;
  386. inputfile->brksize = 0;
  387. inputfile->numsize = 0;
  388. inputfile->linecnt = 0;
  389. inputfile->all_words = 0;
  390. inputfile->arate = 0.0f;
  391. inputfile->frametime = 0.0f;
  392. inputfile->window_size = 0.0f;
  393. inputfile->nyquist = 0.0;
  394. inputfile->duration = 0.0;
  395. inputfile->minbrk = 0.0;
  396. inputfile->maxbrk = 0.0;
  397. inputfile->minnum = 0.0;
  398. inputfile->maxnum = 0.0;
  399. }
  400. /***************************** SET_WLENGTH_AND_CHECK_DATA *******************************/
  401. int set_wlength_and_check_data(char *filename,int ifd,infileptr inputfile)
  402. {
  403. int exit_status;
  404. switch(inputfile->filetype) {
  405. case(ANALFILE):
  406. inputfile->wanted = inputfile->channels;
  407. inputfile->wlength = inputfile->insams/inputfile->wanted;
  408. break;
  409. case(PITCHFILE):
  410. case(TRANSPOSFILE):
  411. inputfile->wlength = inputfile->insams;
  412. inputfile->wanted = 1; /* notional: to avoid error calls with bad command lines */
  413. if((exit_status = check_pitch_or_transpos_binary_data(inputfile,filename,ifd))<0)
  414. return(exit_status);
  415. break;
  416. case(FORMANTFILE):
  417. inputfile->wlength = (inputfile->insams/inputfile->specenvcnt) - DESCRIPTOR_DATA_BLOKS;
  418. inputfile->descriptor_samps = inputfile->specenvcnt * DESCRIPTOR_DATA_BLOKS;
  419. inputfile->wanted = inputfile->origchans; /* temporary val for initialise_specenv */
  420. /* working val set in ...chunklen...() */
  421. break;
  422. default:
  423. sprintf(errstr,"Invalid case: set_wlength_and_check_data()\n");
  424. return(PROGRAM_ERROR);
  425. }
  426. return(FINISHED);
  427. }
  428. /********************* CHECK_PITCH_OR_TRANSPOS_BINARY_DATA *************************/
  429. int check_pitch_or_transpos_binary_data(infileptr inputfile,char *filename,int ifd)
  430. {
  431. int samps_read;
  432. int samps_to_read = inputfile->insams;
  433. int n;
  434. float *thisdata;
  435. if((thisdata = (float *)malloc((size_t)(samps_to_read * sizeof(float))))==NULL) {
  436. sprintf(errstr,"INSUFFICIENT MEMORY for pitch_or_transpos_binary_data of file %s\n",filename);
  437. return(MEMORY_ERROR);
  438. }
  439. samps_read = fgetfbufEx(thisdata, samps_to_read,ifd,0);
  440. if(samps_read!= inputfile->insams) {
  441. /*RWD.6.98 lets discriminate!*/
  442. if(samps_read < 0){
  443. sprintf(errstr,"Failed to read infile data.\n");
  444. return SYSTEM_ERROR;
  445. }
  446. sprintf(errstr,"Problem reading binary pitch or transposition data in file %s.\n",filename);
  447. return(PROGRAM_ERROR);
  448. }
  449. switch(inputfile->filetype) {
  450. case(PITCHFILE):
  451. for(n=0;n<inputfile->insams;n++) {
  452. //TW BRACKETED OUT: NEW CODE DEALS WITH UNPITCHED, AND SILENT WINDOWS
  453. /*
  454. if(thisdata[n] < FLTERR) {
  455. sprintf(errstr,"File %s contains unpitched windows: cannot proceed.\n",filename);
  456. return(DATA_ERROR);
  457. }
  458. */
  459. if(thisdata[n] >= inputfile->nyquist) {
  460. sprintf(errstr,"File %s contains pitches beyond nyquist: cannot proceed.\n",filename);
  461. return(DATA_ERROR);
  462. }
  463. }
  464. break;
  465. case(TRANSPOSFILE):
  466. for(n=0;n<inputfile->insams;n++) {
  467. if(thisdata[n] < MIN_TRANSPOS || thisdata[n] >= MAX_TRANSPOS) {
  468. sprintf(errstr,"Transposition data item %d (%f):file %s: out of range (%lf to %lf)\n",
  469. n+1,thisdata[n],filename,MIN_TRANSPOS,MAX_TRANSPOS);
  470. return(DATA_ERROR);
  471. }
  472. }
  473. inputfile->is_transpos = TRUE;
  474. break;
  475. }
  476. free(thisdata);
  477. return(FINISHED);
  478. }
  479. /************************************* MEGAPARSEC ******************************/
  480. int megaparsec(char *filename,FILE *fp,infileptr inputfile)
  481. {
  482. int exit_status;
  483. /* NEW CODE */
  484. int extended_brkfile = POSSIBLE;
  485. /* NEW CODE */
  486. int sndlist = POSSIBLE;
  487. int numlist = POSSIBLE;
  488. int brklist = POSSIBLE;
  489. int mixlist = POSSIBLE;
  490. int linelist = POSSIBLE;
  491. int synclist = POSSIBLE;
  492. int has_comments = FALSE;
  493. int dB_notation = FALSE;
  494. char temp[/*2000*/LOCALMEMBYTES];
  495. char **wordstor;
  496. int *wordcnt;
  497. int numcnt = 0, linecnt = 0, total_wordcnt = 0, max_line_word_cnt = 0, min_line_word_cnt, n, srate;
  498. double dur = 0.0;
  499. if((exit_status = initial_parse_textfile(filename,fp,&linelist,&has_comments,&dB_notation,
  500. &total_wordcnt,&numcnt,&linecnt,&max_line_word_cnt,&min_line_word_cnt))<0)
  501. return(exit_status);
  502. initial_textfile_check(dB_notation,&sndlist,&mixlist,&brklist,
  503. &numlist,numcnt,total_wordcnt,max_line_word_cnt,min_line_word_cnt);
  504. if((wordstor = (char **)malloc(total_wordcnt * sizeof(char *)))==NULL) {
  505. sprintf(errstr,"INSUFFICIENT MEMORY for wordstor: file %s\n",filename);
  506. return(MEMORY_ERROR);
  507. }
  508. for(n=0;n<total_wordcnt;n++) /* initialise, for testing and safe freeing */
  509. wordstor[n] = NULL;
  510. inputfile->all_words = total_wordcnt;
  511. if((wordcnt = (int *)malloc(linecnt * sizeof(int)))==NULL) {
  512. sprintf(errstr,"INSUFFICIENT MEMORY for wordcnt: file %s\n",filename);
  513. return(MEMORY_ERROR);
  514. }
  515. for(n=0;n<linecnt;n++) /* initialise, for later testing */
  516. wordcnt[n] = 0;
  517. if(fseek(fp,0,0)<0) {
  518. sprintf(errstr,"fseek failed in megaparsec(): 1\n");
  519. return(PROGRAM_ERROR);
  520. }
  521. if((exit_status = store_wordlist_without_comments(fp,temp,inputfile->all_words,wordstor,wordcnt,inputfile))<0)
  522. return(exit_status);
  523. //OCT 2005
  524. if((exit_status = is_a_possible_multichannel_mixfile
  525. (numlist,brklist,sndlist,linecnt,wordstor,wordcnt,filename,inputfile)) == FINISHED) {
  526. inputfile->filetype = MIX_MULTI;
  527. return(FINISHED);
  528. }
  529. if(sndlist==POSSIBLE) {
  530. if((exit_status = check_for_sndlist(wordstor,wordcnt,linecnt,&sndlist))<0)
  531. return(exit_status);
  532. } else if(numlist==POSSIBLE) {
  533. if((exit_status = check_for_brklist_and_count_numbers(wordstor,wordcnt,linecnt,&brklist,inputfile,filename))<0)
  534. return(exit_status);
  535. }
  536. if(sndlist==POSSIBLE || numlist==POSSIBLE)
  537. mixlist = FALSE;
  538. if(mixlist==POSSIBLE) {
  539. if((exit_status = is_a_possible_mixfile(wordstor,wordcnt,linecnt,&mixlist,&srate,inputfile,filename,&dur))<0)
  540. return(exit_status);
  541. if(mixlist==FALSE)
  542. inputfile->out_chans = 0;
  543. else {
  544. inputfile->srate = srate;
  545. inputfile->duration = dur;
  546. synclist = FALSE;
  547. brklist = FALSE;
  548. sndlist = FALSE;
  549. extended_brkfile = FALSE;
  550. }
  551. }
  552. if(linelist==POSSIBLE) {
  553. if((exit_status = check_for_a_linelist(max_line_word_cnt,&linelist,wordstor,inputfile))<0)
  554. return(exit_status);
  555. }
  556. if(sndlist==POSSIBLE) {
  557. if((exit_status = set_sndlist_flags(inputfile,wordstor))<0)
  558. return(exit_status);
  559. if(inputfile->different_srates
  560. #ifdef NO_DUPLICATE_SNDFILES
  561. || inputfile->duplicate_snds
  562. #endif
  563. )
  564. synclist = FALSE;
  565. } else if(synclist==POSSIBLE) {
  566. if((exit_status = check_for_a_synclist(&synclist,wordstor,wordcnt,inputfile,filename))<0)
  567. return(exit_status);
  568. }
  569. //TW REMOVED COMMENTS
  570. if(extended_brkfile==POSSIBLE) {
  571. if((exit_status =
  572. check_for_an_extended_brkfile(&extended_brkfile,wordstor,wordcnt,linecnt,total_wordcnt,inputfile))<0)
  573. return(exit_status);
  574. }
  575. if((inputfile->filetype = assign_type(sndlist,numlist,brklist,mixlist,synclist,linelist,extended_brkfile,inputfile))<0)
  576. return(inputfile->filetype);
  577. return(FINISHED);
  578. }
  579. /************************************* INITIAL_PARSE_TEXTFILE ******************************/
  580. int initial_parse_textfile
  581. (char *filename,FILE *fp,int *linelist,int *has_comments,int *dB_notation,
  582. int *total_wordcnt,int *numcnt,int *linecnt,int *max_line_word_cnt,int *min_line_word_cnt)
  583. {
  584. char temp[LOCALMEMBYTES], *p, *q, c; // RWD was 2000
  585. double val;
  586. int line_num_cnt = 0;
  587. int last_line_word_cnt = 0, last_line_num_cnt = 0;
  588. int line_word_cnt = 0;
  589. *max_line_word_cnt = 0;
  590. *min_line_word_cnt = INT_MAX;
  591. while((c = (char)fgetc(fp))!=EOF) {
  592. if(!isalnum(c) && !ispunct(c) && !isspace(c)) {
  593. sprintf(errstr,"%s is not a valid CDP file\n",filename);
  594. return(DATA_ERROR);
  595. }
  596. }
  597. if(fseek(fp,0,0) != 0) {
  598. sprintf(errstr,"Cannot rewind to start of file %s\n",filename);
  599. return(DATA_ERROR);
  600. }
  601. while(fgets(temp,2000,fp)!=NULL) {
  602. p = temp;
  603. if(is_a_comment(p)) {
  604. *has_comments = TRUE;
  605. continue;
  606. } else if(is_an_empty_line(p))
  607. continue;
  608. line_word_cnt = 0;
  609. line_num_cnt = 0;
  610. while(get_word_from_string(&p,&q)) {
  611. line_word_cnt++;
  612. if(is_a_dB_value(q)) {
  613. *dB_notation = TRUE;
  614. (*numcnt)++;
  615. line_num_cnt++;
  616. } else if(get_float_from_within_string(&q,&val)) {
  617. (*numcnt)++;
  618. line_num_cnt++;
  619. }
  620. }
  621. if(*linecnt) {
  622. if(line_word_cnt != last_line_word_cnt
  623. || line_num_cnt != last_line_num_cnt)
  624. *linelist = FALSE;
  625. }
  626. *max_line_word_cnt = max(*max_line_word_cnt,line_word_cnt);
  627. *min_line_word_cnt = min(*min_line_word_cnt,line_word_cnt);
  628. last_line_word_cnt = line_word_cnt;
  629. last_line_num_cnt = line_num_cnt;
  630. *total_wordcnt += line_word_cnt;
  631. (*linecnt)++;
  632. }
  633. if(*total_wordcnt==0) {
  634. sprintf(errstr,"Cannot get any data from file %s\n",filename);
  635. return(DATA_ERROR);
  636. }
  637. return(FINISHED);
  638. }
  639. /************************************* INITIAL_TEXTFILE_CHECK ******************************/
  640. void initial_textfile_check(int dB_notation,int *sndlist,int *mixlist,int *brklist,int *numlist,
  641. int numcnt,int wordcnt,int max_line_word_cnt,int min_line_word_cnt)
  642. {
  643. if((numcnt < wordcnt) || dB_notation) {
  644. *numlist = FALSE;
  645. *brklist = FALSE;
  646. }
  647. if(numcnt == wordcnt) {
  648. *mixlist = FALSE;
  649. *sndlist = FALSE;
  650. }
  651. if(ODD(numcnt))
  652. *brklist = FALSE;
  653. if(numcnt>0)
  654. *sndlist = FALSE;
  655. else
  656. *mixlist = FALSE;
  657. if(min_line_word_cnt<MIX_MINLINE || max_line_word_cnt>MIX_MAXLINE)
  658. *mixlist = FALSE;
  659. }
  660. /************************************* VALID_START_OF_MIXFILE_LINE ******************************/
  661. #ifdef IS_CDPARSE
  662. int valid_start_of_mixfile_line
  663. (int k,int *chans,int lineno,char **wordstor,int *srate,int *mixlist,infileptr inputfile,char *filename,double *dur)
  664. {
  665. int exit_status;
  666. double time;
  667. char *sndfilename;
  668. sndfilename = wordstor[k++];
  669. if(sscanf(wordstor[k++],"%lf",&time)!=1) {
  670. *mixlist = FALSE;
  671. return(FINISHED);
  672. }
  673. if(time<0.0) {
  674. *mixlist = FALSE;
  675. return(FINISHED);
  676. }
  677. if(sscanf(wordstor[k++],"%d",chans)!=1) {
  678. *mixlist = FALSE;
  679. return(FINISHED);
  680. }
  681. if(*chans < MONO || *chans > STEREO) {
  682. *mixlist = FALSE;
  683. return(FINISHED);
  684. }
  685. if((exit_status = is_a_valid_sndfile_for_mixfile(filename,sndfilename,srate,*chans,lineno,inputfile,time,dur,0))<0)
  686. return(exit_status);
  687. if(exit_status == FALSE) {
  688. *mixlist = FALSE;
  689. return(FINISHED);
  690. }
  691. if(!OK_level(wordstor[k])) { /* must be numeric, and witihin range */
  692. *mixlist = FALSE;
  693. return(FINISHED);
  694. }
  695. return(FINISHED);
  696. }
  697. #else
  698. int valid_start_of_mixfile_line
  699. (int k,int *chans,int lineno,char **wordstor,int *srate,int *mixlist,infileptr inputfile,char *filename,double *dur)
  700. {
  701. int exit_status;
  702. double time;
  703. char *sndfilename;
  704. sndfilename = wordstor[k++];
  705. if(sscanf(wordstor[k++],"%lf",&time)!=1) {
  706. if(lineno>0) {
  707. fprintf(stdout,"WARNING: If %s is a mixfile: Invalid or missing time val on line %d\n",filename,lineno+1);
  708. fflush(stdout);
  709. }
  710. *mixlist = FALSE;
  711. return(FINISHED);
  712. }
  713. if(time<0.0) {
  714. if(lineno>0) {
  715. fprintf(stdout,"WARNING: If %s is a mixfile: starttime less than zero [%lf]: line %d\n",
  716. filename,time,lineno+1);
  717. fflush(stdout);
  718. }
  719. *mixlist = FALSE;
  720. return(FINISHED);
  721. }
  722. if(sscanf(wordstor[k++],"%d",chans)!=1) {
  723. if(lineno>0) {
  724. fprintf(stdout,"WARNING: If %s is a mixfile: Invalid or missing channel val on line %d\n",
  725. filename,lineno+1);
  726. fflush(stdout);
  727. }
  728. *mixlist = FALSE;
  729. return(FINISHED);
  730. }
  731. if(*chans < MONO || *chans > STEREO) {
  732. if(lineno>0) {
  733. fprintf(stdout,"WARNING: If %s is a mixfile: Invalid channel-cnt on line %d\n",filename,lineno+1);
  734. fflush(stdout);
  735. }
  736. *mixlist = FALSE;
  737. return(FINISHED);
  738. }
  739. if((exit_status = is_a_valid_sndfile_for_mixfile(filename,sndfilename,srate,*chans,lineno,inputfile,time,dur,0))<0)
  740. return(exit_status);
  741. if(exit_status == FALSE) {
  742. *mixlist = FALSE;
  743. return(FINISHED);
  744. }
  745. if(!OK_level(wordstor[k])) { /* must be numeric, and witihin range */
  746. if(lineno>0) {
  747. fprintf(stdout,"WARNING: If %s is a mixfile: Invalid [channel 1] level val on line %d\n",
  748. filename,lineno+1);
  749. fflush(stdout);
  750. }
  751. *mixlist = FALSE;
  752. return(FINISHED);
  753. }
  754. return(FINISHED);
  755. }
  756. #endif
  757. /************************************* IS_VALID_END_OF_MIXFILE_LINE ******************************/
  758. #ifdef IS_CDPARSE
  759. int is_valid_end_of_mixfile_line(int j,int chans,int lineno,char **wordstor,int *wordcnt)
  760. {
  761. double pan;
  762. //TW UPDATE: AVOID WARNING
  763. int got_numeric_panval = sscanf(wordstor[j],"%lf",&pan);
  764. if(strcmp(wordstor[j],"C") && strcmp(wordstor[j],"L") && strcmp(wordstor[j],"R")
  765. && got_numeric_panval!=1)
  766. return(FALSE);
  767. if(got_numeric_panval && (pan < MINPAN || pan >MAXPAN))
  768. return(FALSE);
  769. if(chans==MONO) {
  770. if(wordcnt[lineno]>MIX_MIDLINE) {
  771. return(FALSE);
  772. }
  773. return(TRUE);
  774. } else {
  775. if(wordcnt[lineno]<MIX_MAXLINE) {
  776. return(FALSE);
  777. }
  778. }
  779. j++;
  780. if(!OK_level(wordstor[j++])) /* level must be numeric or dB & in range */
  781. return(FALSE);
  782. got_numeric_panval = 0;
  783. //TW UPDATE: AVOID WARNING
  784. got_numeric_panval = sscanf(wordstor[j],"%lf",&pan);
  785. if(strcmp(wordstor[j],"C") && strcmp(wordstor[j],"L") && strcmp(wordstor[j],"R")
  786. && (got_numeric_panval !=1)) /* pan must be C,R,L or numeric */
  787. return(FALSE);
  788. if(got_numeric_panval && (pan < MINPAN || pan > MAXPAN)) {
  789. return(FALSE);
  790. }
  791. return(TRUE);
  792. }
  793. #else
  794. int is_valid_end_of_mixfile_line(int j,int chans,int lineno,char **wordstor,int *wordcnt,char *filename)
  795. {
  796. double pan;
  797. //TW UPDATE: AVOID WARNING
  798. int got_numeric_panval = sscanf(wordstor[j],"%lf",&pan);
  799. if(strcmp(wordstor[j],"C") && strcmp(wordstor[j],"L") && strcmp(wordstor[j],"R")
  800. && got_numeric_panval!=1) {
  801. if(lineno>0) {
  802. fprintf(stdout,"WARNING: If %s is a mixfile: Invalid (1st) pan val, line %d\n",filename,lineno+1);
  803. fflush(stdout);
  804. }
  805. return(FALSE);
  806. }
  807. if(got_numeric_panval && (pan < MINPAN || pan >MAXPAN)) {
  808. if(lineno>0) {
  809. fprintf(stdout,"WARNING: If %s is a mixfile: Invalid (1st) pan val [%lf], line %d\n",
  810. filename,pan,lineno+1);
  811. fflush(stdout);
  812. }
  813. return(FALSE);
  814. }
  815. if(chans==MONO) {
  816. if(wordcnt[lineno]>MIX_MIDLINE) {
  817. if(lineno>0) {
  818. fprintf(stdout,"WARNING: If %s is a mixfile: Too many words on line %d\n",filename,lineno+1);
  819. fflush(stdout);
  820. }
  821. return(FALSE);
  822. }
  823. return(TRUE);
  824. } else {
  825. if(wordcnt[lineno]<MIX_MAXLINE) {
  826. if(lineno>0) {
  827. fprintf(stdout,"WARNING: If %s is a mixfile: Too few entries for stereo file on line %d\n",
  828. filename,lineno+1);
  829. fflush(stdout);
  830. }
  831. return(FALSE);
  832. }
  833. }
  834. j++;
  835. if(!OK_level(wordstor[j++])) { /* level must be numeric or dB & in range */
  836. if(lineno>0) {
  837. fprintf(stdout,"WARNING: If %s is a mixfile: Missing level for chan2 on line %d\n",filename,lineno+1);
  838. fflush(stdout);
  839. }
  840. return(FALSE);
  841. }
  842. got_numeric_panval = 0;
  843. //TW UPDATE: AVOID WARNING
  844. got_numeric_panval = sscanf(wordstor[j],"%lf",&pan);
  845. if(strcmp(wordstor[j],"C") && strcmp(wordstor[j],"L") && strcmp(wordstor[j],"R")
  846. && (got_numeric_panval !=1)) { /* pan must be C,R,L or numeric */
  847. if(lineno>0) {
  848. fprintf(stdout,"WARNING: If %s is a mixfile: Missing chan2 pan val on line %d\n",
  849. filename,lineno+1);
  850. fflush(stdout);
  851. }
  852. return(FALSE);
  853. }
  854. if(got_numeric_panval && (pan < MINPAN || pan > MAXPAN)) {
  855. if(lineno>0) {
  856. fprintf(stdout,"WARNING: If %s is a mixfile: Invalid 2nd pan val [%lf], line %d\n",
  857. filename,pan,lineno+1);
  858. fflush(stdout);
  859. }
  860. return(FALSE);
  861. }
  862. return(TRUE);
  863. }
  864. #endif
  865. /************************************* CONFIRM_TRUE_STEREO ******************************/
  866. int confirm_true_stereo(int *chans,int *is_left,int *is_right,int *is_central,char *panword)
  867. {
  868. double pan;
  869. if(!strcmp(panword,"L")) {
  870. *is_left = TRUE; /* panned hard Left */
  871. *chans = MONO;
  872. } else if(!strcmp(panword,"R")) {
  873. *is_right = TRUE; /* panned hard Right */
  874. *chans = MONO;
  875. } else if(strcmp(panword,"C")) {
  876. if(sscanf(panword,"%lf",&pan)!=1) {
  877. sprintf(errstr,"Parsing error 2: confirm_true_stereo()\n");
  878. return(PROGRAM_ERROR);
  879. }
  880. if(pan <= -1.0) {
  881. *is_left = TRUE; /* panned hard Left */
  882. *chans = MONO;
  883. } else if(pan >= 1.0) {
  884. *is_right = TRUE; /* panned hard Right */
  885. *chans = MONO;
  886. }
  887. // TW REMOVED COMMENTS
  888. else
  889. *chans = STEREO;
  890. }
  891. else
  892. *is_central = TRUE;
  893. return(FINISHED);
  894. }
  895. /**************** IS_A_POSSIBLE_MIXFILE **********************/
  896. int is_a_possible_mixfile(char **wordstor,int *wordcnt,int linecnt,int *mixlist,
  897. int *srate,infileptr inputfile,char *filename,double *dur)
  898. {
  899. int exit_status;
  900. int is_left = FALSE, is_right = FALSE, is_central = FALSE;
  901. int /*cnt = 0,*/ chans;
  902. int k = 0, j, lineno;
  903. if(linecnt > SF_MAXFILES-1) {
  904. #ifndef IS_CDPARSE
  905. fprintf(stdout,"WARNING: If %s is a mixfile: cannot mix more than %d files in one mix\n",
  906. filename,SF_MAXFILES-1);
  907. fflush(stdout);
  908. #endif
  909. *mixlist = FALSE;
  910. return(FINISHED);
  911. }
  912. for(lineno=0;lineno<linecnt;lineno++) {
  913. if((exit_status = valid_start_of_mixfile_line(k,&chans,lineno,wordstor,srate,mixlist,inputfile,filename,dur))<0)
  914. return(exit_status);
  915. if(*mixlist==FALSE)
  916. return(FINISHED);
  917. if(wordcnt[lineno]>MIX_MINLINE) {
  918. j = k + MIX_MINLINE;
  919. #ifdef IS_CDPARSE
  920. if(!is_valid_end_of_mixfile_line(j,chans,lineno,wordstor,wordcnt)) {
  921. #else
  922. if(!is_valid_end_of_mixfile_line(j,chans,lineno,wordstor,wordcnt,filename)) {
  923. #endif
  924. *mixlist = FALSE;
  925. return(FINISHED);
  926. }
  927. if(wordcnt[lineno]==MIX_MIDLINE && chans==MONO) {
  928. if((exit_status = confirm_true_stereo(&chans,&is_left,&is_right,&is_central,wordstor[j]))<0)
  929. return(exit_status);
  930. }
  931. } else
  932. is_central = TRUE;
  933. inputfile->out_chans = max(inputfile->out_chans,chans);
  934. k += wordcnt[lineno];
  935. }
  936. #ifdef NO_DUPLICATE_SNDFILES
  937. #ifdef IS_CDPARSE
  938. if(duplicated_filenames(linecnt,wordstor,wordcnt))
  939. #else
  940. if(duplicated_filenames(linecnt,wordstor,wordcnt,filename))
  941. #endif
  942. {
  943. *mixlist = FALSE;
  944. return(FINISHED);
  945. }
  946. #endif
  947. if(inputfile->out_chans==MONO) {
  948. if((is_left && is_right)
  949. || (is_left && is_central)
  950. || (is_right && is_central))
  951. inputfile->out_chans = STEREO;
  952. }
  953. if(inputfile->out_chans < MONO) {
  954. sprintf(errstr,"Impossible out_chans value\n");
  955. return(PROGRAM_ERROR);
  956. }
  957. return(FINISHED);
  958. }
  959. /******************* DUPLICATED_FILENAMES **************************/
  960. #ifdef IS_CDPARSE
  961. int duplicated_filenames(int linecnt,char **wordstor,int *wordcnt)
  962. {
  963. int n, m;
  964. int j, k = 0;
  965. for(n=0;n<linecnt-1;n++) {
  966. j = k;
  967. for(m=n+1;m<linecnt;m++) {
  968. j += wordcnt[m-1];
  969. if(!strcmp(wordstor[k],wordstor[j]))
  970. return(TRUE);
  971. }
  972. k += wordcnt[n];
  973. }
  974. return(FALSE);
  975. }
  976. #else
  977. int duplicated_filenames(int linecnt,char **wordstor,int *wordcnt,char *filename)
  978. {
  979. int n, m;
  980. int j, k = 0;
  981. for(n=0;n<linecnt-1;n++) {
  982. j = k;
  983. for(m=n+1;m<linecnt;m++) {
  984. j += wordcnt[m-1];
  985. if(!strcmp(wordstor[k],wordstor[j])) {
  986. #ifndef IS_CDPARSE
  987. fprintf(stdout,"WARNING: If %s is a mix or syncfile: filename duplicates found (not allowed).\n",filename);
  988. fflush(stdout);
  989. #endif
  990. return(TRUE);
  991. }
  992. }
  993. k += wordcnt[n];
  994. }
  995. return(FALSE);
  996. }
  997. #endif
  998. /*************** OK_LEVEL ******************/
  999. int OK_level(char *str)
  1000. {
  1001. int exit_status = TRUE;
  1002. double level;
  1003. if(is_a_dB_value(str))
  1004. exit_status = get_leveldb_frame(str,&level);
  1005. else {
  1006. if(sscanf(str,"%lf",&level)!=1)
  1007. exit_status = FALSE;
  1008. }
  1009. if(exit_status==FALSE || level < 0.0)
  1010. return(FALSE);
  1011. return(TRUE);
  1012. }
  1013. /************************************* IS_A_DB_VALUE ******************************/
  1014. int is_a_dB_value(char *str)
  1015. {
  1016. int decimal_point_cnt = 0;
  1017. int has_digits = FALSE;
  1018. double val;
  1019. char *p, *end_of_number;
  1020. //p = str + strlen(str) - 2;
  1021. // RWD debug test - avoid valgrind complaints
  1022. if(strlen(str) < 3)
  1023. return FALSE;
  1024. p = str + strlen(str) - 2;
  1025. if(strcmp(p,"dB") && strcmp(p,"DB") && strcmp(p,"db"))
  1026. return(FALSE);
  1027. if(p==str)
  1028. return(FALSE);
  1029. end_of_number = p;
  1030. p = str;
  1031. switch(*p) {
  1032. case('-'): break;
  1033. case('.'): decimal_point_cnt=1; break;
  1034. default:
  1035. if(!isdigit(*p))
  1036. return(FALSE);
  1037. has_digits = TRUE;
  1038. break;
  1039. }
  1040. p++;
  1041. while(p!=end_of_number) {
  1042. if(isdigit(*p))
  1043. has_digits = TRUE;
  1044. else if(*p == '.') {
  1045. if(++decimal_point_cnt>1)
  1046. return(FALSE);
  1047. } else
  1048. return(FALSE);
  1049. p++;
  1050. }
  1051. if(!has_digits || sscanf(str,"%lf",&val)!=1)
  1052. return(FALSE);
  1053. return(TRUE);
  1054. }
  1055. /**************************** GET_LEVELDB_FRAME ********************************/
  1056. int get_leveldb_frame(char *str,double *val)
  1057. {
  1058. int is_neg = 0;
  1059. if(sscanf(str,"%lf",val)!=1)
  1060. return(FALSE);
  1061. *val = max(*val,MIN_DB_ON_16_BIT);
  1062. if(flteq(*val,0.0)) {
  1063. *val = 1.0;
  1064. return(TRUE);
  1065. }
  1066. if(*val<0.0) {
  1067. *val = -(*val);
  1068. is_neg = 1;
  1069. }
  1070. *val /= 20.0;
  1071. *val = pow(10.0,*val);
  1072. if(is_neg)
  1073. *val = 1.0/(*val);
  1074. return(TRUE);
  1075. }
  1076. /***************************** IS_A_VALID_SNDFILE_FOR_MIXFILE **************************/
  1077. int is_a_valid_sndfile_for_mixfile
  1078. (char *filename,char *sndfilename,int *srate,int chans,int linecnt,infileptr inputfile,double time,double *dur,int multichan)
  1079. {
  1080. int exit_status;
  1081. /*int minsize = 0L;*/
  1082. double thisdur;
  1083. int ifd;
  1084. double maxamp, maxloc;
  1085. int maxrep;
  1086. #ifdef IS_CDPARSE
  1087. int getmaxinfo = 1;
  1088. #else
  1089. int getmaxinfo = 0;
  1090. #endif
  1091. char *p = strrchr(sndfilename, '.');
  1092. if(p == NULL) {
  1093. #ifndef IS_CDPARSE
  1094. fprintf(stdout,"WARNING: If %s is a mixfile: uses %s which has no sndfile extension\n",filename,sndfilename);
  1095. fflush(stdout);
  1096. return(FALSE);
  1097. #endif
  1098. }
  1099. p++;
  1100. #ifdef NOTDEF
  1101. /*RWD 4:2002 this is silly! sfsys accepts aiff files, so cdparse certainly can! */
  1102. // APRIL 2010
  1103. // if(_stricmp(p,(getenv("CDP_SOUND_EXT")))) {
  1104. if(_stricmp(p,".wav") || _stricmp(p,".aiff")) {
  1105. #ifndef IS_CDPARSE
  1106. // APRIL 2010
  1107. // fprintf(stdout,"WARNING: If %s is a mixfile: uses %s which has an invalid sndfile extension : %s is not %s\n",filename,sndfilename,p,getenv("CDP_SOUND_EXT"));
  1108. fprintf(stdout,"WARNING: If %s is a mixfile: uses %s which has an invalid sndfile extension : %s is not '.wav' or '.aiff'\n",filename,sndfilename,p);
  1109. fflush(stdout);
  1110. return(FALSE);
  1111. #endif
  1112. }
  1113. #endif
  1114. if((ifd = sndopenEx(sndfilename,0,CDP_OPEN_RDONLY)) < 0) {
  1115. #ifndef IS_CDPARSE
  1116. fprintf(stdout,"WARNING: If %s is a mixfile: uses %s which is not a sndfile\n",filename,sndfilename);
  1117. fflush(stdout);
  1118. #endif
  1119. return(FALSE);
  1120. }
  1121. if((exit_status = readhead(inputfile,ifd,sndfilename,&maxamp,&maxloc,&maxrep,0,getmaxinfo))<0) { /* READ THE FILE HEADER */
  1122. if(sndcloseEx(ifd)<0)
  1123. sprintf(errstr,"Failed to close file %s when checking file %s\n",sndfilename,filename);
  1124. return(exit_status);
  1125. }
  1126. exit_status = TRUE;
  1127. if(inputfile->filetype!=SNDFILE) {
  1128. #ifndef IS_CDPARSE
  1129. fprintf(stdout,"WARNING: If %s is a mixfile: uses %s which is not a sndfile\n",filename,sndfilename);
  1130. fflush(stdout);
  1131. #endif
  1132. exit_status=FALSE;
  1133. } else if(inputfile->channels != chans) {
  1134. #ifndef IS_CDPARSE
  1135. if(chans==MONO)
  1136. fprintf(stdout,"WARNING: If %s is a mixfile: %s is not a mono sndfile\n",filename,sndfilename);
  1137. else if(chans==STEREO) /*RWD 4:2001 added test */
  1138. fprintf(stdout,"WARNING: If %s is a mixfile: %s is not a stereo sndfile\n",filename,sndfilename);
  1139. //OCT 2005
  1140. else
  1141. fprintf(stdout,"WARNING: If %s is a mixfile: %s has different no. of chans (%d) to that indicated in mixfile line (%d)\n",
  1142. filename,sndfilename,inputfile->channels,chans);
  1143. fflush(stdout);
  1144. #endif
  1145. exit_status=FALSE;
  1146. } else if((inputfile->insams = sndsizeEx(ifd))<0) { /* FIND SIZE OF FILE */
  1147. sprintf(errstr, "Can't read size of input file %s: used in file %s\n",sndfilename,filename);
  1148. exit_status=PROGRAM_ERROR;
  1149. } else if(inputfile->insams <= 0L) {
  1150. #ifndef IS_CDPARSE
  1151. fprintf(stdout,"WARNING: If %s is a mixfile: file %s contains no data.\n",filename,sndfilename);
  1152. fflush(stdout);
  1153. #endif
  1154. exit_status=FALSE;
  1155. } else if (linecnt==multichan) {
  1156. *srate = inputfile->srate;
  1157. } else if(inputfile->srate != *srate) {
  1158. #ifndef IS_CDPARSE
  1159. fprintf(stdout,"WARNING: If %s is a mixfile: Incompatible sample-rate in file %s\n",filename,sndfilename);
  1160. fflush(stdout);
  1161. #endif
  1162. exit_status=FALSE;
  1163. }
  1164. #ifdef NOTDEF /* RWD 4:2001 */
  1165. switch(inputfile->filetype) {
  1166. case(SNDFILE): inputfile->insams = inputfile->infilesize/sizeof(short); break;
  1167. case(FLT_SNDFILE): inputfile->insams = inputfile->infilesize/sizeof(float); break;
  1168. }
  1169. #endif
  1170. #ifdef _DEBUG
  1171. assert(inputfile->insams > 0);
  1172. #endif
  1173. thisdur = time + (inputfile->insams/inputfile->channels/(double)inputfile->srate);
  1174. *dur = max(*dur,thisdur);
  1175. // inputfile->infilesize = 0;
  1176. inputfile->insams = 0;
  1177. inputfile->filetype = 0;
  1178. inputfile->srate = 0;
  1179. inputfile->channels = 0;
  1180. inputfile->stype = 0;
  1181. if(sndcloseEx(ifd)<0) {
  1182. sprintf(errstr,"Failed to close file %s while checking file %s\n",sndfilename,filename);
  1183. exit_status=SYSTEM_ERROR;
  1184. }
  1185. return(exit_status);
  1186. }
  1187. /*************************** CHECK_FOR_BRKLIST_AND_STORE_NUMBERS ***********************/
  1188. int check_for_brklist_and_count_numbers
  1189. (char **wordstor,int *wordcnt,int linecnt,int *brklist,infileptr inputfile,char *filename)
  1190. {
  1191. double p, lasttime = 0.0;
  1192. int istime = TRUE;
  1193. int lineno, word_in_line, dcount = 0, k = 0;
  1194. for(lineno=0;lineno<linecnt;lineno++) {
  1195. for(word_in_line = 0;word_in_line < wordcnt[lineno];word_in_line++) {
  1196. if(sscanf(wordstor[k],"%lf",&p)!=1) {
  1197. sprintf(errstr,"scan anomaly: check_for_brklist_and_count_numbers()\n");
  1198. return(PROGRAM_ERROR);
  1199. }
  1200. if(istime) {
  1201. if(*brklist==POSSIBLE) {
  1202. if(k==0) {
  1203. if(p < 0.0)
  1204. *brklist = FALSE;
  1205. } else if(p <= lasttime)
  1206. *brklist = FALSE;
  1207. lasttime = p;
  1208. }
  1209. if(k==0) {
  1210. inputfile->maxnum = p;
  1211. inputfile->minnum = p;
  1212. } else {
  1213. inputfile->maxnum = max(p,inputfile->maxnum);
  1214. inputfile->minnum = min(p,inputfile->minnum);
  1215. }
  1216. } else {
  1217. if(k==1) {
  1218. inputfile->maxbrk = p;
  1219. inputfile->minbrk = p;
  1220. } else {
  1221. inputfile->maxbrk = max(p,inputfile->maxbrk);
  1222. inputfile->minbrk = min(p,inputfile->minbrk);
  1223. }
  1224. inputfile->maxnum = max(p,inputfile->maxnum);
  1225. inputfile->minnum = min(p,inputfile->minnum);
  1226. }
  1227. istime = !istime;
  1228. k++;
  1229. }
  1230. }
  1231. if(k == 0) {
  1232. sprintf(errstr,"No numeric data found in file %s\n",filename);
  1233. return(DATA_ERROR);
  1234. }
  1235. if(*brklist==POSSIBLE) {
  1236. if(k < 4) /* Must be at least 2 point in a brkfile */
  1237. *brklist = FALSE;
  1238. }
  1239. if(*brklist==POSSIBLE) {
  1240. if(((dcount = k/2) * 2) != k)
  1241. *brklist = FALSE;
  1242. }
  1243. if(*brklist==POSSIBLE) {
  1244. inputfile->brksize = dcount;
  1245. inputfile->duration = lasttime;
  1246. }
  1247. else
  1248. inputfile->brksize = 0;
  1249. inputfile->numsize = k;
  1250. return(FINISHED);
  1251. }
  1252. /*************************** CHECK_FOR_A_LINELIST ***********************/
  1253. #define OTHER (0)
  1254. #define NUMERICAL (1)
  1255. #define DBLIKE (2)
  1256. int check_for_a_linelist(int line_word_cnt,int *linelist,char **wordstor,infileptr inputfile)
  1257. {
  1258. int linecnt = 0, n, m;
  1259. int total_wordcnt = 0;
  1260. //TW AGREED REMOVAL of 'OK'
  1261. int k;
  1262. double val;
  1263. char *wordtype[2], *p;
  1264. if((wordtype[0] = (char *)malloc(line_word_cnt * sizeof(char)))==NULL) {
  1265. sprintf(errstr,"INSUFFICIENT MEMORY for wordtype[0]\n");
  1266. return(MEMORY_ERROR);
  1267. }
  1268. if((wordtype[1] = (char *)malloc(line_word_cnt * sizeof(char)))==NULL) {
  1269. sprintf(errstr,"INSUFFICIENT MEMORY for wordtype[1]\n");
  1270. free(wordtype[0]);
  1271. return(MEMORY_ERROR);
  1272. }
  1273. for(n=0;n<inputfile->linecnt;n++) {
  1274. if(n==0) k = 0;
  1275. else k = 1;
  1276. for(m=0;m<line_word_cnt;m++) {
  1277. p = wordstor[total_wordcnt];
  1278. if(is_a_dB_value(wordstor[total_wordcnt]))
  1279. wordtype[k][m] = (char)DBLIKE;
  1280. else if(get_float_from_within_string(&p,&val))
  1281. wordtype[k][m] = (char)NUMERICAL;
  1282. else
  1283. wordtype[k][m] = (char)OTHER;
  1284. total_wordcnt++;
  1285. }
  1286. if(linecnt>0) {
  1287. for(m=0;m<line_word_cnt;m++) {
  1288. if(wordtype[0][m] != wordtype[1][m]) {
  1289. *linelist = FALSE;
  1290. break;
  1291. }
  1292. }
  1293. }
  1294. if(!(*linelist))
  1295. break;
  1296. linecnt++;
  1297. }
  1298. free(wordtype[0]);
  1299. free(wordtype[1]);
  1300. return(FINISHED);
  1301. }
  1302. /***************************** CHECK_FOR_SNDLIST **************************/
  1303. int check_for_sndlist(char **wordstor,int *wordcnt,int linecnt,int *sndlist)
  1304. {
  1305. char *filename;
  1306. int ifd;
  1307. int k = 0, lineno, word_in_line;
  1308. SFPROPS props = {0};
  1309. for(lineno=0;lineno<linecnt;lineno++) {
  1310. for(word_in_line=0;word_in_line<wordcnt[lineno];word_in_line++) {
  1311. filename = wordstor[k];
  1312. if((ifd = sndopenEx(filename,0,CDP_OPEN_RDONLY)) < 0) {
  1313. *sndlist = FALSE;
  1314. return(FINISHED);
  1315. }
  1316. //RWD added 9.98
  1317. /* TEST THIS !!! */
  1318. if(!snd_headread(ifd,&props)){
  1319. sprintf(errstr,"Cannot read soundfile header: %s\n",filename);
  1320. sndcloseEx(ifd);
  1321. return(SYSTEM_ERROR);
  1322. }
  1323. if(!(props.type==wt_wave)){
  1324. *sndlist = FALSE;
  1325. sprintf(errstr,"soundfile %s is not a wave file\n",filename);
  1326. sndcloseEx(ifd);
  1327. return FINISHED;
  1328. }
  1329. if(sndcloseEx(ifd)<0) {
  1330. sprintf(errstr,"Cannot close sndfile %s: check_for_sndlist()\n",filename);
  1331. return(SYSTEM_ERROR);
  1332. }
  1333. k++;
  1334. }
  1335. }
  1336. return(FINISHED);
  1337. }
  1338. /***************************** STORE_WORDLIST_WITHOUT_COMMENTS **************************/
  1339. int store_wordlist_without_comments(FILE *fp,char *temp,int total_wordcnt,char **wordstor,int *wordcnt,infileptr inputfile)
  1340. {
  1341. char *p , *q;
  1342. int this_wordcnt = 0;
  1343. int wordcnt_in_line;
  1344. int linecnt = 0;
  1345. while(fgets(temp,/*2000*/LOCALMEMBYTES,fp)!=NULL) {
  1346. p = temp;
  1347. if(is_an_empty_line_or_a_comment(p))
  1348. continue;
  1349. wordcnt_in_line = 0;
  1350. while(get_word_from_string(&p,&q)) {
  1351. if((wordstor[this_wordcnt] = (char *)malloc((strlen(q) + 1) * sizeof(char)))==NULL) {
  1352. sprintf(errstr,"INSUFFICIENT MEMORY for word %d\n",this_wordcnt+1);
  1353. return(MEMORY_ERROR);
  1354. }
  1355. strcpy(wordstor[this_wordcnt],q);
  1356. if(++this_wordcnt > total_wordcnt) {
  1357. sprintf(errstr,"Error in word accounting: store_wordlist_without_comments()\n");
  1358. return(PROGRAM_ERROR);
  1359. }
  1360. wordcnt_in_line++;
  1361. }
  1362. wordcnt[linecnt] = wordcnt_in_line;
  1363. linecnt++;
  1364. }
  1365. inputfile->linecnt = linecnt;
  1366. return(FINISHED);
  1367. }
  1368. /***************************** ASSIGN_TYPE **************************/
  1369. //TW REMOVED OLD COMMENT LINES
  1370. int assign_type(int sndlist,int numlist,int brklist,int mixlist,int synclist,int linelist,int extended_brkfile,infileptr inputfile)
  1371. {
  1372. //TW AGREED WARNING SHOULD BE MOVED
  1373. if(sndlist==POSSIBLE) {
  1374. if(synclist==POSSIBLE) {
  1375. if(linelist==POSSIBLE)
  1376. return SNDLIST_OR_SYNCLIST_LINELIST_OR_WORDLIST;
  1377. else
  1378. return SNDLIST_OR_SYNCLIST_OR_WORDLIST;
  1379. } else {
  1380. if(linelist==POSSIBLE)
  1381. return SNDLIST_OR_LINELIST_OR_WORDLIST;
  1382. else
  1383. return SNDLIST_OR_WORDLIST;
  1384. }
  1385. } else if(numlist==POSSIBLE) {
  1386. if(brklist==POSSIBLE)
  1387. return assign_brkfile_type(inputfile,linelist);
  1388. else {
  1389. if(linelist==POSSIBLE)
  1390. return NUMLIST_OR_LINELIST_OR_WORDLIST;
  1391. else
  1392. return NUMLIST_OR_WORDLIST;
  1393. }
  1394. } else if(mixlist==POSSIBLE) {
  1395. if(linelist==POSSIBLE)
  1396. return MIXLIST_OR_LINELIST_OR_WORDLIST;
  1397. else
  1398. return MIXLIST_OR_WORDLIST;
  1399. } else if(synclist==POSSIBLE) {
  1400. if(linelist==POSSIBLE)
  1401. return SYNCLIST_OR_LINELIST_OR_WORDLIST;
  1402. else
  1403. return SYNCLIST_OR_WORDLIST;
  1404. } else if(linelist==POSSIBLE)
  1405. return LINELIST_OR_WORDLIST;
  1406. //RWD.8.98 do this test here!
  1407. if(extended_brkfile==POSSIBLE) {
  1408. fprintf(stderr,"WARNING:Extended format brkfiles not yet supported by commandline programs.\n");
  1409. }
  1410. return WORDLIST;
  1411. }
  1412. /****************************************** CHECK_FOR_A_SYNCLIST ****************************************/
  1413. int check_for_a_synclist(int *synclist,char **wordstor,int *wordcnt,infileptr inputfile,char *filename)
  1414. {
  1415. int exit_status;
  1416. int n;
  1417. int total_words = 0;
  1418. int srate = 0;
  1419. double starttime, endtime;
  1420. for(n=0;n<inputfile->linecnt;n++) { /* Must be 1 or 3 words on each line */
  1421. if(wordcnt[n]!=1 && wordcnt[n]!=3) {
  1422. *synclist = FALSE;
  1423. return(FINISHED);
  1424. }
  1425. }
  1426. for(n=0;n<inputfile->linecnt;n++) { /* Every line must start with a sndfilename */
  1427. if((exit_status = is_a_valid_sndfile_for_sync(filename,wordstor[total_words],&srate,n,inputfile))<0)
  1428. return(exit_status);
  1429. if(exit_status == FALSE) {
  1430. *synclist = FALSE;
  1431. return(FINISHED);
  1432. }
  1433. total_words += wordcnt[n];
  1434. }
  1435. total_words = 0;
  1436. for(n=0;n<inputfile->linecnt;n++) { /* Any other values must be numbers */
  1437. if(wordcnt[n] > 1) {
  1438. if(sscanf(wordstor[total_words+1],"%lf\n",&starttime)!=1) {
  1439. *synclist = FALSE;
  1440. return(FINISHED);
  1441. }
  1442. else if(sscanf(wordstor[total_words+2],"%lf\n",&endtime)!=1) {
  1443. *synclist = FALSE;
  1444. return(FINISHED);
  1445. } else if(starttime < 0.0 || endtime < 0.0) {
  1446. #ifndef IS_CDPARSE
  1447. fprintf(stdout,"WARNING: If %s is a synclist, it contains negative times\n",filename);
  1448. fflush(stdout);
  1449. #endif
  1450. *synclist = FALSE;
  1451. return(FINISHED);
  1452. } else if(starttime > endtime) {
  1453. #ifndef IS_CDPARSE
  1454. fprintf(stdout,"WARNING: If %s is a synclist, starttime > endtime in line %d\n",filename,n+1);
  1455. fflush(stdout);
  1456. #endif
  1457. *synclist = FALSE;
  1458. return(FINISHED);
  1459. }
  1460. }
  1461. total_words += wordcnt[n];
  1462. }
  1463. #ifdef NO_DUPLICATE_SNDFILES
  1464. #ifdef CDPARSE
  1465. if(duplicated_filenames(inputfile->linecnt,wordstor,wordcnt))
  1466. #else
  1467. if(duplicated_filenames(inputfile->linecnt,wordstor,wordcnt,filename))
  1468. #endif
  1469. return(FALSE);
  1470. #endif
  1471. inputfile->srate = srate;
  1472. return(FINISHED);
  1473. }
  1474. /***************************** IS_A_VALID_SNDFILE_FOR_SYNC **************************/
  1475. int is_a_valid_sndfile_for_sync(char *filename,char *sndfilename,int *srate,int linecnt,infileptr inputfile)
  1476. {
  1477. int exit_status;
  1478. //TW AGREED REMOVAL minsize
  1479. int ifd;
  1480. double maxamp, maxloc;
  1481. int maxrep;
  1482. #ifdef IS_CDPARSE
  1483. int getmaxinfo = 1;
  1484. #else
  1485. int getmaxinfo = 0;
  1486. #endif
  1487. if((ifd = sndopenEx(sndfilename,0,CDP_OPEN_RDONLY)) < 0)
  1488. return(FALSE);
  1489. if((exit_status = readhead(inputfile,ifd,sndfilename,&maxamp,&maxloc,&maxrep,0,getmaxinfo))<0) { /* READ THE FILE HEADER */
  1490. if(sndcloseEx(ifd)<0) {
  1491. sprintf(errstr,"Failed to close sndfile %s while checking file %s\n",sndfilename,filename);
  1492. exit_status = SYSTEM_ERROR;
  1493. }
  1494. return(exit_status);
  1495. }
  1496. exit_status = TRUE;
  1497. if(inputfile->filetype!=SNDFILE) {
  1498. #ifndef IS_CDPARSE
  1499. fprintf(stdout,"WARNING: If %s is a syncfile: %s is not a sndfile.\n",filename,sndfilename);
  1500. fflush(stdout);
  1501. #endif
  1502. exit_status=FALSE;
  1503. } else if((inputfile->insams = sndsizeEx(ifd))<0) { /* FIND SIZE OF FILE */
  1504. sprintf(errstr, "Can't read size of input file %s: while checking file %s\n",sndfilename,filename);
  1505. exit_status = SYSTEM_ERROR; /*RWD 4.2001 was PROGRAM_ERROR */
  1506. } else if(inputfile->insams == 0L) /*RWD 4.2001 was <= */
  1507. exit_status=FALSE;
  1508. else if (linecnt==0)
  1509. *srate = inputfile->srate;
  1510. else if(inputfile->srate != *srate) {
  1511. #ifndef IS_CDPARSE
  1512. fprintf(stdout,"WARNING: If %s is a syncfile: Incompatible sample-rate in file %s\n",filename,sndfilename);
  1513. fflush(stdout);
  1514. #endif
  1515. exit_status=FALSE;
  1516. }
  1517. // inputfile->infilesize = 0;
  1518. inputfile->insams = 0;
  1519. inputfile->filetype = 0;
  1520. inputfile->srate = 0;
  1521. inputfile->channels = 0;
  1522. inputfile->stype = 0;
  1523. if(sndcloseEx(ifd)<0) {
  1524. sprintf(errstr,"Failed to close sndfile %s while testing file %s\n",sndfilename,filename);
  1525. return(SYSTEM_ERROR);
  1526. }
  1527. return(exit_status);
  1528. }
  1529. /***************************** SET_SNDLIST_FLAGS **************************/
  1530. int set_sndlist_flags(infileptr inputfile,char **wordstor)
  1531. {
  1532. int exit_status;
  1533. int srate = 0, wordcnt, m;
  1534. char *filename;
  1535. int ifd;
  1536. double maxamp, maxloc;
  1537. int maxrep;
  1538. #ifdef IS_CDPARSE
  1539. int getmaxinfo = 1;
  1540. #else
  1541. int getmaxinfo = 0;
  1542. #endif
  1543. for(wordcnt=0;wordcnt<inputfile->all_words;wordcnt++) {
  1544. filename = wordstor[wordcnt];
  1545. if(inputfile->different_srates == FALSE) {
  1546. if((ifd = sndopenEx(filename,0,CDP_OPEN_RDONLY)) < 0) {
  1547. #ifdef _DEBUG
  1548. sprintf(errstr,"Anomaly reopening sndfile %s: set_sndfilelist_flags()\n",filename);
  1549. #else
  1550. sprintf(errstr,"Anomaly reopening sndfile %s: %s\n",filename,rsferrstr);
  1551. #endif
  1552. return(SYSTEM_ERROR);
  1553. }
  1554. if((exit_status = readhead(inputfile,ifd,filename,&maxamp,&maxloc,&maxrep,0,getmaxinfo))<0) { /* READ THE FILE HEADER */
  1555. sprintf(errstr,"Anomaly Rereading header of sndfile %s: set_sndfilelist_flags()\n",filename);
  1556. if(sndcloseEx(ifd) < 0)
  1557. sprintf(errstr, "Can't close soundfile %s: set_sndlist_flags()\n",filename);
  1558. return(SYSTEM_ERROR);
  1559. }
  1560. if(wordcnt==0)
  1561. srate = inputfile->srate;
  1562. else if(inputfile->srate != srate) {
  1563. inputfile->different_srates = TRUE;
  1564. inputfile->srate = 0;
  1565. }
  1566. // inputfile->infilesize = 0;
  1567. inputfile->insams = 0;
  1568. inputfile->filetype = 0;
  1569. inputfile->channels = 0;
  1570. inputfile->stype = 0;
  1571. if(sndcloseEx(ifd) < 0) {
  1572. sprintf(errstr, "Can't close soundfile %s: set_sndlist_flags()\n",filename);
  1573. return(SYSTEM_ERROR);
  1574. }
  1575. }
  1576. }
  1577. for(wordcnt=0;wordcnt<inputfile->all_words;wordcnt++) {
  1578. for(m=wordcnt+1;m<inputfile->all_words;m++) {
  1579. if(!strcmp(wordstor[wordcnt],wordstor[m])) {
  1580. inputfile->duplicate_snds = TRUE;
  1581. break;
  1582. }
  1583. }
  1584. if(inputfile->duplicate_snds)
  1585. break;
  1586. }
  1587. return(FINISHED);
  1588. }
  1589. /****************************************** ASSIGN_BRKFILE_TYPE ****************************************/
  1590. int assign_brkfile_type(infileptr inputfile,int linelist)
  1591. {
  1592. int normalised_brkfile = FALSE;
  1593. int dB_brkfile = FALSE;
  1594. int pitch_brkfile = FALSE;
  1595. int transpos_brkfile = FALSE;
  1596. int positive_brkfile = FALSE;
  1597. if(inputfile->minbrk >= 0.0)
  1598. positive_brkfile = TRUE;
  1599. if(inputfile->maxbrk <= 1.0 && inputfile->minbrk >= 0.0)
  1600. normalised_brkfile = TRUE;
  1601. else if (inputfile->maxbrk <= DEFAULT_NYQUIST && inputfile->minbrk >= -1.0) {
  1602. inputfile->could_be_pitch = TRUE;
  1603. pitch_brkfile = TRUE;
  1604. }
  1605. if(inputfile->maxbrk <= 0.0 && inputfile->minbrk >= MIN_DB_ON_16_BIT)
  1606. dB_brkfile = TRUE;
  1607. if(inputfile->maxbrk <= MAX_TRANSPOS && inputfile->minbrk >= MIN_TRANSPOS) {
  1608. inputfile->could_be_transpos = TRUE;
  1609. transpos_brkfile = TRUE;
  1610. }
  1611. if(transpos_brkfile) {
  1612. if(normalised_brkfile) {
  1613. if(linelist==POSSIBLE)
  1614. return TRANSPOS_OR_NORMD_BRKFILE_OR_NUMLIST_OR_LINELIST_OR_WORDLIST;
  1615. else
  1616. return TRANSPOS_OR_NORMD_BRKFILE_OR_NUMLIST_OR_WORDLIST;
  1617. } else if(pitch_brkfile) {
  1618. if(linelist==POSSIBLE)
  1619. return TRANSPOS_OR_PITCH_BRKFILE_OR_NUMLIST_OR_LINELIST_OR_WORDLIST;
  1620. else
  1621. return TRANSPOS_OR_PITCH_BRKFILE_OR_NUMLIST_OR_WORDLIST;
  1622. } else {
  1623. if(linelist==POSSIBLE)
  1624. return TRANSPOS_OR_UNRANGED_BRKFILE_OR_NUMLIST_OR_LINELIST_OR_WORDLIST;
  1625. else
  1626. return TRANSPOS_OR_UNRANGED_BRKFILE_OR_NUMLIST_OR_WORDLIST;
  1627. }
  1628. } else {
  1629. if(normalised_brkfile) {
  1630. if(linelist==POSSIBLE)
  1631. return NORMD_BRKFILE_OR_NUMLIST_OR_LINELIST_OR_WORDLIST;
  1632. else
  1633. return NORMD_BRKFILE_OR_NUMLIST_OR_WORDLIST;
  1634. } else if(dB_brkfile) {
  1635. if(linelist==POSSIBLE)
  1636. return DB_BRKFILE_OR_NUMLIST_OR_LINELIST_OR_WORDLIST;
  1637. else
  1638. return DB_BRKFILE_OR_NUMLIST_OR_WORDLIST;
  1639. } else if(pitch_brkfile) {
  1640. if(linelist==POSSIBLE) {
  1641. if(positive_brkfile)
  1642. return PITCH_POSITIVE_BRKFILE_OR_NUMLIST_OR_LINELIST_OR_WORDLIST;
  1643. else
  1644. return PITCH_BRKFILE_OR_NUMLIST_OR_LINELIST_OR_WORDLIST;
  1645. } else {
  1646. if(positive_brkfile)
  1647. return PITCH_POSITIVE_BRKFILE_OR_NUMLIST_OR_WORDLIST;
  1648. else
  1649. return PITCH_BRKFILE_OR_NUMLIST_OR_WORDLIST;
  1650. }
  1651. } else if(positive_brkfile) {
  1652. if(linelist==POSSIBLE)
  1653. return POSITIVE_BRKFILE_OR_NUMLIST_OR_LINELIST_OR_WORDLIST;
  1654. else
  1655. return POSITIVE_BRKFILE_OR_NUMLIST_OR_WORDLIST;
  1656. } else {
  1657. if(linelist==POSSIBLE)
  1658. return UNRANGED_BRKFILE_OR_NUMLIST_OR_LINELIST_OR_WORDLIST;
  1659. else
  1660. return UNRANGED_BRKFILE_OR_NUMLIST_OR_WORDLIST;
  1661. }
  1662. }
  1663. }
  1664. #define MIN_BRKSLOPE (1.0)
  1665. #define MAX_BRKSLOPE (6.0)
  1666. /************************************ CHECK_FOR_AN_EXTENDED_BRKFILE *********************************/
  1667. int check_for_an_extended_brkfile
  1668. (int *extended_brkfile,char **wordstor,int *wordcnt,int linecnt,int total_words,infileptr inputfile)
  1669. {
  1670. int wordno = 0, lineno;
  1671. int is_extended_format = FALSE;
  1672. double lasttime = -1.0, time, val;
  1673. double maxval = -(double)(MAXRANGE+1);
  1674. double minval = (double)(MAXRANGE+1);
  1675. if(wordcnt[0]!=2) {
  1676. *extended_brkfile = FALSE;
  1677. return(FINISHED);
  1678. }
  1679. if(!extract_value_pair(&wordno,&time,&val,&maxval,&minval,&lasttime,wordstor)) {
  1680. *extended_brkfile = FALSE;
  1681. return(FINISHED);
  1682. }
  1683. if(time!=0.0) {
  1684. *extended_brkfile = FALSE;
  1685. return(FINISHED);
  1686. }
  1687. for(lineno=1;lineno<linecnt;lineno++) {
  1688. if(wordno+2 > total_words) {
  1689. *extended_brkfile = FALSE;
  1690. return(FINISHED);
  1691. }
  1692. if(wordcnt[lineno]<2 || wordcnt[lineno]>4) {
  1693. *extended_brkfile = FALSE;
  1694. return(FINISHED);
  1695. }
  1696. if(!extract_value_pair(&wordno,&time,&val,&maxval,&minval,&lasttime,wordstor)) {
  1697. *extended_brkfile = FALSE;
  1698. return(FINISHED);
  1699. }
  1700. if(wordcnt[lineno]>2) {
  1701. if(wordno >=total_words) {
  1702. sprintf(errstr,"Failure in word-counting logic 2: check_for_an_extended_brkfile()\n");
  1703. return(PROGRAM_ERROR);
  1704. }
  1705. utol(wordstor[wordno]);
  1706. if(strcmp(wordstor[wordno],"lin")
  1707. && strcmp(wordstor[wordno],"exp")
  1708. && strcmp(wordstor[wordno],"log")) {
  1709. *extended_brkfile = FALSE;
  1710. return(FINISHED);
  1711. }
  1712. wordno++;
  1713. is_extended_format = TRUE;
  1714. }
  1715. if(wordcnt[lineno]>3) {
  1716. if(wordno >=total_words) {
  1717. sprintf(errstr,"Failure in word-counting logic 3: check_for_an_extended_brkfile()\n");
  1718. return(PROGRAM_ERROR);
  1719. }
  1720. if(sscanf(wordstor[wordno],"%lf",&val)!=1
  1721. || val < MIN_BRKSLOPE || val > MAX_BRKSLOPE) {
  1722. *extended_brkfile = FALSE;
  1723. return(FINISHED);
  1724. }
  1725. wordno++;
  1726. }
  1727. }
  1728. if(is_extended_format) {
  1729. inputfile->maxbrk = maxval;
  1730. inputfile->minbrk = minval;
  1731. } else
  1732. *extended_brkfile = FALSE;
  1733. return(FINISHED);
  1734. }
  1735. /****************************************** EXTRACT_VALUE_PAIR ****************************************/
  1736. int extract_value_pair(int *n,double *time, double *val,double *maxval,double *minval, double *lasttime, char **wordstor)
  1737. {
  1738. if(sscanf(wordstor[*n],"%lf",time)!=1 || sscanf(wordstor[(*n)+1],"%lf",val)!=1)
  1739. return(FALSE);
  1740. //TW
  1741. // if(*time <= *lasttime || *val > (double)MAXSAMP || *val < -(double)MAXSAMP)
  1742. if(*time <= *lasttime || *val > (double)MAXRANGE || *val < -(double)MAXRANGE)
  1743. return(FALSE);
  1744. *lasttime = *time;
  1745. *n += 2;
  1746. *maxval = max(*maxval,*val);
  1747. *minval = min(*minval,*val);
  1748. return(TRUE);
  1749. }
  1750. /****************************************** UTOL ****************************************/
  1751. #define UPPER_TO_LOWER_CASE (32)
  1752. void utol(char *str)
  1753. {
  1754. int n, k = (int) strlen(str);
  1755. for(n=0;n<k;n++) {
  1756. if(str[n] >= 'A' && str[n] <= 'Z')
  1757. str[n] += UPPER_TO_LOWER_CASE;
  1758. }
  1759. }
  1760. /* NEW CODE : June 1st : 2000 */
  1761. /****************************************** MAXSAMP ****************************************/
  1762. //TW Rewritten: floating point data only is retained:
  1763. //This version cannot write maxsamp info to header
  1764. void maxsamp(int ifd,double *maxamp,double *maxloc,int *maxrep)
  1765. {
  1766. int got, totalsamps = 0, samps, i /*, maxxloc*/;
  1767. double maxdamp = 0.0;
  1768. float *bigbuf, *fbuf;
  1769. int repeats = 0; /* counts how many times the max repeats */
  1770. size_t bufsize;
  1771. *maxrep = -1; /* flags that maxamp and maxloc are not found */
  1772. *maxamp = 0.0;
  1773. *maxloc = 0.0;
  1774. // if((bufsize =(int) (long)Malloc(-1)) < sizeof(float))
  1775. if ((bufsize = (size_t) Malloc(-1)) < sizeof(float))
  1776. return;
  1777. /*bufsize = (bufsize/SECSIZE)*SECSIZE; */ /* round to sector boundary */
  1778. bufsize /= sizeof(float);
  1779. if((bigbuf = (float *)malloc(bufsize * sizeof(float)))==NULL)
  1780. return;
  1781. fbuf = (float *)bigbuf;
  1782. while((got = fgetfbufEx(bigbuf,(int) bufsize,ifd,0)) > 0 ) {
  1783. samps = got;
  1784. for( i=0 ; i<samps ; i++ ) {
  1785. if(smpflteq(fbuf[i],maxdamp) || smpflteq(-fbuf[i],maxdamp))
  1786. repeats++;
  1787. else if(fbuf[i] >= 0.0) {
  1788. if(fbuf[i] > maxdamp) {
  1789. maxdamp = fbuf[i];
  1790. *maxloc = (double)(totalsamps + i);
  1791. repeats = 1;
  1792. }
  1793. } else {
  1794. if (-fbuf[i] > maxdamp) {
  1795. maxdamp = -fbuf[i];
  1796. *maxloc = (double)(totalsamps + i);
  1797. repeats = 1;
  1798. }
  1799. }
  1800. }
  1801. totalsamps += got;
  1802. }
  1803. if( got < 0 ) {
  1804. free(bigbuf);
  1805. return;
  1806. }
  1807. if(totalsamps > 0) {
  1808. if(repeats <= 0) {
  1809. Mfree(bigbuf);
  1810. return;
  1811. }
  1812. *maxamp = maxdamp; /* return info to SoundLoom */
  1813. // maxxloc = (int)round(*maxloc); /*RWD NB: NOTUSED */
  1814. *maxrep = repeats;
  1815. }
  1816. Mfree(bigbuf);
  1817. }
  1818. /************************************** DO_EXIT ************************************/
  1819. int do_exit(int exit_status) {
  1820. #ifdef IS_CDPARSE
  1821. if(exit_status == DATA_ERROR)
  1822. fprintf(stdout,"WARNING: %s",errstr); /* Sound Loom responds to message headers */
  1823. else /* and differently to different message headers */
  1824. fprintf(stdout,"ERROR: %s",errstr); /* but ignores the return value */
  1825. fflush(stdout);
  1826. #endif
  1827. return(exit_status); /* cmdline responds to value of 'exit_status' */
  1828. }
  1829. /***************************** PARSE_A_TEXTFILE *****************************/
  1830. int parse_a_textfile(char *filename,infileptr inputfile)
  1831. {
  1832. int exit_status;
  1833. FILE *fp;
  1834. if((fp = fopen(filename,"r"))==NULL) {
  1835. sprintf(errstr, "Can't open file %s to read data.\n",filename);
  1836. exit_status = DATA_ERROR;
  1837. return do_exit(exit_status);
  1838. }
  1839. if(file_has_reserved_extension(filename)) {
  1840. sprintf(errstr, "File %s either has unredable header, or is a textfile with a CDP reserved extension.\n",filename);
  1841. //TW ADDED: ESSENTIAL TO CLOSE FILE or NOTIFY SOUND LOOM OF FAILURE TO CLOSE: for Sound Loom INTEGRITY
  1842. if(fclose(fp)<0) {
  1843. sprintf(errstr, "Failed to close file %s\n",filename);
  1844. exit_status = SYSTEM_ERROR;
  1845. return do_exit(exit_status);
  1846. }
  1847. exit_status = DATA_ERROR;
  1848. return do_exit(exit_status);
  1849. }
  1850. if((exit_status = megaparsec(filename,fp,inputfile))<0) {
  1851. if(fclose(fp)<0) {
  1852. sprintf(errstr, "Failed to close file %s\n",filename);
  1853. exit_status = SYSTEM_ERROR;
  1854. }
  1855. return do_exit(exit_status);
  1856. }
  1857. if(fclose(fp)<0) {
  1858. sprintf(errstr, "Failed to close file %s\n",filename);
  1859. exit_status = SYSTEM_ERROR;
  1860. return do_exit(exit_status);
  1861. }
  1862. return FINISHED;
  1863. }
  1864. /**************************** IS_A_POSSIBLE_MULTICHANNEL_MIXFILE ********************************/
  1865. int is_a_possible_multichannel_mixfile
  1866. (int numlist,int brklist,int sndlist,int linecnt,char **wordstor,int *wordcnt,char *mixfilename,infileptr inputfile)
  1867. {
  1868. int exit_status;
  1869. int total_words = 0;
  1870. int srate = 0;
  1871. double dur = 0.0, time;
  1872. int n, chans, maxoutchan = 0;
  1873. char *filename, *p, *q;
  1874. if(numlist == POSSIBLE || brklist == POSSIBLE || sndlist == POSSIBLE)
  1875. return -1;
  1876. if(wordcnt[0] != 1) /* 1st mixfile line shouldv be = outchannels */
  1877. return -1;
  1878. p = wordstor[0];
  1879. q = p + strlen(wordstor[0]);
  1880. while(p < q) {
  1881. if(!isdigit(*p))
  1882. return -1;
  1883. p++;
  1884. }
  1885. maxoutchan = atoi(wordstor[0]);
  1886. if(maxoutchan < 1 || maxoutchan > MAX_OUTCHAN)
  1887. return -1;
  1888. total_words++;
  1889. for(n=1;n<linecnt;n++) { /* for each mixfile line */
  1890. filename = wordstor[total_words]; /* get the filename */
  1891. if(strlen(filename)<=0)
  1892. return -1;
  1893. if((exit_status = get_multichan_mixdata_in_line(wordcnt[n],wordstor,total_words,&time,&chans,maxoutchan))<0)
  1894. return(exit_status);
  1895. total_words += wordcnt[n];
  1896. if((exit_status = is_a_valid_sndfile_for_mixfile(mixfilename,filename,&srate,chans,n,inputfile,time,&dur,1))<=0)
  1897. return -1;
  1898. }
  1899. inputfile->srate = srate;
  1900. inputfile->linecnt = linecnt;
  1901. inputfile->duration = dur;
  1902. inputfile->out_chans = maxoutchan;
  1903. inputfile->all_words = total_words;
  1904. return FINISHED;
  1905. }
  1906. /**************************** GET_MULTICHAN_MIXDATA_IN_LINE ********************************/
  1907. int get_multichan_mixdata_in_line(int wordcnt,char **wordstor,int total_words,double *time,int *chans,int maxoutchan)
  1908. {
  1909. int here, is_level, inchan = 0, outchan;
  1910. int got_colon;
  1911. char *p;
  1912. char *q, *z = NULL;
  1913. double level;
  1914. int entrycnt = 0;
  1915. if((wordcnt <= 3) || EVEN(wordcnt))
  1916. return -1;
  1917. if(sscanf(wordstor[total_words+1],"%lf",time)!=1
  1918. || sscanf(wordstor[total_words+2],"%d",chans)!=1)
  1919. return -1;
  1920. here = total_words+3;
  1921. is_level = 0;
  1922. while(here < total_words + wordcnt) {
  1923. if(entrycnt >= 256)
  1924. return -1;
  1925. if(is_level) {
  1926. if(is_dB(wordstor[here])) {
  1927. if(!get_leveldb(wordstor[here],&level))
  1928. return -1;
  1929. } else if(!(IsNumeric(wordstor[here])))
  1930. return -1;
  1931. else if(sscanf(wordstor[here],"%lf",&level)!=1)
  1932. return -1;
  1933. } else {
  1934. if(strlen(wordstor[here]) < 3)
  1935. return -1;
  1936. p = wordstor[here];
  1937. q = p + strlen(wordstor[here]);
  1938. got_colon = 0;
  1939. while(p < q) {
  1940. if(!isdigit(*p)) {
  1941. if(p == wordstor[here])
  1942. return -1;
  1943. else if(got_colon)
  1944. return -1;
  1945. else if(*p != ':')
  1946. return -1;
  1947. else {
  1948. *p = ENDOFSTR;
  1949. inchan = atoi(wordstor[here]);
  1950. *p = ':';
  1951. z = p+1;
  1952. got_colon = 1;
  1953. }
  1954. }
  1955. p++;
  1956. }
  1957. if(!got_colon || z == p)
  1958. return -1;
  1959. outchan = atoi(z);
  1960. if(inchan > *chans || inchan <= 0)
  1961. return -1;
  1962. if(outchan > maxoutchan)
  1963. return -1;
  1964. // END OF NEW CODE 2007
  1965. }
  1966. if(is_level)
  1967. entrycnt++;
  1968. is_level = !is_level;
  1969. here++;
  1970. }
  1971. return(FINISHED);
  1972. }
  1973. /*************************** ISNUMERIC **************************/
  1974. int IsNumeric(char *str)
  1975. {
  1976. char *p;
  1977. int got_point = 0;
  1978. p = str;
  1979. while(*p != ENDOFSTR) {
  1980. if(isdigit(*p))
  1981. p++;
  1982. else if(*p == '.') {
  1983. if(got_point)
  1984. return 0;
  1985. got_point = 1;
  1986. p++;
  1987. } else
  1988. return 0;
  1989. }
  1990. if(p == str)
  1991. return 0;
  1992. return 1;
  1993. }