File: bristoldx.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 (875 lines) | stat: -rw-r--r-- 28,607 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

/*
 *  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 DEBUG */

#include "bristol.h"
#include "dxop.h"

extern int bristolGlobalController(struct BAudio *, u_char, u_char, float);

float *lfobuf, *op0buf, *op1buf, *op2buf, *op3buf, *op4buf, *modbuf;

int
DXGlobalController(Baudio *baudio, u_char controller,
u_char operator, float value)
{
	int op, index;
	dxmix *mix = (dxmix *) baudio->mixlocals;

	/*
	 * Rhodes Chorus
	 */
	if (controller == 123)
	{
		if ((baudio->effect[0] == NULL) || (operator > 3))
		{
			printf("no effect to process\n");
			return(0);
		}

		baudio->effect[0]->param->param[operator].float_val = value;

		return(0);
	}

	/*
	 * DX global controller code.
	 */
/*printf("DXGlobalController(%i, %i, %f)\n", controller, operator, value); */

	if (operator == 99)
	{
/*
		if (operator == 0) {
			baudio->gtune = 1.0
				+ (baudio->note_diff - 1)
				* (value * 2 - 1);

			buildCurrentTable(baudio, baudio->gtune);
			alterAllNotes(baudio);
		} else {
			baudio->midi_pitch = value * 24;
		}
*/
		baudio->midi_pitch = value * 24;
		return(0);
	}

	if (operator == 100)
	{
		baudio->glide = value * value * baudio->glidemax;
		return(0);
	}

	if (operator == 101)
	{
		baudio->mixflags &= ~DX_ALGO_M;
		baudio->mixflags |= (int) (value * CONTROLLER_RANGE);
/*printf("flags are now %x from %i\n", baudio->mixflags, */
/*(int) (value * CONTROLLER_RANGE)); */
		return(0);
	}

	/*
	 * Main volume
	 */
	if (operator == 102)
	{
		mix[0].vol = value;
		return(0);
	}

	/*
	 * We have an algorithm parameter which configures the order of IO for the
	 * fm operators, and a set of flags for key tracking per operator.
	 */
	op = operator / 10;
	index = operator - (op * 10);

	switch (index) {
		case 0:
			mix[op].igain = value * 4;
			break;
		case 1:
			/*
			 * Key tracking (ie, may function as LFO).
			 */
			if (value != 0)
				mix[op].flags &= ~DX_KEY;
			else
				mix[op].flags |= DX_KEY;
			break;
		case 2:
			mix[op].pan = value;
			break;
		case 3:
			/*
			 * Configure cont controller 1 to adust IGAIN.
			 */
			if (value == 0)
				mix[op].flags &= ~DX_IGC;
			else
				mix[op].flags |= DX_IGC;
			break;
	}
	return(0);
}

void
dxOpOne(int ind, float *kbuf, float *opbuf, float *obuf, int count,
dxmix *mix, audioMain *am, Baudio *ba, bristolVoice *v)
{
	float igain = mix[ind].igain;
	int flags = v->flags & BRISTOL_KEYDONE;

	bufmerge(opbuf, 1.0, modbuf, 0.0, count);
/*printf("dxOpOne(%i)\n", ind); */

	if (mix[ind].flags & DX_IGC)
		igain *= ba->contcontroller[1];
		
	/*
	 * Check on our mods,
	 */
	if (mix[ind].flags & DX_KEY)
		bufmerge(kbuf, 1.0, modbuf, igain, count);
	else
		bufmerge(lfobuf, 1.0, modbuf, igain, count);

	/*
	 * Push in our pointers. Note that if we move the pointers into the
	 * params structure we could avoid doing this for each op.
	 */
	am->palette[(*ba->sound[0]).index]->specs->io[0].buf = modbuf;
	am->palette[(*ba->sound[0]).index]->specs->io[1].buf = obuf;

	/*
	 * Call the operator.
	 */
	(*ba->sound[ind]).operate(
		(am->palette)[9],
		v,
		(*ba->sound[ind]).param,
		v->locals[v->index][ind]);

	v->flags = v->flags & flags? v->flags: v->flags & ~BRISTOL_KEYDONE;
}

