Java Synthesizer, Part 6 – Others


The next three circuits are pretty short and simple, so I’ll put them together here.

keyboard

The keyboard class is very straightforward. When the user presses a key (either the Play button in the Java GUI, or a real key on the Roland A-300), the MIDI standard tells us that a NOTE_ON MIDI message should be generated, which includes the note number (0-127) and the velocity the key was pressed at (0-127). When the user releases the key, a NOTE_OFF message should be generated, including the note number. It’s up to us to convert the MIDI note number to an actual frequency value. I took the piano frequencies from wikipedia, extended them for numbers beyond the plain 88 piano keys and put that in an array called keyFreqAry. After this, I use the NOTE_ON(int n, int v) and NOTE_OFF(n) methods to mimic the MIDI events. gateOut() lets me send the gate signal to the oscillators or ADSR. And noteOut() sends the specified frequency value to the target oscillator.

Example usage:

keyboard keyBoard = new keyboard();

adsr1.gateIn(keyBoard.gateOut());
osc1.setFreq(keyBoard.noteOut());

Raw formatted textfile here.

—————-

VCA

The Voltage-Controlled Amplifier was originally a hardware circuit that allowed the operator to include volume control in the analog synth. Generally, it was patched in between the ADSR output and the speaker amp as a form of pre-amp. I need to use the VCA in order to scale the +/- 1.0 magnitude audio signal to be audible. The sound engine expects a short value of +/- 16K for max volume. Additionally, I may want to apply a “DC offset” to the signal for things like two-tone arpeggiating (e.g. – between 200 hz and 400 hz). So, max. voltage is selectable from 0 to 16,384; and offset technically can go from -16K to +16k, although +/- 8000 might be more reasonable.

Example usage (for volume control to speaker out):

vca      vca1     = new vca(16000, 0);

for(int pCnt = 0; pCnt < 320; pCnt++){
shortBuffer.put( (short)( vca1.out( adsr1.nextSlice(osc1.nextSlice() ) ) ) );
}

Raw formatted textfile here.

——————-

Noise

Noise is an important part of sound, especially if you look at snare drums and electric guitars. In the real world, getting pure “white” noise (absolutely random) was quite difficult. “Pink” noise was more common, in that certain frequencies were more dominant in the frequency domain. With a computer, generating random numbers between 0 and 1.0 is very easy, and the “color” of the noise may approach “white” depending on the algorithm used. However, noise gets overpowering very quickly and could cause hearing damage if it’s too strong. Plus, you may not always want a solid block of hiss in your signal. So, I included 4 noise “waveforms” to choose from.

0: Random, with selectable density at random intervals
1: Random, with selectable density at fixed intervals
2: Brownian, with random interval density
3: Brownian, with fixed interval density

By “density”, I mean that a random value will be generated every ‘x’ milliseconds, where you pick the value of x.

For Brownian, I start at zero, and add a small +/- random value to that. Next time, I add another +/- random value. This gives me a “random walking pattern” that should wander all over the place.

With simple experimentation, I’ve found that only 10% noise is enough to make a regular signal interesting (much more than that threatens to be painful to the ears). Straight random is very harsh, while random interval Brownian noise is almost “velvet-like”.

Example usage:

noise      noise1     = new noise(10, 1);

for(int pCnt = 0; pCnt < 320; pCnt++) {
shortBuffer.put( (short) vca1.out( adsr1.nextSlice( osc1.nextSlice()  + vca2.out( noise1.addNoise() ) ) ) );
}

The purpose of vca2 is to just scale noise1 between 0.0 and 0.1;

Raw formatted textfile here.

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: