InsertSample(src, dst, pos[, len, table])
len
PCM frames of the sample specified
in src
into PCM frame position pos
of the sample specified in dst
.
If the optional argument len
is not specified, the whole sample will
be inserted into the position specified in pos
. If the two samples do
not use the same format, this function will automatically perform an
appropriate conversion of the audio data so that sample depth, channel layout,
and sampling rate of the two samples match.
The optional table argument allows you to configure advanced options for the insert operation. The following tags are currently recognized by the optional table argument:
Start, End:
Start
and length of
the source sample for End
. This means that by default the whole sample will
be inserted.
Offset:
InsertSample()
should
start fetching PCM data for the destination sample. This offset must be specified
in PCM frames and is relative to the position specified in Start
. For instance,
if you pass 10000 in Start
and 100 in Offset
, then InsertSample()
will start
fetching PCM data at offset 10100. This tag defaults to 0 which means start
fetching PCM data from the beginning of the source sample.
Loop:
InsertSample()
should continue to fetch PCM data at the
beginning of the source sample once its end has been reached. This defaults to True
which means InsertSample()
will automatically revert to the beginning of the
sample if its end has been reached and more PCM data is required. The beginning
of the sample is defined by the value specified in the Start
tag.
Please note that this command will extend the length of the destination sample. Existing audio data will not be overwritten. It will just be shifted forward by the insert operation.
src
should be inserted into dst
src
(defaults to
the length of dst
)InsertSample(1, 2, 44100, 44100, {Start = 25000, End = 30000})The code above inserts one second of audio data from sample 1 into sample 2. The sample will be inserted at offset 44100. Audio data will be fetched from sample 1 but only in the range of PCM frames 25000 to 30000 in a loop.