File: bristolsampler.c

package info (click to toggle)
bristol 0.60.11-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 15,756 kB
  • sloc: ansic: 124,460; sh: 11,542; makefile: 100
file content (664 lines) | stat: -rw-r--r-- 17,822 bytes parent folder | download | duplicates (6)
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

/*
 *  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 "bristolmm.h"
#include "bristolsampler.h"

/*
 * Use of these sampler global buffers will be an issue with use of multiple
 * audio threads, unless we ensure a single thread deals with any given algo
 * type, since then they are only used sequencially.
 */
static float *freqbuf = (float *) NULL;
static float *pmodbuf = (float *) NULL;
static float *adsrbuf = (float *) NULL;
static float *filtbuf = (float *) NULL;
static float *oscbbuf = (float *) NULL;
static float *oscabuf = (float *) NULL;
static float *sbuf = (float *) NULL;

/*
 * These need to go into some local structure for multiple instances
 * of the sampler - malloc()ed into the baudio->mixlocals.
 */
typedef struct jMods {
	float lfo_fgain;
	unsigned int flags;
	void *lfolocals;
	void *adsrlocals;
	int pwmod;
	float pwmodval;
	int envtype;
	float vcfmodval;
	int negenv;
	float env2vcf;
	float lfo2vcf;
	float key2vcf;
	float wheel2vcf;
	float level;
	float chgain;
	int chspeed;
} jmods;

extern int s440holder;

int
samplerController(Baudio *baudio, u_char operator,
u_char controller, float value)
{
#ifdef DEBUG
	printf("bristolSamplerControl(%i, %i, %f)\n", operator, controller, value);
#endif

	/*
	 * These will be for our chorus.
	 */
	if (operator == 100)
	{
		int tval = value * CONTROLLER_RANGE;

printf("switch on %i\n", tval);
		switch (tval) {
			case 0:
				baudio->effect[0]->param->param[0].int_val = 500;
				baudio->effect[0]->param->param[0].float_val = 0;
				baudio->effect[0]->param->param[1].int_val = 500;
				break;
			case 1:
				baudio->effect[0]->param->param[0].int_val = 500;
				baudio->effect[0]->param->param[0].float_val = 0.4;
				baudio->effect[0]->param->param[1].int_val = 500;
				break;
			case 2:
				baudio->effect[0]->param->param[0].int_val = 100;
				baudio->effect[0]->param->param[0].float_val = 0.6;
				baudio->effect[0]->param->param[1].int_val = 100;
				break;
			case 3:
				baudio->effect[0]->param->param[0].int_val = 14;
				baudio->effect[0]->param->param[0].float_val = 0.7;
				baudio->effect[0]->param->param[1].int_val = 14;
				break;
			case 5:
				if (value == 0)
					baudio->effect[0]->param->param[operator].int_val = 0;
				else
					baudio->effect[0]->param->param[operator].int_val = 1;
				break;
		}
	}

	if (operator != 126)
		return(0);

	switch (controller) {
		case 0:
			baudio->glide = value * value * baudio->glidemax;
			break;
		case 1:
			baudio->gtune = 1.0
				+ (baudio->note_diff - 1)
				* (value * 2 - 1);

			buildCurrentTable(baudio, baudio->gtune);
			alterAllNotes(baudio);
			break;
		case 3:
			if (value == 0)
				((jmods *) baudio->mixlocals)->flags &= ~J_LFO_MAN;
			else
				((jmods *) baudio->mixlocals)->flags |= J_LFO_MAN;
			break;
		case 4:
			if (value == 0)
				((jmods *) baudio->mixlocals)->flags &= ~J_LFO_AUTO;
			else
				((jmods *) baudio->mixlocals)->flags |= J_LFO_AUTO;
			break;
		case 5:
			((jmods *) baudio->mixlocals)->lfo_fgain = value / 128;
			break;
		case 6:
			((jmods *) baudio->mixlocals)->pwmod =
				value * CONTROLLER_RANGE;
			break;
		case 7:
			((jmods *) baudio->mixlocals)->pwmodval = value;
			break;
		case 8:
			if (value == 0)
				((jmods *) baudio->mixlocals)->envtype = 0;
			else
				((jmods *) baudio->mixlocals)->envtype = 1;
			break;
		case 9:
			baudio->midi_pitch = value * 24;
			break;
		case 10:
			((jmods *) baudio->mixlocals)->vcfmodval = value;
			break;
		case 11:
			if (value == 0)
				((jmods *) baudio->mixlocals)->negenv = 0;
			else
				((jmods *) baudio->mixlocals)->negenv = 1;
			break;
		case 12:
			((jmods *) baudio->mixlocals)->env2vcf = value / 4;
			break;
		case 13:
			((jmods *) baudio->mixlocals)->lfo2vcf = value * 0.01;
			break;
		case 14:
			((jmods *) baudio->mixlocals)->key2vcf = value / 16;
			break;
		case 15:
			((jmods *) baudio->mixlocals)->level = value * 2;
			break;
		case 16:
			((jmods *) baudio->mixlocals)->wheel2vcf = value;
			break;
		case 17:
			if (value == 0)
				baudio->mixflags &= ~MASTER_ONOFF;
			else
				baudio->mixflags |= MASTER_ONOFF;
			break;
	}
	return(0);
}

int
samplerPreops(audioMain *audiomain, Baudio *baudio,
bristolVoice *voice, register float *startbuf)
{
	register int samplecount = audiomain->samplecount, i;
	register float rate = baudio->contcontroller[1] / 2;
	int flags;

	bristolbzero(oscbbuf, audiomain->segmentsize);

	if (((jmods *) baudio->mixlocals)->lfolocals == 0)
	{
		((jmods *) baudio->mixlocals)->lfolocals =
			baudio->locals[voice->index][0];
		((jmods *) baudio->mixlocals)->adsrlocals = 
			voice->locals[voice->index][7];
	}

	flags = voice->flags;
	/*
	 * If we are configured for auto, only do autoops.
	 */
	if (((jmods *) baudio->mixlocals)->flags & J_LFO_AUTO)
	{
		/*
		 * If we are not active, and we get a key on, or reon, start the
		 * envelope for LFO delay.
		 *
		 * If we have not started, but we have a key start, that is great.
		 * If we have started, and we have a keyon/reon, remove it.
		 */
		if ((((jmods *) baudio->mixlocals)->flags & HAVE_STARTED)
			&& (voice->flags & (BRISTOL_KEYON|BRISTOL_KEYREON))
			&& (baudio->lvoices != 0))
			voice->flags &= ~(BRISTOL_KEYON|BRISTOL_KEYREON);

		if ((voice->flags & (BRISTOL_KEYON|BRISTOL_KEYREON))
			&& (baudio->lvoices == 0))
		{
/*printf("lfo auto on\n"); */
			((jmods *) baudio->mixlocals)->flags |= HAVE_STARTED;
		}

		/*
		 * We only accept key off if this is the last voice on the list.
		 */
		if ((((jmods *) baudio->mixlocals)->flags & HAVE_STARTED)
			&& (voice->flags & BRISTOL_KEYOFF))
		{
			if (baudio->lvoices > 1)
			{
				voice->flags &= ~BRISTOL_KEYOFF;
			} else {
/*printf("lfo auto off\n"); */
				((jmods *) baudio->mixlocals)->flags &= ~HAVE_STARTED;
			}
		}
/*printf("auto mode: %x, %x, %i\n", ((jmods *) baudio->mixlocals)->flags, */
/*voice->flags, voice->index); */
	} else if (((jmods *) baudio->mixlocals)->flags & J_LFO_MAN) {
/*printf("manual mode: %x\n", ((jmods *) baudio->mixlocals)->flags); */
		/*
		 * In man mode, if we have J_LFO_MAN and not started, then configure a
		 * keyon operation.
		 */
		if ((((jmods *) baudio->mixlocals)->flags & HAVE_STARTED) == 0)
		{
			((jmods *) baudio->mixlocals)->flags |= HAVE_STARTED;
/*printf("lfo manual on\n"); */
			voice->flags |= BRISTOL_KEYON;
		}
	} else {
		voice->flags |= BRISTOL_KEYOFF;
		((jmods *) baudio->mixlocals)->flags &= ~HAVE_STARTED;
/*printf("lfo manual off\n"); */
	}

	/*
	 * Put the correct buffer index into the oscillator freqbuf now.
	 */
	audiomain->palette[(*baudio->sound[0]).index]->specs->io[0].buf = startbuf;
	/*
	 * Fill a freq table for the LFO.
	 */
	for (i = 0; i < samplecount; i+=8)
	{
		*startbuf++ = 0.025 + rate;
		*startbuf++ = 0.025 + rate;
		*startbuf++ = 0.025 + rate;
		*startbuf++ = 0.025 + rate;
		*startbuf++ = 0.025 + rate;
		*startbuf++ = 0.025 + rate;
		*startbuf++ = 0.025 + rate;
		*startbuf++ = 0.025 + rate;
	}
	/*
	 * Run an ADSR for the LFO amplifier.
	 */
	audiomain->palette[(*baudio->sound[7]).index]->specs->io[0].buf = adsrbuf;
	(*baudio->sound[7]).operate(
		(audiomain->palette)[1],
		voice,
		(*baudio->sound[7]).param,
		((jmods *) baudio->mixlocals)->adsrlocals);

	bristolbzero(oscabuf, audiomain->segmentsize);
	/*
	 * Run the LFO into the oscbbuf
	 */
	audiomain->palette[(*baudio->sound[0]).index]->specs->io[1].buf = oscabuf;
	(*baudio->sound[0]).operate(
		(audiomain->palette)[0],
		voice,
		(*baudio->sound[0]).param,
		((jmods *) baudio->mixlocals)->lfolocals);

	/*
	 * And amplifly it 
	 */
	audiomain->palette[(*baudio->sound[8]).index]->specs->io[0].buf = oscabuf;
	audiomain->palette[(*baudio->sound[8]).index]->specs->io[1].buf = adsrbuf;
	audiomain->palette[(*baudio->sound[8]).index]->specs->io[2].buf = oscbbuf;
	(*baudio->sound[8]).operate(
		(audiomain->palette)[2],
		voice,
		(*baudio->sound[8]).param,
		baudio->locals[voice->index][8]);

/*printf("%f %f, %f %f\n", adsrbuf[0], adsrbuf[1], oscabuf[0], oscabuf[1]); */

	voice->flags = flags;

	return(0);
}

