main.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * Copyright (c) 1983-2023 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 <tkglobals.h>
  25. #include <filters.h>
  26. #include <filetype.h>
  27. #include <processno.h>
  28. #include <modeno.h>
  29. #include <formants.h>
  30. #include <cdpmain.h>
  31. #include <special.h>
  32. #include <logic.h>
  33. #include <globcon.h>
  34. #include <cdpmain.h>
  35. #include <sfsys.h>
  36. #include <ctype.h>
  37. #include <string.h>
  38. #include <arrays.h>
  39. /* RWD Apr 2011 rebuilt to fix bug in filter bankfrqs (memory overrun) */
  40. /* subject to revision from TW etc */
  41. char errstr[2400];
  42. /*extern*/ int sloom = 0;
  43. /* TW May 2001 */
  44. /*extern*/ int sloombatch = 0; /*TW may 2001 */
  45. /*extern*/ int anal_infiles = 0;
  46. /*extern*/ int is_converted_to_stereo = -1;
  47. const char* cdp_version = "7.1.0";
  48. // TW MULTICHAN 2010
  49. static int setup_internal_arrays_and_array_pointers_for_lphp(dataptr dz);
  50. /**************************************** MAIN *********************************************/
  51. int main(int argc,char *argv[])
  52. {
  53. int exit_status;
  54. /* FILE *fp = NULL;*/
  55. dataptr dz = NULL;
  56. /* char *special_data_string = NULL;*/
  57. char **cmdline;
  58. int cmdlinecnt;
  59. // aplptr ap;
  60. int *valid = NULL;
  61. int is_launched = FALSE;
  62. int validcnt;
  63. if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
  64. fprintf(stdout,"%s\n",cdp_version);
  65. fflush(stdout);
  66. return 0;
  67. }
  68. /* CHECK FOR SOUNDLOOM */
  69. /* TW May 2001 */
  70. if((sloom = sound_loom_in_use(&argc,&argv)) > 1) {
  71. sloom = 0;
  72. sloombatch = 1;
  73. }
  74. if(!sloom) {
  75. if((exit_status = allocate_and_initialise_validity_flags(&valid,&validcnt))<0) {
  76. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  77. return(FAILED);
  78. }
  79. }
  80. if(sflinit("cdp")){
  81. sfperror("cdp: initialisation\n");
  82. return(FAILED);
  83. }
  84. /* SET UP THE PRINCIPLE DATASTRUCTURE */
  85. if((exit_status = establish_datastructure(&dz))<0) {
  86. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  87. return(FAILED);
  88. }
  89. if(!sloom) {
  90. /* INITIAL CHECK OF CMDLINE DATA */
  91. if((exit_status = make_initial_cmdline_check(&argc,&argv))<0) {
  92. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  93. return(FAILED);
  94. }
  95. cmdline = argv; /* GET PRE_DATA, ALLOCATE THE APPLICATION, CHECK FOR EXTRA INFILES */
  96. cmdlinecnt = argc;
  97. if((exit_status = get_process_and_mode_from_cmdline(&cmdlinecnt,&cmdline,dz))<0) {
  98. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  99. return(FAILED);
  100. }
  101. if((exit_status = setup_particular_application(dz))<0) {
  102. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  103. return(FAILED);
  104. }
  105. if((exit_status = count_and_allocate_for_infiles(cmdlinecnt,cmdline,dz))<0) {
  106. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  107. return(FAILED);
  108. }
  109. } else {
  110. if((exit_status = parse_tk_data(argc,argv,&cmdline,&cmdlinecnt,dz))<0) { /* includes setup_particular_application() */
  111. exit_status = print_messages_and_close_sndfiles(exit_status,is_launched,dz);/* and cmdlinelength check = sees extra-infiles */
  112. return(exit_status);
  113. }
  114. }
  115. // ap = dz->application;
  116. /*********************************************************************************************************************
  117. cmdline[0] 2 vals ACTIVE
  118. TK (infile) (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  119. CMDLINE (infile) (more-infiles) (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  120. 1 val
  121. *********************************************************************************************************************/
  122. if((exit_status = parse_infile_and_hone_type(cmdline[0],valid,dz))<0) {
  123. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  124. return(FAILED);
  125. }
  126. if((exit_status = setup_param_ranges_and_defaults(dz))<0) {
  127. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  128. return(FAILED);
  129. }
  130. /* OPEN FIRST INFILE AND STORE DATA, AND INFORMATION, APPROPRIATELY */
  131. if(dz->input_data_type!=NO_FILE_AT_ALL) {
  132. if((exit_status = open_first_infile(cmdline[0],dz))<0) {
  133. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  134. return(FAILED);
  135. }
  136. //TW UPDATE
  137. cmdlinecnt--;
  138. cmdline++;
  139. }
  140. // TW MULTICHAN 2010
  141. if(dz->process == LPHP) {
  142. if((exit_status = setup_internal_arrays_and_array_pointers_for_lphp(dz))<0) {
  143. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  144. return(FAILED);
  145. }
  146. }
  147. /*********************************************************************************************************************
  148. cmdline[0] 2 vals ACTIVE
  149. TK (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  150. CMDLINE (more-infiles) (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  151. 1 val
  152. *********************************************************************************************************************/
  153. if((exit_status = handle_extra_infiles(&cmdline,&cmdlinecnt,dz))<0) {
  154. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  155. return(FAILED);
  156. }
  157. /*********************************************************************************************************************
  158. cmdline[0] 2 ACTIVE
  159. TK (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  160. CMDLINE (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  161. 1
  162. *********************************************************************************************************************/
  163. if((exit_status = handle_outfile(&cmdlinecnt,&cmdline,is_launched,dz))<0) {
  164. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  165. return(FAILED);
  166. }
  167. /****************************************************************************************
  168. cmdline[0] ACTIVE
  169. TK (flag val) (formantsqksrch) (special) params options variant-params flags
  170. CMDLINE (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  171. *****************************************************************************************/
  172. if((exit_status = handle_formants(&cmdlinecnt,&cmdline,dz))<0) {
  173. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  174. return(FAILED);
  175. }
  176. if((exit_status = handle_formant_quiksearch(&cmdlinecnt,&cmdline,dz))<0) {
  177. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  178. return(FAILED);
  179. }
  180. if((exit_status = handle_special_data(&cmdlinecnt,&cmdline,dz))<0) {
  181. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  182. return(FAILED);
  183. }
  184. /****************************************************************************************
  185. cmdline[0]
  186. TK active_params options variant-params flags
  187. CMDLINE active_params POSSIBLY POSSIBLY POSSIBLY
  188. *****************************************************************************************/
  189. if((exit_status = read_parameters_and_flags(&cmdline,&cmdlinecnt,dz))<0) {
  190. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  191. return(FAILED);
  192. }
  193. if((exit_status = check_param_validity_and_consistency(dz))<0) {
  194. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  195. return(FAILED);
  196. }
  197. is_launched = TRUE;
  198. if((exit_status = allocate_large_buffers(dz))<0){
  199. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  200. return(FAILED);
  201. }
  202. if((exit_status = param_preprocess(dz))<0){
  203. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  204. return(FAILED);
  205. }
  206. if((exit_status = groucho_process_file(dz))<0) {
  207. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  208. return(FAILED);
  209. }
  210. if((exit_status = complete_output(dz))<0) {
  211. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  212. return(FAILED);
  213. }
  214. exit_status = print_messages_and_close_sndfiles(FINISHED,is_launched,dz);
  215. free(dz);
  216. return(SUCCEEDED);
  217. }
  218. // TW MULTICHAN 2010
  219. /***************************** SETUP_INTERNAL_ARRAYS_AND_ARRAY_POINTERS_FOR_LPHP **************************/
  220. int setup_internal_arrays_and_array_pointers_for_lphp(dataptr dz)
  221. {
  222. int n;
  223. dz->array_cnt = 3 + (FLT_LPHP_ARRAYS_PER_FILTER * dz->infile->channels);
  224. if((dz->parray = (double **)malloc(dz->array_cnt * sizeof(double *)))==NULL) {
  225. sprintf(errstr,"INSUFFICIENT MEMORY for internal double arrays.\n");
  226. return(MEMORY_ERROR);
  227. }
  228. for(n=0;n<dz->array_cnt;n++)
  229. dz->parray[n] = NULL;
  230. return(FINISHED);
  231. }