int
DXalgoN(audioMain *am, register Baudio *ba, bristolVoice *voice, float *kb)
{
	register int i, sc = am->samplecount;
	register float *bufptr = lfobuf;
	dxmix *mix = (dxmix *) ba->mixlocals;

	/*
	 * Fill the wavetable with the correct note value
	 */
	fillFreqTable(ba, voice, kb, sc, 1);
	/*
	 * Build a LFO frequency table
	 */
	for (i = 0; i < sc ; i+=8)
	{
		*bufptr++ = 0.001 + ba->contcontroller[1] / 2;
		*bufptr++ = 0.001 + ba->contcontroller[1] / 2;
		*bufptr++ = 0.001 + ba->contcontroller[1] / 2;
		*bufptr++ = 0.001 + ba->contcontroller[1] / 2;
		*bufptr++ = 0.001 + ba->contcontroller[1] / 2;
		*bufptr++ = 0.001 + ba->contcontroller[1] / 2;
		*bufptr++ = 0.001 + ba->contcontroller[1] / 2;
		*bufptr++ = 0.001 + ba->contcontroller[1] / 2;
	}

	bzero(op0buf, am->segmentsize);
	bzero(op1buf, am->segmentsize);
	bzero(op2buf, am->segmentsize);

	switch (ba->mixflags & DX_ALGO_M) {
		case 0:
			/*
			 * Op0 feeds op1, op2 feeds op3, op4 feeds op5.
			 */
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(3, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[3].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[3].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op1buf, am->segmentsize);
			bzero(op2buf, am->segmentsize);
			dxOpOne(1, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[4].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[4].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op1buf, am->segmentsize);
			bzero(op2buf, am->segmentsize);
			dxOpOne(2, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(5, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 1:
			/*
			 * Op0 feeds op1 into op2, then op3 feeds op4 into op5.
			 */
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(2, kb, op2buf, op0buf, sc, mix, am, ba, voice);
			bufmerge(op0buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op0buf, am->segmentsize);
			bzero(op1buf, am->segmentsize);
			bzero(op2buf, am->segmentsize);
			dxOpOne(3, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(5, kb, op2buf, op0buf, sc, mix, am, ba, voice);
			bufmerge(op0buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 2:
		case 19:
		case 20:
			/*
			 * Op0 feeds op1 and op2, then op3 feeds op4 and op5.
			 */
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(2, kb, op1buf, op0buf, sc, mix, am, ba, voice);

			bufmerge(op2buf, mix[0].vol * mix[1].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[1].pan), ba->leftbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op0buf, am->segmentsize);
			bzero(op1buf, am->segmentsize);
			bzero(op2buf, am->segmentsize);
			dxOpOne(3, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(5, kb, op1buf, op0buf, sc, mix, am, ba, voice);

			bufmerge(op2buf, mix[0].vol * mix[4].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[4].pan), ba->leftbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 3:
			/*
			 * Op0 and op1 feed op2, then op3 and op4 feed op5.
			 * These then need a crossover between the L and R channels.
			 */
			bzero(op3buf, am->segmentsize);
			bzero(op4buf, am->segmentsize);
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(2, kb, op1buf, op3buf, sc, mix, am, ba, voice);

			bzero(op0buf, am->segmentsize);
			dxOpOne(3, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(5, kb, op2buf, op4buf, sc, mix, am, ba, voice);

			bufmerge(op3buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);
			bufmerge(op4buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op4buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);
			break;
		case 4:
		case 11: /* Same algo, just 4 and 5 take no input from 1. */
			/*
			 * Op0 feeds op1, op2 into op3. It also feeds op4 and op5 into op6.
			 */
			bzero(op3buf, am->segmentsize);
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(2, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			bzero(op3buf, am->segmentsize);
			dxOpOne(3, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(5, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);
			break;
		case 5:
			/*
			 * op1 feeds op2 into op3, and op4 into op5 and op6.
			 */
			bzero(op3buf, am->segmentsize);
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(2, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			bzero(op3buf, am->segmentsize);
			dxOpOne(3, kb, op1buf, op0buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(5, kb, op0buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[4].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[4].pan), ba->leftbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);
			break;
		case 6:
			/*
			 * Op0 feeds op4. Op4 feeds op2, op3, op5 and op6.
			 */
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(3, kb, op1buf, op2buf, sc, mix, am, ba, voice);

			bzero(op3buf, am->segmentsize);
			dxOpOne(1, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[1].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[1].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op3buf, am->segmentsize);
			dxOpOne(2, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op3buf, am->segmentsize);
			dxOpOne(4, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[4].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[4].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op3buf, am->segmentsize);
			dxOpOne(5, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 7:
		case 18:
			/*
			 * Op0 and op1 feed op2, then op3 feeds op4 and op5.
			 */
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(2, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			bzero(op3buf, am->segmentsize);
			dxOpOne(3, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[4].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[4].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op3buf, am->segmentsize);
			dxOpOne(5, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 8:
			/*
			 * Op0 and op1 feed op2, and ops 3 to 6 feed eachother.
			 */
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op1buf, op0buf, sc, mix, am, ba, voice);
			bufmerge(op0buf, mix[0].vol * mix[1].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * (1.0 - mix[1].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op0buf, am->segmentsize);
			bzero(op1buf, am->segmentsize);
			bzero(op3buf, am->segmentsize);
			bzero(op4buf, am->segmentsize);
			dxOpOne(2, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(3, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			dxOpOne(5, kb, op3buf, op4buf, sc, mix, am, ba, voice);
			bufmerge(op4buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op4buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 9:
			/*
			 * Op2 feeds op3 into op4. Then 0, 1 and  op4 feed 5.
			 */
			bzero(op3buf, am->segmentsize);
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op0buf, op1buf, sc, mix, am, ba, voice);

			dxOpOne(2, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(3, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op3buf, op1buf, sc, mix, am, ba, voice);

			dxOpOne(5, kb, op1buf, op0buf, sc, mix, am, ba, voice);
			bufmerge(op0buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 10:
			/*
			 * Op0 feeds op1, op 3 feed op4, then 4 and 2 feed 5.
			 */
			dxOpOne(0, kb, op1buf, op0buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			bufmerge(op1buf, mix[0].vol * mix[1].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op1buf, mix[0].vol * (1.0 - mix[1].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op3buf, am->segmentsize);
			bzero(op4buf, am->segmentsize);
			dxOpOne(2, kb, op3buf, op4buf, sc, mix, am, ba, voice);

			dxOpOne(3, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op3buf, op4buf, sc, mix, am, ba, voice);

			dxOpOne(5, kb, op4buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		/*case 11: // offloaded into algo 4 - good as the same. */
		case 12:
			/*
			 * Op0 feeds op1, and 2, 3 and 4 feed op 5.
			 */
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op1buf, op0buf, sc, mix, am, ba, voice);
			bufmerge(op0buf, mix[0].vol * mix[1].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * (1.0 - mix[1].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op3buf, am->segmentsize);
			bzero(op4buf, am->segmentsize);
			dxOpOne(2, kb, op3buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(3, kb, op3buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			dxOpOne(5, kb, op3buf, op4buf, sc, mix, am, ba, voice);
			bufmerge(op4buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op4buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 13:
			bzero(op3buf, am->segmentsize);
			dxOpOne(0, kb, op3buf, op0buf, sc, mix, am, ba, voice);

			dxOpOne(1, kb, op3buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(2, kb, op1buf, op0buf, sc, mix, am, ba, voice);

			dxOpOne(3, kb, op3buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op2buf, op0buf, sc, mix, am, ba, voice);

			dxOpOne(5, kb, op0buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op4buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op4buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 14:
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op1buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(2, kb, op2buf, op0buf, sc, mix, am, ba, voice);
			bufmerge(op0buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op4buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op0buf, am->segmentsize);
			bzero(op1buf, am->segmentsize);
			dxOpOne(3, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op1buf, op0buf, sc, mix, am, ba, voice);
			bufmerge(op0buf, mix[0].vol * mix[4].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op4buf, mix[0].vol * (1.0 - mix[4].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op0buf, am->segmentsize);
			bzero(op1buf, am->segmentsize);
			dxOpOne(5, kb, op1buf, op0buf, sc, mix, am, ba, voice);
			bufmerge(op0buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op4buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;

		case 15:
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op1buf, op0buf, sc, mix, am, ba, voice);

			bzero(op2buf, am->segmentsize);
			dxOpOne(2, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			dxOpOne(3, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[3].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[3].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			dxOpOne(4, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[4].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[4].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			dxOpOne(5, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 16:
			/*
			 * Op0 feeds op1, and 2, 3 and 4 feed op 5.
			 */
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op1buf, op0buf, sc, mix, am, ba, voice);
			bufmerge(op0buf, mix[0].vol * mix[1].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * (1.0 - mix[1].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op3buf, am->segmentsize);
			dxOpOne(2, kb, op3buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(3, kb, op3buf, op2buf, sc, mix, am, ba, voice);
			dxOpOne(4, kb, op3buf, op2buf, sc, mix, am, ba, voice);

			dxOpOne(5, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 17:
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			dxOpOne(1, kb, op1buf, op0buf, sc, mix, am, ba, voice);
			bufmerge(op0buf, mix[0].vol * mix[1].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op0buf, mix[0].vol * (1.0 - mix[1].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op3buf, am->segmentsize);
			dxOpOne(2, kb, op3buf, op2buf, sc, mix, am, ba, voice);

			dxOpOne(3, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[3].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[3].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op3buf, am->segmentsize);
			dxOpOne(4, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[4].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[4].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op3buf, am->segmentsize);
			dxOpOne(5, kb, op2buf, op3buf, sc, mix, am, ba, voice);
			bufmerge(op3buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op3buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 21:
		case 22:
			dxOpOne(0, kb, op1buf, op0buf, sc, mix, am, ba, voice);

			dxOpOne(1, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			bufmerge(op1buf, mix[0].vol * mix[1].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op1buf, mix[0].vol * (1.0 - mix[1].pan), ba->leftbuf, 1.0,
				am->samplecount);

			dxOpOne(2, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			dxOpOne(3, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[3].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[3].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			dxOpOne(4, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[4].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[4].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			dxOpOne(5, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
		case 23:
			dxOpOne(0, kb, op0buf, op1buf, sc, mix, am, ba, voice);
			bufmerge(op1buf, mix[0].vol * mix[0].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op1buf, mix[0].vol * (1.0 - mix[0].pan), ba->leftbuf, 1.0,
				am->samplecount);

			dxOpOne(1, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[1].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[1].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			dxOpOne(2, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[2].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[2].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			dxOpOne(3, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[3].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[3].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			dxOpOne(4, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[4].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[4].pan), ba->leftbuf, 1.0,
				am->samplecount);

			bzero(op2buf, am->segmentsize);
			dxOpOne(5, kb, op0buf, op2buf, sc, mix, am, ba, voice);
			bufmerge(op2buf, mix[0].vol * mix[5].pan, ba->rightbuf, 1.0,
				am->samplecount);
			bufmerge(op2buf, mix[0].vol * (1.0 - mix[5].pan), ba->leftbuf, 1.0,
				am->samplecount);

			break;
	}

	return(0);
}

int
DXalgoNpostops(audioMain *am, Baudio *ba, bristolVoice *v, register float *s)
{
	bufmerge(ba->leftbuf, 0.0, ba->leftbuf, 8.0, am->samplecount);
	bufmerge(ba->rightbuf, 0.0, ba->rightbuf, 8.0, am->samplecount);

	return(0);
}

int
destroyOneDXVoice(audioMain *audiomain, Baudio *baudio)
{
	printf("destroy DX sound\n");
	return(0);
	bristolfree(lfobuf);
	bristolfree(op0buf);
	bristolfree(op1buf);
	bristolfree(op2buf);
}

int
bristolDXInit(audioMain *audiomain, Baudio *baudio)
{
printf("initialising one DX sound\n");

	baudio->soundCount = 6; /* Number of operators in this DX voice */

	/*
	 * Assign an array of sound pointers.
	 */
	baudio->sound = (bristolSound **)
		bristolmalloc0(sizeof(bristolOP *) * baudio->soundCount);
	baudio->effect = (bristolSound **)
		bristolmalloc0(sizeof(bristolOP *) * baudio->soundCount);

	/*
	 * DX oscillators.
	 */
	initSoundAlgo(9, 0, baudio, audiomain, baudio->sound);
	initSoundAlgo(9, 1, baudio, audiomain, baudio->sound);
	initSoundAlgo(9, 2, baudio, audiomain, baudio->sound);
	initSoundAlgo(9, 3, baudio, audiomain, baudio->sound);
	initSoundAlgo(9, 4, baudio, audiomain, baudio->sound);
	initSoundAlgo(9, 5, baudio, audiomain, baudio->sound);

	baudio->param = DXGlobalController;
	baudio->destroy = destroyOneDXVoice;
	baudio->operate = DXalgoN;
	baudio->postops = DXalgoNpostops;

	if (lfobuf == 0)
		lfobuf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (op0buf == 0)
		op0buf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (op1buf == 0)
		op1buf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (op2buf == 0)
		op2buf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (op3buf == 0)
		op3buf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (op4buf == 0)
		op4buf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (modbuf == 0)
		modbuf = (float *) bristolmalloc0(audiomain->segmentsize);

	baudio->mixlocals = (float *) bristolmalloc0(12 * sizeof(dxmix));
	baudio->mixflags |= BRISTOL_STEREO;
	return(0);
}

int
bristolRhodesInit(audioMain *audiomain, Baudio *baudio)
{
printf("initialising one Rhodes sound\n");

	baudio->soundCount = 6; /* Number of operators in this DX voice */

	/*
	 * Assign an array of sound pointers.
	 */
	baudio->sound = (bristolSound **)
		bristolmalloc0(sizeof(bristolOP *) * baudio->soundCount);
	baudio->effect = (bristolSound **)
		bristolmalloc0(sizeof(bristolOP *) * baudio->soundCount);

	/*
	 * DX oscillators.
	 */
	initSoundAlgo(9, 0, baudio, audiomain, baudio->sound);
	initSoundAlgo(9, 1, baudio, audiomain, baudio->sound);
	initSoundAlgo(9, 2, baudio, audiomain, baudio->sound);
	initSoundAlgo(9, 3, baudio, audiomain, baudio->sound);
	initSoundAlgo(9, 4, baudio, audiomain, baudio->sound);
	initSoundAlgo(9, 5, baudio, audiomain, baudio->sound);

	/*
	 * Put in a vibrachorus on our effects list.
	 */
	initSoundAlgo(12, 0, baudio, audiomain, baudio->effect);

	baudio->param = DXGlobalController;
	baudio->destroy = destroyOneDXVoice;
	baudio->operate = DXalgoN;
	baudio->postops = DXalgoNpostops;

	if (lfobuf == 0)
		lfobuf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (op0buf == 0)
		op0buf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (op1buf == 0)
		op1buf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (op2buf == 0)
		op2buf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (op3buf == 0)
		op3buf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (op4buf == 0)
		op4buf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (modbuf == 0)
		modbuf = (float *) bristolmalloc0(audiomain->segmentsize);

	baudio->mixlocals = (float *) bristolmalloc0(12 * sizeof(dxmix));
	baudio->mixflags |= BRISTOL_STEREO;
	return(0);
}