int
operateOneSampler(audioMain *audiomain, Baudio *baudio,
bristolVoice *voice, register float *startbuf)
{
	/*
	 * Master ON/OFF is an audiomain flags, but it is typically posted to the
	 * baudio structure.
	 */
	if ((voice->baudio->mixflags & MASTER_ONOFF) == 0)
	{
#ifdef DEBUG
		if ((audiomain->debuglevel & BRISTOL_DEBUG_MASK) > BRISTOL_DEBUG5)
			printf("Mini Master OFF\n");
#endif
		return(0);
	}

	bristolbzero(pmodbuf, audiomain->segmentsize);
	bristolbzero(filtbuf, audiomain->segmentsize);
	bristolbzero(sbuf, audiomain->segmentsize);
	bristolbzero(oscabuf, audiomain->segmentsize);

	/*
	 * Run the main ADSR.
	 */
	audiomain->palette[(*baudio->sound[4]).index]->specs->io[0].buf = adsrbuf;
	(*baudio->sound[4]).operate(
		(audiomain->palette)[1],
		voice,
		(*baudio->sound[4]).param,
		voice->locals[voice->index][4]);

	/*
	 * Build a frequency table for the DCO.
	 */
	fillFreqTable(baudio, voice, freqbuf, audiomain->samplecount, 1);
	bufmerge(oscbbuf, ((jmods *) baudio->mixlocals)->lfo_fgain
		+ (voice->press + voice->chanpressure),
		freqbuf, 1.0, audiomain->samplecount);
	/*
	 * Put in some PWm modulations. Range up to 500.
	 */
	switch (((jmods *) baudio->mixlocals)->pwmod) {
		default:
		{
			register int i, samplecount = audiomain->samplecount;
			register float value, *modbuf = pmodbuf;

			/*
			 * MAN
			 */
			value = ((jmods *) baudio->mixlocals)->pwmodval * 500;

			for (i = 0; i < samplecount; i+=8)
			{
				*modbuf++ = value;
				*modbuf++ = value;
				*modbuf++ = value;
				*modbuf++ = value;
				*modbuf++ = value;
				*modbuf++ = value;
				*modbuf++ = value;
				*modbuf++ = value;
			}
			break;
		}
		case 1:
		{
			register int i, samplecount = audiomain->samplecount;
			register float *modbuf = pmodbuf;

			/* LFO - needs normalising */
			bufmerge(oscbbuf, ((jmods *) baudio->mixlocals)->pwmodval * 3,
				pmodbuf, 0.0, audiomain->samplecount);
			break;
			for (i = 0; i < samplecount; i+=8)
			{
				*modbuf++ += 256;
				*modbuf++ += 256;
				*modbuf++ += 256;
				*modbuf++ += 256;
				*modbuf++ += 256;
				*modbuf++ += 256;
				*modbuf++ += 256;
				*modbuf++ += 256;
			}
			break;
		}
		case 2:
			/* env */
			bufmerge(adsrbuf, ((jmods *) baudio->mixlocals)->pwmodval * 40,
				pmodbuf, 0.0, audiomain->samplecount);
			break;
	}
	bristolbzero(freqbuf, audiomain->segmentsize);
	audiomain->palette[(*baudio->sound[1]).index]->specs->io[0].buf = freqbuf;
	audiomain->palette[(*baudio->sound[1]).index]->specs->io[1].buf = oscabuf;
	(*baudio->sound[1]).operate(
		(audiomain->palette)[18],
		voice,
		(*baudio->sound[1]).param,
		voice->locals[voice->index][1]);

	/* 
	 * Put the noise into the same oscillator buf.
	 */
	audiomain->palette[(*baudio->sound[6]).index]->specs->io[0].buf = oscabuf;
	(*baudio->sound[6]).operate(
		(audiomain->palette)[4],
		voice,
		(*baudio->sound[6]).param,
		voice->locals[voice->index][6]);

	/*
	 * Put the HPF filter in.
	 */
	audiomain->palette[(*baudio->sound[2]).index]->specs->io[0].buf = oscabuf;
	audiomain->palette[(*baudio->sound[2]).index]->specs->io[1].buf = sbuf;
	(*baudio->sound[2]).operate(
		(audiomain->palette)[10],
		voice,
		(*baudio->sound[2]).param,
		voice->locals[voice->index][2]);

	bristolbzero(pmodbuf, audiomain->segmentsize);

	/*
	 * Put all our VCF mods in here. They should be normalised to 1.0 range.
	 */
	if (((jmods *) baudio->mixlocals)->negenv)
	{
		register int i, samplecount = audiomain->samplecount;
		register float *modbuf = pmodbuf;

		for (i = 0; i < samplecount; i+=8)
		{
			*modbuf++ = 1;
			*modbuf++ = 1;
			*modbuf++ = 1;
			*modbuf++ = 1;
			*modbuf++ = 1;
			*modbuf++ = 1;
			*modbuf++ = 1;
			*modbuf++ = 1;
		}

		bufmerge(adsrbuf, -((jmods *) baudio->mixlocals)->env2vcf,
			pmodbuf, 0.0, audiomain->samplecount);
	} else {
		bufmerge(adsrbuf, ((jmods *) baudio->mixlocals)->env2vcf,
			pmodbuf, 0.0, audiomain->samplecount);
	}
	/*
	 * Add in the LFO
	 */
	bufmerge(oscbbuf, ((jmods *) baudio->mixlocals)->lfo2vcf,
		pmodbuf, 1.0, audiomain->samplecount);
	/*
	 * The keyboard
	bufmerge(oscbbuf, ((jmods *) baudio->mixlocals)->lfo2vcf,
		pmodbuf, 1.0, audiomain->samplecount);
	 */
	{
		register int i, samplecount = audiomain->samplecount;
		register float *modbuf = pmodbuf, value;

		value = baudio->ctab[voice->key.key].step
			* ((jmods *) baudio->mixlocals)->key2vcf
			+ baudio->pitchwheel * ((jmods *) baudio->mixlocals)->wheel2vcf;

		for (i = 0; i < samplecount; i+=8)
		{
			*modbuf++ += value;
			*modbuf++ += value;
			*modbuf++ += value;
			*modbuf++ += value;
			*modbuf++ += value;
			*modbuf++ += value;
			*modbuf++ += value;
			*modbuf++ += value;
		}
	}
	/*
	 * And the control wheel
	bufmerge(oscbbuf, ((jmods *) baudio->mixlocals)->lfo2vcf,
		pmodbuf, 1.0, audiomain->samplecount);
	 */
	/*
	 * Put the VCF filter in here.
	 */
	audiomain->palette[(*baudio->sound[3]).index]->specs->io[0].buf = sbuf;
	audiomain->palette[(*baudio->sound[3]).index]->specs->io[1].buf = pmodbuf;
	audiomain->palette[(*baudio->sound[3]).index]->specs->io[2].buf = filtbuf;
	(*baudio->sound[3]).operate(
		(audiomain->palette)[3],
		voice,
		(*baudio->sound[3]).param,
		voice->locals[voice->index][3]);

	/*
	 * And merge this into the outbuf via the amplifier.
	 */
	audiomain->palette[(*baudio->sound[5]).index]->specs->io[1].buf = adsrbuf;
	if (((jmods *) baudio->mixlocals)->envtype)
	{
		register int i, samplecount = audiomain->samplecount;
		register float *buf = adsrbuf, value, diff = 0;

		value = voice->velocity * 12 * ((jmods *) baudio->mixlocals)->level;

		if (voice->flags & BRISTOL_KEYDONE)
		{
			samplecount -= 16;
			diff = value / 16;
		}

		for (i = 0; i < samplecount; i+=8)
		{
			*buf++ = value;
			*buf++ = value;
			*buf++ = value;
			*buf++ = value;
			*buf++ = value;
			*buf++ = value;
			*buf++ = value;
			*buf++ = value;
		}
		if (voice->flags & BRISTOL_KEYDONE)
		{
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
			*buf++ = (value -= diff);
		}
	} else {
		bufmerge(oscbbuf, 0.0,
			adsrbuf, ((jmods *) baudio->mixlocals)->level * voice->velocity,
			audiomain->samplecount);
	}
	audiomain->palette[(*baudio->sound[5]).index]->specs->io[0].buf = filtbuf;
	audiomain->palette[(*baudio->sound[5]).index]->specs->io[2].buf =
		baudio->leftbuf;

	(*baudio->sound[5]).operate(
		(audiomain->palette)[2],
		voice,
		(*baudio->sound[5]).param,
		voice->locals[voice->index][5]);
	return(0);
}

