File: vox.c

package info (click to toggle)
bristol 0.60.10-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,652 kB
  • sloc: ansic: 124,457; sh: 10,579; makefile: 111
file content (940 lines) | stat: -rw-r--r-- 22,571 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940

/*
 *  Diverse Bristol audio routines.
 *  Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
 *
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 */
/*#define BRISTOL_DBG */
/*
 * Need to have basic template for an operator. Will consist of
 *
 *	voxinit()
 *	operate()
 *	reset()
 *	destroy()
 *
 *	destroy() is in the library.
 *
 * Operate will be called when all the inputs have been loaded, and the result
 * will be an output buffer written to the next operator.
 */

#include <stdlib.h>
#include <math.h>

#include "bristol.h"
#include "bristolblo.h"
#include "vox.h"

float note_diff;
int samplecount;

static void fillWave(float *, int, int);
static void buildVoxSound(bristolOP *, bristolOPParams *, unsigned char);
static void fillVoxWave(bristolOP *, int);
static void fillVoxM2Wave(bristolOP *, bristolOPParams *);

/*
 * Use of these mean that we can only product a single vox oscillator.
 * Even though it is reasonably flexible this does lead to problems, and if
 * we move to a dual manual Vox it will need to be resolved.
 *
 * The same is true of using single global result waves, wave[6] and wave[7].
 * These need to be moved to private address space, ie, we need more 
 * instantiation.
 */
static int *wavelevel;

float *wave1;
float *wave2;

/*
 * This can be a single list, it is used to generate the different pipes.
 *
 * We have 16, 8, 4, 2, 1
{16', 8', 4', 5-1/3', 2-2/3', 2', 1-1/3', 1-1/5', 1', 0,0,0,0,0,0,0};
{ 2,  4,  8,      6,     12, 16,     20,     24, 32, 0,0,0,0,0,0,0};
 */
static float sweeps[16] = {2, 4, 8, 6, 12, 16, 20, 24, 32, 0,0,0,0,0,0,0};

/*
 * The name of this operator, IO count, and IO names.
 */
#define OPNAME "Vox"
#define OPDESCRIPTION "Digitally Controlled Oscillator"
#define PCOUNT 3
#define IOCOUNT 2

#define VOX_IN_IND 0
#define VOX_OUT_IND 1
#define VOX_PERC_IND 2

/*
 * Reset any local memory information.
 */
static int destroy(bristolOP *operator)
{
#ifdef BRISTOL_DBG
	printf("voxdestroy(%x)\n", operator);
#endif

	/*
	 * Unmalloc anything we added to this structure
	 */
	bristolfree(((bristolVOX *) operator)->wave[0]);
	bristolfree(((bristolVOX *) operator)->wave[1]);
	bristolfree(((bristolVOX *) operator)->wave[2]);
	bristolfree(((bristolVOX *) operator)->wave[3]);
	bristolfree(((bristolVOX *) operator)->wave[4]);
	bristolfree(((bristolVOX *) operator)->wave[5]);
	bristolfree(((bristolVOX *) operator)->wave[6]);
	bristolfree(((bristolVOX *) operator)->wave[7]);

	bristolfree(operator->specs);

	/*
	 * Free any local memory. We should also free ourselves, since we did the
	 * initial allocation.
	 */
	cleanup(operator);
	return(0);
}

/*
 * Reset any local memory information.
 */
static int reset(bristolOP *operator, bristolOPParams *param)
{
#ifdef BRISTOL_DBG
	printf("voxreset(%x, %x)\n", operator, param);
#endif

	/*
	 * For the vox we want to put in a few local memory variables for this
	 * operator specifically.
	 *
	 * These are sineform, waveindex, wavelevel, and percussions, plus two
	 * unique wavetables.
	 */
	param->param[0].mem = bristolmalloc0(sizeof(int) * 16);
	param->param[1].mem = bristolmalloc0(sizeof(float) * VOX_WAVE_SZE);
	param->param[2].mem = bristolmalloc0(sizeof(int) * 16);
	param->param[3].mem = bristolmalloc0(sizeof(int) * 16);
	param->param[4].mem = bristolmalloc0(sizeof(float) * VOX_WAVE_SZE);
	param->param[5].mem = bristolmalloc0(sizeof(int) * 16);
	param->param[6].mem = bristolmalloc0(sizeof(float) * VOX_WAVE_SZE);
	param->param[7].int_val = 1;
	param->param[7].int_val = 0;
	param->param[4].float_val = 0.166880;
	param->param[1].float_val = 1;
	param->param[5].int_val = 0;
	return(0);
}

