[id] = MixSample(id, len, pitch, fmt, smp1, opt1, ...)
id. If you pass Nil
in id, MixSample() will automatically select an identifier and
return it to you. The second argument len specifies the desired
length of the new sample in PCM frames. The third argument pitch specifies
how many frames per second should be sent to the audio device. For CD quality,
you would pass 44100 as the pitch argument but in many cases 22050
is also sufficient. The fmt argument specifies the desired sample format
for the new sample. Currently, the following formats are supported: #MONO8,
#STEREO8, #MONO16, and #STEREO16. The former two specify 8-bit PCM encodings
while the latter two use 16-bits per channel.
The samples that should be mixed into the new sample are passed to MixSample()
from argument 5 onwards. For each sample that should be mixed into the new
sample you have to pass its identifier as well as a table that contains
further parameters for the mixing operation. You can repeat this pattern
as many times as you like. The options table that has to be passed for
each sample supports the following tags:
Pitch:
Offset:
Length:
Loop:True
which means the mixer will automatically revert to the beginning of the
sample if its end has been reached and more PCM data is required.
Scale:
Threshold:
Hardware:Hardware
tag in table argument 6 is then used for the new sample. By default, Hollywood
will always create hardware samples. These are samples that
can be played instantly. If you don't want to play the sample, however, you can
set this tag to False to create a software sample. Software samples are more
efficient because they are completely independent of the audio hardware because
they will never be played. Defaults to True. (V11.0)
This function is powerful. It will perform automatic conversion between
different sample encodings, sampling rates, and channel layouts. Also, you
can mix as many samples into the new sample as you like. The samples to be
mixed can also be the same, i.e. you can mix the same sample into the new
samples multiple times using different mixing parameters like varying pitch
speed or thresholds. If you get unwanted noise artefacts, try reducing the
volume of single samples using the Scale tag (see above).
MixSample(1, 10 * 44100, 44100, #STEREO16, 2, {}, 3,
{Threshold = 3 * 44100}, 4, {6 * 44100})
The code above creates a new sample in 44.1 format, using 16 bits per PCM
frame and two channels. The sample's length will be exactly 10 seconds.
The sample will start with sample 2. After three seconds sample 3 will kick in
and after six seconds sample 4 will start to play.