writedata.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  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 <tkglobals.h>
  25. #include <processno.h>
  26. #include <modeno.h>
  27. #include <filtcon.h>
  28. #include <cdpmain.h>
  29. #include <globcon.h>
  30. #include <logic.h>
  31. #include <standalone.h>
  32. #include <pnames.h>
  33. #include <sfsys.h>
  34. //TW ADDED
  35. #include <limits.h>
  36. //#ifdef unix
  37. #define round(x) lround((x))
  38. //#endif
  39. static int set_output_header_properties(dataptr dz);
  40. static int pt_datareduce(double **q,double sharp,double flat,double *thisarray,int *bsize);
  41. static int incremental_pt_datareduction(int array_no,int *bsize,double sharpness,dataptr dz);
  42. /* OTHER */
  43. static int print_screen_message(void);
  44. /* AUGUST 2000 */
  45. unsigned int superzargo;
  46. /***************************** COMPLETE_OUTPUT *******************************/
  47. int complete_output(dataptr dz)
  48. {
  49. if(dz->process_type==PITCH_TO_PITCH || dz->process_type==PITCH_TO_BIGPITCH) {
  50. if(dz->is_transpos)
  51. dz->outfiletype = TRANSPOS_OUT;
  52. else
  53. dz->outfiletype = PITCH_OUT;
  54. }
  55. switch(dz->process_type) {
  56. case(UNEQUAL_SNDFILE):
  57. case(BIG_ANALFILE):
  58. case(UNEQUAL_ENVFILE):
  59. case(CREATE_ENVFILE):
  60. case(EXTRACT_ENVFILE):
  61. case(PITCH_TO_ANAL):
  62. case(ANAL_TO_FORMANTS):
  63. case(PITCH_TO_BIGPITCH):
  64. case(PSEUDOSNDFILE):
  65. //TW No longer used:
  66. // if((exit_status = truncate_outfile(dz))<0)
  67. // return(exit_status);
  68. /* fall thro */
  69. case(EQUAL_ANALFILE):
  70. case(MAX_ANALFILE):
  71. case(MIN_ANALFILE):
  72. case(EQUAL_FORMANTS):
  73. case(EQUAL_SNDFILE):
  74. case(EQUAL_ENVFILE):
  75. case(PITCH_TO_PITCH):
  76. case(PITCH_TO_PSEUDOSND):
  77. return headwrite(dz->ofd,dz);
  78. break;
  79. case(SCREEN_MESSAGE):
  80. return print_screen_message();
  81. case(ANAL_TO_PITCH):
  82. sprintf(errstr,"ANAL_TO_PITCH process_type (%d) in complete_output()\n",dz->process_type);
  83. return(PROGRAM_ERROR);
  84. case(TO_TEXTFILE):
  85. if(fclose(dz->fp)<0) {
  86. fprintf(stdout,"WARNING: Failed to close output textfile.\n");
  87. fflush(stdout);
  88. }
  89. break;
  90. case(OTHER_PROCESS):
  91. break;
  92. default:
  93. sprintf(errstr,"Unknown process_type (%d) in complete_output()\n",dz->process_type);
  94. return(PROGRAM_ERROR);
  95. }
  96. return(FINISHED);
  97. }
  98. /***************************** TRUNCATE_OUTFILE *******************************/
  99. #ifdef NOTDEF
  100. int truncate_outfile(dataptr dz)
  101. {
  102. if(sfadjust(dz->ofd,dz->total_bytes_written - dz->outfilesize)<0) {
  103. sprintf(errstr,"Cannot truncate output file (Is hard-disk full?).\n");
  104. return(SYSTEM_ERROR);
  105. }
  106. return(FINISHED);
  107. }
  108. #endif
  109. /***************************** HEADWRITE *******************************/
  110. int headwrite(int ofd,dataptr dz)
  111. {
  112. int exit_status;
  113. int isenv = 1;
  114. int property_marker = 1;
  115. // int samptype, srate, channels;
  116. float window_size = 0.0f;
  117. if(!(dz->process == PVOC_ANAL || dz->process == PVOC_EXTRACT || dz->process == PVOC_SYNTH)) {
  118. if((exit_status = set_output_header_properties(dz))<0)
  119. return(exit_status);
  120. }
  121. switch(dz->outfiletype) {
  122. case(FORMANTS_OUT):
  123. if(sndputprop(ofd,"specenvcnt", (char *)&(dz->outfile->specenvcnt), sizeof(int)) < 0){
  124. sprintf(errstr,"Failure to write specenvcnt: headwrite()\n");
  125. return(PROGRAM_ERROR);
  126. }
  127. /* drop through */
  128. case(PITCH_OUT):
  129. case(TRANSPOS_OUT):
  130. if(sndputprop(ofd,"orig channels", (char *)&(dz->outfile->origchans), sizeof(int)) < 0){
  131. sprintf(errstr,"Failure to write original channel data: headwrite()\n");
  132. return(PROGRAM_ERROR);
  133. }
  134. /* drop through */
  135. case(ANALFILE_OUT):
  136. if(sndputprop(ofd,"original sampsize", (char *)&(dz->outfile->origstype), sizeof(int)) < 0){
  137. sprintf(errstr,"Failure to write original sample size. headwrite()\n");
  138. return(PROGRAM_ERROR);
  139. }
  140. if(sndputprop(ofd,"original sample rate", (char *)&(dz->outfile->origrate), sizeof(int)) < 0){
  141. sprintf(errstr,"Failure to write original sample rate. headwrite()\n");
  142. return(PROGRAM_ERROR);
  143. }
  144. if(sndputprop(ofd,"arate",(char *)&(dz->outfile->arate),sizeof(float)) < 0){
  145. sprintf(errstr,"Failed to write analysis sample rate. headwrite()\n");
  146. return(PROGRAM_ERROR);
  147. }
  148. if(sndputprop(ofd,"analwinlen",(char *)&(dz->outfile->Mlen),sizeof(int)) < 0){
  149. sprintf(errstr,"Failure to write analysis window length. headwrite()\n");
  150. return(PROGRAM_ERROR);
  151. }
  152. if(sndputprop(ofd,"decfactor",(char *)&(dz->outfile->Dfac),sizeof(int)) < 0){
  153. sprintf(errstr,"Failure to write decimation factor. headwrite()\n");
  154. return(PROGRAM_ERROR);
  155. }
  156. /* drop through */
  157. case(SNDFILE_OUT):
  158. //TW these properties can either be created at the outset (sndcreat_formatted()
  159. // in which case they are not alterable here.
  160. // or they can be left open (sndcreat e.g. for PITCH, or CUT for dz->otherfile)
  161. sndputprop(ofd,"sample rate", (char *)&(dz->outfile->srate), sizeof(int));
  162. sndputprop(ofd,"channels", (char *)&(dz->outfile->channels), sizeof(int));
  163. break;
  164. case(ENVFILE_OUT):
  165. // samptype = SAMP_FLOAT;
  166. // srate = round(SECS_TO_MS/dz->outfile->window_size);
  167. // channels = 1;
  168. window_size = dz->outfile->window_size;
  169. /* JUNE 2004
  170. if(sndputprop(ofd,"sample rate", (char *)&srate, sizeof(int)) < 0){
  171. sprintf(errstr,"Failure to write sample rate. headwrite()\n");
  172. return(PROGRAM_ERROR);
  173. }
  174. if(sndputprop(ofd,"channels", (char *)&channels, sizeof(int)) < 0){
  175. sprintf(errstr,"Failure to write channel data. headwrite()\n");
  176. return(PROGRAM_ERROR);
  177. }
  178. */
  179. if(sndputprop(ofd,"is an envelope",(char *)&isenv, sizeof(int)) < 0){
  180. sprintf(errstr,"Failure to write envelope property. headwrite()\n");
  181. return(PROGRAM_ERROR);
  182. }
  183. if(sndputprop(ofd,"window size", (char *)(&window_size), sizeof(float)) < 0) {
  184. sprintf(errstr,"Failure to write window size. headwrite()\n");
  185. return(DATA_ERROR);
  186. }
  187. break;
  188. default:
  189. sprintf(errstr,"Unknown outfile type: headwrite()\n");
  190. return(PROGRAM_ERROR);
  191. }
  192. switch(dz->outfiletype) {
  193. case(PITCH_OUT):
  194. if(sndputprop(ofd,"is a pitch file", (char *)&property_marker, sizeof(int)) < 0){
  195. sprintf(errstr,"Failure to write pitch property: headwrite()\n");
  196. return(PROGRAM_ERROR);
  197. }
  198. break;
  199. case(TRANSPOS_OUT):
  200. if(sndputprop(ofd,"is a transpos file", (char *)&property_marker, sizeof(int)) < 0){
  201. sprintf(errstr,"Failure to write transposition property: headwrite()\n");
  202. return(PROGRAM_ERROR);
  203. }
  204. break;
  205. case(FORMANTS_OUT):
  206. if(sndputprop(ofd,"is a formant file", (char *)&property_marker, sizeof(int)) < 0){
  207. sprintf(errstr,"Failure to write formant property: headwrite()\n");
  208. return(PROGRAM_ERROR);
  209. }
  210. break;
  211. }
  212. return(FINISHED);
  213. }
  214. /***************************** SET_OUTPUT_HEADER_PROPERTIES ******************************/
  215. int set_output_header_properties(dataptr dz)
  216. {
  217. switch(dz->process_type) {
  218. case(EQUAL_SNDFILE):
  219. case(UNEQUAL_SNDFILE):
  220. case(EQUAL_ENVFILE):
  221. case(UNEQUAL_ENVFILE):
  222. dz->outfile->channels = dz->infile->channels;
  223. dz->outfile->srate = dz->infile->srate;
  224. dz->outfile->stype = dz->infile->stype;
  225. break;
  226. case(EXTRACT_ENVFILE):
  227. case(CREATE_ENVFILE):
  228. break;
  229. case(PSEUDOSNDFILE): /* Assumption of conversion from anal,formant,pitch or transpos filetype */
  230. case(PITCH_TO_PSEUDOSND):
  231. dz->outfile->channels = 1;
  232. dz->outfile->srate = dz->infile->origrate;
  233. dz->outfile->stype = SAMP_SHORT;
  234. break;
  235. case(ANAL_TO_FORMANTS):
  236. dz->outfile->specenvcnt= dz->infile->specenvcnt;
  237. /* fall through */
  238. case(ANAL_TO_PITCH):
  239. dz->outfile->origchans = dz->infile->channels;
  240. dz->outfile->channels = 1;
  241. dz->outfile->origstype = dz->infile->origstype;
  242. dz->outfile->origrate = dz->infile->origrate;
  243. dz->outfile->arate = dz->infile->arate;
  244. dz->outfile->Mlen = dz->infile->Mlen;
  245. dz->outfile->Dfac = dz->infile->Dfac;
  246. dz->outfile->srate = dz->infile->srate;
  247. dz->outfile->stype = dz->infile->stype;
  248. break;
  249. case(EQUAL_FORMANTS):
  250. dz->outfile->specenvcnt = dz->infile->specenvcnt;
  251. /* fall through */
  252. case(PITCH_TO_PITCH):
  253. case(PITCH_TO_BIGPITCH):
  254. dz->outfile->origchans = dz->infile->origchans;
  255. /* fall through */
  256. case(EQUAL_ANALFILE):
  257. case(MAX_ANALFILE):
  258. case(MIN_ANALFILE):
  259. case(BIG_ANALFILE):
  260. case(PITCH_TO_ANAL):
  261. dz->outfile->origstype = dz->infile->origstype;
  262. dz->outfile->origrate = dz->infile->origrate;
  263. dz->outfile->arate = dz->infile->arate;
  264. dz->outfile->Mlen = dz->infile->Mlen;
  265. dz->outfile->Dfac = dz->infile->Dfac;
  266. dz->outfile->srate = dz->infile->srate;
  267. dz->outfile->stype = dz->infile->stype;
  268. if(dz->process_type==PITCH_TO_ANAL)
  269. dz->outfile->channels = dz->infile->origchans;
  270. else
  271. dz->outfile->channels = dz->infile->channels;
  272. break;
  273. case(TO_TEXTFILE):
  274. case(SCREEN_MESSAGE):
  275. break;
  276. default:
  277. sprintf(errstr,"Unknown process: set_output_header_properties()\n");
  278. return(PROGRAM_ERROR);
  279. }
  280. return(FINISHED);
  281. }
  282. /***************************** WRITE_EXACT_SAMPS ******************************
  283. *
  284. * Writes a block of known length to file area of same length.
  285. * Checks it has all been written.
  286. */
  287. #ifdef NOTDEF
  288. int write_exact_bytes(char *buffer,int bytes_to_write,dataptr dz)
  289. {
  290. int pseudo_bytes_to_write = bytes_to_write;
  291. int secs_to_write = bytes_to_write/SECSIZE;
  292. int bytes_written;
  293. if((secs_to_write * SECSIZE)!=bytes_to_write) {
  294. secs_to_write++;
  295. pseudo_bytes_to_write = secs_to_write * SECSIZE;
  296. }
  297. if((bytes_written = sfwrite(dz->ofd, buffer, pseudo_bytes_to_write))<0) {
  298. sprintf(errstr, "Can't write to output soundfile: (is hard-disk full?).\n");
  299. return(SYSTEM_ERROR);
  300. }
  301. if(bytes_written != bytes_to_write) {
  302. sprintf(errstr, "Incorrect number of bytes written\nbytes_written = %ld\n"
  303. "bytes_to_write = %ld\n (is hard-disk full?).\n",
  304. bytes_written,bytes_to_write);
  305. return(SYSTEM_ERROR);
  306. }
  307. dz->total_bytes_written += bytes_to_write;
  308. display_virtual_time(dz->total_bytes_written,dz);
  309. return(FINISHED);
  310. }
  311. #else
  312. int write_exact_samps(float *buffer,int samps_to_write,dataptr dz)
  313. {
  314. int i,j;
  315. int samps_written;
  316. float val;
  317. if(dz->needpeaks){
  318. for(i=0;i < samps_to_write; i += dz->outchans){
  319. for(j = 0;j < dz->outchans;j++){
  320. val = (float)fabs(buffer[i+j]);
  321. /* this way, posiiton of first peak value is stored */
  322. if(val > dz->outpeaks[j].value){
  323. dz->outpeaks[j].value = val;
  324. dz->outpeaks[j].position = dz->outpeakpos[j];
  325. }
  326. }
  327. /* count framepos */
  328. for(j=0;j < dz->outchans;j++)
  329. dz->outpeakpos[j]++;
  330. }
  331. }
  332. if((samps_written = fputfbufEx(buffer, samps_to_write,dz->ofd))<=0) {
  333. sprintf(errstr, "Can't write to output soundfile: %s\n",sferrstr());
  334. return(SYSTEM_ERROR);
  335. }
  336. if(samps_written != samps_to_write) {
  337. sprintf(errstr, "Incorrect number of samples written\nsamps_written = %d\n"
  338. "samps_to_write = %d\n (is hard-disk full?).\n",
  339. samps_written,samps_to_write);
  340. return(SYSTEM_ERROR);
  341. }
  342. dz->total_samps_written += samps_to_write;
  343. display_virtual_time(dz->total_samps_written,dz);
  344. return(FINISHED);
  345. }
  346. #endif
  347. #ifdef NOTDEF
  348. /*************************** WRITE_SAMPS ***********************/
  349. int write_bytes(char *bbuf,int bytes_to_write,dataptr dz)
  350. {
  351. int pseudo_bytes_to_write = bytes_to_write;
  352. int secs_to_write = bytes_to_write/SECSIZE;
  353. int bytes_written;
  354. if((secs_to_write * SECSIZE)!=bytes_to_write) {
  355. secs_to_write++;
  356. pseudo_bytes_to_write = secs_to_write * SECSIZE;
  357. }
  358. if((bytes_written = sfwrite(dz->ofd,bbuf,pseudo_bytes_to_write))<0) {
  359. sprintf(errstr,"Can't write to output soundfile: (is hard-disk full?).\n");
  360. return(SYSTEM_ERROR);
  361. }
  362. dz->total_bytes_written += bytes_to_write;
  363. dz->total_samps_written = dz->total_bytes_written/sizeof(short); /* IRRELEVANT TO SPEC */
  364. display_virtual_time(dz->total_bytes_written,dz);
  365. return(FINISHED);
  366. }
  367. #else
  368. int write_samps(float *bbuf,int samps_to_write,dataptr dz)
  369. {
  370. int samps_written;
  371. int i,j;
  372. float val;
  373. if(dz->needpeaks){
  374. for(i=0;i < samps_to_write; i += dz->outchans){
  375. for(j = 0;j < dz->outchans;j++){
  376. val = (float)fabs(bbuf[i+j]);
  377. /* this way, posiiton of first peak value is stored */
  378. if(val > dz->outpeaks[j].value){
  379. dz->outpeaks[j].value = val;
  380. dz->outpeaks[j].position = dz->outpeakpos[j];
  381. }
  382. }
  383. /* count framepos */
  384. for(j=0;j < dz->outchans;j++)
  385. dz->outpeakpos[j]++;
  386. }
  387. }
  388. if((samps_written = fputfbufEx(bbuf,samps_to_write,dz->ofd))<=0) {
  389. sprintf(errstr,"Can't write to output soundfile: %s\n",sferrstr());
  390. return(SYSTEM_ERROR);
  391. }
  392. dz->total_samps_written += samps_written;
  393. display_virtual_time(dz->total_samps_written,dz);
  394. return(FINISHED);
  395. }
  396. #endif
  397. /*************************** WRITE_SAMPS_NO_REPORT ***********************/
  398. #ifdef NOTDEF
  399. int write_bytes_no_report(char *bbuf,int bytes_to_write,dataptr dz)
  400. {
  401. int pseudo_bytes_to_write = bytes_to_write;
  402. int secs_to_write = bytes_to_write/SECSIZE;
  403. int bytes_written;
  404. if((secs_to_write * SECSIZE)!=bytes_to_write) {
  405. secs_to_write++;
  406. pseudo_bytes_to_write = secs_to_write * SECSIZE;
  407. }
  408. if((bytes_written = sfwrite(dz->ofd,bbuf,pseudo_bytes_to_write))<0) {
  409. sprintf(errstr,"Can't write to output soundfile: (is hard-disk full?).\n");
  410. return(SYSTEM_ERROR);
  411. }
  412. dz->total_bytes_written += bytes_to_write;
  413. dz->total_samps_written = dz->total_bytes_written/sizeof(short); /* IRRELEVANT TO SPEC */
  414. return(FINISHED);
  415. }
  416. #else
  417. int write_samps_no_report(float *bbuf,int samps_to_write,int *samps_written,dataptr dz)
  418. {
  419. int i;
  420. int j;
  421. float val;
  422. if(dz->needpeaks){
  423. for(i=0;i < samps_to_write; i += dz->outchans){
  424. for(j = 0;j < dz->outchans;j++){
  425. val = (float)fabs(bbuf[i+j]);
  426. /* this way, posiiton of first peak value is stored */
  427. if(val > dz->outpeaks[j].value){
  428. dz->outpeaks[j].value = val;
  429. dz->outpeaks[j].position = dz->outpeakpos[j];
  430. }
  431. }
  432. /* count framepos */
  433. for(j=0;j < dz->outchans;j++)
  434. dz->outpeakpos[j]++;
  435. }
  436. }
  437. if((*samps_written = fputfbufEx(bbuf,samps_to_write,dz->ofd))<=0) {
  438. sprintf(errstr,"Can't write to output soundfile: %s\n",sferrstr());
  439. return(SYSTEM_ERROR);
  440. }
  441. dz->total_samps_written += samps_to_write;
  442. return(FINISHED);
  443. }
  444. #endif
  445. /*********************** DISPLAY_VIRTUAL_TIME *********************/
  446. void display_virtual_time(int samps_sent,dataptr dz)
  447. {
  448. int mins;
  449. double secs = 0.0;
  450. int startwindow, endwindow, windows_to_write, total_samps_to_write = 0, maxlen, minlen, offset;
  451. unsigned int zargo = 0;
  452. int n, display_time;
  453. double float_time = 0.0;
  454. if(sloombatch)
  455. return;
  456. if(!sloom) {
  457. if(dz->process==HOUSE_COPY && dz->mode==COPYSF)
  458. secs = (double)samps_sent/(double)(dz->infile->srate * dz->infile->channels);
  459. else {
  460. switch(dz->outfiletype) {
  461. case(NO_OUTPUTFILE):
  462. if(dz->process==MIXMAX)
  463. secs = (double)samps_sent/(double)(dz->infile->srate * dz->infile->channels);
  464. else
  465. return;
  466. case(SNDFILE_OUT):
  467. secs = (double)samps_sent/(double)(dz->infile->srate * dz->infile->channels);
  468. break;
  469. case(ANALFILE_OUT):
  470. secs = (double)(samps_sent/dz->wanted) * dz->frametime;
  471. break;
  472. case(PITCH_OUT):
  473. case(TRANSPOS_OUT):
  474. secs = (double)(samps_sent) * dz->frametime;
  475. break;
  476. case(FORMANTS_OUT):
  477. secs = (double)((samps_sent - dz->descriptor_samps)/dz->infile->specenvcnt) * dz->frametime;
  478. break;
  479. case(ENVFILE_OUT):
  480. secs = (double)(samps_sent) * dz->outfile->window_size * MS_TO_SECS;
  481. break;
  482. case(TEXTFILE_OUT):
  483. switch(dz->process) {
  484. case(INFO_PRNTSND):
  485. secs = (double)samps_sent/(double)(dz->infile->srate * dz->infile->channels);
  486. break;
  487. }
  488. break;
  489. }
  490. }
  491. mins = (int)(secs/60.0); /* TRUNCATE */
  492. secs -= (double)(mins * 60);
  493. fprintf(stdout,"\r%d min %5.2lf sec", mins, secs);
  494. fflush(stdout);
  495. } else {
  496. switch(dz->process_type) {
  497. case(EQUAL_ANALFILE):
  498. float_time = min(1.0,(double)samps_sent/(double)dz->insams[0]);
  499. break;
  500. case(MAX_ANALFILE):
  501. switch(dz->process) {
  502. case(MAX): /* file 0 is forced to be largest by program */
  503. float_time = (double)samps_sent/(double)dz->insams[0];
  504. break;
  505. default:
  506. maxlen = dz->insams[0];
  507. for(n=1;n<dz->infilecnt;n++)
  508. maxlen = max(maxlen,dz->insams[n]);
  509. float_time = (double)samps_sent/(double)maxlen;
  510. break;
  511. }
  512. break;
  513. case(MIN_ANALFILE):
  514. minlen = dz->insams[0];
  515. for(n=1;n<dz->infilecnt;n++)
  516. minlen = min(minlen,dz->insams[n]);
  517. float_time = (double)samps_sent/(double)minlen;
  518. break;
  519. case(BIG_ANALFILE):
  520. switch(dz->process) {
  521. case(CUT):
  522. startwindow = (int)(dz->param[CUT_STIME]/dz->frametime);
  523. endwindow = (int)(dz->param[CUT_ETIME]/dz->frametime);
  524. endwindow = min(endwindow,dz->wlength);
  525. windows_to_write = endwindow - startwindow;
  526. total_samps_to_write = windows_to_write * dz->wanted;
  527. float_time = (double)samps_sent/(double)total_samps_to_write;
  528. break;
  529. case(GRAB):
  530. total_samps_to_write = dz->wanted;
  531. float_time = (double)samps_sent/(double)total_samps_to_write;
  532. break;
  533. case(MAGNIFY):
  534. windows_to_write = dz->total_windows + 1;
  535. total_samps_to_write = windows_to_write * dz->wanted;
  536. float_time = (double)samps_sent/(double)total_samps_to_write;
  537. break;
  538. case(TSTRETCH): case(SHUFFLE): case(WEAVE): case(WARP): case(FORM):
  539. float_time = (double)dz->total_samps_read/(double)dz->insams[0];
  540. break;
  541. case(DRUNK):
  542. total_samps_to_write = round((dz->param[DRNK_DUR]/dz->frametime) * dz->wanted);
  543. float_time = min((double)samps_sent/(double)total_samps_to_write,1.0);
  544. break;
  545. case(GLIDE):
  546. //TW total_samps_to_write = dz->wlength * dz->sampswanted;
  547. total_samps_to_write = dz->wlength * dz->wanted;
  548. float_time = (double)samps_sent/(double)total_samps_to_write;
  549. break;
  550. case(BRIDGE):
  551. offset = round(dz->param[BRG_OFFSET]/dz->frametime) * dz->wanted;
  552. switch(dz->iparam[BRG_TAILIS]) {
  553. case(0):
  554. case(1): total_samps_to_write = dz->insams[0]; break;
  555. case(2): total_samps_to_write = offset + dz->insams[1]; break;
  556. case(3): total_samps_to_write = min(dz->insams[0],offset + dz->insams[1]); break;
  557. }
  558. float_time = min(1.0,(double)samps_sent/(double)total_samps_to_write);
  559. break;
  560. case(MORPH):
  561. total_samps_to_write = (dz->iparam[MPH_STAGW] * dz->wanted) + dz->insams[1];
  562. float_time = min(1.0,(double)samps_sent/(double)total_samps_to_write);
  563. break;
  564. case(SYNTH_SPEC):
  565. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  566. break;
  567. case(CLICK):
  568. if(samps_sent < 0)
  569. samps_sent = INT_MAX;
  570. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  571. break;
  572. default:
  573. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  574. break;
  575. }
  576. break;
  577. case(ANAL_TO_FORMANTS):
  578. float_time = (double)dz->total_samps_read/(double)dz->insams[0];
  579. break;
  580. case(PSEUDOSNDFILE):
  581. switch(dz->process) {
  582. case(FMNTSEE):
  583. case(FORMSEE):
  584. case(LEVEL):
  585. float_time = (double)dz->total_samps_read/(double)dz->insams[0];
  586. break;
  587. }
  588. break;
  589. case(PITCH_TO_ANAL):
  590. switch(dz->process) {
  591. case(MAKE):
  592. //TW NEW CASE
  593. case(MAKE2):
  594. /* windows_to_write = dz->wlength, in this case based on specenvcnt-len formant-windows */
  595. total_samps_to_write = dz->wlength * (dz->infile->origchans);
  596. float_time = min(1.0,(double)samps_sent/(double)total_samps_to_write);
  597. break;
  598. //TW NEW CASES ADDED, therefore
  599. // case(P_HEAR):
  600. default:
  601. /* windows_to_write = dz->insams[0] as each pitch is converted to a window */
  602. total_samps_to_write = dz->insams[0] * dz->wanted;
  603. float_time = (double)samps_sent/(double)total_samps_to_write;
  604. break;
  605. }
  606. break;
  607. case(PITCH_TO_PSEUDOSND):
  608. total_samps_to_write = dz->insams[0];
  609. float_time = (double)samps_sent/(double)total_samps_to_write;
  610. break;
  611. case(UNEQUAL_SNDFILE):
  612. switch(dz->process) {
  613. case(DISTORT_AVG): case(DISTORT_MLT): case(DISTORT_DIV): case(DISTORT_HRM): case(DISTORT_FRC):
  614. case(DISTORT_REV): case(DISTORT_SHUF): case(DISTORT_RPT): case(DISTORT_INTP): case(DISTORT_DEL):
  615. case(DISTORT_RPL): case(DISTORT_TEL): case(DISTORT_FLT): case(DISTORT_PCH):
  616. //TW NEW CASE
  617. case(DISTORT_OVERLOAD): case(DISTORT_RPT2):
  618. case(GRAIN_OMIT): case(GRAIN_DUPLICATE): case(GRAIN_REORDER): case(GRAIN_REPITCH):
  619. case(GRAIN_RERHYTHM): case(GRAIN_REMOTIF): case(GRAIN_TIMEWARP):
  620. case(GRAIN_POSITION): case(GRAIN_ALIGN):
  621. float_time = min(1.0,(double)dz->total_samps_read/(double)dz->insams[0]);
  622. break;
  623. //TW NEW CASE
  624. case(DISTORT_PULSED):
  625. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  626. break;
  627. case(GRAIN_REVERSE):
  628. float_time = (double)dz->total_samps_written/(double)dz->insams[0];
  629. break;
  630. case(TOPNTAIL_CLICKS):
  631. float_time = min(1.0,(double)dz->total_samps_read/(double)dz->tempsize);
  632. break;
  633. case(DISTORT_INT):
  634. total_samps_to_write = (dz->insams[0] + dz->insams[1]) >> 1;/* averaged,as is bytes_read !! */
  635. float_time = min(1.0,(double)dz->total_samps_read/(double)total_samps_to_write);
  636. break;
  637. case(HF_PERM1): case(HF_PERM2):
  638. zargo = superzargo + samps_sent;
  639. float_time = min(1.0,(double)zargo/(double)dz->tempsize);
  640. break;
  641. case(SCRAMBLE):
  642. total_samps_to_write = dz->iparam[SCRAMBLE_OUTLEN];
  643. float_time = min(1.0,(double)samps_sent/(double)total_samps_to_write);
  644. break;
  645. case(DRUNKWALK):
  646. total_samps_to_write = dz->iparam[DRNK_TOTALDUR];
  647. float_time = min(1.0,(double)samps_sent/(double)total_samps_to_write);
  648. break;
  649. case(SIMPLE_TEX): case(TIMED): case(GROUPS): case(TGROUPS): case(DECORATED): case(PREDECOR):
  650. case(POSTDECOR): case(ORNATE): case(PREORNATE): case(POSTORNATE): case(MOTIFS): case(TMOTIFS):
  651. case(MOTIFSIN): case(TMOTIFSIN):
  652. total_samps_to_write = round(dz->param[TEXTURE_DUR] * dz->infile->srate) * STEREO;
  653. float_time = min(1.0,(double)samps_sent/(double)total_samps_to_write);
  654. break;
  655. case(TEX_MCHAN):
  656. total_samps_to_write = round(dz->param[TEXTURE_DUR] * dz->infile->srate) * dz->iparam[TEXTURE_OUTCHANS];
  657. float_time = min(1.0,(double)samps_sent/(double)total_samps_to_write);
  658. break;
  659. case(ENV_CURTAILING):
  660. total_samps_to_write =
  661. round(dz->param[ENV_ENDTIME] * dz->infile->srate) * dz->infile->channels;
  662. float_time = min(1.0,(double)samps_sent/(double)total_samps_to_write);
  663. break;
  664. case(ENV_IMPOSE): /* In these cases the 'bytes_sent' may be bytes_written or bytes_read */
  665. case(ENV_REPLACE):
  666. //TW NEW CASE
  667. case(ENV_PROPOR):
  668. float_time = (double)samps_sent/(double)dz->insams[0];
  669. break;
  670. case(ENV_PLUCK):
  671. float_time = min(1.0,(double)dz->total_samps_read/(double)dz->insams[0]);
  672. break;
  673. case(EQ): case(LPHP): case(FSTATVAR): case(FLTBANKN):
  674. //TW UPDATE
  675. case(FLTBANKU): case(FLTSWEEP): case(ALLPASS):
  676. total_samps_to_write = dz->insams[0] +
  677. (round(FLT_TAIL * (double)dz->infile->srate) * dz->infile->channels);
  678. float_time = (double)samps_sent/(double)total_samps_to_write;
  679. break;
  680. case(FLTBANKV):
  681. total_samps_to_write = dz->insams[0] +
  682. ( round(dz->param[FILT_TAILV] * (double)dz->infile->srate) * dz->infile->channels);
  683. float_time = (double)samps_sent/(double)total_samps_to_write;
  684. break;
  685. case(FLTITER):
  686. total_samps_to_write = dz->iparam[FLT_OUTDUR];
  687. float_time = min(1.0,(double)samps_sent/(double)total_samps_to_write);
  688. break;
  689. case(MIXCROSS):
  690. float_time = min(1.0,(double)samps_sent/(double)(dz->iparam[MCR_STAGGER] + dz->insams[1]));
  691. break;
  692. case(MIXINTERL):
  693. total_samps_to_write = dz->insams[0];
  694. for(n=0;n<dz->infilecnt;n++)
  695. total_samps_to_write = max(total_samps_to_write,dz->insams[n]);
  696. total_samps_to_write *= dz->infilecnt;
  697. float_time = min(1.0,(double)samps_sent/(double)total_samps_to_write);
  698. break;
  699. case(MIX):
  700. case(MIXMULTI):
  701. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  702. break;
  703. //TW NEW CASES
  704. case(HOUSE_BAKUP):
  705. case(SEQUENCER):
  706. case(SEQUENCER2):
  707. case(RRRR_EXTEND):
  708. case(CONVOLVE):
  709. case(BAKTOBAK):
  710. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  711. break;
  712. case(MOD_PITCH):
  713. float_time = min(1.0,(double)dz->total_samps_read/(double)dz->insams[0]);
  714. break;
  715. case(MOD_REVECHO):
  716. if(dz->mode==MOD_STADIUM)
  717. float_time = min(1.0,(double)samps_sent/(double)(dz->insams[0] * 2));
  718. else
  719. float_time = min(1.0,(double)samps_sent/(double)dz->insams[0]);
  720. break;
  721. case(MOD_SPACE):
  722. if(dz->mode==MOD_PAN)
  723. float_time = min(1.0,(double)dz->total_samps_read/(double)dz->insams[0]);
  724. else
  725. float_time = min(1.0,(double)samps_sent/(double)dz->insams[0]);
  726. break;
  727. //TW NEW CASE
  728. case(SCALED_PAN):
  729. float_time = min(1.0,(double)dz->total_samps_read/(double)dz->insams[0]);
  730. break;
  731. case(MOD_RADICAL):
  732. switch(dz->mode) {
  733. case(MOD_SCRUB):
  734. float_time = min(1.0,(double)dz->total_samps_written/(double)dz->iparam[SCRUB_TOTALDUR]);
  735. break;
  736. case(MOD_CROSSMOD):
  737. float_time = (double)samps_sent/(double)dz->tempsize;
  738. break;
  739. default:
  740. float_time = min(1.0,(double)samps_sent/(double)dz->insams[0]);
  741. break;
  742. }
  743. break;
  744. case(PVOC_SYNTH):
  745. case(EDIT_CUT): case(EDIT_CUTEND): case(EDIT_ZCUT): case(EDIT_EXCISE):
  746. case(EDIT_EXCISEMANY): case(EDIT_INSERT): case(EDIT_INSERTSIL): case(EDIT_JOIN):
  747. case(HOUSE_CHANS): case(HOUSE_ZCHANNEL): case(STOM): case(MTOS):
  748. case(ZIGZAG): case(LOOP): case(ITERATE): /* case(HOUSE_BAKUP): */
  749. case(DEL_PERM): case(DEL_PERM2): case(MIXTWO): case(MIXBALANCE):
  750. case(HOUSE_SPEC): case(SYNTH_SPEC): case(JOIN_SEQ): case(JOIN_SEQDYN):
  751. case(ACC_STREAM): case(ITERATE_EXTEND):
  752. case(STACK):
  753. case(SYNTH_WAVE):
  754. case(SYNTH_NOISE):
  755. case(SYNTH_SIL):
  756. case(MULTI_SYN):
  757. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  758. break;
  759. case(DOUBLETS):
  760. if(samps_sent < 0)
  761. samps_sent = INT_MAX;
  762. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  763. break;
  764. case(AUTOMIX): case(MIXMANY): case(EDIT_INSERT2):
  765. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  766. break;
  767. case(BRASSAGE):
  768. float_time = min(1.0,(double)dz->total_samps_read/(double)dz->insams[0]);
  769. break;
  770. case(TWIXT):
  771. case(SPHINX):
  772. float_time = min(1.0,(double)superzargo/(double)dz->tempsize);
  773. break;
  774. case(EDIT_CUTMANY):
  775. case(MANY_ZCUTS):
  776. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  777. break;
  778. case(GREV):
  779. float_time = min(1.0,(double)dz->total_samps_written/(double)dz->tempsize);
  780. break;
  781. default:
  782. float_time = min(1.0,(double)samps_sent/(double)dz->insams[0]);
  783. break;
  784. }
  785. break;
  786. case(EQUAL_SNDFILE):
  787. switch(dz->process) {
  788. case(HOUSE_CHANS):
  789. //TW NEW CASE
  790. case(TIME_GRID):
  791. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  792. break;
  793. //TW NEW CASE
  794. case(SHUDDER):
  795. float_time = min(1.0,(double)dz->total_samps_written/(double)dz->tempsize);
  796. break;
  797. case(MOD_RADICAL):
  798. if(dz->mode == MOD_SHRED) { /* based on number of shreds completed */
  799. /*RWD NB: SHRED_CNT was in bytes --- make sure it is now in samps */
  800. float_time = min(1.0,(double)samps_sent/(double)dz->iparam[SHRED_CNT]);
  801. }
  802. /* fall thro */
  803. default:
  804. float_time = min(1.0,(double)samps_sent/(double)dz->insams[0]);
  805. break;
  806. }
  807. break;
  808. case(EXTRACT_ENVFILE): /* In these cases the 'bytes_sent' is bytes_read */
  809. float_time = (double)samps_sent/(double)dz->insams[0];
  810. break;
  811. case(OTHER_PROCESS):
  812. switch(dz->process) {
  813. case(HOUSE_EXTRACT):
  814. case(HOUSE_GATE):
  815. float_time = (double)samps_sent/(double)dz->insams[0];
  816. break;
  817. case(MIXINBETWEEN):
  818. case(CYCINBETWEEN):
  819. total_samps_to_write = max(dz->insams[0],dz->insams[1]);
  820. float_time = (double)samps_sent/(double)total_samps_to_write;
  821. break;
  822. case(HOUSE_COPY):
  823. switch(dz->mode) {
  824. case(COPYSF):
  825. float_time = (double)samps_sent/(double)dz->insams[0];
  826. break;
  827. case(DUPL):
  828. superzargo += samps_sent;
  829. float_time = min(1.0,(double)superzargo/(double)dz->tempsize);
  830. break;
  831. }
  832. break;
  833. /* NEW */
  834. case(INFO_DIFF):
  835. float_time = min(1.0,(double)dz->total_samps_read/(double)dz->insams[0]);
  836. break;
  837. }
  838. break;
  839. case(TO_TEXTFILE):
  840. switch(dz->process) {
  841. case(INFO_PRNTSND):
  842. zargo = (dz->iparam[PRNT_END] - dz->iparam[PRNT_START]);
  843. float_time = min(1.0,(double)samps_sent/(double)zargo);
  844. break;
  845. case(HOUSE_EXTRACT):
  846. float_time = min(1.0,(double)samps_sent/(double)dz->insams[0]);
  847. break;
  848. case(GRAIN_GET):
  849. float_time = min(1.0,(double)dz->total_samps_read/(double)dz->insams[0]);
  850. break;
  851. }
  852. break;
  853. case(SCREEN_MESSAGE):
  854. switch(dz->process) {
  855. case(MIXMAX):
  856. case(FIND_PANPOS):
  857. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  858. break;
  859. }
  860. break;
  861. case(CREATE_ENVFILE):
  862. switch(dz->process) {
  863. case(ENVSYN):
  864. float_time = min(1.0,(double)samps_sent/(double)dz->tempsize);
  865. break;
  866. }
  867. }
  868. display_time = round(float_time * PBAR_LENGTH);
  869. fprintf(stdout,"TIME: %d\n",display_time);
  870. fflush(stdout);
  871. }
  872. }
  873. /***************************** PRINT_SCREEN_MESSAGE **************************/
  874. int print_screen_message(void)
  875. {
  876. if(!sloom && !sloombatch) /*TW May 2001 */
  877. fprintf(stdout,"%s",errstr);
  878. else
  879. splice_multiline_string(errstr,"INFO:");
  880. fflush(stdout);
  881. return(FINISHED);
  882. }
  883. /***************************** WRITE_SAMPS_TO_ELSEWHERE ******************************
  884. *
  885. * Allows bytes to be written to files other than standard outfile.
  886. * No byte-count checking.
  887. */
  888. #ifdef NOTDEF
  889. int write_bytes_to_elsewhere(int ofd, char *buffer,int bytes_to_write,dataptr dz)
  890. {
  891. int pseudo_bytes_to_write = bytes_to_write;
  892. int secs_to_write = bytes_to_write/SECSIZE;
  893. int bytes_written;
  894. if((secs_to_write * SECSIZE)!=bytes_to_write) {
  895. secs_to_write++;
  896. pseudo_bytes_to_write = secs_to_write * SECSIZE;
  897. }
  898. if((bytes_written = sfwrite(ofd, (char *)buffer, pseudo_bytes_to_write))<0) {
  899. sprintf(errstr, "Can't write to output soundfile: (is hard-disk full?).\n");
  900. return(SYSTEM_ERROR);
  901. }
  902. dz->total_bytes_written += bytes_to_write;
  903. return(FINISHED);
  904. }
  905. #else
  906. int write_samps_to_elsewhere(int ofd, float *buffer,int samps_to_write,dataptr dz)
  907. {
  908. int i,j;
  909. int samps_written;
  910. if(dz->needotherpeaks){
  911. for(i=0;i < samps_to_write; i += dz->otheroutchans){
  912. for(j = 0;j < dz->otheroutchans;j++){
  913. /* this way, posiiton of first peak value is stored */
  914. if(buffer[i+j] > dz->outpeaks[j].value){
  915. dz->otherpeaks[j].value = buffer[i+j];
  916. dz->otherpeaks[j].position = dz->otherpeakpos[j];
  917. }
  918. }
  919. /* count framepos */
  920. for(j=0;j < dz->otheroutchans;j++)
  921. dz->otherpeakpos[j]++;
  922. }
  923. }
  924. if((samps_written = fputfbufEx(buffer, samps_to_write,ofd))<=0) {
  925. sprintf(errstr, "Can't write to output soundfile: %s\n",sferrstr());
  926. return(SYSTEM_ERROR);
  927. }
  928. dz->total_samps_written += samps_to_write;
  929. return(FINISHED);
  930. }
  931. #endif
  932. /****************************** WRITE_BRKFILE *************************/
  933. int write_brkfile(FILE *fptext,int brklen,int array_no,dataptr dz)
  934. {
  935. int n;
  936. double *p = dz->parray[array_no];
  937. for(n=0;n<brklen;n++) {
  938. fprintf(fptext,"%lf \t%lf\n",*p,*(p+1));
  939. p += 2;
  940. }
  941. return(FINISHED);
  942. }
  943. /***************** CONVERT_PCH_OR_TRANSPOS_DATA_TO_BRKPNTTABLE ***********************/
  944. #define TONE_CENT (.01) /* SEMITONES */
  945. int convert_pch_or_transpos_data_to_brkpnttable(int *brksize,float *floatbuf,float frametime,int array_no,dataptr dz)
  946. {
  947. int exit_status;
  948. double *q;
  949. float *p = floatbuf;
  950. float *endptab = floatbuf + dz->wlength;
  951. int n, bsize;
  952. double sharpness = TONE_CENT; /* sharpness in semitones */
  953. if(dz->wlength<2) {
  954. sprintf(errstr,"Not enough pitchdata to convert to brktable.\n");
  955. return(DATA_ERROR);
  956. }
  957. q = dz->parray[array_no];
  958. n = 0;
  959. *q++ = 0.0;
  960. *q++ = (double)*p++;
  961. *q++ = frametime;
  962. *q++ = (double)*p++;
  963. n = 2;
  964. while(endptab-p > 0) {
  965. *q++ = (double)n * frametime;
  966. *q++ = (double)*p++;
  967. n++;
  968. }
  969. bsize = q - dz->parray[array_no];
  970. if((exit_status = incremental_pt_datareduction(array_no,&bsize,sharpness,dz))<0)
  971. return(exit_status);
  972. n = bsize;
  973. if((dz->parray[array_no] = (double *)realloc((char *)dz->parray[array_no],n*sizeof(double)))==NULL) {
  974. sprintf(errstr,"convert_pch_or_transpos_data_to_brkpnttable()\n");
  975. return(MEMORY_ERROR);
  976. }
  977. *brksize = n/2;
  978. return(FINISHED);
  979. }
  980. /***************************** PT_DATAREDUCE **********************
  981. *
  982. * Reduce data on passing from pitch or transposition to brkpnt representation.
  983. *
  984. * Note, these are identical, becuase the root-pitch from which pitch-vals are measured
  985. * cancels out in the maths (and doesn't of course occur in the transposition calc).
  986. *
  987. * Take last 3 points, and if middle point has (approx) same value as
  988. * a point derived by interpolating between first and last points, then
  989. * ommit midpoint from brkpnt representation.
  990. */
  991. int pt_datareduce(double **q,double sharp,double flat,double *thisarray,int *bsize)
  992. {
  993. double interval;
  994. double *arrayend;
  995. double *p = (*q)-6, *midpair = (*q)-4, *endpair = (*q)-2;
  996. double startime = *p++;
  997. double startval = LOG2(*p++); /* pitch = LOG(p/root) = LOG(p) - LOG(root) */
  998. double midtime = *p++;
  999. double midval = LOG2(*p++); /* pitch = LOG(p/root) = LOG(p) - LOG(root) */
  1000. double endtime = *p++;
  1001. double endval = LOG2(*p);
  1002. double valrange = endval-startval; /* LOG(root) cancels out */
  1003. double midtimeratio = (midtime-startime)/(endtime-startime);
  1004. double guessval = (valrange * midtimeratio) + startval; /* -LOG(root) reintroduced */
  1005. if((interval = (guessval - midval) * SEMITONES_PER_OCTAVE) < sharp && interval > flat) { /* but cancels again */
  1006. arrayend = thisarray + *bsize;
  1007. while(endpair < arrayend)
  1008. *midpair++ = *endpair++;
  1009. (*q) -= 2;
  1010. *bsize -= 2;
  1011. }
  1012. return(FINISHED);
  1013. }
  1014. /***************************** INCREMENTAL_PT_DATAREDUCTION ******************************/
  1015. int incremental_pt_datareduction(int array_no,int *bsize,double sharp,dataptr dz)
  1016. {
  1017. int exit_status;
  1018. double flat;
  1019. double *q;
  1020. double sharp_semitones = LOG2(dz->is_sharp) * SEMITONES_PER_OCTAVE;
  1021. double *thisarray = dz->parray[array_no];
  1022. while(*bsize >= 6 && sharp < sharp_semitones) {
  1023. flat = -sharp;
  1024. q = thisarray + 4;
  1025. while(q < thisarray + (*bsize) - 1) {
  1026. q +=2;
  1027. if((exit_status = pt_datareduce(&q,sharp,flat,thisarray,bsize))<0)
  1028. return(exit_status);
  1029. }
  1030. sharp *= 2.0; /* interval-size doubles */
  1031. }
  1032. if(*bsize >= 6) {
  1033. sharp = sharp_semitones;
  1034. flat = -sharp;
  1035. q = thisarray + 4;
  1036. while(q < thisarray + (*bsize) - 1) {
  1037. q +=2;
  1038. if((exit_status = pt_datareduce(&q,sharp,flat,thisarray,bsize))<0)
  1039. return(exit_status);
  1040. }
  1041. }
  1042. return(FINISHED);
  1043. }
  1044. /****************************** SPLICE_MULTILINE_STRING ******************************/
  1045. void splice_multiline_string(char *str,char *prefix)
  1046. {
  1047. char *p, *q, c;
  1048. p = str;
  1049. q = str;
  1050. while(*q != ENDOFSTR) {
  1051. while(*p != '\n' && *p != ENDOFSTR)
  1052. p++;
  1053. c = *p;
  1054. *p = ENDOFSTR;
  1055. fprintf(stdout,"%s %s\n",prefix,q);
  1056. *p = c;
  1057. if(*p == '\n')
  1058. p++;
  1059. while(*p == '\n') {
  1060. fprintf(stdout,"%s \n",prefix);
  1061. p++;
  1062. }
  1063. q = p;
  1064. p++;
  1065. }
  1066. }