Back Home
ALab User Tutorial Part 3
In the last part of the user tutorial we will learn how to integrate soundfiles
in ALab. But before doing so we will shortly look at the trigger classes. Usually
an AObject always returns updated values.
But with the class AHold we can force any
AObject to update its values only if it
is 'triggered'. This means that internally the values are updated as usually, but
these updated values are only returned if the object is triggered. If not, the
last returned value is returned.
sample and hold
Any subclass of AObject can be used as
trigger (values above zero trigger; values below or equal to zero don't). But
there are some special trigger classes that return 0
for no trigger
and 1
for triggering. If we want to generate one single trigger we
can use ASimpleTrigger. The class
ARandomTrigger triggers randomly.
AWaveTrigger triggers at every start
of a new circle of an AWave. And if we need
triggers everytime an AObject's values
are crossing zero: AZeroTrigger. To
make triggering hearable we use an ASquare
and set its amplitude with an AAmp. This
amplification is modulated by an ASin. In the
second example we will hold this modulating sine by triggering it randomly.
tremolo
,
randomamp
If we want to integrate soundfiles in ALab, we use the class
ASample. This class can read raw PCM coded
data from any AInputStream. If you
don't have any tool converting to raw data you have to skip the header bytes before
using the input stream with ALab. We will start simply playing one soundfile. You can
record your own file or use this one. To import a
soundfile in ALab, we need to know the amount of channels and the bitrate. The sample
rate is not neccessary, because ASample will
return the next value stored in the soundfile every time a value is asked for. So if
we set the samplerate in the method
write() higher than the soundfiles samplerate is, the result will be a transposed
(higher) version of the original soundfile. If we know the soundfiles samplerate we
can use this samplerate when writing the values to disk, to ensure, that the result
has the same pitch as the original soundfile.
soundfile
A soundfile consists of several values. For every sample there are as much values
as the soundfile's amount of channels. The first sample is the physical beginning
of the soundfile. The last sample is the physical end of the soundfile. But the
start
and length
values in
ASample are independet of the physical
beginning and end of the soundfile. The start of the soundfile can be set to any
position, even before the physical beginning. The length of the soundfile can be set
positive (plays forward) or negative (plays backwards) and can be longer than the
physical length of the soundfile. At positions where no physical values can be found
(before physical beginning and after physical end) zero is returned. At positions
out of the range (defined by start
and length
) zero is
returned, too (nevertheless if there is a physical value or not).
example1
,
example2
,
example3
The class ASample is used by
ASampleLoop that is much complexer and
is a subclass of AWave. This means, that
soundfiles can be frequency modulated and the samplerate and pitch are completely
independent. In the next example we will listen to our example soundfile again.
But this time, the result will be a 44kHz, 16bit, mono and stereo soundfile. The
stereo version plays with left and right channel for more dramatic effect.
re mono
,
re stereo
Now we will frequency modulate the soundfile, by setting the FM modulator to a sine.
Then we let the soundfile be played backwards (by setting start
to end
and length
negative) and with double speed by multiplying the frequency
by two. Then we take only a part of the soundfile and let it be played in a loop.
soundfileFM
,
backward
,
doublespeed
,
loop
Now we will do a kind of pitchshifting by looping a small part of the soundfile and
moving the startpoint of the loop a little bit forward until the end of the soundfile
is reached. We achieve this by using a ramp that modulates the start value, using
setStartMod().
To ensure that the startpoint of the loop doesn't move while the loop is played, but
only moves if a new loop starts, the ramp is hold and triggered every time the loop
start a new circle. The result sounds noisy sometimes because the difference
between the value at the loopstartpoint and loopendpoint may be too high. We use
setSmooth() to reduce
this effect.
pitchshift
This is the end of the user tutorial. If you want to know more about any class or
method, see the package documentation. There are still some classes that we didn't
use in this tutorial, but if you understand the basics of ALab you will have no
problems learning these classes too. If you need help or missing informations you
can send a mail to the support address.
Back Home