Creating a Noise
This class shows the rendering of an audio
file with white noise.
To hear the result download the MP3 file
below.
WaveformExample4.mp3
[148K]
View
/ Download source
Lets have a closer look.
import jm.music.data.*;
import jm.JMC;
import jm.audio.*;
import jm.util.*;
public class WaveformExample4 implements JMC {
public static void main(String[] args) {
new WaveformExample4();
}
public WaveformExample4() {
Phrase melody = new Phrase();
for(int i = 0; i < 24; i++) {
Note n = new Note(
(int)(Math.random() * 12) * 2 + 60,
(int)(Math.random()* 5) * 0.25 + 0.25);
melody.addNote(n);
}
Score score = new Score(new Part(melody));
Instrument wave = new NoiseInst(44100);
Write.au(score, "WaveformExample4.au", wave);
}
}
|
On the surface this example is identical to
the previous two tutorials in this series, apart from the use of yet another
instrument, the NoiseInst class. Hopefully a pattern is clear in how to
instantiate jMusic instruments and render a score with them.
At a deeper level, however, the noise instrument
is somewhat different - although we need not be concerned with that
if we only want to be users, but then you would not be using jMusic
if you were just a software user : -)
The noise instrument is different from the sine or triangle (or any
other oscillator) because it does not use a wavetable.
Wavetables are ideal for repeated sounds, but noise is made up of random
and unpredictable sample values and so any repetition
from cycling through a wavetable undermines the unpredicaility of pure
noise.
The noise instrument continually calculates random sample values as
required.
Despite the synthesis process, jMusic presents the same code interface
to the user in order to simplify the compositional process.