/*
 * Alter an internal parameter of an operator.
 */
static int param(bristolOP *operator, bristolOPParams *param,
	unsigned char index, float value)
{
	wavelevel = (int *) param->param[2].mem;

	wave1 = (float *) param->param[1].mem;
	wave2 = (float *) param->param[6].mem;

#ifdef BRISTOL_DBG
	printf("	voxparam(%x, %x, %i, %x)\n", operator, param, index,
		((int) (value * CONTROLLER_RANGE)));
#endif

	switch (index) {
		case 0:
			param->param[index].float_val = value;
			buildVoxSound(operator, param, (int) (value * CONTROLLER_RANGE));
			break;
		case 1: /* gain */
			param->param[index].float_val = value;
			break;
		case 2: /* First percussive */
		case 3: /* Second percussive */
			if (value == 0.0)
				param->param[index].int_val = 0;
			else
				param->param[index].int_val = 1;
			break;
		case 4: /* Mark-1 or Mark-II oscillator */
			if (value == 0.0)
				param->param[index].int_val = 0;
			else
				param->param[index].int_val = 1;
			break;
		case 5:
			/* Wavefore - 0=infinite, X=deformed */
			param->param[index].int_val =  (int) (value * CONTROLLER_RANGE);;
			buildVoxSound(operator, param,
				(int) (param->param[0].float_val * CONTROLLER_RANGE));
			break;
	}

	return(0);
}

/*
 * As of the first write, 9/11/01, this takes nearly 20mips to operate a single
 * oscillator. Will work on optimisation of the code, using non-referenced 
 * variables in register workspace.
 *
 *	output buffer pointer.
 *	output buffer index.
 *	input buffer index.
 *	wavetable.
 *	wavetable index.
 *	count.
 *	gain.
 *
 * With optimisations this is reduced to a nominal amount. Put most parameters
 * in registers, and then stretched the for loop to multiples of 16 samples.
 */
static int operate(bristolOP *operator,
	bristolVoice *voice,
	bristolOPParams *param,
	void *lcl)
{
	register bristolVOXlocal *local = lcl;
	register int obp = 0, count;
	register float *ib, *ob, *pb, *pt, *wt, wtp, gain;
	bristolVOX *specs;

	specs = (bristolVOX *) operator->specs;

#ifdef BRISTOL_DBG
	printf("vox(%x, %x, %x)\n", operator, param, local);
#endif

	count = specs->spec.io[VOX_OUT_IND].samplecount;
	ib = specs->spec.io[VOX_IN_IND].buf;
	ob = specs->spec.io[VOX_OUT_IND].buf;
	pb = specs->spec.io[VOX_PERC_IND].buf;
	wt = (float *) param->param[1].mem;
	pt = (float *) param->param[6].mem;
	gain = param->param[1].float_val;
	wtp = local->wtp;

	if (voice->flags & BRISTOL_KEYON)
	{
		wtp = 0;
		if ((~voice->flags & BRISTOL_KEYREON) &&
			(voice->offset > 0) && (voice->offset < count))
		{
			if (voice->baudio->midiflags & BRISTOL_MIDI_DEBUG1)
				printf("envelope trigger offset %i frames\n", voice->offset);

			//count += voice->offset;
			obp += voice->offset;
		}
	}

	for (; obp < count;)
	{
		/*
		 * Take a sample from the wavetable into the output buffer. This 
		 * should also be scaled by gain parameter.
		 */
		if (wtp >= VOX_WAVE_SZE_M) {
			ob[obp] += (wt[0] * (wtp - ((float) ((int) wtp)))
				+ wt[(int) wtp] * (1.0 - (wtp - ((float) ((int) wtp)))))
				* gain;
			pb[obp] += (pt[0] * (wtp - ((float) ((int) wtp)))
				+ pt[(int) wtp] * (1.0 - (wtp - ((float) ((int) wtp)))))
				* gain;
		} else {
			ob[obp] += (wt[(int) wtp + 1] * (wtp - ((float) ((int) wtp)))
				+ wt[(int) wtp] * (1.0 - (wtp - ((float) ((int) wtp)))))
				* gain;
			pb[obp] += (pt[(int) wtp + 1] * (wtp - ((float) ((int) wtp)))
				+ pt[(int) wtp] * (1.0 - (wtp - ((float) ((int) wtp)))))
				* gain;
		}

		if ((wtp += ib[obp++] * 0.25) >= (float) VOX_WAVE_SZE)
			wtp -= VOX_WAVE_SZE;
	}

	local->wtp = wtp;
	return(0);
}

