ap_combine.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <structures.h>
  24. #include <cdpmain.h>
  25. #include <tkglobals.h>
  26. #include <pnames.h>
  27. #include <combine.h>
  28. #include <processno.h>
  29. #include <modeno.h>
  30. #include <globcon.h>
  31. #include <logic.h>
  32. #include <filetype.h>
  33. #include <mixxcon.h>
  34. #include <speccon.h>
  35. #include <flags.h>
  36. #include <arrays.h>
  37. #include <formants.h>
  38. #include <sfsys.h>
  39. #include <osbind.h>
  40. #include <string.h>
  41. #include <math.h>
  42. #include <srates.h>
  43. /********************************************************************************************/
  44. /********************************** FORMERLY IN preprocess.c ********************************/
  45. /********************************************************************************************/
  46. static int force_file_zero_to_be_largest_file(dataptr dz);
  47. static int mean_preprocess(dataptr dz);
  48. static void integer_swap(int *a,int *b);
  49. static int allocate_specleaf_buffer(dataptr dz);
  50. /***************************************************************************************/
  51. /****************************** FORMERLY IN aplinit.c **********************************/
  52. /***************************************************************************************/
  53. /***************************** ESTABLISH_BUFPTRS_AND_EXTRA_BUFFERS **************************/
  54. int establish_bufptrs_and_extra_buffers(dataptr dz)
  55. {
  56. int exit_status;
  57. int is_spec = FALSE;
  58. dz->extra_bufcnt = -1; /* ENSURE EVERY CASE HAS A PAIR OF ENTRIES !! */
  59. dz->bptrcnt = 0;
  60. dz->bufcnt = 0;
  61. switch(dz->process) {
  62. //TW NEW CASE
  63. case(MAKE2):
  64. case(MAKE): dz->extra_bufcnt = 0; dz->bptrcnt = 4; is_spec = TRUE; break;
  65. case(SUM): dz->extra_bufcnt = 0; dz->bptrcnt = 4; is_spec = TRUE; break;
  66. case(DIFF): dz->extra_bufcnt = 0; dz->bptrcnt = 4; is_spec = TRUE; break;
  67. case(LEAF): dz->extra_bufcnt = 0; dz->bptrcnt = 4; is_spec = TRUE; break;
  68. case(MAX): dz->extra_bufcnt = 0; dz->bptrcnt = 4; is_spec = TRUE; break;
  69. case(MEAN): dz->extra_bufcnt = 3; dz->bptrcnt = 4; is_spec = TRUE; break; /* TW August 19 */
  70. case(CROSS): dz->extra_bufcnt = 0; dz->bptrcnt = 4; is_spec = TRUE; break;
  71. default:
  72. sprintf(errstr,"Unknown program type [%d] in establish_bufptrs_and_extra_buffers()\n",dz->process);
  73. return(PROGRAM_ERROR);
  74. }
  75. if(dz->extra_bufcnt < 0) {
  76. sprintf(errstr,"bufcnts have not been set: establish_bufptrs_and_extra_buffers()\n");
  77. return(PROGRAM_ERROR);
  78. }
  79. if(is_spec)
  80. return establish_spec_bufptrs_and_extra_buffers(dz);
  81. else if((dz->process==HOUSE_SPEC && dz->mode==HOUSE_CONVERT) || dz->process==INFO_DIFF) {
  82. if((exit_status = establish_spec_bufptrs_and_extra_buffers(dz))<0)
  83. return(exit_status);
  84. }
  85. return establish_groucho_bufptrs_and_extra_buffers(dz);
  86. }
  87. /***************************** SETUP_INTERNAL_ARRAYS_AND_ARRAY_POINTERS **************************/
  88. int setup_internal_arrays_and_array_pointers(dataptr dz)
  89. {
  90. int n;
  91. dz->ptr_cnt = -1; //base constructor...process
  92. dz->array_cnt = -1;
  93. dz->iarray_cnt = -1;
  94. dz->larray_cnt = -1;
  95. switch(dz->process) {
  96. //TW NEW CASE
  97. case(MAKE2):
  98. case(MAKE): dz->array_cnt = 0; dz->iarray_cnt = 0; dz->larray_cnt = 0; dz->ptr_cnt = 0; dz->fptr_cnt = 0; break;
  99. case(SUM): dz->array_cnt = 0; dz->iarray_cnt = 0; dz->larray_cnt = 0; dz->ptr_cnt = 0; dz->fptr_cnt = 0; break;
  100. case(DIFF): dz->array_cnt = 0; dz->iarray_cnt = 0; dz->larray_cnt = 0; dz->ptr_cnt = 0; dz->fptr_cnt = 0; break;
  101. case(LEAF): dz->array_cnt = 0; dz->iarray_cnt = 0; dz->larray_cnt = 0; dz->ptr_cnt = 0; dz->fptr_cnt = 0; break;
  102. case(MAX): dz->array_cnt = 0; dz->iarray_cnt = 0; dz->larray_cnt = 0; dz->ptr_cnt = 0; dz->fptr_cnt = 0; break;
  103. case(MEAN): dz->array_cnt = 0; dz->iarray_cnt = 2; dz->larray_cnt = 0; dz->ptr_cnt = 0; dz->fptr_cnt = 0; break;
  104. case(CROSS): dz->array_cnt = 0; dz->iarray_cnt = 0; dz->larray_cnt = 0; dz->ptr_cnt = 0; dz->fptr_cnt = 0; break;
  105. }
  106. /*** WARNING ***
  107. ANY APPLICATION DEALING WITH A NUMLIST INPUT: MUST establish AT LEAST 1 double array: i.e. dz->array_cnt = at least 1
  108. **** WARNING ***/
  109. if(dz->array_cnt < 0 || dz->iarray_cnt < 0 || dz->larray_cnt < 0 || dz->ptr_cnt < 0 || dz->fptr_cnt < 0) {
  110. sprintf(errstr,"array_cnt not set in setup_internal_arrays_and_array_pointers()\n");
  111. return(PROGRAM_ERROR);
  112. }
  113. if(dz->array_cnt > 0) {
  114. if((dz->parray = (double **)malloc(dz->array_cnt * sizeof(double *)))==NULL) {
  115. sprintf(errstr,"INSUFFICIENT MEMORY for internal double arrays.\n");
  116. return(MEMORY_ERROR);
  117. }
  118. for(n=0;n<dz->array_cnt;n++)
  119. dz->parray[n] = NULL;
  120. }
  121. if(dz->iarray_cnt > 0) {
  122. if((dz->iparray = (int **)malloc(dz->iarray_cnt * sizeof(int *)))==NULL) {
  123. sprintf(errstr,"INSUFFICIENT MEMORY for internal int arrays.\n");
  124. return(MEMORY_ERROR);
  125. }
  126. for(n=0;n<dz->iarray_cnt;n++)
  127. dz->iparray[n] = NULL;
  128. }
  129. if(dz->larray_cnt > 0) {
  130. if((dz->lparray = (int **)malloc(dz->larray_cnt * sizeof(int *)))==NULL) {
  131. sprintf(errstr,"INSUFFICIENT MEMORY for internal long arrays.\n");
  132. return(MEMORY_ERROR);
  133. }
  134. for(n=0;n<dz->larray_cnt;n++)
  135. dz->lparray[n] = NULL;
  136. }
  137. if(dz->ptr_cnt > 0) {
  138. if((dz->ptr = (double **)malloc(dz->ptr_cnt * sizeof(double *)))==NULL) {
  139. sprintf(errstr,"INSUFFICIENT MEMORY for internal pointer arrays.\n");
  140. return(MEMORY_ERROR);
  141. }
  142. for(n=0;n<dz->ptr_cnt;n++)
  143. dz->ptr[n] = NULL;
  144. }
  145. if(dz->fptr_cnt > 0) {
  146. if((dz->fptr = (float **)malloc(dz->fptr_cnt * sizeof(float *)))==NULL) {
  147. sprintf(errstr,"INSUFFICIENT MEMORY for internal float-pointer arrays.\n");
  148. return(MEMORY_ERROR);
  149. }
  150. for(n=0;n<dz->fptr_cnt;n++)
  151. dz->fptr[n] = NULL;
  152. }
  153. return(FINISHED);
  154. }
  155. /****************************** ASSIGN_PROCESS_LOGIC *********************************/
  156. int assign_process_logic(dataptr dz)
  157. {
  158. switch(dz->process) {
  159. case(MAKE): setup_process_logic(PITCH_AND_FORMANTS, PITCH_TO_ANAL, ANALFILE_OUT, dz); break;
  160. //TW NEW CASE
  161. case(MAKE2): setup_process_logic(PFE, PITCH_TO_ANAL, ANALFILE_OUT, dz); break;
  162. case(SUM): setup_process_logic(TWO_ANALFILES, MAX_ANALFILE, ANALFILE_OUT, dz); break;
  163. case(DIFF): setup_process_logic(TWO_ANALFILES, EQUAL_ANALFILE, ANALFILE_OUT, dz); break;
  164. case(LEAF): setup_process_logic(MANY_ANALFILES, MIN_ANALFILE, ANALFILE_OUT, dz); break;
  165. case(MAX): setup_process_logic(MANY_ANALFILES, MAX_ANALFILE, ANALFILE_OUT, dz); break;
  166. case(MEAN): setup_process_logic(TWO_ANALFILES, MIN_ANALFILE, ANALFILE_OUT, dz); break;
  167. case(CROSS): setup_process_logic(TWO_ANALFILES, MIN_ANALFILE, ANALFILE_OUT, dz); break;
  168. default:
  169. sprintf(errstr,"Unknown process: assign_process_logic()\n");
  170. return(PROGRAM_ERROR);
  171. break;
  172. }
  173. if(dz->has_otherfile) {
  174. switch(dz->input_data_type) {
  175. case(ALL_FILES):
  176. case(TWO_SNDFILES):
  177. case(SNDFILE_AND_ENVFILE):
  178. case(SNDFILE_AND_BRKFILE):
  179. case(SNDFILE_AND_UNRANGED_BRKFILE):
  180. case(SNDFILE_AND_DB_BRKFILE):
  181. break;
  182. case(MANY_SNDFILES):
  183. if(dz->process==INFO_TIMELIST)
  184. break;
  185. /* fall thro */
  186. default:
  187. sprintf(errstr,"Most processes accepting files with different properties\n"
  188. "can only take 2 sound infiles.\n");
  189. return(PROGRAM_ERROR);
  190. }
  191. }
  192. return(FINISHED);
  193. }
  194. /***************************** SET_LEGAL_INFILE_STRUCTURE **************************
  195. *
  196. * Allows 2nd infile to have different props to first infile.
  197. */
  198. void set_legal_infile_structure(dataptr dz)
  199. {
  200. switch(dz->process) {
  201. default:
  202. dz->has_otherfile = FALSE;
  203. break;
  204. }
  205. }
  206. /***************************************************************************************/
  207. /****************************** FORMERLY IN internal.c *********************************/
  208. /***************************************************************************************/
  209. /****************************** SET_LEGAL_INTERNALPARAM_STRUCTURE *********************************/
  210. int set_legal_internalparam_structure(int process,int mode,aplptr ap)
  211. {
  212. int exit_status = FINISHED;
  213. switch(process) {
  214. //TW NEW CASE
  215. case(MAKE2):
  216. case(MAKE): return(FINISHED);
  217. case(SUM): return(FINISHED);
  218. case(DIFF): return(FINISHED);
  219. case(LEAF): return(FINISHED);
  220. case(MAX): return(FINISHED);
  221. case(MEAN): exit_status = set_internalparam_data("ii",ap); break;
  222. case(CROSS): return(FINISHED);
  223. default:
  224. sprintf(errstr,"Unknown process in set_legal_internalparam_structure()\n");
  225. return(PROGRAM_ERROR);
  226. }
  227. return(exit_status);
  228. }
  229. /********************************************************************************************/
  230. /********************************** FORMERLY IN specialin.c *********************************/
  231. /********************************************************************************************/
  232. /********************** READ_SPECIAL_DATA ************************/
  233. int read_special_data(char *str,dataptr dz)
  234. {
  235. // int exit_status = FINISHED;
  236. aplptr ap = dz->application;
  237. //TW AVOIDS WARNING
  238. //str = str;
  239. switch(ap->special_data) {
  240. default:
  241. sprintf(errstr,"Unknown special_data type: read_special_data()\n");
  242. return(PROGRAM_ERROR);
  243. }
  244. return(FINISHED); /* NOTREACHED */
  245. }
  246. /********************************************************************************************/
  247. /********************************** FORMERLY IN preprocess.c ********************************/
  248. /********************************************************************************************/
  249. /****************************** PARAM_PREPROCESS *********************************/
  250. int param_preprocess(dataptr dz)
  251. {
  252. switch(dz->process) {
  253. case(MAX): return force_file_zero_to_be_largest_file(dz);
  254. case(MEAN): return mean_preprocess(dz);
  255. //TW NEW CASE
  256. case(MAKE2):
  257. case(MAKE): case(SUM): case(DIFF): case(LEAF): case(CROSS):
  258. return(FINISHED);
  259. default:
  260. sprintf(errstr,"PROGRAMMING PROBLEM: Unknown process in param_preprocess()\n");
  261. return(PROGRAM_ERROR);
  262. }
  263. return(FINISHED); /* NOTREACHED */
  264. }
  265. /********************** FORCE_FILE_ZERO_TO_BE_LARGEST_FILE **********************/
  266. int force_file_zero_to_be_largest_file(dataptr dz)
  267. {
  268. int maxsize = dz->insams[0];
  269. int maxfile = 0, n, k;
  270. for(n=1;n<dz->infilecnt;n++) {
  271. if(dz->insams[n] > maxsize) {
  272. maxsize = dz->insams[n];
  273. maxfile = n;
  274. }
  275. }
  276. if(n!=0) { /* Force file zero to be largest file */
  277. k = dz->ifd[0];
  278. dz->ifd[0] = dz->ifd[maxfile];
  279. dz->ifd[maxfile] = k;
  280. k = dz->insams[0];
  281. dz->insams[0] = dz->insams[maxfile];
  282. dz->insams[maxfile] = k;
  283. }
  284. return(FINISHED);
  285. }
  286. /************************** MEAN_PREPROCESS ******************************/
  287. int mean_preprocess(dataptr dz)
  288. {
  289. int exit_status;
  290. if(dz->zeroset) {
  291. sprintf(errstr,"zeroset flag set: Needed unset for later use: mean_preprocess()\n");
  292. return(PROGRAM_ERROR);
  293. }
  294. if((dz->iparray[MEAN_LOC1] = (int *)malloc(dz->clength * sizeof(int)))==NULL
  295. || (dz->iparray[MEAN_LOC2] = (int *)malloc(dz->clength * sizeof(int)))==NULL) {
  296. sprintf(errstr,"INSUFFICIENT MEMORY for mean location arrays.\n");
  297. return(MEMORY_ERROR);
  298. }
  299. if((exit_status = get_channel_corresponding_to_frq(&(dz->iparam[MEAN_BOT]),dz->param[MEAN_LOF],dz))<0)
  300. return(exit_status);
  301. if((exit_status = get_channel_corresponding_to_frq(&(dz->iparam[MEAN_TOP]),dz->param[MEAN_HIF],dz))<0)
  302. return(exit_status);
  303. if(dz->iparam[MEAN_TOP] < dz->iparam[MEAN_BOT])
  304. integer_swap(&(dz->iparam[MEAN_TOP]),&(dz->iparam[MEAN_BOT]));
  305. if(dz->iparam[MEAN_TOP] - dz->iparam[MEAN_BOT] + 1 < dz->iparam[MEAN_CHAN])
  306. /* Reducing chans parameter to fit into frq limits. */
  307. dz->iparam[MEAN_CHAN] = dz->iparam[MEAN_TOP] - dz->iparam[MEAN_BOT] + 1;
  308. dz->iparam[MEAN_TOP] *= 2; /* CONVERT FROM CHANNEL-NO TO FLOAT-NO IN BUFFER */
  309. dz->iparam[MEAN_BOT] *= 2;
  310. dz->iparam[MEAN_TOP] += 2; /* INCLUSIVE LOOP LIMIT */
  311. dz->iparam[MEAN_TOP] = min(dz->iparam[MEAN_TOP],dz->wanted);
  312. return(FINISHED);
  313. }
  314. /***************************** INTEGER_SWAP **************************/
  315. void integer_swap(int *a,int *b)
  316. {
  317. int k;
  318. k = *a;
  319. *a = *b;
  320. *b = k;
  321. }
  322. /***************************** INNER_LOOP (redundant) **************************/
  323. int inner_loop
  324. (int *peakscore,int *descnt,int *in_start_portion,int *least,int *pitchcnt,int windows_in_buf,dataptr dz)
  325. {
  326. return(FINISHED);
  327. }
  328. /***************** SKIP_OR_SPECIAL_OPERATION_ON_WINDOW_ZERO ************/
  329. int skip_or_special_operation_on_window_zero(dataptr dz)
  330. {
  331. return(FALSE);
  332. }
  333. /********************************************************************************************/
  334. /********************************** FORMERLY IN procspec.c **********************************/
  335. /********************************************************************************************/
  336. /**************************** SPEC_PROCESS_FILE ****************************/
  337. int spec_process_file(dataptr dz)
  338. {
  339. dz->total_windows = 0;
  340. display_virtual_time(0L,dz);
  341. switch(dz->process) {
  342. //TW NEW CASE
  343. case(MAKE2):
  344. case(MAKE): return specmake(dz);
  345. case(SUM): return outer_twofileinput_loop(dz);
  346. case(DIFF): return outer_twofileinput_loop(dz);
  347. case(LEAF): return specleaf(dz);
  348. case(MAX): return specmax(dz);
  349. case(MEAN): return outer_twofileinput_loop(dz);
  350. case(CROSS): return outer_twofileinput_loop(dz);
  351. default:
  352. sprintf(errstr,"Unknown process in procspec()\n");
  353. return(PROGRAM_ERROR);
  354. }
  355. return(FINISHED); /* NOTREACHED */
  356. }
  357. /**************************** OUTER_TWOFILEINPUT_LOOP ***************************/
  358. int outer_twofileinput_loop(dataptr dz)
  359. {
  360. int exit_status;
  361. int windows_to_process, windows_in_buf, samps_read, samps_to_write, wc, got;
  362. int file_to_keep = 0, finished = 0, stop_at_end_of_shortest_file = 0;
  363. int stop_at_end_of_process = 0;
  364. dz->time = 0.0f;
  365. switch(dz->process) {
  366. case(CROSS):
  367. case(MEAN):
  368. windows_to_process = min(dz->insams[0],dz->insams[1])/dz->wanted;
  369. stop_at_end_of_shortest_file = 1;
  370. break;
  371. case(SUM):
  372. windows_to_process = min(dz->insams[0],dz->insams[1])/dz->wanted;
  373. file_to_keep = get_longer_file(dz);
  374. break;
  375. case(DIFF):
  376. windows_to_process = min(dz->insams[0],dz->insams[1])/dz->wanted;
  377. if(dz->insams[0] > dz->insams[1])
  378. file_to_keep = 1;
  379. break;
  380. default:
  381. sprintf(errstr,"unknown case in outer_twofileinput_loop()\n");
  382. return(PROGRAM_ERROR);
  383. }
  384. while(!finished) {
  385. if((exit_status = read_both_files(&windows_in_buf,&got,dz))<0)
  386. return(exit_status);
  387. samps_to_write = got;
  388. for(wc=0; wc<windows_in_buf; wc++) {
  389. if(dz->total_windows==0) {
  390. if((exit_status = skip_or_special_operation_on_window_zero(dz))<0)
  391. return(exit_status);
  392. if(exit_status==TRUE) {
  393. if((exit_status = advance_one_2fileinput_window(dz))<0)
  394. return(exit_status);
  395. continue;
  396. }
  397. }
  398. if((exit_status = read_values_from_all_existing_brktables((double)dz->time,dz))<0)
  399. return(exit_status);
  400. switch(dz->process) {
  401. case(CROSS):
  402. if((exit_status = speccross(dz))<0)
  403. return(exit_status);
  404. break;
  405. case(DIFF):
  406. if((exit_status = specdiff(dz))<0)
  407. return(exit_status);
  408. break;
  409. case(MEAN):
  410. if((exit_status = specmean(dz))<0)
  411. return(exit_status);
  412. break;
  413. case(SUM):
  414. if((exit_status = specsum(dz))<0)
  415. return(exit_status);
  416. break;
  417. default:
  418. sprintf(errstr,"unknown process in outer_twofileinput_loop()\n");
  419. return(PROGRAM_ERROR);
  420. }
  421. if((exit_status = advance_one_2fileinput_window(dz))<0)
  422. return(exit_status);
  423. if(dz->total_windows >= windows_to_process) {
  424. if((exit_status = keep_excess_samps_from_correct_file(&samps_to_write,file_to_keep,got,wc,dz))<0)
  425. return(exit_status);
  426. finished = 1;
  427. break;
  428. }
  429. }
  430. if(samps_to_write > 0) {
  431. if((exit_status = write_samps(dz->bigfbuf,samps_to_write,dz))<0)
  432. return(exit_status);
  433. }
  434. }
  435. if(!stop_at_end_of_process && !stop_at_end_of_shortest_file) {
  436. if((exit_status = read_either_file(&samps_read,file_to_keep,dz))<0)
  437. return(exit_status);
  438. while(samps_read > 0) {
  439. if((exit_status = write_samps(dz->bigfbuf,samps_read,dz))<0)
  440. return(exit_status);
  441. if((exit_status = read_either_file(&samps_read,file_to_keep,dz))<0)
  442. return(exit_status);
  443. }
  444. }
  445. return(FINISHED);
  446. }
  447. /********************************************************************************************/
  448. /********************************** FORMERLY IN pconsistency.c ******************************/
  449. /********************************************************************************************/
  450. /****************************** CHECK_PARAM_VALIDITY_AND_CONSISTENCY *********************************/
  451. int check_param_validity_and_consistency(dataptr dz)
  452. {
  453. return(FINISHED);
  454. }
  455. /********************************************************************************************/
  456. /********************************** FORMERLY IN buffers.c ***********************************/
  457. /********************************************************************************************/
  458. /**************************** ALLOCATE_LARGE_BUFFERS ******************************/
  459. int allocate_large_buffers(dataptr dz)
  460. {
  461. switch(dz->process) {
  462. case(SUM): case(DIFF):
  463. case(MAX): case(MEAN): case(CROSS):
  464. return allocate_double_buffer(dz);
  465. case(LEAF):
  466. return allocate_specleaf_buffer(dz);
  467. case(MAKE):
  468. //TW NEW CASE
  469. case(MAKE2):
  470. return allocate_analdata_plus_formantdata_buffer(dz);
  471. default:
  472. sprintf(errstr,"Unknown program no. in allocate_large_buffers()\n");
  473. return(PROGRAM_ERROR);
  474. }
  475. return(FINISHED); /* NOTREACHED */
  476. }
  477. /********************************************************************************************/
  478. /********************************** FORMERLY IN cmdline.c ***********************************/
  479. /********************************************************************************************/
  480. int get_process_no(char *prog_identifier_from_cmdline,dataptr dz)
  481. {
  482. if (!strcmp(prog_identifier_from_cmdline,"make")) dz->process = MAKE;
  483. //TW NEW CASE
  484. else if(!strcmp(prog_identifier_from_cmdline,"make2")) dz->process = MAKE2;
  485. else if(!strcmp(prog_identifier_from_cmdline,"sum")) dz->process = SUM;
  486. else if(!strcmp(prog_identifier_from_cmdline,"diff")) dz->process = DIFF;
  487. else if(!strcmp(prog_identifier_from_cmdline,"interleave")) dz->process = LEAF;
  488. else if(!strcmp(prog_identifier_from_cmdline,"max")) dz->process = MAX;
  489. else if(!strcmp(prog_identifier_from_cmdline,"mean")) dz->process = MEAN;
  490. else if(!strcmp(prog_identifier_from_cmdline,"cross")) dz->process = CROSS;
  491. else {
  492. sprintf(errstr,"Unknown program identification string '%s'\n",prog_identifier_from_cmdline);
  493. return(USAGE_ONLY);
  494. }
  495. //TW UPDATE
  496. return(FINISHED);
  497. }
  498. /********************************************************************************************/
  499. /********************************** FORMERLY IN usage.c *************************************/
  500. /********************************************************************************************/
  501. /******************************** USAGE1 ********************************/
  502. int usage1(void)
  503. {
  504. sprintf(errstr,
  505. "\nCOMBINATION OF SPECTRAL FILES\n\n"
  506. "USAGE: combine NAME (mode) infile (infile2...) outfile parameters: \n"
  507. "\n"
  508. "where NAME can be any one of\n"
  509. "\n"
  510. //TW ADDED NEW CASE
  511. "make make2 sum diff interleave max mean cross\n\n"
  512. "Type 'combine make' for more info on combine make..ETC.\n");
  513. return(USAGE_ONLY);
  514. }
  515. /******************************** USAGE2 ********************************/
  516. int usage2(char *str)
  517. {
  518. if(!strcmp(str,"make")) {
  519. sprintf(errstr,
  520. "combine make pitchfile formantfile outfile\n\n"
  521. "GENERATE SPECTRUM FROM PITCH & FORMANT DATA ONLY.\n\n"
  522. "pitchfile is a binary pitchdata file\n"
  523. "formantfile is a binary formantdata file\n"
  524. "outfile is an analysis file which can be resynthesized with PVOC\n"
  525. "\n"
  526. //TW temporary cmdline restriction
  527. "** Do not use output filenames which end in '1'\n");
  528. //TW NEW CASE
  529. } else if(!strcmp(str,"make2")) {
  530. sprintf(errstr,
  531. "combine make2 pitchfile formantfile envfile outfile\n\n"
  532. "GENERATE SPECTRUM FROM PITCH, FORMANT AND ENVELOPE DATA ONLY.\n\n"
  533. "pitchfile is a binary pitchdata file\n"
  534. "formantfile is a binary formantdata file\n"
  535. "envfile is a binary envelope file derived from an ANALYSIS file\n"
  536. "outfile is an analysis file which can be resynthesized with PVOC\n");
  537. } else if(!strcmp(str,"sum")) {
  538. sprintf(errstr,
  539. "combine sum infile infile2 outfile [-ccrossover]\n\n"
  540. "FIND SUM OF TWO SPECTRA.\n\n"
  541. "-c CROSSOVER is amount of 2nd spectrum added to 1st (range 0 to 1)\n\n"
  542. "crossover may vary over time.\n");
  543. } else if(!strcmp(str,"diff")) {
  544. sprintf(errstr,
  545. "combine diff infile infile2 outfile [-ccrossover] [-a]\n\n"
  546. "FIND DIFFERENCE OF TWO SPECTRA.\n\n"
  547. "-c CROSSOVER is amount of 2nd spectrum subtracted from 1st (range 0 to 1)\n"
  548. "-a retains any subzero amplitudes produced (Default: sets these to zero).\n\n"
  549. "crossover may vary over time.\n");
  550. } else if(!strcmp(str,"interleave")) {
  551. sprintf(errstr,
  552. "combine interleave infile infile2 [infile3 ....] outfile leafsize\n\n"
  553. "INTERLEAVE WINDOWS FROM INFILES, LEAFSIZE WINDOWS PER LEAF.\n");
  554. } else if(!strcmp(str,"max")) {
  555. sprintf(errstr,
  556. "combine max infile infile2 [infile3 ....] outfile\n\n"
  557. "IN EACH ANALYSIS CHANNEL, IN EACH WINDOW, TAKE MAX VAL AMONGST INPUT FILES.\n");
  558. } else if(!strcmp(str,"mean")) {
  559. sprintf(errstr,
  560. "combine mean mode infile infile2 outfile [-llofrq] [-hhifrq] [-cchans] [-z]\n\n"
  561. "GENERATE SPECTRAL 'MEAN' OF 2 SOUNDS.\n\n"
  562. "LOFRQ is low freq limit of channels to look at.\n"
  563. "HIFRQ is high freq limit of channels to look at.\n"
  564. "CHANS no. of significant channels to compare..Default: All within range.\n"
  565. "-z Zeroes channels OUTSIDE frq range specified.\n\n"
  566. "MODES are...\n"
  567. "(1) mean channel amp of 2 files : mean of two pitches\n"
  568. "(2) mean channel amp of 2 files : mean of two frqs\n"
  569. "(3) channel amp from file1 : mean of two pitches\n"
  570. "(4) channel amp from file1 : mean of two frqs\n"
  571. "(5) channel amp from file2 : mean of two pitches\n"
  572. "(6) channel amp from file2 : mean of two frqs\n"
  573. "(7) max channel amp of 2 files : mean of two pitches\n"
  574. "(8) max channel amp of 2 files : mean of two frqs\n");
  575. } else if(!strcmp(str,"cross")) {
  576. sprintf(errstr,
  577. "combine cross infile infile2 outfile [-iinterp]\n\n"
  578. "REPLACE SPECTRAL AMPLITUDES OF 1st FILE WITH THOSE OF 2nd.\n\n"
  579. "-i INTERP is degree of replacement.\n\n"
  580. " interp may vary over time.\n");
  581. } else
  582. sprintf(errstr,"Unknown option '%s'\n",str);
  583. return(USAGE_ONLY);
  584. }
  585. /******************************** USAGE3 ********************************/
  586. int usage3(char *str1,char *str2)
  587. {
  588. sprintf(errstr,"Insufficient parameters on command line.\n");
  589. return(USAGE_ONLY);
  590. }
  591. /**************************** ALLOCATE_SPECLEAF_BUFFER ******************************/
  592. int allocate_specleaf_buffer(dataptr dz)
  593. {
  594. unsigned int buffersize;
  595. if(dz->bptrcnt <= 0) {
  596. sprintf(errstr,"bufptr not established in allocate_specleaf_buffer()\n");
  597. return(PROGRAM_ERROR);
  598. }
  599. buffersize = dz->wanted * dz->iparam[LEAF_SIZE];
  600. dz->buflen = buffersize;
  601. buffersize += 1;
  602. if((dz->bigfbuf = (float*) malloc(buffersize * sizeof(float)))==NULL) {
  603. sprintf(errstr,"INSUFFICIENT MEMORY for sound buffers.\n");
  604. return(MEMORY_ERROR);
  605. }
  606. dz->big_fsize = dz->buflen;
  607. dz->bigfbuf[dz->big_fsize] = 0.0f; /* safety value */
  608. return(FINISHED);
  609. }