globcon.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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 verison */
  22. #define SHORT_BUFFERS 1 /* RWD TODO: ??? */
  23. #define CHARBITSIZE (8) /* size of char in bits */
  24. /************************ ERROR HANDLING/RETURN **************/
  25. #define CONTINUE (1)
  26. #define FINISHED (0)
  27. #define GOAL_FAILED (-1) /* program succeeds, but users goal not achieved: e.g. find pitch */
  28. #define USER_ERROR (-2) /* program fails because wrong data, no data etc given by user */
  29. #define DATA_ERROR (-3) /* Data is unsuitable, incorrect or missing */
  30. #define MEMORY_ERROR (-4) /* program fails because ran out of, or mismanaged, memory */
  31. #define SYSTEM_ERROR (-5) /* failure to write to or truncate outfile: usually means H/D is full */
  32. #define PROGRAM_ERROR (-6) /* program fails because the programming is naff */
  33. #define USAGE_ONLY (-7) /* program interrogated for usage_message only */
  34. #define TK_USAGE (-8) /* program interrogated by TK for usage_message only */
  35. #define BAD_INFILECNT (-9) /* Bad infilecnt sent from TK at program testing stage */
  36. extern char errstr[];
  37. extern char warnstr[];
  38. extern char informstr[];
  39. extern char username[];
  40. extern int sloom;
  41. /* TW May 2001 */
  42. extern int sloombatch;
  43. extern int anal_infiles;
  44. extern int is_converted_to_stereo;
  45. /************************** GENERAL **************************/
  46. #ifndef FALSE
  47. #define FALSE (0)
  48. #endif
  49. #ifndef TRUE
  50. #define TRUE (1)
  51. #endif
  52. #define LAST (TRUE)
  53. #define MAX_PARAM_LEN (64)
  54. //#define MAX_CHANNELS (4) /* maximum number of SNDFILE channels */
  55. #define MAX_CHANNELS (16)
  56. #define MAX_MIX_CHANS (STEREO) /* maximum number of SNDFILE channels for mixing */
  57. /* PROBLEM : maxfloat applies only to PC and I'm not sure I got it right !! */
  58. /* RWD this is unix version */
  59. /* defined in math.h on unix platforms */
  60. #if defined _MSC_VER || defined __GNUC__
  61. # ifndef MAXFLOAT
  62. # define MAXFLOAT ((float)3.40282346638528860e+38)
  63. # endif
  64. #endif
  65. #define FLTERR (0.000002)
  66. /******************* UNIVERSAL CONSTANTS AND MACROS ***********************************/
  67. //#define MAX_SNDFILE_OUTCHANS (4) /* quad output, max for sndfiles, 1997 */
  68. //allow for double ADAT chancount!
  69. #define MAX_SNDFILE_OUTCHANS (16) /* quad output, max for sndfiles, 1997 */
  70. #define MIN_FRACTION_OF_LEVEL (1.0/32767.0)
  71. //TODO: need to add 96000 and 88200
  72. #define LEGAL_SRATE(x) ((x)==16000 || (x)==24000 || (x)==22050 || (x)==32000 || (x)==44100 || (x)==48000)
  73. #define ODD(x) ((x)&1)
  74. #define EVEN(x) (!ODD(x))
  75. #define MAXSAMP (32767)
  76. #define MINSAMP (-32768)
  77. #define ABSMAXSAMP (32768.0)
  78. //RWD floatsam versions
  79. #define F_MAXSAMP (1.0)
  80. #define F_MINSAMP (-1.0)
  81. #define F_ABSMAXSAMP F_MAXSAMP
  82. //RWD.7.99 for BRASSAGE/GRANULA
  83. //#define LFACTOR (sizeof(long) / sizeof(short))
  84. //or
  85. #define LFACTOR (1) /* RWD 4:2001 missing from tw2K verssion */
  86. #define MIN_DB_ON_16_BIT (-96.0)
  87. /* RWD define positive too! */
  88. #define MAX_DB_ON_16_BIT (96.0)
  89. #define MAXIMUM_SHORT (32767)
  90. #define ABSMAXIMUM_SHORT (32768.0)
  91. #define MINIMUM_SHORT (-32768)
  92. #define BIG_TIME (32767.0)
  93. #define BIGARRAY (200)
  94. #define FLTERR (0.000002)
  95. #define CHARSIZE (8)
  96. #define TWO_POW_15 (32768.0)
  97. #define TWO_POW_14 (16384)
  98. //RWD floatsam versions (???)
  99. #define F_TWO_POW_15 F_MAXSAMP
  100. #define F_TWO_POW_14 (F_MAXSAMP * 0.5)
  101. /* PROBLEM : maxfloat applies only to PC and I'm not sure I got it right !! */
  102. /******************* UNIVERSAL SPEC MACROS ***********************************/
  103. #define AMPP (vc) /* accesses an ampitude value in a float window */
  104. #define FREQ (vc+1) /* accesses a frequency value in a float window */
  105. /* PROBLEM : maxfloat applies only to PC and I'm not sure I got it right !! */
  106. #define SPAN_FACTOR (1.5)
  107. /******************* UNIVERSAL CONSTANTS AND MACROS ***********************************/
  108. /* RWD need this! */
  109. #ifndef PI
  110. #define PI (3.141592654)
  111. #define TWOPI (2.0 * PI)
  112. #endif
  113. #define ROOT_2 (1.414213562)
  114. #define ONE_OVER_LN2 (1.442695)
  115. #define LOG2(x) (log(x) * ONE_OVER_LN2)
  116. #define LOG10_OF_2 (0.301029995)
  117. #define ENDOFSTR ('\0')
  118. #define NEWLINE ('\n')
  119. #define SEMITONES_PER_OCTAVE (12.0)
  120. #define OCTAVES_PER_SEMITONE (0.08333333333)
  121. #define SEMITONE_INTERVAL (1.05946309436)
  122. #define SEMITONE_DOWN (0.9438743127)
  123. #define SEMITONES_AS_RATIO(x) (pow(SEMITONE_INTERVAL,(x)))
  124. #define VERY_TINY_VAL (0.00000000000000000001) /* 10^-20 */
  125. #define MINAMP (0.000000003)
  126. #define BIGAMP (10000.0)
  127. #define SPECIAL (0.00000000314159f) /* marker value for specbare chans */
  128. #define TIME_INTERVAL (0.05)
  129. #define MS_TO_SECS (0.001)
  130. #define SECS_TO_MS (1000.0)
  131. #define MINPITCH (9.0) /* Pitch (Hz) corresponding, approx, to MIDI 0 */
  132. #define LOW_A (6.875) /* Frequency of A below MIDI 0 */
  133. #ifndef MIDIMAX
  134. #define MIDIMAX (127) /* RWD 12:2003 written as doubles, but otherwise duplicates defs in columns.h */
  135. #define MIDIMIN (0)
  136. #endif
  137. #define MAXWAVELEN (.5) /* seconds: for distort type progs */
  138. #define MONO (1)
  139. #define STEREO (2)
  140. #define MU_MIN_DELAY (0.1)
  141. #define MU_MAX_DELAY (100.0)
  142. #define MU_MINTEMPO_DELAY (1.0)
  143. #define MU_MAXTEMPO_DELAY (2000.0)
  144. #define MU_MIN_TEMPO (30)
  145. #define MU_MAX_TEMPO (1000)
  146. /***************** CONSTANT CONNECTED WITH PITCHDATA *****/
  147. #define DEFAULT_NYQUIST (10000) /* Fudge to allow brkpnt pitchdata to be tested */
  148. /***************** CONSTANT CONNECTED WITH FORMANTS *****/
  149. #define MINFBANDVAL (1) /* min number of formant bands */
  150. #define LOW_OCTAVE_BANDS (4)
  151. #define DESCRIPTOR_DATA_BLOKS (2)
  152. /***************** CONSTANT CONNECTED WITH MIXFILES *****/
  153. #define MINPAN (-32767.0)
  154. #define MAXPAN (32767.0)
  155. #define PAN_LEFT (-1.0)
  156. #define PAN_RIGHT (1.0)
  157. #define PAN_CENTRE (0.0)
  158. #define MIX_MAXLINE (7)
  159. #define MIX_MIDLINE (5)
  160. #define MIX_MINLINE (4)
  161. #define MIX_NAMEPOS (0)
  162. #define MIX_TIMEPOS (1)
  163. #define MIX_CHANPOS (2)
  164. #define MIX_LEVELPOS (3)
  165. #define MIX_PANPOS (4)
  166. #define MIX_RLEVELPOS (5)
  167. #define MIX_RPANPOS (6)
  168. #define MIDDLE_C_MIDI (60)
  169. int get_word_from_string(char **p,char **q);
  170. int get_float_from_within_string(char **str,double *val);
  171. int flteq(double f1,double f2);
  172. void swap(double *d1, double *d2);
  173. void iiswap(int *d1, int *d2);
  174. double miditohz(double val);
  175. int hztomidi(double *midi,double hz);
  176. double unchecked_hztomidi(double hz);
  177. int get_leveldb(char *str,double *val);
  178. int get_level(char *thisword,double *level);
  179. int is_dB(char *str);
  180. double dbtogain(double val);
  181. int is_an_empty_line_or_a_comment(char *p);
  182. int is_a_comment(char *p);
  183. int is_an_empty_line(char *p);
  184. int float_array(float **q,int size);
  185. int first_param_greater_than_second(int paramno1,int paramno2,dataptr dz);
  186. int first_param_not_less_than_second(int paramno1,int paramno2,dataptr dz);
  187. int establish_additional_brktable(dataptr dz);
  188. void reset_filedata_counters(dataptr dz);
  189. int open_first_infile(char *filename,dataptr dz);
  190. int handle_other_infile(int fileno,char *filename,dataptr dz);
  191. int get_maxvalue_in_brktable(double *brkmax,int paramno,dataptr dz);
  192. int get_minvalue_in_brktable(double *brkmin,int paramno,dataptr dz);
  193. int establish_file_data_storage_for_mix(int filecnt,dataptr dz);
  194. int establish_bufptrs_and_extra_buffers(dataptr dz);
  195. int setup_internal_arrays_and_array_pointers(dataptr dz);
  196. int assign_process_logic(dataptr dz);
  197. void set_legal_infile_structure(dataptr dz);
  198. /* BUFFERS */
  199. int allocate_large_buffers(dataptr dz);
  200. int create_iterbufs(double maxpscat,dataptr dz);
  201. int create_drunk_buffers(dataptr dz);
  202. int get_maxvalue(int paramno,double *maxval,dataptr dz);
  203. int convert_time_and_vals_to_samplecnts(int paramno,dataptr dz);
  204. int convert_time_to_samplecnts(int paramno,dataptr dz);
  205. void delete_notes_here_and_beyond(noteptr startnote);
  206. int make_new_note(noteptr *thisnote);
  207. /* PCONSISTENCY in distinct files */
  208. int filter_pconsistency(dataptr dz);
  209. int granula_pconsistency(dataptr dz);
  210. int param_preprocess(dataptr dz);
  211. /* PREPROCESSING in distinct files */
  212. int distort_preprocess(dataptr dz);
  213. int distortenv_preprocess(dataptr dz);
  214. int distortmlt_preprocess(dataptr dz);
  215. int distortdiv_preprocess(dataptr dz);
  216. int distortshuf_preprocess(dataptr dz);
  217. int distortdel_preprocess(dataptr dz);
  218. int distortflt_preprocess(dataptr dz);
  219. int distorter_preprocess(int param1,int param2,int param3,dataptr dz);
  220. int texture_preprocess(dataptr dz);
  221. int zigzag_preprocess(dataptr dz);
  222. int loop_preprocess(dataptr dz);
  223. int scramble_preprocess(dataptr dz);
  224. int iterate_preprocess(dataptr dz);
  225. int drunk_preprocess(dataptr dz);
  226. int grain_preprocess(int gate_paramno,dataptr dz);
  227. int envel_preprocess(dataptr dz);
  228. int mix_preprocess(dataptr dz);
  229. int mixtwo_preprocess(dataptr dz);
  230. int mixcross_preprocess(dataptr dz);
  231. int get_inbetween_ratios(dataptr dz);
  232. int check_new_filename(char *filename,dataptr dz);
  233. int filter_preprocess(dataptr dz);
  234. int check_new_filename(char *filename,dataptr dz);
  235. void initialise_random_sequence(int seed_flagno,int seed_paramno,dataptr dz);
  236. /* SOUND INPUT-OUTPUT, TABLE READING AND GLOBAL FUNCS FOR PROCESSING */
  237. /*int read_bytes(char *bbuf,dataptr dz);*/
  238. int read_samps(float *bbuf,dataptr dz);
  239. int read_values_from_all_existing_brktables(double thistime,dataptr dz);
  240. int read_value_from_brktable(double thistime,int paramno,dataptr dz);
  241. /* spec */
  242. int get_totalamp(double *totalamp,float *sbuf,int wanted);
  243. int inner_loop(int *peakscore,int *descnt,int *in_start_portion,int *least,
  244. int *pitchcnt,int windows_in_buf,dataptr dz);
  245. int specbare(int *pitchcnt,dataptr dz);
  246. int normalise(double pre_totalamp,double post_totalamp,dataptr dz);
  247. int initialise_ring_vals(int thissize,double initial_amp,dataptr dz);
  248. int if_one_of_loudest_chans_store_in_ring(int vc,dataptr dz);
  249. int if_one_of_quietest_chans_store_in_ring(int vc,dataptr dz);
  250. int rearrange_ring_to_allow_new_entry_and_return_entry_address(chvptr *here,dataptr dz);
  251. int choose_bflagno_and_reset_mask_if_ness(int *bflagno,int cc,int *mask,int longpow2,int divmask);
  252. int move_data_into_appropriate_channel(int vc,int truevc,float thisamp,float thisfrq,dataptr dz);
  253. int move_data_into_some_appropriate_channel(int truevc,float thisamp,float thisfrq,dataptr dz);
  254. int construct_filter_envelope(int pkcnt_here,float *fbuf,dataptr dz);
  255. int spec_blur_and_bltr(dataptr dz);
  256. int get_amp_and_frq(float *floatbuf,dataptr dz);
  257. int put_amp_and_frq(float *floatbuf,dataptr dz);
  258. int get_amp(float *floatbuf,dataptr dz);
  259. int put_amp(float *floatbuf,dataptr dz);
  260. int get_statechanges(int avcnt,int scantableno,int avpitcharrayno,int statechangearrayno,
  261. double min_up_interval,double min_dn_interval,int datatype,dataptr dz);
  262. int rectify_frqs(float *floatbuf,dataptr dz);
  263. int advance_one_2fileinput_window(dataptr dz);
  264. int skip_or_special_operation_on_window_zero(dataptr dz);
  265. int move_along_formant_buffer(dataptr dz);
  266. int outer_twofileinput_loop(dataptr dz);
  267. int extract_formant_peaks2(int sl1param,int *thispkcnt,double lofrq_limit,double hifrq_limit,dataptr dz);
  268. int score_peaks(int *peakscore,int sl1_var,int stabl_var,dataptr dz);
  269. int collect_scores(int *cnt,int *descnt,dataptr dz);
  270. int sort_design(int no_of_design_elements,dataptr dz);
  271. int sort_equivalent_scores(int this_pkcnt,dataptr dz);
  272. int unscore_peaks(int *peakscore,dataptr dz);
  273. int specpfix(dataptr dz);
  274. int specrepitch(dataptr dz);
  275. /* filters */
  276. void get_coeffs1(int n,dataptr dz);
  277. void get_coeffs2(int n,dataptr dz);
  278. int file_has_invalid_startchar(char *filename);
  279. int file_has_reserved_extension(char *filename);
  280. int file_has_invalid_extension(char *filename);
  281. int derived_filetype(int filetype);
  282. int pvoc_preprocess(dataptr dz);
  283. int set_internalparam_data(const char *this_paramlist,aplptr ap);
  284. int convert_msecs_to_secs(int brktableno,dataptr dz);
  285. int establish_bottom_frqs_of_channels(dataptr dz);
  286. int establish_testtone_amps(dataptr dz);
  287. int setup_ring(dataptr dz);
  288. int setup_internal_bitflags(int bflag_array_no,int longpow,int divmask, dataptr dz);
  289. int log2_of_the_number_which_is_a_power_of_2(int *n,int k);
  290. int two_to_the_power_of(int k);
  291. int init_bitflags_to_zero(int bflag_array_no,dataptr dz);
  292. int setup_stability_arrays_and_constants(int stability_val,int sval_less_one,dataptr dz);
  293. int zero_sound_buffers(dataptr dz);
  294. int initialise_window_frqs(dataptr dz);
  295. int read_both_files(int *windows_in_buf,int *got,dataptr dz);
  296. int outer_loop(dataptr dz);
  297. int gen_amplitude_in_lo_half_filterband(double *thisamp,double thisfrq,double filt_centre_frq,dataptr dz);
  298. int gen_amplitude_in_hi_half_filterband(double *thisamp,double thisfrq,double filt_centre_frq,dataptr dz);
  299. int filter_band_test(dataptr dz);
  300. void convert_shiftp_vals(dataptr dz);
  301. int create_sndbufs(dataptr dz);
  302. int allocate_single_buffer(dataptr dz);
  303. int allocate_double_buffer(dataptr dz);
  304. int allocate_triple_buffer(dataptr dz);
  305. int allocate_single_buffer_plus_extra_pointer(dataptr dz);
  306. int lcm_for_buffers(unsigned int *lcm,int a,int b);
  307. int allocate_analdata_plus_formantdata_buffer(dataptr dz);
  308. int calculate_analdata_plus_formantdata_buffer(unsigned int *buffersize,dataptr dz);
  309. int get_process_no(char *prog_identifier_from_cmdline,dataptr dz);
  310. int get_mode_from_cmdline(char *str,dataptr dz);
  311. int get_process_no(char *prog_identifier_from_cmdline,dataptr dz);
  312. int establish_spec_bufptrs_and_extra_buffers(dataptr dz);
  313. void setup_process_logic(int input,int process,int output,dataptr dz);
  314. int do_the_bltr(int *last_total_windows,float *ampdif,float *freqdif,int blurfactor,dataptr dz);
  315. void handle_pitch_zeros(dataptr dz);
  316. int check_depth_vals(int param_no,dataptr dz);
  317. void rectify_window(float *flbuf,dataptr dz);
  318. int get_longer_file(dataptr dz);
  319. //TW UPDATE
  320. //int keep_excess_bytes_from_correct_file(int *bytes_to_write,int file_to_keep,int got,int wc,dataptr dz);
  321. int keep_excess_samps_from_correct_file(int *bytes_to_write,int file_to_keep,int got,int wc,dataptr dz);
  322. int read_either_file(int *bytes_read,int file_to_keep,dataptr dz);
  323. int sound_loom_in_use(int *argc, char **argv[]);
  324. /* TEST ONLY */
  325. int x(int y);
  326. #define MAX_CYCLECNT (32767.0) /* arbitrary */
  327. #define MAX_GRS_HVELOCITY (32767.0) /* max when using shorts, so has to be max */
  328. #define BIG_VALUE (32767.0) /* arbitrary */
  329. #define NOT_PITCH (-1.0)
  330. #define NOT_SOUND (-2.0)
  331. //TW FLOAT REVISIONS
  332. /* replace MAXSAMP by a maximum range value, where it is used only for this purpose */
  333. #define MAXRANGE (32767)
  334. #define MINRANGE (-32768)