main.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 <synth.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. char errstr[2400];
  39. int sloom = 0;
  40. int sloombatch = 0;
  41. int anal_infiles = 0;
  42. int is_converted_to_stereo = -1;
  43. /**************************************** MAIN *********************************************/
  44. /* RWD N0v 2011: removed bad call to sndsetbuf, caused synth spectra to fail */
  45. /* TODO: fix malloc of dz->ifd array - default is one channel, but this code tries to use two. */
  46. /* RWD 22/02/2018 fixed output interleave (glitch on ch 2),
  47. replaced hamming with vonhann window in pvoc for clean frame transitions
  48. bumped version number
  49. */
  50. const char* cdp_version = "7.1.1";
  51. int main(int argc,char *argv[])
  52. {
  53. int exit_status;
  54. // FILE *fp = NULL;
  55. dataptr dz = NULL;
  56. char **cmdline;
  57. int cmdlinecnt;
  58. // aplptr ap;
  59. int *valid = NULL;
  60. int is_launched = FALSE;
  61. int validcnt;
  62. /* CHECK FOR SOUNDLOOM */
  63. //TW UPDATE
  64. if((argc==2) && strcmp(argv[1],"--version")==0) {
  65. fprintf(stdout,"%s\n",cdp_version);
  66. fflush(stdout);
  67. return 0;
  68. }
  69. if((sloom = sound_loom_in_use(&argc,&argv)) > 1) {
  70. sloom = 0;
  71. sloombatch = 1;
  72. }
  73. if(!sloom) {
  74. if((exit_status = allocate_and_initialise_validity_flags(&valid,&validcnt))<0) {
  75. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  76. return(FAILED);
  77. }
  78. }
  79. if(sflinit("cdp")){
  80. sfperror("cdp: initialisation\n");
  81. return(FAILED);
  82. }
  83. /* SET UP THE PRINCIPLE DATASTRUCTURE */
  84. if((exit_status = establish_datastructure(&dz))<0) {
  85. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  86. return(FAILED);
  87. }
  88. if(!sloom) {
  89. /* INITIAL CHECK OF CMDLINE DATA */
  90. if((exit_status = make_initial_cmdline_check(&argc,&argv))<0) {
  91. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  92. return(FAILED);
  93. }
  94. cmdline = argv; /* GET PRE_DATA, ALLOCATE THE APPLICATION, CHECK FOR EXTRA INFILES */
  95. cmdlinecnt = argc;
  96. if((exit_status = get_process_and_mode_from_cmdline(&cmdlinecnt,&cmdline,dz))<0) {
  97. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  98. return(FAILED);
  99. }
  100. if((exit_status = setup_particular_application(dz))<0) {
  101. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  102. return(FAILED);
  103. }
  104. if((exit_status = count_and_allocate_for_infiles(cmdlinecnt,cmdline,dz))<0) {
  105. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  106. return(FAILED);
  107. }
  108. } else {
  109. if((exit_status = parse_tk_data(argc,argv,&cmdline,&cmdlinecnt,dz))<0) { /* includes setup_particular_application() */
  110. exit_status = print_messages_and_close_sndfiles(exit_status,is_launched,dz);/* and cmdlinelength check = sees extra-infiles */
  111. return(exit_status);
  112. }
  113. }
  114. // ap = dz->application;
  115. /*********************************************************************************************************************
  116. cmdline[0] 2 vals ACTIVE
  117. TK (infile) (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  118. CMDLINE (infile) (more-infiles) (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  119. 1 val
  120. *********************************************************************************************************************/
  121. if((exit_status = setup_param_ranges_and_defaults(dz))<0) {
  122. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  123. return(FAILED);
  124. }
  125. /*********************************************************************************************************************
  126. cmdline[0] 2 vals ACTIVE
  127. TK (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  128. CMDLINE (more-infiles) (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  129. 1 val
  130. *********************************************************************************************************************/
  131. if((exit_status = handle_extra_infiles(&cmdline,&cmdlinecnt,dz))<0) {
  132. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  133. return(FAILED);
  134. }
  135. /*********************************************************************************************************************
  136. cmdline[0] 2 ACTIVE
  137. TK (outfile) (flag val) (formantsqksrch) (special) params options variant-params flags
  138. CMDLINE (outfile) (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  139. 1
  140. *********************************************************************************************************************/
  141. if((exit_status = handle_outfile(&cmdlinecnt,&cmdline,is_launched,dz))<0) {
  142. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  143. return(FAILED);
  144. }
  145. /****************************************************************************************
  146. cmdline[0] ACTIVE
  147. TK (flag val) (formantsqksrch) (special) params options variant-params flags
  148. CMDLINE (formants) (formantsqksrch) (special) params POSSIBLY POSSIBLY POSSIBLY
  149. *****************************************************************************************/
  150. if((exit_status = handle_formants(&cmdlinecnt,&cmdline,dz))<0) {
  151. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  152. return(FAILED);
  153. }
  154. if((exit_status = handle_formant_quiksearch(&cmdlinecnt,&cmdline,dz))<0) {
  155. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  156. return(FAILED);
  157. }
  158. if((exit_status = handle_special_data(&cmdlinecnt,&cmdline,dz))<0) {
  159. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  160. return(FAILED);
  161. }
  162. /****************************************************************************************
  163. cmdline[0]
  164. TK active_params options variant-params flags
  165. CMDLINE active_params POSSIBLY POSSIBLY POSSIBLY
  166. *****************************************************************************************/
  167. if((exit_status = read_parameters_and_flags(&cmdline,&cmdlinecnt,dz))<0) {
  168. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  169. return(FAILED);
  170. }
  171. if((exit_status = check_param_validity_and_consistency(dz))<0) {
  172. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  173. return(FAILED);
  174. }
  175. is_launched = TRUE;
  176. if((exit_status = allocate_large_buffers(dz))<0){
  177. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  178. return(FAILED);
  179. }
  180. if((exit_status = param_preprocess(dz))<0){
  181. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  182. return(FAILED);
  183. }
  184. if((exit_status = groucho_process_file(dz))<0) {
  185. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  186. return(FAILED);
  187. }
  188. if((exit_status = complete_output(dz))<0) {
  189. print_messages_and_close_sndfiles(exit_status,is_launched,dz);
  190. return(FAILED);
  191. }
  192. exit_status = print_messages_and_close_sndfiles(FINISHED,is_launched,dz);
  193. /* RWD we MUST free all allocs */
  194. /*free(dz);*/
  195. superfree(dz);
  196. return(SUCCEEDED);
  197. }