/*
 * Setup any variables in our OP structure, in our IO structures, and malloc
 * any memory we need.
 */
bristolOP *
voxdcoinit(bristolOP **operator, int index, int samplerate, int samplecount)
{
	bristolVOX *specs;

#ifdef BRISTOL_DBG
	printf("voxinit(%x(%x), %i, %i, %i)\n",
		operator, *operator, index, samplerate, samplecount);
#endif

	*operator = bristolOPinit(operator, index, samplecount);
	note_diff = pow(2, ((float) 1)/12);;

	/*
	 * Then the local parameters specific to this operator. These will be
	 * the same for each operator, but must be inited in the local code.
	 */
	(*operator)->operate = operate;
	(*operator)->destroy = destroy;
	(*operator)->reset = reset;
	(*operator)->param = param;

	specs = (bristolVOX *) bristolmalloc0(sizeof(bristolVOX));
	(*operator)->specs = (bristolOPSpec *) specs;
	(*operator)->size = sizeof(bristolVOX);

	/*
	 * These are specific to this operator, and will need to be altered for
	 * each operator.
	 */
	specs->spec.opname = OPNAME;
	specs->spec.description = OPDESCRIPTION;
	specs->spec.pcount = PCOUNT;
	specs->spec.iocount = IOCOUNT;
	specs->spec.localsize = sizeof(bristolVOXlocal);

	/*
	 * We are going to assign multiple waves to this oscillator.
	 * sine, ramp, square, triangle?
	 */
	specs->wave[0] = (float *) bristolmalloc(VOX_WAVE_SZE * sizeof(float));
	specs->wave[1] = (float *) bristolmalloc(VOX_WAVE_SZE * sizeof(float));
	specs->wave[2] = (float *) bristolmalloc(VOX_WAVE_SZE * sizeof(float));
	specs->wave[3] = (float *) bristolmalloc(VOX_WAVE_SZE * sizeof(float));
	specs->wave[4] = (float *) bristolmalloc(VOX_WAVE_SZE * sizeof(float));
	specs->wave[5] = (float *) bristolmalloc(VOX_WAVE_SZE * sizeof(float));
	specs->wave[6] = (float *) bristolmalloc(VOX_WAVE_SZE * sizeof(float));
	specs->wave[7] = (float *) bristolmalloc(VOX_WAVE_SZE * sizeof(float));

	/*
	 * FillWave is something that should be called as a parameter change, but
	 * for testing will load it here.
	 */
	fillWave(specs->wave[0], VOX_WAVE_SZE, 0);
	fillWave(specs->wave[1], VOX_WAVE_SZE, 1);
	fillWave(specs->wave[2], VOX_WAVE_SZE, 2);
	fillWave(specs->wave[3], VOX_WAVE_SZE, 3);
	fillWave(specs->wave[4], VOX_WAVE_SZE, 4);
	fillWave(specs->wave[5], VOX_WAVE_SZE, 5);
	fillWave(specs->wave[6], VOX_WAVE_SZE, 6);
	fillWave(specs->wave[7], VOX_WAVE_SZE, 7);

	/*
	 * Now fill in the vox specs for this operator. These are specific to an
	 * oscillator.
	 */
	specs->spec.param[0].pname = "Sineform";
	specs->spec.param[0].description = "Pulse code of sinewave";
	specs->spec.param[0].type = BRISTOL_INT;
	specs->spec.param[0].low = 0;
	specs->spec.param[0].high = 1;
	specs->spec.param[0].flags = BRISTOL_ROTARY|BRISTOL_SLIDER;

	specs->spec.param[1].pname = "Gain";
	specs->spec.param[1].description = "Pitch correction factor";
	specs->spec.param[1].type = BRISTOL_FLOAT;
	specs->spec.param[1].low = 0;
	specs->spec.param[1].high = 1;
	specs->spec.param[1].flags = BRISTOL_ROTARY|BRISTOL_SLIDER;

	/*
	 * Now fill in the vox IO specs.
	 */
	specs->spec.io[0].ioname = "input";
	specs->spec.io[0].description = "input rate modulation signal";
	specs->spec.io[0].samplerate = samplerate;
	specs->spec.io[0].samplecount = samplecount;
	specs->spec.io[0].flags = BRISTOL_DC|BRISTOL_INPUT;

	specs->spec.io[1].ioname = "output";
	specs->spec.io[1].description = "oscillator output signal";
	specs->spec.io[1].samplerate = samplerate;
	specs->spec.io[1].samplecount = samplecount;
	specs->spec.io[1].flags = BRISTOL_AC|BRISTOL_OUTPUT;

	specs->spec.io[2].ioname = "percussive output";
	specs->spec.io[2].description = "output of signals for percussive process";
	specs->spec.io[2].samplerate = samplerate;
	specs->spec.io[2].samplecount = samplecount;
	specs->spec.io[2].flags = BRISTOL_AC|BRISTOL_OUTPUT;

	return(*operator);
}