int
static bristolSamplerDestroy(audioMain *audiomain, Baudio *baudio)
{
printf("removing one sampler\n");
	return(0);
	bristolfree(freqbuf);
	bristolfree(sbuf);
	bristolfree(pmodbuf);
	bristolfree(adsrbuf);
	bristolfree(filtbuf);
	bristolfree(oscbbuf);
	bristolfree(oscabuf);
	return(0);
}

int
bristolSamplerInit(audioMain *audiomain, Baudio *baudio)
{
printf("initialising one sampler\n");
	baudio->soundCount = 9; /* Number of operators in this voice */
	/*
	 * Assign an array of sound pointers.
	 */
	baudio->sound = (bristolSound **)
		bristolmalloc0(sizeof(bristolOP *) * baudio->soundCount);
	baudio->effect = (bristolSound **)
		bristolmalloc0(sizeof(bristolOP *) * baudio->soundCount);

	/* LFO */
	initSoundAlgo(0, 0, baudio, audiomain, baudio->sound);
	/* Main oscillator */
	initSoundAlgo(18, 1, baudio, audiomain, baudio->sound);
	/* HPF */
	initSoundAlgo(10, 2, baudio, audiomain, baudio->sound);
	/* A filter */
	initSoundAlgo(3, 3, baudio, audiomain, baudio->sound);
	/* Another ADSR */
	initSoundAlgo(1, 4, baudio, audiomain, baudio->sound);
	/* An amplifier */
	initSoundAlgo(2, 5, baudio, audiomain, baudio->sound);
	/* An noise source */
	initSoundAlgo(4, 6, baudio, audiomain, baudio->sound);
	/* LFO ADSR */
	initSoundAlgo(1, 7, baudio, audiomain, baudio->sound);
	/* LFO amplifier */
	initSoundAlgo(2, 8, baudio, audiomain, baudio->sound);

	baudio->param = samplerController;
	baudio->destroy = bristolSamplerDestroy;
	baudio->operate = operateOneSampler;
	baudio->preops = samplerPreops;

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

	if (freqbuf == NULL)
		freqbuf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (sbuf == NULL)
		sbuf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (pmodbuf == NULL)
		pmodbuf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (adsrbuf == NULL)
		adsrbuf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (filtbuf == NULL)
		filtbuf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (oscbbuf == NULL)
		oscbbuf = (float *) bristolmalloc0(audiomain->segmentsize);
	if (oscabuf == NULL)
		oscabuf = (float *) bristolmalloc0(audiomain->segmentsize);

	baudio->mixlocals = (float *) bristolmalloc0(sizeof(jmods));
	return(0);
}