1 
2 /*
3  *  Diverse Bristol audio routines.
4  *  Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
5  *
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License as published by
9  *   the Free Software Foundation; either version 3 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with this program; if not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 /*#define DEBUG */
22 
23 #include "bristol.h"
24 #include "bristolmm.h"
25 #include "bristoljuno.h"
26 
27 /*
28  * Use of these juno global buffers will be an issue with use of multiple
29  * audio threads, unless we ensure a single thread deals with any given algo
30  * type, since then they are only used sequentially.
31  */
32 static float *freqbuf = (float *) NULL;
33 static float *pmodbuf = (float *) NULL;
34 static float *adsrbuf = (float *) NULL;
35 static float *filtbuf = (float *) NULL;
36 static float *oscbbuf = (float *) NULL;
37 static float *oscabuf = (float *) NULL;
38 static float *sbuf = (float *) NULL;
39 
40 /*
41  * These need to go into some local structure for multiple instances
42  * of the juno - malloc()ed into the baudio->mixlocals.
43  */
44 typedef struct jMods {
45 	float lfo_fgain;
46 	unsigned int flags;
47 	void *lfolocals;
48 	void *adsrlocals;
49 	int pwmod;
50 	float pwmodval;
51 	int envtype;
52 	float vcfmodval;
53 	int negenv;
54 	float env2vcf;
55 	float lfo2vcf;
56 	float key2vcf;
57 	float wheel2vcf;
58 	float level;
59 	float chgain;
60 	int chspeed;
61 } jmods;
62 
63 extern int s440holder;
64 
65 int
junoController(Baudio * baudio,u_char operator,u_char controller,float value)66 junoController(Baudio *baudio, u_char operator,
67 u_char controller, float value)
68 {
69 	int tval = value * C_RANGE_MIN_1;
70 
71 #ifdef DEBUG
72 	printf("bristolJunoControl(%i, %i, %f)\n", operator, controller, value);
73 #endif
74 
75 	/*
76 	 * These will be for our chorus.
77 	 */
78 	if (operator == 100)
79 	{
80 		switch (tval) {
81 			case 0:
82 				baudio->effect[0]->param->param[0].float_val = 0.2;
83 				baudio->effect[0]->param->param[1].float_val = 0.2;
84 				baudio->effect[0]->param->param[2].float_val = 0.2;
85 				baudio->effect[0]->param->param[3].float_val = 0.0;
86 				break;
87 			case 1:
88 				baudio->effect[0]->param->param[0].float_val = 0.005;
89 				baudio->effect[0]->param->param[1].float_val = 0.0168;
90 				baudio->effect[0]->param->param[2].float_val = 0.02;
91 				baudio->effect[0]->param->param[3].float_val = 0.65;
92 				break;
93 			case 2:
94 				baudio->effect[0]->param->param[0].float_val = 0.008;
95 				baudio->effect[0]->param->param[1].float_val = 0.016;
96 				baudio->effect[0]->param->param[2].float_val = 0.070;
97 				baudio->effect[0]->param->param[3].float_val = 0.65;
98 				break;
99 			case 3:
100 				baudio->effect[0]->param->param[0].float_val = 0.015;
101 				baudio->effect[0]->param->param[1].float_val = 0.015;
102 				baudio->effect[0]->param->param[2].float_val = 0.2;
103 				baudio->effect[0]->param->param[3].float_val = 0.65;
104 				break;
105 			case 4:
106 				baudio->effect[0]->param->param[0].float_val = 0.030;
107 				baudio->effect[0]->param->param[1].float_val = 0.014;
108 				baudio->effect[0]->param->param[2].float_val = 0.3;
109 				baudio->effect[0]->param->param[3].float_val = 0.65;
110 				break;
111 			case 5:
112 				baudio->effect[0]->param->param[0].float_val = 0.1;
113 				baudio->effect[0]->param->param[1].float_val = 0.013;
114 				baudio->effect[0]->param->param[2].float_val = 0.4;
115 				baudio->effect[0]->param->param[3].float_val = 0.65;
116 				break;
117 			case 6:
118 				baudio->effect[0]->param->param[0].float_val = 0.02;
119 				baudio->effect[0]->param->param[1].float_val = 0.012;
120 				baudio->effect[0]->param->param[2].float_val = 0.5;
121 				baudio->effect[0]->param->param[3].float_val = 0.75;
122 				break;
123 			case 7:
124 				baudio->effect[0]->param->param[0].float_val = 0.333;
125 				baudio->effect[0]->param->param[1].float_val = 0.011;
126 				baudio->effect[0]->param->param[2].float_val = 0.62;
127 				baudio->effect[0]->param->param[3].float_val = 0.75;
128 				break;
129 		}
130 		return(0);
131 	}
132 
133 	if (operator != 126)
134 		return(0);
135 
136 	switch (controller) {
137 		case 0:
138 			baudio->glide = value * value * baudio->glidemax;
139 			break;
140 		case 1:
141 			baudio->gtune = 1.0
142 				+ (baudio->note_diff - 1)
143 				* (value * 2 - 1);
144 
145 			buildCurrentTable(baudio, baudio->gtune);
146 			alterAllNotes(baudio);
147 			break;
148 		case 3:
149 			if (value == 0)
150 				((jmods *) baudio->mixlocals)->flags &= ~J_LFO_MAN;
151 			else
152 				((jmods *) baudio->mixlocals)->flags |= J_LFO_MAN;
153 			break;
154 		case 4:
155 			if (value == 0)
156 				((jmods *) baudio->mixlocals)->flags &= ~J_LFO_AUTO;
157 			else
158 				((jmods *) baudio->mixlocals)->flags |= J_LFO_AUTO;
159 			break;
160 		case 5:
161 			((jmods *) baudio->mixlocals)->lfo_fgain = value / 128;
162 			break;
163 		case 6:
164 			((jmods *) baudio->mixlocals)->pwmod =
165 				value * CONTROLLER_RANGE;
166 			break;
167 		case 7:
168 			((jmods *) baudio->mixlocals)->pwmodval = value;
169 			break;
170 		case 8:
171 			if (value == 0)
172 				((jmods *) baudio->mixlocals)->envtype = 0;
173 			else
174 				((jmods *) baudio->mixlocals)->envtype = 1;
175 			break;
176 		case 9:
177 			baudio->midi_pitch = value * 24;
178 			break;
179 		case 10:
180 			((jmods *) baudio->mixlocals)->vcfmodval = value;
181 			break;
182 		case 11:
183 			if (value == 0)
184 				((jmods *) baudio->mixlocals)->negenv = 0;
185 			else
186 				((jmods *) baudio->mixlocals)->negenv = 1;
187 			break;
188 		case 12:
189 			((jmods *) baudio->mixlocals)->env2vcf = value / 4;
190 			break;
191 		case 13:
192 			((jmods *) baudio->mixlocals)->lfo2vcf = value * 0.01;
193 			break;
194 		case 14:
195 			((jmods *) baudio->mixlocals)->key2vcf = value / 16;
196 			break;
197 		case 15:
198 			((jmods *) baudio->mixlocals)->level = value * 2;
199 			break;
200 		case 16:
201 			((jmods *) baudio->mixlocals)->wheel2vcf = value;
202 			break;
203 		case 17:
204 			if (value == 0)
205 				baudio->mixflags &= ~MASTER_ONOFF;
206 			else
207 				baudio->mixflags |= MASTER_ONOFF;
208 			break;
209 	}
210 	return(0);
211 }
212 
213 int
junoPreops(audioMain * audiomain,Baudio * baudio,bristolVoice * voice,register float * startbuf)214 junoPreops(audioMain *audiomain, Baudio *baudio,
215 bristolVoice *voice, register float *startbuf)
216 {
217 	register int samplecount = audiomain->samplecount, i;
218 	register float rate = baudio->contcontroller[1] / 2;
219 	int flags;
220 
221 	bristolbzero(oscbbuf, audiomain->segmentsize);
222 
223 	if (((jmods *) baudio->mixlocals)->lfolocals == 0)
224 	{
225 		((jmods *) baudio->mixlocals)->lfolocals =
226 			baudio->locals[voice->index][0];
227 		((jmods *) baudio->mixlocals)->adsrlocals =
228 			voice->locals[voice->index][7];
229 	}
230 
231 	flags = voice->flags;
232 	/*
233 	 * If we are configured for auto, only do autoops.
234 	 */
235 	if (((jmods *) baudio->mixlocals)->flags & J_LFO_AUTO)
236 	{
237 		/*
238 		 * If we are not active, and we get a key on, or reon, start the
239 		 * envelope for LFO delay.
240 		 *
241 		 * If we have not started, but we have a key start, that is great.
242 		 * If we have started, and we have a keyon/reon, remove it.
243 		 */
244 		if ((((jmods *) baudio->mixlocals)->flags & HAVE_STARTED)
245 			&& (voice->flags & (BRISTOL_KEYON|BRISTOL_KEYREON))
246 			&& (baudio->lvoices != 0))
247 			voice->flags &= ~(BRISTOL_KEYON|BRISTOL_KEYREON);
248 
249 		if ((voice->flags & (BRISTOL_KEYON|BRISTOL_KEYREON))
250 			&& (baudio->lvoices == 0))
251 		{
252 /*printf("lfo auto on\n"); */
253 			((jmods *) baudio->mixlocals)->flags |= HAVE_STARTED;
254 		}
255 
256 		/*
257 		 * We only accept key off if this is the last voice on the list.
258 		 */
259 		if ((((jmods *) baudio->mixlocals)->flags & HAVE_STARTED)
260 			&& (voice->flags & BRISTOL_KEYOFF))
261 		{
262 			if (baudio->lvoices > 1)
263 			{
264 				voice->flags &= ~BRISTOL_KEYOFF;
265 			} else {
266 /*printf("lfo auto off\n"); */
267 				((jmods *) baudio->mixlocals)->flags &= ~HAVE_STARTED;
268 			}
269 		}
270 
271 /*printf("auto mode: %x, %x, %i\n", ((jmods *) baudio->mixlocals)->flags, */
272 /*voice->flags, voice->index); */
273 	} else if (((jmods *) baudio->mixlocals)->flags & J_LFO_MAN) {
274 /*printf("manual mode: %x\n", ((jmods *) baudio->mixlocals)->flags); */
275 		/*
276 		 * In man mode, if we have J_LFO_MAN and not started, then configure a
277 		 * keyon operation.
278 		 */
279 		if ((((jmods *) baudio->mixlocals)->flags & HAVE_STARTED) == 0)
280 		{
281 			((jmods *) baudio->mixlocals)->flags |= HAVE_STARTED;
282 /*printf("lfo manual on\n"); */
283 			voice->flags |= BRISTOL_KEYON;
284 		}
285 	} else {
286 		voice->flags |= BRISTOL_KEYOFF;
287 		((jmods *) baudio->mixlocals)->flags &= ~HAVE_STARTED;
288 /*printf("lfo manual off\n"); */
289 	}
290 
291 	/*
292 	 * Put the correct buffer index into the oscillator freqbuf now.
293 	 */
294 	audiomain->palette[(*baudio->sound[0]).index]->specs->io[0].buf = startbuf;
295 	/*
296 	 * Fill a freq table for the LFO.
297 	 */
298 	for (i = 0; i < samplecount; i+=8)
299 	{
300 		*startbuf++ = 0.0025 + rate;
301 		*startbuf++ = 0.0025 + rate;
302 		*startbuf++ = 0.0025 + rate;
303 		*startbuf++ = 0.0025 + rate;
304 		*startbuf++ = 0.0025 + rate;
305 		*startbuf++ = 0.0025 + rate;
306 		*startbuf++ = 0.0025 + rate;
307 		*startbuf++ = 0.0025 + rate;
308 	}
309 	/*
310 	 * Run an ADSR for the LFO amplifier.
311 	 */
312 	audiomain->palette[(*baudio->sound[7]).index]->specs->io[0].buf = adsrbuf;
313 	(*baudio->sound[7]).operate(
314 		(audiomain->palette)[1],
315 		voice,
316 		(*baudio->sound[7]).param,
317 		((jmods *) baudio->mixlocals)->adsrlocals);
318 
319 	bristolbzero(oscabuf, audiomain->segmentsize);
320 	/*
321 	 * Run the LFO into the oscbbuf
322 	 */
323 	audiomain->palette[(*baudio->sound[0]).index]->specs->io[1].buf = oscabuf;
324 	(*baudio->sound[0]).operate(
325 		(audiomain->palette)[0],
326 		voice,
327 		(*baudio->sound[0]).param,
328 		((jmods *) baudio->mixlocals)->lfolocals);
329 
330 	/*
331 	 * And amplifly it
332 	 */
333 	audiomain->palette[(*baudio->sound[8]).index]->specs->io[0].buf = oscabuf;
334 	audiomain->palette[(*baudio->sound[8]).index]->specs->io[1].buf = adsrbuf;
335 	audiomain->palette[(*baudio->sound[8]).index]->specs->io[2].buf = oscbbuf;
336 	(*baudio->sound[8]).operate(
337 		(audiomain->palette)[2],
338 		voice,
339 		(*baudio->sound[8]).param,
340 		baudio->locals[voice->index][8]);
341 
342 /*printf("%f %f, %f %f\n", adsrbuf[0], adsrbuf[1], oscabuf[0], oscabuf[1]); */
343 
344 	voice->flags = flags;
345 
346 	return(0);
347 }
348 
349 int
operateOneJuno(audioMain * audiomain,Baudio * baudio,bristolVoice * voice,register float * startbuf)350 operateOneJuno(audioMain *audiomain, Baudio *baudio,
351 bristolVoice *voice, register float *startbuf)
352 {
353 	/*
354 	 * Master ON/OFF is an audiomain flags, but it is typically posted to the
355 	 * baudio structure.
356 	 */
357 	if ((voice->baudio->mixflags & MASTER_ONOFF) == 0)
358 	{
359 #ifdef DEBUG
360 		if ((audiomain->debuglevel & BRISTOL_DEBUG_MASK) > BRISTOL_DEBUG5)
361 			printf("Juno Master OFF\n");
362 #endif
363 		return(0);
364 	}
365 
366 	bristolbzero(pmodbuf, audiomain->segmentsize);
367 	bristolbzero(filtbuf, audiomain->segmentsize);
368 	bristolbzero(sbuf, audiomain->segmentsize);
369 	bristolbzero(oscabuf, audiomain->segmentsize);
370 
371 	/*
372 	 * Run the main ADSR.
373 	 */
374 	audiomain->palette[(*baudio->sound[4]).index]->specs->io[0].buf = adsrbuf;
375 	(*baudio->sound[4]).operate(
376 		(audiomain->palette)[1],
377 		voice,
378 		(*baudio->sound[4]).param,
379 		voice->locals[voice->index][4]);
380 
381 	/*
382 	 * Build a frequency table for the DCO.
383 	 */
384 	fillFreqTable(baudio, voice, freqbuf, audiomain->samplecount, 1);
385 	bufmerge(oscbbuf, ((jmods *) baudio->mixlocals)->lfo_fgain
386 		+ (voice->press + voice->chanpressure),
387 		freqbuf, 1.0, audiomain->samplecount);
388 
389 	/*
390 	 * Put in some PWM modulations. Range up to 500.
391 	 */
392 	switch (((jmods *) baudio->mixlocals)->pwmod) {
393 		default:
394 		{
395 			register int i, samplecount = audiomain->samplecount;
396 			register float value, *modbuf = pmodbuf;
397 
398 			/*
399 			 * MAN
400 			 */
401 			value = ((jmods *) baudio->mixlocals)->pwmodval * 500;
402 
403 			for (i = 0; i < samplecount; i+=8)
404 			{
405 				*modbuf++ = value;
406 				*modbuf++ = value;
407 				*modbuf++ = value;
408 				*modbuf++ = value;
409 				*modbuf++ = value;
410 				*modbuf++ = value;
411 				*modbuf++ = value;
412 				*modbuf++ = value;
413 			}
414 			break;
415 		}
416 		case 1:
417 		{
418 			register int i, samplecount = audiomain->samplecount;
419 			register float *modbuf = pmodbuf;
420 
421 			/* LFO - needs normalising */
422 			bufmerge(oscbbuf, ((jmods *) baudio->mixlocals)->pwmodval * 3,
423 				pmodbuf, 0.0, audiomain->samplecount);
424 			break;
425 			for (i = 0; i < samplecount; i+=8)
426 			{
427 				*modbuf++ += 256;
428 				*modbuf++ += 256;
429 				*modbuf++ += 256;
430 				*modbuf++ += 256;
431 				*modbuf++ += 256;
432 				*modbuf++ += 256;
433 				*modbuf++ += 256;
434 				*modbuf++ += 256;
435 			}
436 			break;
437 		}
438 		case 2:
439 			/* env */
440 			bufmerge(adsrbuf, ((jmods *) baudio->mixlocals)->pwmodval * 40,
441 				pmodbuf, 0.0, audiomain->samplecount);
442 			break;
443 	}
444 	audiomain->palette[(*baudio->sound[1]).index]->specs->io[0].buf = freqbuf;
445 	audiomain->palette[(*baudio->sound[1]).index]->specs->io[1].buf = pmodbuf;
446 	audiomain->palette[(*baudio->sound[1]).index]->specs->io[2].buf = oscabuf;
447 	(*baudio->sound[1]).operate(
448 		(audiomain->palette)[11],
449 		voice,
450 		(*baudio->sound[1]).param,
451 		voice->locals[voice->index][1]);
452 
453 	/*
454 	 * Put the noise into the same oscillator buf.
455 	 */
456 	audiomain->palette[(*baudio->sound[6]).index]->specs->io[0].buf = oscabuf;
457 	(*baudio->sound[6]).operate(
458 		(audiomain->palette)[4],
459 		voice,
460 		(*baudio->sound[6]).param,
461 		voice->locals[voice->index][6]);
462 
463 	/*
464 	 * Put the HPF filter in.
465 	 */
466 	audiomain->palette[(*baudio->sound[2]).index]->specs->io[0].buf = oscabuf;
467 	audiomain->palette[(*baudio->sound[2]).index]->specs->io[1].buf = sbuf;
468 	(*baudio->sound[2]).operate(
469 		(audiomain->palette)[10],
470 		voice,
471 		(*baudio->sound[2]).param,
472 		voice->locals[voice->index][2]);
473 
474 	/* This is EQ to drive into the filter with a normalised gain */
475 	bufmerge(adsrbuf, 0, sbuf, 48.0, audiomain->samplecount);
476 	bristolbzero(pmodbuf, audiomain->segmentsize);
477 
478 	/*
479 	 * Put all our VCF mods in here. They should be normalised to 1.0 range.
480 	 */
481 	if (((jmods *) baudio->mixlocals)->negenv)
482 	{
483 		register int i, samplecount = audiomain->samplecount;
484 		register float *modbuf = pmodbuf;
485 
486 		for (i = 0; i < samplecount; i+=8)
487 		{
488 			*modbuf++ = 1;
489 			*modbuf++ = 1;
490 			*modbuf++ = 1;
491 			*modbuf++ = 1;
492 			*modbuf++ = 1;
493 			*modbuf++ = 1;
494 			*modbuf++ = 1;
495 			*modbuf++ = 1;
496 		}
497 
498 		bufmerge(adsrbuf, -((jmods *) baudio->mixlocals)->env2vcf * 12.0,
499 			pmodbuf, 0.0, audiomain->samplecount);
500 	} else {
501 		bufmerge(adsrbuf, ((jmods *) baudio->mixlocals)->env2vcf * 12.0,
502 			pmodbuf, 0.0, audiomain->samplecount);
503 	}
504 	/*
505 	 * Add in the LFO
506 	 */
507 	bufmerge(oscbbuf, ((jmods *) baudio->mixlocals)->lfo2vcf,
508 		pmodbuf, 1.0, audiomain->samplecount);
509 	/*
510 	 * The keyboard
511 	bufmerge(oscbbuf, ((jmods *) baudio->mixlocals)->lfo2vcf,
512 		pmodbuf, 1.0, audiomain->samplecount);
513 	 */
514 	{
515 		register int i, samplecount = audiomain->samplecount;
516 		register float *modbuf = pmodbuf, value;
517 
518 		value = baudio->pitchwheel * 8.0 *
519 			((jmods *) baudio->mixlocals)->wheel2vcf;
520 
521 		for (i = 0; i < samplecount; i+=8)
522 		{
523 			*modbuf++ += value;
524 			*modbuf++ += value;
525 			*modbuf++ += value;
526 			*modbuf++ += value;
527 			*modbuf++ += value;
528 			*modbuf++ += value;
529 			*modbuf++ += value;
530 			*modbuf++ += value;
531 		}
532 	}
533 	/*
534 	 * Put the VCF filter in here.
535 	 */
536 	audiomain->palette[(*baudio->sound[3]).index]->specs->io[0].buf = sbuf;
537 	audiomain->palette[(*baudio->sound[3]).index]->specs->io[1].buf = pmodbuf;
538 	audiomain->palette[(*baudio->sound[3]).index]->specs->io[2].buf = filtbuf;
539 	(*baudio->sound[3]).operate(
540 		(audiomain->palette)[3],
541 		voice,
542 		(*baudio->sound[3]).param,
543 		voice->locals[voice->index][3]);
544 
545 	/*
546 	 * And merge this into the outbuf via the amplifier.
547 	 */
548 	audiomain->palette[(*baudio->sound[5]).index]->specs->io[1].buf = adsrbuf;
549 	if (((jmods *) baudio->mixlocals)->envtype)
550 	{
551 		register int i, samplecount = audiomain->samplecount;
552 		register float *buf = adsrbuf, value, diff = 0;
553 
554 		value = voice->velocity * ((jmods *) baudio->mixlocals)->level;
555 
556 		if (voice->flags & BRISTOL_KEYDONE)
557 		{
558 			samplecount -= 16;
559 			diff = value / 16;
560 		}
561 
562 		for (i = 0; i < samplecount; i+=8)
563 		{
564 			*buf++ = value;
565 			*buf++ = value;
566 			*buf++ = value;
567 			*buf++ = value;
568 			*buf++ = value;
569 			*buf++ = value;
570 			*buf++ = value;
571 			*buf++ = value;
572 		}
573 		if (voice->flags & BRISTOL_KEYDONE)
574 		{
575 			*buf++ = (value -= diff);
576 			*buf++ = (value -= diff);
577 			*buf++ = (value -= diff);
578 			*buf++ = (value -= diff);
579 			*buf++ = (value -= diff);
580 			*buf++ = (value -= diff);
581 			*buf++ = (value -= diff);
582 			*buf++ = (value -= diff);
583 			*buf++ = (value -= diff);
584 			*buf++ = (value -= diff);
585 			*buf++ = (value -= diff);
586 			*buf++ = (value -= diff);
587 			*buf++ = (value -= diff);
588 			*buf++ = (value -= diff);
589 			*buf++ = (value -= diff);
590 			*buf++ = (value -= diff);
591 		}
592 	} else {
593 		bufmerge(oscbbuf, 0.0,
594 			adsrbuf, ((jmods *) baudio->mixlocals)->level * voice->velocity,
595 			audiomain->samplecount);
596 	}
597 	audiomain->palette[(*baudio->sound[5]).index]->specs->io[0].buf = filtbuf;
598 	audiomain->palette[(*baudio->sound[5]).index]->specs->io[2].buf =
599 		baudio->leftbuf;
600 
601 	(*baudio->sound[5]).operate(
602 		(audiomain->palette)[2],
603 		voice,
604 		(*baudio->sound[5]).param,
605 		voice->locals[voice->index][5]);
606 
607 	return(0);
608 }
609 
610 int
bristolJunoDestroy(audioMain * audiomain,Baudio * baudio)611 static bristolJunoDestroy(audioMain *audiomain, Baudio *baudio)
612 {
613 printf("removing one juno\n");
614 	return(0);
615 	bristolfree(freqbuf);
616 	bristolfree(sbuf);
617 	bristolfree(pmodbuf);
618 	bristolfree(adsrbuf);
619 	bristolfree(filtbuf);
620 	bristolfree(oscbbuf);
621 	bristolfree(oscabuf);
622 
623 	return(0);
624 }
625 
626 int
bristolJunoInit(audioMain * audiomain,Baudio * baudio)627 bristolJunoInit(audioMain *audiomain, Baudio *baudio)
628 {
629 printf("initialising one juno\n");
630 	baudio->soundCount = 9; /* Number of operators in this voice */
631 	/*
632 	 * Assign an array of sound pointers.
633 	 */
634 	baudio->sound = (bristolSound **)
635 		bristolmalloc0(sizeof(bristolOP *) * baudio->soundCount);
636 	baudio->effect = (bristolSound **)
637 		bristolmalloc0(sizeof(bristolOP *) * baudio->soundCount);
638 
639 	/* LFO */
640 	initSoundAlgo(0, 0, baudio, audiomain, baudio->sound);
641 	/* Main oscillator */
642 	initSoundAlgo(11, 1, baudio, audiomain, baudio->sound);
643 	/* HPF */
644 	initSoundAlgo(10, 2, baudio, audiomain, baudio->sound);
645 	/* A filter */
646 	initSoundAlgo(3, 3, baudio, audiomain, baudio->sound);
647 	/* Another ADSR */
648 	initSoundAlgo(1, 4, baudio, audiomain, baudio->sound);
649 	/* An amplifier */
650 	initSoundAlgo(2, 5, baudio, audiomain, baudio->sound);
651 	/* An noise source */
652 	initSoundAlgo(4, 6, baudio, audiomain, baudio->sound);
653 	/* LFO ADSR */
654 	initSoundAlgo(1, 7, baudio, audiomain, baudio->sound);
655 	/* LFO amplifier */
656 	initSoundAlgo(2, 8, baudio, audiomain, baudio->sound);
657 
658 	baudio->param = junoController;
659 	baudio->destroy = bristolJunoDestroy;
660 	baudio->operate = operateOneJuno;
661 	baudio->preops = junoPreops;
662 
663 	/*
664 	 * Put in a vibrachorus on our effects list.
665 	 */
666 	initSoundAlgo(12, 0, baudio, audiomain, baudio->effect);
667 
668 	if (freqbuf == NULL)
669 		freqbuf = (float *) bristolmalloc0(audiomain->segmentsize);
670 	if (sbuf == NULL)
671 		sbuf = (float *) bristolmalloc0(audiomain->segmentsize);
672 	if (pmodbuf == NULL)
673 		pmodbuf = (float *) bristolmalloc0(audiomain->segmentsize);
674 	if (adsrbuf == NULL)
675 		adsrbuf = (float *) bristolmalloc0(audiomain->segmentsize);
676 	if (filtbuf == NULL)
677 		filtbuf = (float *) bristolmalloc0(audiomain->segmentsize);
678 	if (oscbbuf == NULL)
679 		oscbbuf = (float *) bristolmalloc0(audiomain->segmentsize);
680 	if (oscabuf == NULL)
681 		oscabuf = (float *) bristolmalloc0(audiomain->segmentsize);
682 
683 	baudio->mixlocals = (float *) bristolmalloc0(sizeof(jmods));
684 
685 	return(0);
686 }
687 
688