rtinrepos
INSTRUMENT design -- reposition input pointer for arbitrary file-reading
The rtinrepos() function is used in RTcmix
instrument design to set the input point for reading.
This is done in preparation for a subsequent call to
rtgetin.
Designed for use by instruments that want to reposition the input
file arbitrarily (like
REVMIX,
which reads a file backwards).
Typically it is used in the INSTRUMENT::run() member function
of an instrument. It only works on file input, as arbitrary movement
forwards and backwards in real-time isn't quite possible (yet).
It replaces
the older inrepos function used in
disk-only cmix.
Usage
int rtinrepos(Instrument *inst, int nframes, int whence)
-
*inst is a pointer to the INSTRUMENT object being scheduled.
Usually this is the token this
(i.e. a pointer to the INSTRUMENT calling the rtinrepos() function).
nframes is the number of samples to move the input
pointer forwards or backwards from a point set by whence.
nframes can take a negative value.
whence works the same way that the unix lseek()
function does:
- If whence is SEEK_SET, then the input read
pointer will be set nframes from the beginning of the
soundfile.
- If whence is SEEK_CUR, the the input
read pointer will be set nframes from the current
read position (positive or negative values).
[note: The values of SEEK_SET and SEEK_CUR
are defined in the system header file "unistd.h".
SEEK_END is not defined for use by rtinrepos().]
The rtinrepos()
function returns 0 if it is successful, it will exit if there
is an error.
Examples
#include <Instrument.h>
#include <unistd.h>
float in[];
int MYINSTRUMENT::run()
{
int rsamps;
int somenumber;
...
if (in == NULL) // first time, we need to allocate the buffer memory
in = new float[RTBUFSAMPS*inputChannels()]
rsamps = framesToRun() * inputChannels();
rtinrepos(this, somenumber, SEEK_CUR);
rtgetin(in, this, rsamps);
...
}
See Also