newmix1.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  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. /* floatsam version */
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <structures.h>
  25. #include <tkglobals.h>
  26. #include <globcon.h>
  27. #include <processno.h>
  28. #include <modeno.h>
  29. #include <arrays.h>
  30. #include <filetype.h>
  31. #include <mix.h>
  32. #include <cdpmain.h>
  33. #include <sfsys.h>
  34. #include <string.h>
  35. #define START (0)
  36. #define LEFT (0)
  37. #define RIGHT (1)
  38. #define MAX_CLIP_DISPLAY (16)
  39. static int adjust_buffer_status(int n,int *thispos,int *active_bufcnt,dataptr dz);
  40. static int read_samps_to_an_inbuf(int n,dataptr dz);
  41. static void make_stereo(float *inbuf,dataptr dz);
  42. static int make_stereo_left_only(float *inbuf,dataptr dz);
  43. static int make_stereo_right_only(float *inbuf,dataptr dz);
  44. static int adjust_activebufs_list(int active_bufcnt,dataptr dz);
  45. static int do_mix(int samps_to_mix,int *position_in_outbuf,int active_bufcnt,int *outbuf_space,dataptr dz);
  46. static void do_level_check(int samps_to_mix,double *d_maxsamp,int *maxloc,int active_bufcnt,
  47. int *outbuf_space,int *clipsize,int *total_samps_used,int *position_in_outbuf,dataptr dz);
  48. static int do_silence(int samps_to_mix,int *position_in_outbuf,int *outbuf_space,dataptr dz);
  49. static void do_zero_level(int samps_to_mix,int *position_in_outbuf,
  50. int *outbuf_space,int *total_samps_used,dataptr dz);
  51. static int do_mix2(int samps_to_mix,int *position_in_outbuf,int active_bufcnt,int *outbuf_space,dataptr dz);
  52. static void do_the_level(float *olbuf,int *opos,int cnt,double *d_maxsamp,int *maxloc,int *clipsize,
  53. int total_samps_used,dataptr dz);
  54. static double gain_to_db(double val);
  55. static int mix_read_samps(float *inbuf,int samps_to_read,int n,dataptr dz);
  56. static int scale_smps(int n,dataptr dz);
  57. static int clipcnt = 0;
  58. /*************************** MMIX *******************************/
  59. int mmix(dataptr dz)
  60. {
  61. int exit_status;
  62. int n;
  63. int thispos, nextpos, samps_to_mix;
  64. int position_in_outbuf = 0;
  65. int active_bufcnt = 0;
  66. int outbuf_space = dz->buflen;
  67. display_virtual_time(0L,dz);
  68. if(sloom) {
  69. if(dz->iparam[MIX_STRTPOS_IN_ACTION] > 0) {
  70. fprintf(stdout,"INFO: Skipping initial part of mix.\n");
  71. fflush(stdout);
  72. }
  73. }
  74. for(n=0;n<dz->iparam[MIX_TOTAL_ACTCNT]-1;n++) { /* Switch bufs ON or OFF as indicated in act[], & get position */
  75. if((exit_status = adjust_buffer_status(n,&thispos,&active_bufcnt,dz))<0)
  76. return(exit_status); /* and while doing so, count active buffers. */
  77. nextpos = (dz->act[n+1])->position; /* Get next position, (from which to calc dur of this mix-chunk) */
  78. if((exit_status = adjust_activebufs_list(active_bufcnt,dz))<0)
  79. return(exit_status); /* Ensure only pointers in ACTIVE bufs are in buf-pointer list */
  80. if(dz->iparam[MIX_STRTPOS] > 0) { /* If mix does not start at zero */
  81. if(nextpos <= dz->iparam[MIX_STRTPOS]){ /* update MIX_STRTPOS_IN_ACTION */
  82. dz->iparam[MIX_STRTPOS_IN_ACTION] = (int)(dz->iparam[MIX_STRTPOS_IN_ACTION] - (nextpos - thispos));
  83. continue; /* and skip action until we reach a valid mix-action */
  84. }
  85. } /* If we're in a valid mix action */
  86. /* i.e. there is >zero time between this action and next */
  87. /* AND time is later than time where mix-action starts */
  88. if((samps_to_mix = nextpos - thispos - dz->iparam[MIX_STRTPOS_IN_ACTION])>0) {
  89. if(active_bufcnt==0) { /* If no buffers are active, fill time with silence. */
  90. if((exit_status = do_silence(samps_to_mix,&position_in_outbuf,&outbuf_space,dz))<0)
  91. return(exit_status);
  92. } else { /* Else, do mix */
  93. switch(dz->vflag[ALTERNATIVE_MIX]) {
  94. case(FALSE):
  95. if((exit_status = do_mix(samps_to_mix,&position_in_outbuf,active_bufcnt,&outbuf_space,dz))<0)
  96. return(exit_status);
  97. break;
  98. case(TRUE):
  99. if((exit_status = do_mix2(samps_to_mix,&position_in_outbuf,active_bufcnt,&outbuf_space,dz))<0)
  100. return(exit_status);
  101. break;
  102. default:
  103. sprintf(errstr,"Unknown mixtype. mmix()\n");
  104. return(PROGRAM_ERROR);
  105. } /* Having got to start of actual mixing, */
  106. } /* MIX_STRTPOS_IN_ACTION is set to zero */
  107. /* and NO LONGER affects calculations. */
  108. dz->iparam[MIX_STRTPOS_IN_ACTION] = dz->iparam[MIX_STRTPOS] = 0;
  109. }
  110. } /* Write any data remaining in output buffer. */
  111. if(position_in_outbuf > 0)
  112. return write_samps(dz->sampbuf[OBUFMIX],position_in_outbuf,dz);
  113. return FINISHED;
  114. }
  115. /*************************** MIX_LEVEL_CHECK *****************************/
  116. int mix_level_check(double *normalisation, dataptr dz)
  117. {
  118. int exit_status;
  119. int n;
  120. int thispos, nextpos, samps_to_mix;
  121. /* JUNE 2000 --> */
  122. double dbnormalisation;
  123. /* <-- JUNE 2000 */
  124. int position_in_outbuf = 0;
  125. //TW REMOVED 'maxsamp' and corrected printing of long (now double) items
  126. int maxloc = 0;
  127. int active_bufcnt = 0;
  128. int outbuf_space = dz->buflen;
  129. int clipsize = 0;
  130. int total_samps_used = 0;
  131. /* RWD */
  132. double d_maxsamp = 0.0;
  133. switch(dz->mode) {
  134. case(MIX_LEVEL_ONLY):
  135. break;
  136. case(MIX_LEVEL_AND_CLIPS):
  137. case(MIX_CLIPS_ONLY):
  138. if(dz->fp == NULL) {
  139. sprintf(errstr,"Output textfile not established: mix_level_check()\n");
  140. return(PROGRAM_ERROR);
  141. }
  142. break;
  143. }
  144. display_virtual_time(0L,dz);
  145. for(n=0;n<dz->iparam[MIX_TOTAL_ACTCNT]-1;n++) {
  146. if((exit_status = adjust_buffer_status(n,&thispos,&active_bufcnt,dz))<0)
  147. return(exit_status);
  148. nextpos = (dz->act[n+1])->position;
  149. if((exit_status = adjust_activebufs_list(active_bufcnt,dz))<0)
  150. return(exit_status);
  151. if(dz->iparam[MIX_STRTPOS] > 0) {
  152. if(nextpos <= dz->iparam[MIX_STRTPOS]) {
  153. dz->iparam[MIX_STRTPOS_IN_ACTION] = (int)(dz->iparam[MIX_STRTPOS_IN_ACTION] - (nextpos - thispos));
  154. continue;
  155. }
  156. }
  157. if((samps_to_mix = nextpos - thispos - dz->iparam[MIX_STRTPOS_IN_ACTION])>0) {
  158. if(active_bufcnt==0)
  159. do_zero_level(samps_to_mix,&position_in_outbuf,&outbuf_space,&total_samps_used,dz);
  160. else
  161. do_level_check(samps_to_mix,&d_maxsamp,&maxloc,active_bufcnt,
  162. &outbuf_space,&clipsize,&total_samps_used,&position_in_outbuf,dz);
  163. dz->iparam[MIX_STRTPOS_IN_ACTION] = dz->iparam[MIX_STRTPOS] = 0;
  164. }
  165. }
  166. //TW makes code function clear
  167. *normalisation = F_MAXSAMP / d_maxsamp;
  168. /* JUNE 2000 --> */
  169. dbnormalisation = gain_to_db(*normalisation);
  170. /* <-- JUNE 2000 */
  171. switch(dz->mode) {
  172. case(MIX_LEVEL_ONLY):
  173. sprintf(errstr,"MAX SAMPLE ENCOUNTERED : %lf at %lf secs\nNORMALISATION REQUIRED : %lf OR %.4lfdB\n",
  174. d_maxsamp,(double)maxloc/(double)dz->out_chans/(double)dz->infile->srate,*normalisation,dbnormalisation);
  175. break;
  176. case(MIX_LEVEL_AND_CLIPS):
  177. fprintf(dz->fp,"\nMAX SAMPLE ENCOUNTERED : %lf at %lf secs\n",
  178. d_maxsamp,(double)maxloc/(double)dz->out_chans/(double)dz->infile->srate);
  179. fprintf(dz->fp,"NORMALISATION REQUIRED : %lf OR %.4lfdB\n",
  180. *normalisation,dbnormalisation);
  181. if(sloom) {
  182. fprintf(stdout,"INFO: MAX SAMPLE ENCOUNTERED : %lf at %lf secs\n",
  183. d_maxsamp,(double)maxloc/(double)dz->out_chans/(double)dz->infile->srate);
  184. fprintf(stdout,"INFO: NORMALISATION REQUIRED : %lf OR %.4lfdB\n",*normalisation,dbnormalisation);
  185. fflush(stdout);
  186. }
  187. break;
  188. case(MIX_CLIPS_ONLY):
  189. if(sloom) {
  190. if(dz->mode == MIX_CLIPS_ONLY && clipcnt == 0) {
  191. fprintf(dz->fp,"No clipping.\n");
  192. fprintf(stdout,"INFO: No clipping.\n");
  193. fflush(stdout);
  194. }
  195. }
  196. break;
  197. default:
  198. sprintf(errstr,"Unknown case in mix_level_check()\n");
  199. return(PROGRAM_ERROR);
  200. }
  201. return(FINISHED);
  202. }
  203. /************************** ADJUST_BUFFER_STATUS **************************
  204. *
  205. * And keep track of number of active buffers (active_bufcnt).
  206. */
  207. int adjust_buffer_status(int n,int *thispos,int *active_bufcnt,dataptr dz)
  208. {
  209. int exit_status;
  210. switch(dz->act[n]->role) {
  211. case(MIX_ACTION_ON): /* buffer is being used for 1st time in this mix-action */
  212. (*active_bufcnt)++; /* Increment the count of ACTIVE buffers */
  213. dz->buflist[dz->act[n]->val->bufno]->status = MIX_ACTION_ON; /* Change buffer status to ON */
  214. /* fall thro */
  215. case(MIX_ACTION_REFILL): /* buffer is being reused OR used for 1st time */
  216. if((exit_status = read_samps_to_an_inbuf(n,dz))<0) /* Read_samples into buffer */
  217. return(exit_status);
  218. if((exit_status = scale_smps(n,dz))<0) /* Scale the samples */
  219. return(exit_status);
  220. dz->buflist[dz->act[n]->val->bufno]->here = dz->buflist[dz->act[n]->val->bufno]->buf;
  221. break; /* Reset location_in_buffer_pointer (here) to buffer start */
  222. case(MIX_ACTION_OFF): /* buffer is finished with */
  223. dz->buflist[dz->act[n]->val->bufno]->status = MIX_ACTION_OFF; /* Change buffer status to OFF */
  224. (*active_bufcnt)--; /* Decrement the number of ACTIVE buffers */
  225. break;
  226. default:
  227. sprintf(errstr,"Unknown case in adjust_buffer_status()\n");
  228. return(PROGRAM_ERROR);
  229. }
  230. *thispos = dz->act[n]->position; /* Return position (starttime-in-samps) of the action */
  231. return(FINISHED);
  232. }
  233. /************************* READ_SAMPS_TO_AN_INBUF ***************************/
  234. int read_samps_to_an_inbuf(int n,dataptr dz)
  235. {
  236. int exit_status;
  237. int samps_to_read = dz->buflen;
  238. float *inbuf = dz->buflist[dz->act[n]->val->bufno]->buf;
  239. switch(dz->act[n]->val->stereo) {
  240. case(MONO):
  241. case(STEREO):
  242. if((exit_status = mix_read_samps(inbuf,samps_to_read,n,dz))<0)
  243. return(exit_status);
  244. break;
  245. case(MONO_TO_STEREO):
  246. samps_to_read /= 2;
  247. if((exit_status = mix_read_samps(dz->sampbuf[STEREOBUF],samps_to_read,n,dz))<0)
  248. return(exit_status);
  249. make_stereo(inbuf,dz);
  250. dz->ssampsread *= 2;
  251. break;
  252. case(MONO_TO_CENTRE):
  253. samps_to_read /= 2;
  254. if((exit_status = mix_read_samps(dz->sampbuf[STEREOBUF],samps_to_read,n,dz))<0)
  255. return(exit_status);
  256. break;
  257. case(MONO_TO_LEFT):
  258. samps_to_read /= 2;
  259. if((exit_status = mix_read_samps(dz->sampbuf[STEREOBUF],samps_to_read,n,dz))<0)
  260. return(exit_status);
  261. if((exit_status = make_stereo_left_only(inbuf,dz))<0)
  262. return(exit_status);
  263. dz->ssampsread *= 2;
  264. break;
  265. case(MONO_TO_RIGHT):
  266. samps_to_read /= 2;
  267. if((exit_status = mix_read_samps(dz->sampbuf[STEREOBUF],samps_to_read,n,dz))<0)
  268. return(exit_status);
  269. if((exit_status = make_stereo_right_only(inbuf,dz))<0)
  270. return(exit_status);
  271. dz->ssampsread *= 2;
  272. break;
  273. case(STEREO_MIRROR):
  274. case(STEREO_TO_CENTRE):
  275. case(STEREO_TO_LEFT):
  276. case(STEREO_TO_RIGHT):
  277. case(STEREOLEFT_TO_LEFT):
  278. case(STEREOLEFT_TO_RIGHT):
  279. case(STEREOLEFT_PANNED):
  280. case(STEREORIGHT_TO_LEFT):
  281. case(STEREORIGHT_TO_RIGHT):
  282. case(STEREORIGHT_PANNED):
  283. case(STEREO_PANNED):
  284. if((exit_status = mix_read_samps(dz->sampbuf[STEREOBUF],samps_to_read,n,dz))<0)
  285. return(exit_status);
  286. break;
  287. default:
  288. sprintf(errstr,"Unknown case in read_samps_to_an_inbuf()\n");
  289. return(PROGRAM_ERROR);
  290. }
  291. return(FINISHED);
  292. }
  293. /****************************** MAKE_STEREO ***************************#
  294. *
  295. * Duplicate mono samples to make stereo buffer.
  296. */
  297. void make_stereo(float *inbuf,dataptr dz)
  298. {
  299. int m, k;
  300. for(k=0;k<dz->ssampsread;k++) {
  301. m = k * 2;
  302. inbuf[m++] = dz->sampbuf[STEREOBUF][k];
  303. inbuf[m] = dz->sampbuf[STEREOBUF][k];
  304. }
  305. }
  306. /******************** MAKE_STEREO_LEFT_ONLY ***************************#
  307. *
  308. * Put mono samples in left ONLY of stereo buffer.
  309. */
  310. int make_stereo_left_only(float *inbuf,dataptr dz)
  311. {
  312. int m, k;
  313. memset((char *)inbuf,0,dz->buflen * sizeof(float));
  314. for(k=0,m=0;k<dz->ssampsread;k++,m+=2)
  315. inbuf[m] = dz->sampbuf[STEREOBUF][k];
  316. return(FINISHED);
  317. }
  318. /******************** MAKE_STEREO_RIGHT_ONLY ***************************#
  319. *
  320. * Put mono samples in left ONLY of stereo buffer.
  321. */
  322. int make_stereo_right_only(float *inbuf,dataptr dz)
  323. {
  324. int m, k;
  325. memset((char *)inbuf,0,dz->buflen * sizeof(float));
  326. for(k=0,m=1;k<dz->ssampsread;k++,m+=2)
  327. inbuf[m] = dz->sampbuf[STEREOBUF][k];
  328. return(FINISHED);
  329. }
  330. /*********************** ADJUST_ACTIVEBUFS_LIST **************************
  331. *
  332. * Set the activebuf pointers to point only to the active buffers!!
  333. *
  334. * NB active_bufcnt has been reset by adjust_buffer_status()
  335. */
  336. int adjust_activebufs_list(int active_bufcnt,dataptr dz)
  337. {
  338. int n, k = 0;
  339. for(n=0;n<dz->bufcnt;n++) {
  340. if(dz->buflist[n]->status == MIX_ACTION_ON) {
  341. dz->activebuf[k] = n;
  342. dz->activebuf_ptr[k++] = dz->buflist[n]->here;
  343. }
  344. }
  345. if(k>active_bufcnt) {
  346. sprintf(errstr,"Accounting error: adjust_activebufs_list()\n");
  347. return(PROGRAM_ERROR);
  348. }
  349. return(FINISHED);
  350. }
  351. /************************* DO_MIX **********************************
  352. *
  353. * This algorithm puts all the samples from buffer 1 into output, then
  354. * sums in all the samples form buffer 2, and so on. This is fastest
  355. * routine (slightly) but risks a sample overflowing on the Nth buffer
  356. * and hence giving CLIPPING, whereas, in do_mix2, the sample sums are
  357. * accumulated in a long & hence later sample additions might negate
  358. * the overflow, negating the clipping in the final output.
  359. */
  360. int do_mix(int samps_to_mix,int *position_in_outbuf,int active_bufcnt,int *outbuf_space,dataptr dz)
  361. {
  362. int exit_status;
  363. int opos = *position_in_outbuf;
  364. int m, start = opos;
  365. int n, overflow;
  366. float *obuf = dz->sampbuf[OBUFMIX];
  367. float *outptr = obuf+opos;
  368. if(dz->iparam[MIX_STRTPOS] > 0) { /* If mix doesn't start at mixlist start, */
  369. for(n=0;n<active_bufcnt;n++) /* and hence most likely not at buffer start, */
  370. dz->activebuf_ptr[n] += dz->iparam[MIX_STRTPOS_IN_ACTION];
  371. } /* increment pointers in all active_bufs to actual mix start */
  372. if((overflow = samps_to_mix - (*outbuf_space)) <= 0) { /* If samps_to_write DOESN'T overflow output buffer */
  373. memmove((char *)outptr,(char *)(dz->activebuf_ptr[0]),samps_to_mix *sizeof(float));
  374. dz->activebuf_ptr[0] += samps_to_mix; /* Increment pointer in this active buf */
  375. dz->buflist[dz->activebuf[0]]->here += samps_to_mix;/* Increment current_position_in_buffer_pointer also */
  376. opos += samps_to_mix; /* Increment position_in_outbuf */
  377. for(m=1;m<active_bufcnt;m++) { /* For each of remaining ACTIVE buffers */
  378. opos = start; /* Reset output-buf pointer to start-of-write point */
  379. for(n=0;n<samps_to_mix;n++) /* Add in samples from the other buffers */
  380. obuf[opos++] += *(dz->activebuf_ptr[m]++);
  381. dz->buflist[dz->activebuf[m]]->here += samps_to_mix;
  382. /* And update current_position_in_buffer_pointers */
  383. }
  384. if((*outbuf_space = dz->buflen - opos)<=0) { /* if output buffer is full */
  385. if((exit_status = write_samps(obuf,dz->buflen ,dz))<0)
  386. return(exit_status); /* write a full buffer */
  387. *outbuf_space = dz->buflen; /* and reset available space and buffer position */
  388. opos = 0;
  389. }
  390. *position_in_outbuf = opos;
  391. return(FINISHED);
  392. /* IF samps_to_write DOES overflow output buffer */
  393. } else { /* which can only happen ONCE, */
  394. /* as in- & out- bufs are same size */
  395. if(*outbuf_space>0) {
  396. memmove((char *)(outptr),(char *)(dz->activebuf_ptr[0]),(*outbuf_space) * sizeof(float));
  397. dz->activebuf_ptr[0] += *outbuf_space;
  398. dz->buflist[dz->activebuf[0]]->here += *outbuf_space;
  399. opos += *outbuf_space;
  400. for(m=1;m<active_bufcnt;m++) {
  401. opos = start;
  402. for(n=0;n<*outbuf_space;n++)
  403. obuf[opos++] += *(dz->activebuf_ptr[m]++);
  404. dz->buflist[dz->activebuf[m]]->here += *outbuf_space;
  405. }
  406. }
  407. if((exit_status = write_samps(obuf,dz->buflen,dz))<0)
  408. return(exit_status);
  409. if(overflow) {
  410. start = opos = 0;
  411. memmove((char *)obuf,(char *)(dz->activebuf_ptr[0]),overflow*sizeof(float));
  412. dz->activebuf_ptr[0] += overflow;
  413. dz->buflist[dz->activebuf[0]]->here += overflow;
  414. opos = overflow;
  415. for(m=1;m<active_bufcnt;m++) {
  416. opos = start;
  417. for(n=0;n<overflow;n++)
  418. obuf[opos++] += *(dz->activebuf_ptr[m]++);
  419. dz->buflist[dz->activebuf[m]]->here += overflow;
  420. }
  421. }
  422. }
  423. *outbuf_space = dz->buflen - opos; /* Reset the space-left-in-outbuf */
  424. *position_in_outbuf = opos;
  425. return(FINISHED);
  426. }
  427. /************************* DO_LEVEL_CHECK **********************************
  428. *
  429. * As do_mix, but finds max sample.
  430. */
  431. void do_level_check(int samps_to_mix,double *d_maxsamp,int *maxloc,int active_bufcnt,
  432. int *outbuf_space,int *clipsize,int *total_samps_used,int *position_in_outbuf,dataptr dz)
  433. {
  434. int opos = *position_in_outbuf;
  435. int m, start = opos;
  436. float *active_start = dz->activebuf_ptr[0];
  437. int n, overflow, k;
  438. float *olbuf = dz->sampbuf[OBUFMIX];
  439. if(sloom) {
  440. if(dz->iparam[MIX_STRTPOS_IN_ACTION] > 0) {
  441. fprintf(stdout,"INFO: Skipping initial part of mix.\n");
  442. fflush(stdout);
  443. }
  444. }
  445. if(dz->iparam[MIX_STRTPOS] > 0) {
  446. for(n=0;n<active_bufcnt;n++)
  447. dz->activebuf_ptr[n] += dz->iparam[MIX_STRTPOS_IN_ACTION];
  448. }
  449. if((overflow = samps_to_mix - (*outbuf_space)) <= 0) {
  450. for(k=0;k<samps_to_mix;k++)
  451. olbuf[opos++] = *active_start++;
  452. dz->buflist[dz->activebuf[0]]->here += samps_to_mix;
  453. opos += samps_to_mix;
  454. for(m=1;m<active_bufcnt;m++) {
  455. opos = start;
  456. for(n=0;n<samps_to_mix;n++)
  457. olbuf[opos++] += *(dz->activebuf_ptr[m]++);
  458. dz->buflist[dz->activebuf[m]]->here += samps_to_mix;
  459. }
  460. opos = start;
  461. do_the_level(olbuf,&opos,samps_to_mix,d_maxsamp,maxloc,clipsize,*total_samps_used,dz);
  462. *total_samps_used += samps_to_mix;
  463. } else {
  464. if(*outbuf_space > 0) {
  465. for(k=0;k<*outbuf_space;k++)
  466. olbuf[opos++] = *active_start++;
  467. dz->activebuf_ptr[0] += *outbuf_space;
  468. dz->buflist[dz->activebuf[0]]->here += *outbuf_space;
  469. for(m=1;m<active_bufcnt;m++) {
  470. opos = start;
  471. for(n=0;n<*outbuf_space;n++)
  472. olbuf[opos++] += *(dz->activebuf_ptr[m]++);
  473. dz->buflist[dz->activebuf[m]]->here += *outbuf_space;
  474. }
  475. opos = start;
  476. do_the_level(olbuf,&opos,*outbuf_space,d_maxsamp,maxloc,clipsize,*total_samps_used,dz);
  477. *total_samps_used += *outbuf_space;
  478. }
  479. if(!sloom)
  480. display_virtual_time(*total_samps_used,dz);
  481. if(overflow) {
  482. start = opos = 0;
  483. active_start = dz->activebuf_ptr[0];
  484. for(k=0;k<overflow;k++)
  485. olbuf[opos++] = *active_start++;
  486. dz->buflist[dz->activebuf[0]]->here += overflow;
  487. for(m=1;m<active_bufcnt;m++) {
  488. opos = start;
  489. for(n=0;n<overflow;n++)
  490. olbuf[opos++] += *(dz->activebuf_ptr[m]++);
  491. dz->buflist[dz->activebuf[m]]->here += overflow;
  492. }
  493. opos = start;
  494. do_the_level(olbuf,&opos,overflow,d_maxsamp,maxloc,clipsize,*total_samps_used,dz);
  495. *total_samps_used += overflow;
  496. }
  497. }
  498. *outbuf_space = dz->buflen - opos;
  499. *position_in_outbuf = opos;
  500. return;
  501. }
  502. /************************* DO_SILENCE ***********************************/
  503. int do_silence(int samps_to_mix,int *position_in_outbuf,int *outbuf_space,dataptr dz)
  504. {
  505. int exit_status;
  506. int opos = *position_in_outbuf;
  507. int overflow;
  508. float *obuf = dz->sampbuf[OBUFMIX];
  509. while((overflow = samps_to_mix - *outbuf_space) > 0) {
  510. memset((char *)(obuf+opos),0,(*outbuf_space) * sizeof(float));
  511. if((exit_status = write_samps(obuf,dz->buflen,dz))<0)
  512. return(exit_status);
  513. opos = 0;
  514. *outbuf_space = dz->buflen;
  515. samps_to_mix = overflow;
  516. }
  517. if(samps_to_mix) {
  518. memset((char *)(obuf+opos),0,samps_to_mix*sizeof(float));
  519. opos += samps_to_mix;
  520. *outbuf_space = dz->buflen - opos;
  521. }
  522. *position_in_outbuf = opos;
  523. return(FINISHED);
  524. }
  525. /************************* DO_ZERO_LEVEL ***********************************/
  526. void do_zero_level(int samps_to_mix,int *position_in_outbuf,int *outbuf_space,int *total_samps_used,dataptr dz)
  527. {
  528. int overflow;
  529. while((overflow = samps_to_mix - *outbuf_space) > 0) {
  530. *total_samps_used += dz->buflen;
  531. display_virtual_time(*total_samps_used,dz);
  532. *position_in_outbuf = 0;
  533. *outbuf_space = dz->buflen;
  534. samps_to_mix = overflow;
  535. }
  536. if(samps_to_mix) {
  537. *total_samps_used += samps_to_mix;
  538. *position_in_outbuf += samps_to_mix;
  539. *outbuf_space = dz->buflen - *position_in_outbuf;
  540. }
  541. }
  542. /******************************** DO_MIX2 ***************************
  543. *
  544. * Alternative mix algorithm that SUMS all the buffers for a single sample
  545. * then puts into output, before proceeding to next sample.
  546. * In this routine some +ve overflow may be cancelled by a subsequent -ve
  547. * sample (and vice versa), preventing final signal overflow.
  548. * However this is slightly slower.
  549. */
  550. int do_mix2(int samps_to_mix,int *position_in_outbuf,int active_bufcnt,int *outbuf_space,dataptr dz)
  551. {
  552. int exit_status;
  553. int m /*, samp_sum*/;
  554. double d_samp_sum; /*RWD*/
  555. int n, overflow;
  556. float *obuf = dz->sampbuf[OBUFMIX];
  557. int opos = *position_in_outbuf;
  558. if(dz->iparam[MIX_STRTPOS] > 0) {
  559. for(n=0;n<active_bufcnt;n++)
  560. dz->activebuf_ptr[n] += dz->iparam[MIX_STRTPOS_IN_ACTION];
  561. }
  562. if((overflow = samps_to_mix - *outbuf_space) <= 0) {
  563. for(n=0;n<samps_to_mix;n++) {
  564. d_samp_sum = *(dz->activebuf_ptr[0]++);
  565. for(m=1;m<active_bufcnt;m++)
  566. d_samp_sum += *(dz->activebuf_ptr[m]++);
  567. obuf[opos++] = (float)d_samp_sum;
  568. }
  569. for(m=0;m<active_bufcnt;m++)
  570. dz->buflist[dz->activebuf[m]]->here += samps_to_mix;
  571. } else {
  572. if(*outbuf_space > 0) { /* APRIL 1995 */
  573. for(n=0;n<*outbuf_space;n++) {
  574. d_samp_sum = *(dz->activebuf_ptr[0]++);
  575. for(m=1;m<active_bufcnt;m++)
  576. d_samp_sum += *(dz->activebuf_ptr[m]++);
  577. obuf[opos++] = (float)d_samp_sum;
  578. }
  579. for(m=0;m<active_bufcnt;m++)
  580. dz->buflist[dz->activebuf[m]]->here += *outbuf_space;
  581. }
  582. if((exit_status = write_samps(obuf,dz->buflen,dz))<0)
  583. return(exit_status);
  584. if(overflow) {
  585. opos = 0;
  586. for(n=0;n<overflow;n++) {
  587. d_samp_sum = *(dz->activebuf_ptr[0]++);
  588. for(m=1;m<active_bufcnt;m++)
  589. d_samp_sum += *(dz->activebuf_ptr[m]++);
  590. obuf[opos++] = (float)d_samp_sum;
  591. }
  592. for(m=0;m<active_bufcnt;m++)
  593. dz->buflist[dz->activebuf[m]]->here += overflow;
  594. }
  595. }
  596. *outbuf_space = dz->buflen - opos;
  597. *position_in_outbuf = opos;
  598. return(FINISHED);
  599. }
  600. /***************************** DO_THE_LEVEL ********************************/
  601. void do_the_level
  602. (float *olbuf,int *opos,int cnt,double *d_maxsamp,int *maxloc,int *clipsize,int total_samps_used,dataptr dz)
  603. {
  604. int clipstart = 0, z /*, thisval*/;
  605. double d_thisval; /*RWD */
  606. int this_opos = *opos;
  607. switch(dz->mode) {
  608. case(MIX_LEVEL_ONLY):
  609. for(z=0;z<cnt;z++) {
  610. if((d_thisval = fabs(olbuf[this_opos])) > *d_maxsamp) {
  611. *d_maxsamp = d_thisval;
  612. *maxloc = total_samps_used + this_opos;
  613. }
  614. this_opos++;
  615. }
  616. break;
  617. case(MIX_CLIPS_ONLY):
  618. for(z=0;z<cnt;z++) {
  619. if(fabs(olbuf[this_opos]) > F_MAXSAMP) {
  620. if(*clipsize==0)
  621. clipstart = total_samps_used + this_opos;
  622. (*clipsize)++;
  623. } else {
  624. if(*clipsize > 0) {
  625. if(sloom) {
  626. if(clipcnt <= MAX_CLIP_DISPLAY) {
  627. if(clipcnt == MAX_CLIP_DISPLAY) {
  628. fprintf(stdout,"INFO: See output data file for more information on clipping.\n");
  629. } else {
  630. fprintf(stdout,"INFO: Clip at time %lf secs : sample %d : For %d samples\n",
  631. (double)clipstart/(double)dz->out_chans/(double)dz->infile->srate,clipstart,*clipsize);
  632. }
  633. fflush(stdout);
  634. }
  635. }
  636. fprintf(dz->fp,"Clip at time %lf secs : sample %d : For %d samples\n",
  637. (double)clipstart/(double)dz->out_chans/(double)dz->infile->srate,clipstart,*clipsize);
  638. *clipsize = 0;
  639. clipcnt++;
  640. }
  641. }
  642. this_opos++;
  643. }
  644. break;
  645. case(MIX_LEVEL_AND_CLIPS):
  646. for(z=0;z<cnt;z++) {
  647. if((d_thisval = fabs(olbuf[this_opos])) > *d_maxsamp) {
  648. *d_maxsamp = d_thisval;
  649. *maxloc = total_samps_used + this_opos;
  650. }
  651. if(d_thisval > F_MAXSAMP) {
  652. if(*clipsize==0)
  653. clipstart = total_samps_used + this_opos;
  654. (*clipsize)++;
  655. } else {
  656. if(*clipsize>0) {
  657. if(sloom) {
  658. if(clipcnt <= MAX_CLIP_DISPLAY) {
  659. if(clipcnt == MAX_CLIP_DISPLAY) {
  660. fprintf(stdout,"INFO: See output data file for more information on clipping.\n");
  661. } else {
  662. fprintf(stdout,"INFO: Clip at time %lf secs : sample %d : For %d samples\n",
  663. (double)clipstart/(double)dz->out_chans/(double)dz->infile->srate,clipstart,*clipsize);
  664. }
  665. fflush(stdout);
  666. }
  667. }
  668. fprintf(dz->fp,"Clip at time %lf secs : sample %d : For %d samples\n",
  669. (double)clipstart/(double)dz->out_chans/(double)dz->infile->srate,clipstart,*clipsize);
  670. *clipsize = 0;
  671. clipcnt++;
  672. }
  673. }
  674. this_opos++;
  675. }
  676. break;
  677. }
  678. *opos = this_opos;
  679. if(sloom)
  680. display_virtual_time((total_samps_used + this_opos),dz);
  681. }
  682. /************************ GAIN_TO_DB ************************/
  683. double gain_to_db(double val)
  684. {
  685. val = log10(val);
  686. val *= 20.0;
  687. return(val);
  688. }
  689. /*************************** MIX_READ_SAMPS **************************/
  690. int mix_read_samps(float *inbuf,int samps_to_read,int n,dataptr dz)
  691. {
  692. int thisfile = dz->act[n]->val->ifd;
  693. if((dz->ssampsread = fgetfbufEx(inbuf, samps_to_read,thisfile,0)) < 0) {
  694. sprintf(errstr, "Can't read samps from input soundfile %d\n",n+1);
  695. return(SYSTEM_ERROR);
  696. }
  697. return(FINISHED);
  698. }
  699. /************************* SCALE_SMPS **************************/
  700. int scale_smps(int n,dataptr dz)
  701. {
  702. int m, k;
  703. double thisscale;
  704. float *inbuf = dz->buflist[dz->act[n]->val->bufno]->buf;
  705. float *stereobuf = dz->sampbuf[STEREOBUF];
  706. int stereo_state = dz->act[n]->val->stereo;
  707. switch(stereo_state) {
  708. case(MONO): /* Scale the mono source. */
  709. m = 0;
  710. thisscale = dz->act[n]->val->llscale;
  711. if(thisscale==0.0) {
  712. memset((char *)inbuf,0,dz->buflen * sizeof(float));
  713. }
  714. else if(thisscale != 1.0){
  715. while(m<dz->ssampsread) {
  716. inbuf[m] = (float)(inbuf[m] * thisscale);
  717. m++;
  718. }
  719. break;
  720. }
  721. break;
  722. case(MONO_TO_CENTRE): /* work on the 1/2 buflen still in the stereobuf. */
  723. m = 0; /* Scale it and copy to both L and R in inbuf. */
  724. k = 0;
  725. thisscale = dz->act[n]->val->llscale;
  726. if(thisscale==0.0) {
  727. memset((char *)inbuf,0,dz->buflen * sizeof(float));
  728. }
  729. else if(thisscale == 1.0){
  730. while(m<dz->ssampsread) {
  731. inbuf[k] = stereobuf[m];
  732. inbuf[k+1] = inbuf[k];
  733. k+=2;
  734. m++;
  735. }
  736. }
  737. else{
  738. while(m<dz->ssampsread) {
  739. inbuf[k] = (float)(stereobuf[m] * thisscale);
  740. inbuf[k+1] = inbuf[k];
  741. k+=2;
  742. m++;
  743. }
  744. break;
  745. }
  746. dz->ssampsread *= 2;
  747. break;
  748. case(STEREO_TO_CENTRE): /* sum the stereo pair in stereobuf */
  749. m = 0; /* Scale the result (already adjusted for centring) */
  750. k = 0; /*and copy to both L and R in inbuf */
  751. thisscale = dz->act[n]->val->llscale;
  752. if(thisscale==0.0) {
  753. memset((char *)inbuf,0,dz->buflen * sizeof(float));
  754. }
  755. else if(thisscale==1.0){
  756. while(m<dz->ssampsread) {
  757. inbuf[k] = (float)(stereobuf[m]+stereobuf[m+1]);
  758. inbuf[k+1] = inbuf[k];
  759. k+=2;
  760. m+=2;
  761. }
  762. }
  763. else{
  764. while(m<dz->ssampsread) {
  765. inbuf[k] = (float)((stereobuf[m]+stereobuf[m+1]) * thisscale);
  766. inbuf[k+1] = inbuf[k];
  767. k+=2;
  768. m+=2;
  769. }
  770. break;
  771. }
  772. break;
  773. case(MONO_TO_LEFT): /* scale left of stereo source only: (right is preset to zero!). */
  774. thisscale = dz->act[n]->val->llscale;
  775. if(thisscale==0.0) {
  776. memset((char *)inbuf,0,dz->buflen * sizeof(float));
  777. }
  778. else if(thisscale!=1.0){
  779. m = LEFT;
  780. while(m<dz->ssampsread) {
  781. inbuf[m] = (float)(inbuf[m] * thisscale);
  782. m += 2;
  783. }
  784. }
  785. break;
  786. case(MONO_TO_RIGHT): /* scale right of stereo source only: (left is preset to zero!).*/
  787. thisscale = dz->act[n]->val->rrscale;
  788. if(thisscale==0.0) {
  789. memset((char *)inbuf,0,dz->buflen * sizeof(float));
  790. }
  791. else if(thisscale != 1.0){
  792. m = RIGHT;
  793. while(m<dz->ssampsread) {
  794. inbuf[m] = (float)(inbuf[m] * thisscale);
  795. m += 2;
  796. }
  797. }
  798. break;
  799. case(MONO_TO_STEREO): /* scale each channel of stereo_ified source.*/
  800. case(STEREO): /* scale each channel of stereo source.*/
  801. m = LEFT;
  802. thisscale = dz->act[n]->val->llscale;
  803. if(thisscale==0.0) {
  804. while(m<dz->ssampsread) {
  805. inbuf[m] = 0.0f;
  806. m += 2;
  807. }
  808. }
  809. else if(thisscale != 1.0){
  810. while(m<dz->ssampsread) {
  811. inbuf[m] = (float)(inbuf[m] * thisscale);
  812. m += 2;
  813. }
  814. }
  815. m = RIGHT;
  816. thisscale = dz->act[n]->val->rrscale;
  817. if(thisscale==0.0) {
  818. while(m<dz->ssampsread) {
  819. inbuf[m] = 0.0f;
  820. m += 2;
  821. }
  822. }
  823. else if(thisscale != 1.0){
  824. while(m<dz->ssampsread) {
  825. inbuf[m] = (float)(inbuf[m] * thisscale);
  826. m += 2;
  827. }
  828. }
  829. break;
  830. case(STEREO_MIRROR): /* Scale L channel (in stereobuf) & copy to R. */
  831. /* Then scale R channel (in stereobuf) & copy to L */
  832. m = RIGHT; /* put to right */
  833. k = LEFT; /* the scaled left channel */
  834. thisscale = dz->act[n]->val->llscale;
  835. if(thisscale==0.0) {
  836. while(m<dz->ssampsread) {
  837. inbuf[m] = 0.0f;
  838. m += 2;
  839. }
  840. }
  841. else if(thisscale==1.0){
  842. while(m<dz->ssampsread) {
  843. inbuf[m] = stereobuf[k];
  844. m += 2;
  845. k += 2;
  846. }
  847. }
  848. else{
  849. while(m<dz->ssampsread) {
  850. inbuf[m] = (float)(stereobuf[k] * thisscale);
  851. m += 2;
  852. k += 2;
  853. }
  854. }
  855. m = LEFT; /* put to left */
  856. k = RIGHT; /* the scaled right channel */
  857. thisscale = dz->act[n]->val->rrscale;
  858. if(thisscale==0.0) {
  859. while(m<dz->ssampsread) {
  860. inbuf[m] = 0.0f;
  861. m += 2;
  862. }
  863. }
  864. else if(thisscale==1.0){
  865. while(m<dz->ssampsread) {
  866. inbuf[m] = stereobuf[k];
  867. m += 2;
  868. k += 2;
  869. }
  870. }
  871. else {
  872. while(k<dz->ssampsread) {
  873. inbuf[m] = (float)(stereobuf[k] * thisscale);
  874. m += 2;
  875. k += 2;
  876. }
  877. }
  878. break;
  879. case(STEREO_PANNED): /* each stereo INPUT channel contributes to each stereo OUTPUT channel. */
  880. /* So copy scaled version of first to each outchan, */
  881. /* then do same to 2nd inchans, ADDING it into the outbuf */
  882. m = 0;
  883. thisscale = dz->act[n]->val->llscale;
  884. while(m<dz->ssampsread) {
  885. inbuf[m] =(float)(stereobuf[m] * thisscale);
  886. m += 2;
  887. }
  888. m = 0;
  889. thisscale = dz->act[n]->val->lrscale;
  890. while(m<dz->ssampsread) {
  891. inbuf[m+1] = (float)(stereobuf[m] * thisscale);
  892. m += 2;
  893. }
  894. m = 1;
  895. thisscale = dz->act[n]->val->rlscale;
  896. while(m<dz->ssampsread) {
  897. inbuf[m-1] = (float)(inbuf[m-1] + (stereobuf[m] * thisscale));
  898. m += 2;
  899. }
  900. m = 1;
  901. thisscale = dz->act[n]->val->rrscale;
  902. while(m<dz->ssampsread) {
  903. inbuf[m] = (float)(inbuf[m] + (stereobuf[m] * thisscale));
  904. m += 2;
  905. }
  906. break;
  907. case(STEREO_TO_LEFT): /* both channels are at same level, but both panned to left. */
  908. case(STEREO_TO_RIGHT): /* Preset outbuf to zero, then sum each pair of stereo channels, */
  909. /* scale result and write to left. */
  910. /* For STEREO_TO_RIGHT Ditto , but write to right. */
  911. if(stereo_state==STEREO_TO_LEFT) {
  912. m = START; /* read from start */
  913. k = LEFT; /* write to left */
  914. thisscale = dz->act[n]->val->llscale;
  915. } else {
  916. m = START; /* read from start */
  917. k = RIGHT; /* write to right */
  918. thisscale = dz->act[n]->val->rrscale;
  919. }
  920. memset((char *)inbuf,0,dz->buflen * sizeof(float));
  921. if(thisscale==0.0) {
  922. ;
  923. }
  924. else if(thisscale==1.0){
  925. while(m<dz->ssampsread) {
  926. inbuf[k] = (float)(stereobuf[m]+stereobuf[m+1]);
  927. k+=2;
  928. m+=2;
  929. }
  930. }
  931. else{
  932. while(m<dz->ssampsread) {
  933. inbuf[k] = (float)((stereobuf[m]+stereobuf[m+1]) * thisscale);
  934. k+=2;
  935. m+=2;
  936. }
  937. }
  938. break;
  939. case(STEREOLEFT_TO_LEFT): /* for STEREOLEFT_TO_LEFT there is no right channel output or input. */
  940. case(STEREORIGHT_TO_RIGHT): /* zero outbuf, & copy scaled left channel to left outchan */
  941. /* For STEREORIGHT_TO_RIGHT there is no left channel output or input. */
  942. /* zero outbuf, & copy scaled right channel to right output */
  943. if(stereo_state==STEREOLEFT_TO_LEFT) {
  944. m = LEFT; /* write from left to left */
  945. thisscale = dz->act[n]->val->llscale;
  946. } else {
  947. m = RIGHT; /* write from right to right */
  948. thisscale = dz->act[n]->val->rrscale;
  949. }
  950. memset((char *)inbuf,0,dz->buflen * sizeof(float));
  951. if(thisscale==0.0) {
  952. ;
  953. }
  954. else if(thisscale==1.0){
  955. while(m<dz->ssampsread) {
  956. inbuf[m] = stereobuf[m];
  957. m+=2;
  958. }
  959. }
  960. else {
  961. while(m<dz->ssampsread) {
  962. inbuf[m] = (float)(stereobuf[m] * thisscale);
  963. m+=2;
  964. }
  965. }
  966. break;
  967. case(STEREOLEFT_TO_RIGHT): /* For STEREOLEFT_TO_RIGHT there is no L chan output or R chan input. */
  968. case(STEREORIGHT_TO_LEFT): /* Zero buffer, & copy scaled left chan to right */
  969. /* For STEREORIGHT_TO_LEFT there is no R chan output or L chan input. */
  970. /* Zero buffer, & copy scaled right chan to left */
  971. if(stereo_state==STEREOLEFT_TO_RIGHT) {
  972. m = LEFT; /* write from left to right */
  973. k = RIGHT;
  974. thisscale = dz->act[n]->val->rrscale;
  975. } else {
  976. m = RIGHT; /* write from right to left */
  977. k = LEFT;
  978. thisscale = dz->act[n]->val->llscale;
  979. }
  980. memset((char *)inbuf,0,dz->buflen * sizeof(float));
  981. if(thisscale==0.0) {
  982. ;
  983. }
  984. else if(thisscale==1.0){
  985. while(m<dz->ssampsread) {
  986. inbuf[k] = stereobuf[m];
  987. m+=2;
  988. k+=2;
  989. }
  990. }
  991. else{
  992. while(m<dz->ssampsread) {
  993. inbuf[k] = (float)(stereobuf[m] * thisscale);
  994. m+=2;
  995. k+=2;
  996. }
  997. }
  998. break;
  999. case(STEREOLEFT_PANNED): /* For STEREOLEFT_PANNED there is no R chan input. */
  1000. case(STEREORIGHT_PANNED): /* Copy left input, left_scaled, to left. */
  1001. /* Then copy left input right_scaled to right. */
  1002. /* For STEREORIGHT_PANNED there is no L chan input. */
  1003. /* Copy right input, right_scaled, to right. */
  1004. /* Then copy right input left_scaled to left.*/
  1005. if(stereo_state==STEREOLEFT_PANNED) {
  1006. m = LEFT; /* left to left */
  1007. thisscale = dz->act[n]->val->llscale;
  1008. } else {
  1009. m = RIGHT; /* right to right */
  1010. thisscale = dz->act[n]->val->rrscale;
  1011. }
  1012. if(thisscale==0.0) {
  1013. while(m<dz->ssampsread) {
  1014. inbuf[m] = 0.0f;
  1015. m+=2;
  1016. }
  1017. }
  1018. else if(thisscale==1.0){
  1019. while(m<dz->ssampsread) {
  1020. inbuf[m] = stereobuf[m];
  1021. m+=2;
  1022. }
  1023. }
  1024. else{
  1025. while(m<dz->ssampsread) {
  1026. inbuf[m] = (float)(stereobuf[m] * thisscale);
  1027. m+=2;
  1028. }
  1029. }
  1030. if(stereo_state==STEREOLEFT_PANNED) {
  1031. m = LEFT; /* left to right */
  1032. k = RIGHT;
  1033. thisscale = dz->act[n]->val->rrscale;
  1034. } else {
  1035. m = RIGHT; /* right to left */
  1036. k = LEFT;
  1037. thisscale = dz->act[n]->val->llscale;
  1038. }
  1039. if(thisscale==0.0) {
  1040. while(m<dz->ssampsread) {
  1041. inbuf[m] = 0.0f;
  1042. m+=2;
  1043. }
  1044. }
  1045. else if(thisscale==1.0){
  1046. while(m<dz->ssampsread) {
  1047. inbuf[k] = stereobuf[m];
  1048. m+=2;
  1049. k+=2;
  1050. }
  1051. }
  1052. else{
  1053. while(m<dz->ssampsread) {
  1054. inbuf[k] = (float)(stereobuf[m] * thisscale);
  1055. m+=2;
  1056. k+=2;
  1057. }
  1058. }
  1059. break;
  1060. default:
  1061. sprintf(errstr,"Unknown case in scale_smps()\n");
  1062. return (PROGRAM_ERROR);
  1063. }
  1064. return(FINISHED);
  1065. }