/*
static void filltriwave(register float *mem, register int count,
register double reach)
{
	register int i;

	if (bloflags & BRISTOL_BLO)
	{
		for (i = 0;i < count; i++)
			mem[i] = blotriangle[i];
		return;
	}
}
*/

/*
 * Hm, just in case you could not tell, this is a phase distortion oscillator.
 * It is somewhat warmer than the original vox.
 */
static void fillpdwave(register float *mem, register int count,
register double reach)
{
	register int i, recalc1 = 1, recalc2 = 1;
	register double j = 0, Count = (double) count, inc = reach;

	for (i = 0;i < count; i++)
	{
		mem[i] = sin(((double) (2 * M_PI * j)) / Count) * VOX_WAVE_GAIN;

		if ((j > (count * 3 / 4)) && recalc2)
		{
			recalc2 = 0;
			inc = ((float) (count / 4)) / (((float) count) - i);
		} else if ((j > (count / 4)) && recalc1) {
			recalc1 = 0;
			/* 
			 * J has the sine on a peak, we need to calculate the number
			 * of steps required to get the sine back to zero crossing by
			 * the time i = count / 2, ie, count /4 steps in total.
			 */
			inc = ((float) (count / 4)) / (((float) (count / 2)) - i);
		}

		j += inc;
	}

/*
	printf("\n%f, %f\n", j, inc);
	for (i = 0; i < count; i+=8)
	{
		printf("\n%i: ", i + k);
		for (k = 0; k < 8; k++)
			printf("%03.1f, ", mem[i + k]);
	}
	printf("\n");
*/
}

static void
fillWave(register float *mem, register int count, int type)
{
	register double Count;

#ifdef BRISTOL_DBG
	printf("fillWave(%x, %i, %i)\n", mem, count, type);
#endif

	Count = (double) count;

	switch (type) {
		case 0:
			/*
			 * This will be a sine wave. We have count samples, and
			 * 2PI radians in a full sine wave. Thus we take
			 * 		(2PI * i / count) * 2048.
			filltriwave(mem, count, 1.0);
			 */
			fillpdwave(mem, count, 1.0);
		case 1:
		default:
			fillpdwave(mem, count, 1.05);
			return;
		case 2:
			fillpdwave(mem, count, 1.10);
			return;
		case 3:
			fillpdwave(mem, count, 1.30);
			return;
		case 4:
			fillpdwave(mem, count, 1.60);
			return;
		case 5:
			fillpdwave(mem, count, 2.0);
			return;
		case 6:
			fillpdwave(mem, count, 3.0);
			return;
		case 7:
			fillpdwave(mem, count, 10.0);
			return;
	}
}

static void
buildVoxSound(bristolOP *operator, bristolOPParams *params, unsigned char parm)
{
	int controller;

#ifdef BRISTOL_DBG
	printf("buildVoxSound(%x, %i, %i, %i)\n", operator, parm, parm >> 3, parm & 0x07);
#endif

	if (parm != 0xff)
	{
		if ((controller = parm >> 4) > 16)
			return;

		/*
		 * Mask out the level of this wave.
		 */
		wavelevel[controller] = parm & 0x0f;
	}

	if (params->param[4].int_val == 0)
		fillVoxWave(operator, params->param[5].int_val);
	else
		fillVoxM2Wave(operator, params);
}

