Back Next
ALab User Tutorial Part 2
In this part of the user tutorial we will learn how to handle tables, that
can be used for several reasons. We will use them for wavetable synthesis at
first. An ATable is NOT a subclass
of AObject, but it is used by
ATablelize. A table can be
described as a list of values. These values are used to replace other
values. So a table has one input and one output. The input value is
replaced by another value and sent to the output. The method
valueAt() is
used for this transformation. Any input value between -1
and
1
is replaced by the table value and returned. This returned
value is also in the range -1..1
.
example1
In this example every input value was represented in the table. To ensure,
that every input value results in a correct output value, the values in the
table are linear interpolated, if there is no exact representation in the
table. The next example shows a table with only two values in it
(0
and -1
). All values between 0
and
1
are calculated by interpolating these values. Values below
zero are handled the following way in ALab: the absolut value is used as
input and the output is multiplied by -1
.
example2
The last example was a linear reversation. If we want to create a table,
that transforms incoming values that way, that it cuts values above
0.5
, we have to use three values. To cut values above
0.6
we need six values. Usually a table will consist of much
more (100..10000
) values to make the table 'round'.
example3
To create tables such as the above, we only need to write an ASCII text file
an put the values in it. The values can be written as usual, but can also be
apostrophed (eg. '-0.86'
). Comments can be added by using java
style comments (eg. // this line is ignored
). The following
example shows how such a table file should look like and how a table is
created by using such a table file.
cut.txt
,
code
Another way to generate tables is to use the values of any
AObject and put
them into the table. This can be done by using
this
constructor. Using the method
write()
stores all values in a table file.
Now we will use the last table for doing wavetable synthesis. We take a sine
oscillator and let its values be modified by the table by using the class
ATablelize. This will result in
a sine that is cutted at 0.6
. To demonstrate the difference
between cutted and noncutted sine, we will modulate the mix
(setMixMod())
by an ARamp.
cutSine
We could use any subclass of AWave
to be tablelized, but there is one special class for doing wavetable
synthesis, called ASimpleWave.
It starts at zero running up to 1
(at phase PI
).
Then again it starts at zero running down to -1
. Used by an
ATable the result is exactly the
table followed by the reversed table (simply replace ASin
by
ASimpleWave
in the last example to demonstrate this). In the
next example we will generate new waveforms by creating several table files.
table1
,
table2
,
wavetable
Now we will interpolate between two wavetables to make the result sounding
more alive. We create two tables (table1
and table2
)
and use them with ATablelize.
With an ARamp we start with
table1
and slowly transform the waveform to table2
.
In the second example we replace the ramp by a FM-sound so the sound becomes
still more alive. This sound is enveloped by a ramp, but before using this
ramp we transform the ramp by tablelizing it by table2
.
waveinterpol
,
waveinterpolFM
The result doesn't sound good, but we can hear what we did. The sounds amplitude
raises and falls like table2
does and the sound is alive, due to
the modulation with a FM sound. Let us asume, that we like the result and want
to use this created sound later again. We could copy the source and use it
whenever we need that sound, but this solution is much work, and the sound has
to be recalculated everytime we need it. Another possibility is to store the
sound in a file and use this file again later. This procedure is automated by
the class AStore. The next example is
equal to the last, but this time the result is stored in the file
waveinterpolFM.tmp
. If we run this class the first time, the
sound is calculated and stored. If we run it the second time, the values are
not calculated but read from the file.
store
In the next part of the user tutorial we will learn how to handle soundfiles
and the trigger classes are explained.
Back Next