Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
|
Macros | |
#define | BELA_AUDIO_PRIORITY 95 |
Typedefs | |
typedef void * | AuxiliaryTask |
Functions | |
AuxiliaryTask | Bela_createAuxiliaryTask (void(*callback)(void *), int priority, const char *name, void *arg=NULL) |
Create a new auxiliary task. More... | |
int | Bela_scheduleAuxiliaryTask (AuxiliaryTask task) |
Run an auxiliary task which has previously been created. More... | |
AuxiliaryTask | Bela_runAuxiliaryTask (void(*callback)(void *), int priority=0, void *arg=nullptr) |
Create and start an AuxiliaryTask. More... | |
int | Bela_startAuxiliaryTask (AuxiliaryTask task) |
Initialize an auxiliary task so that it can be scheduled. More... | |
int | Bela_startAllAuxiliaryTasks () |
void | Bela_stopAllAuxiliaryTasks () |
void | Bela_deleteAllAuxiliaryTasks () |
These functions are used to create separate real-time tasks (threads) which run at lower priority than the audio processing. They can be used, for example, for large time-consuming calculations which would take more than one audio frame length to process, or they could be used to communicate with external hardware when that communication might block or be delayed.
All auxiliary tasks used by the program should be created in setup(). The tasks can then be scheduled at will within the render() function.
#define BELA_AUDIO_PRIORITY 95 |
Xenomai priority level for audio processing. Maximum possible priority is 99. In general, all auxiliary tasks should have a level lower than this unless for\ special purposes where the task needs to interrupt audio processing.
typedef void* AuxiliaryTask |
Auxiliary task variable. Auxiliary tasks are created using createAuxiliaryTask() and automatically cleaned up after cleanup() finishes.
AuxiliaryTask Bela_createAuxiliaryTask | ( | void(*)(void *) | callback, |
int | priority, | ||
const char * | name, | ||
void * | arg = NULL |
||
) |
Create a new auxiliary task.
This function creates a new auxiliary task which, when scheduled, runs the function specified in the first argument. Note that the task does not run until scheduleAuxiliaryTask() is called. Auxiliary tasks should be created in setup()
and never in render()
itself.
The second argument specifies the real-time priority. Valid values are between 0 and 99, and usually should be lower than BELA_AUDIO_PRIORITY. Tasks with higher priority always preempt tasks with lower priority.
callback | Function which will be called each time the auxiliary task is scheduled, unless it is already running. |
priority | Xenomai priority level at which the task should run. |
name | Name for this task, which should be unique system-wide (no other running program should use this name). |
arg | The argument passed to the callback function. |
int Bela_scheduleAuxiliaryTask | ( | AuxiliaryTask | task | ) |
Run an auxiliary task which has previously been created.
This function will schedule an auxiliary task to run.
If the task is already running, calling this function has no effect. If the task is not running (e.g.: a previous invocation has returned), the callback function defined in Bela_createAuxiliaryTask() will be called and it will be passed the arg pointer as its only parameter.
This function is typically called from render() to start a lower-priority task. The function will not run immediately, but only once any active higher priority tasks have finished.
task | Task to schedule for running. |
AuxiliaryTask Bela_runAuxiliaryTask | ( | void(*)(void *) | callback, |
int | priority = 0 , |
||
void * | arg = nullptr |
||
) |
Create and start an AuxiliaryTask.
Effectively this is a shorthand for Bela_createAuxiliaryTask() followed by Bela_scheduleAuxiliaryTask(), with fewer parameters to make it easier to use.
callback | the function to run in the thread. |
priority | the priority of the thread. Defaults to 0. |
arg | the argument to be passed to the callback. Defaults to nullptr . |
AuxiliaryTask
on success, so that it can be scheduled again later if needed, or 0
if an error occurred. int Bela_startAuxiliaryTask | ( | AuxiliaryTask | task | ) |
Initialize an auxiliary task so that it can be scheduled.
User normally do not need to call this function.
This function will start an auxiliary task but will NOT schedule it. This means that the callback function associated with the task will NOT be executed.
It will also set a flag in the associate InternalAuxiliaryTask to flag the task as "started", so that successive calls to the same function for a given AuxiliaryTask have no effect. The user should never be required to call this function directly, as it is called by Bela_scheduleAuxiliaryTask if needed (e.g.: if a task is scheduled in setup() ) or immediately after starting the audio thread.
task | Task to start. |