static void
fillVoxWave(bristolOP *operator, int form)
{
	register float gain, *source, *dest, sweep, oscindex;
	register int i, j;
	bristolVOX *specs;

	specs = (bristolVOX *) operator->specs;

#ifdef BRISTOL_DBG
	printf("fillVoxWave(%x, %i)\n", operator, form);
#endif

	/*
	 * Dest is actually the local wave for this operator.
	 */
	bristolbzero(wave1, VOX_WAVE_SZE * sizeof(float));

	/*
	 * We now have a volume array:

		f 16'
		2f 8'
		3f 4'
		2-2/3 2, 1 1/3 1
		flute level (sine)
		reed level (ramp)
	 */

/*	printf("%4i %4i %4i %4i %4i %4i %4i %4i %4i\n", */
/*	wavelevel[0], wavelevel[1], wavelevel[2], wavelevel[3], wavelevel[4], */
/*	wavelevel[5], wavelevel[6], wavelevel[7], wavelevel[8]); */

	/*
	 * Do this for the flute, or sine waves.
	 */
	for (i = 0; i < 3; i++)
	{
		oscindex = 0;

		/*
		 * Take the sinewave and the destination wave.
		 */
		if (form == 0) {
			source = specs->wave[0];
			gain = ((float) (wavelevel[i] * wavelevel[4])) / 64.0;
		} else {
			source = blotriangle;
			gain = ((float) (wavelevel[i] * wavelevel[4])) / 3.0;
		}

		dest = wave1;

		if (gain == 0)
			continue;

		sweep = sweeps[i] * 2;

		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}
	}

	/*
	 * Do this for the reed, or ramp waves.
	 */
	for (i = 0; i < 3; i++)
	{
		oscindex = 0;
		/*
		 * Take the sinewave and the destination wave.
		 */
		source = specs->wave[7];

		dest = wave1;

		gain = ((float) (wavelevel[i] * wavelevel[5])) / 64.0;

		if (gain == 0)
			continue;

		sweep = sweeps[i] * 4;

		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}
	}

	/*
	 * Do Draw-IV for the flute, or sine waves.
	 */
	for (i = 3; i < 9; i++)
	{
		if ((i == 6) || (i == 7))
			continue;

		oscindex = 0;
		/*
		 * Take the sinewave and the destination wave.
		 */
		if (form == 0) {
			source = specs->wave[0];
			gain = ((float) (wavelevel[3] * wavelevel[4])) / 64.0;
		} else {
			source = blotriangle;
			gain = ((float) (wavelevel[3] * wavelevel[4])) / 3.0;
		}

		dest = wave1;

		if (gain == 0)
			continue;

		sweep = sweeps[i];

		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}
	}

	/*
	 * Do Draw-IV for the reed, or ramp waves.
	 */
	for (i = 3; i < 9; i++)
	{
		if ((i == 6) || (i == 7))
			continue;

		oscindex = 0;
		/*
		 * Take the sinewave and the destination wave.
		 */
		source = specs->wave[7];

		dest = wave1;

		gain = ((float) (wavelevel[3] * wavelevel[5])) / 64.0;

		if (gain == 0)
			continue;

		sweep = sweeps[i] * 2;

		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}
	}
}

/*
 * This was changed for release 0.10.9 so that it could support two wave table
 * sources, one for the drawbars and another for the percussives.
 */
static void
fillVoxM2Wave(bristolOP *operator, bristolOPParams *params)
{
	register float gain, *source, *dest, sweep, oscindex;
	register int i, j;
	bristolVOX *specs;

	specs = (bristolVOX *) operator->specs;

#ifdef BRISTOL_DBG
	printf("fillVoxM2Wave(%x)\n", operator);
#endif

	/*
	 * Dest is actually the local wave for this operator.
	 */
	bristolbzero(wave1, VOX_WAVE_SZE * sizeof(float));
	bristolbzero(wave2, VOX_WAVE_SZE * sizeof(float));

	/*
	 * We now have a volume array:

		f 16'
		2f 8'
		3f 4'
		2-2/3, 2, 1-1/3, 1
		flute level (sine)
		reed level (ramp)
		5-1/3, 1-3/5
		2-2/3, 2, 1


	printf("%4i %4i %4i %4i %4i %4i %4i %4i %4i\n",
	wavelevel[0], wavelevel[1], wavelevel[2], wavelevel[3], wavelevel[4],
	wavelevel[5], wavelevel[6], wavelevel[7], wavelevel[8]);
	 */

	/*
	 * Do 16/8/4 for the flute, or sine waves.
	 */
	for (i = 0; i < 3; i++)
	{
		oscindex = 0;

		/*
		 * Take the sinewave and the destination wave.
		 */
		source = specs->wave[0];

		dest = wave1;
		if ((i == 2) && (params->param[2].int_val != 0))
			dest = wave2;

		gain = ((float) (wavelevel[i] * wavelevel[4])) / 64.0;

		if (gain == 0)
			continue;

		sweep = sweeps[i] * 2;

		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}
	}

	/*
	 * Do 16/8/4 for the reed, or ramp waves.
	 */
	for (i = 0; i < 3; i++)
	{
		oscindex = 0;
		/*
		 * Take the sinewave and the destination wave.
		 */
		source = specs->wave[7];

		dest = wave1;
		if ((i == 2) && (params->param[2].int_val != 0))
			dest = wave2;

		gain = ((float) (wavelevel[i] * wavelevel[5])) / 64.0;

		if (gain == 0)
			continue;

		sweep = sweeps[i] * 4;

		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}
	}

	/*
	 * Do Draw-II for the flute, or sine waves. This is 5-1/3 and 1-3/5
	 * which are indeces 3 and 7. There is an optional percussive.
	 */
	gain = ((float) (wavelevel[6] * wavelevel[4])) / 64.0;
	if (gain != 0)
	{
		oscindex = 0;
		/*
		 * Take the sinewave and the destination wave.
		 */
		source = specs->wave[0];
		dest = wave1;
		if (params->param[3].int_val != 0)
			dest = wave2;

		sweep = sweeps[3];

		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}

		oscindex = 0;
		dest = wave1;
		if (params->param[3].int_val != 0)
			dest = wave2;

		sweep = sweeps[7];

		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}
	}
	gain = ((float) (wavelevel[6] * wavelevel[5])) / 64.0;
	if (gain != 0)
	{
		oscindex = 0;
		/*
		 * Take the rempwave and the destination wave.
		 */
		source = specs->wave[7];
		dest = wave1;
		if (params->param[3].int_val != 0)
			dest = wave2;

		sweep = sweeps[3] * 2;

		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}

		oscindex = 0;
		dest = wave1;
		if (params->param[3].int_val != 0)
			dest = wave2;

		sweep = sweeps[7] * 2;

		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}
	}




	/*
	 * Do Draw-III for the reed, or ramp waves. This is 2-2/3, 2 and 1 which 
	 * are indices 4, 5 and 8.
	 */
	gain = ((float) (wavelevel[7] * wavelevel[4])) / 64.0;
	if (gain != 0)
	{
		oscindex = 0;
		/*
		 * Take the sinewave and the destination wave.
		 */
		source = specs->wave[0];
		dest = wave1;
		sweep = sweeps[4];
		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}

		oscindex = 0;
		dest = wave1;
		sweep = sweeps[5];
		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}

		oscindex = 0;
		dest = wave1;
		sweep = sweeps[8];
		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}
	}

	gain = ((float) (wavelevel[7] * wavelevel[5])) / 64.0;
	if (gain != 0)
	{
		oscindex = 0;
		/*
		 * Take the rampwave and the destination wave.
		 */
		source = specs->wave[7];

		dest = wave1;
		sweep = sweeps[4];
		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}

		oscindex = 0;
		dest = wave1;
		sweep = sweeps[5];
		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}

		oscindex = 0;
		dest = wave1;
		sweep = sweeps[8];
		for (j = 0; j < VOX_WAVE_SZE; j++)
		{
			*dest++ += source[(int) oscindex] * gain;
			if ((oscindex += sweep) >= VOX_WAVE_SZE)
				oscindex -= VOX_WAVE_SZE;
		}
	}
}