Allolib
1.0
C++ Components For Interactive Multimedia
|
The DynamicScene class. More...
Public Types | |
typedef const std::function< void(AudioIOData &internalVoiceIO, Pose &channelPose)> | BusRoutingCallback |
Public Member Functions | |
DynamicScene (int threadPoolSize=0, TimeMasterMode masterMode=TimeMasterMode::TIME_MASTER_AUDIO) | |
template<class TSpatializer > | |
std::shared_ptr< TSpatializer > | setSpatializer (Speakers &sl) |
Set a Spatializar to use. More... | |
void | prepare (AudioIOData &io) |
Prepares internals for run. More... | |
virtual void | cleanup () |
Pose & | listenerPose () |
The listener pose is used to determine both the graphic view and the audio spatialization. More... | |
void | listenerPose (Pose &pose) |
virtual void | render (Graphics &g) final |
render graphics for all active voices | |
virtual void | render (AudioIOData &io) final |
render all the active voices into the audio buffers More... | |
virtual void | update (double dt=0) final |
This function runs the simulation/update of internal states for each voice. More... | |
void | setUpdateThreaded (bool threaded) |
void | setAudioThreaded (bool threaded) |
DistAtten & | distanceAttenuation () |
void | print (std::ostream &stream=std::cout) |
void | showWorldMarker (bool show=true) |
void | sortDrawingByDistance (bool sort=true) |
Enables/disables sorting by distance to listener on graphics render. | |
void | stopAudioThreads () |
Stop all audio threads. No processing is possible after calling this function. More... | |
int | triggerOn (SynthVoice *voice, int offsetFrames=0, int id=-1, void *userData=nullptr) |
trigger Puts voice in active voice lit and calls triggerOn() for it More... | |
void | triggerOff (int id) |
trigger release of voice with id | |
virtual void | allNotesOff () |
Turn off all notes immediately (without calling triggerOff() ) | |
template<class TSynthVoice > | |
TSynthVoice * | getVoice (bool forceAlloc=false) |
Get a reference to a voice. More... | |
SynthVoice * | getVoice (std::string name, bool forceAlloc=false) |
Get a reference to a free voice by voice type name. More... | |
SynthVoice * | getFreeVoice () |
Get the first available voice with minimal checks. More... | |
template<class TSynthVoice > | |
void | allocatePolyphony (int number) |
void | allocatePolyphony (std::string name, int number) |
template<class TSynthVoice > | |
void | disableAllocation () |
void | disableAllocation (std::string name) |
void | insertFreeVoice (SynthVoice *voice) |
Use this function to insert a voice allocated externally into the free voice pool. More... | |
bool | popFreeVoice (SynthVoice *voice) |
Remove voice from the free voice pool. More... | |
void | setDefaultUserData (void *userData) |
Set default user data to set to voices before the are returned by getVoice() More... | |
void | setTimeMaster (TimeMasterMode masterMode) |
Set time master context. More... | |
PolySynth & | append (AudioCallback &v) |
Insert an AudioCallback object at the end of the callback queue. More... | |
PolySynth & | prepend (AudioCallback &v) |
Insert an AudioCallback object at the head of the callback queue. More... | |
PolySynth & | insertBefore (AudioCallback &v, AudioCallback &beforeThis) |
Insert an AudioCallback object before another in the queue. More... | |
PolySynth & | insertAfter (AudioCallback &v, AudioCallback &afterThis) |
Insert an AudioCallback object after another in the queue. More... | |
PolySynth & | remove (AudioCallback &v) |
Remove an AudioCallback object from the queue. More... | |
void | gain (float gainValue) |
Set audio output gain. More... | |
float | gain () |
get current audio gain More... | |
void | registerTriggerOnCallback (std::function< bool(SynthVoice *voice, int offsetFrames, int id, void *userData)> cb, void *userData=nullptr) |
register a callback to be notified of a trigger on event | |
void | registerTriggerOffCallback (std::function< bool(int id, void *userData)> cb, void *userData=nullptr) |
register a callback to be notified of a trigger off event | |
void | registerFreeCallback (std::function< bool(int id, void *userData)> cb, void *userData=nullptr) |
register a callback to be notified of a note is moved to the free pool from the active list | |
void | registerAllocateCallback (std::function< void(SynthVoice *voice, void *)> cb, void *userData=nullptr) |
register a callback to be notified of allocation of a voice. | |
template<class TSynthVoice > | |
void | registerSynthClass (std::string name="", bool allowAutoAllocation=true) |
SynthVoice * | allocateVoice (std::string name) |
template<class TSynthVoice > | |
TSynthVoice * | allocateVoice () |
bool | verbose () |
void | verbose (bool verbose) |
SynthVoice * | getActiveVoices () |
SynthVoice * | getFreeVoices () |
getFreeVoices More... | |
void | setVoiceMaxOutputChannels (uint16_t channels) |
Determines the number of output channels allocated for the internal AudioIOData objects. More... | |
void | setVoiceBusChannels (uint16_t channels) |
Determines the number of buses for the internal AudioIOData objects. More... | |
void | setBusRoutingCallback (BusRoutingCallback cb) |
setBusRoutingCallback More... | |
void | setChannelMap (std::vector< size_t > channelMap) |
Set channel map for output. More... | |
void | setCpuClockGranularity (double timeSecs) |
Set the time in seconds to wait between sequencer updates when time master is CPU. More... | |
void | processVoices () |
Add new voices to the chain. More... | |
void | processVoiceTurnOff () |
Check for voices that need trigger off and execute. More... | |
void | processInactiveVoices () |
Check for voices marked as free and move them to the free voice pool. More... | |
Protected Types | |
typedef std::pair< std::function< bool(SynthVoice *voice, int offsetFrames, int id, void *)>, void * > | TriggerOnCallback |
typedef std::pair< std::function< bool(int id, void *)>, void * > | TriggerOffCallback |
typedef std::pair< std::function< bool(int id, void *)>, void * > | FreeCallback |
typedef std::pair< std::function< void(SynthVoice *voice, void *)>, void * > | AllocationCallback |
typedef std::function< SynthVoice *()> | VoiceCreatorFunc |
typedef std::map< std::string, VoiceCreatorFunc > | Creators |
Protected Member Functions | |
void | startCpuClockThread () |
void | processGain (AudioIOData &io) |
Protected Attributes | |
SynthVoice * | mVoicesToInsert {nullptr} |
SynthVoice * | mFreeVoices {nullptr} |
Allocated voices available for reuse. | |
SynthVoice * | mActiveVoices {nullptr} |
std::mutex | mVoiceToInsertLock |
std::mutex | mFreeVoiceLock |
std::mutex | mGraphicsLock |
bool | m_useInternalAudioIO = true |
bool | m_internalAudioConfigured = false |
uint16_t | mVoiceMaxOutputChannels = 2 |
uint16_t | mVoiceMaxInputChannels = 0 |
uint16_t | mVoiceBusChannels = 0 |
std::shared_ptr< BusRoutingCallback > | mBusRoutingCallback |
AudioIOData | internalAudioIO |
SingleRWRingBuffer | mVoiceIdsToTurnOff {64 * sizeof(int)} |
SingleRWRingBuffer | mVoiceIdsToFree {64 * sizeof(int)} |
TimeMasterMode | mMasterMode |
std::vector< AudioCallback * > | mPostProcessing |
std::vector< TriggerOnCallback > | mTriggerOnCallbacks |
std::vector< TriggerOffCallback > | mTriggerOffCallbacks |
std::vector< FreeCallback > | mFreeCallbacks |
std::vector< AllocationCallback > | mAllocationCallbacks |
float | mAudioGain {1.0f} |
int | mIdCounter {1000} |
bool | mAllNotesOff {false} |
void * | mDefaultUserData {nullptr} |
Creators | mCreators |
std::vector< std::string > | mNoAllocationList |
std::vector< size_t > | mChannelMap |
bool | mRunCPUClock {true} |
double | mCpuGranularitySec = 0.001 |
std::unique_ptr< std::thread > | mCpuClockThread |
bool | mVerbose {false} |
The DynamicScene class.
Definition at line 211 of file al_DynamicScene.hpp.
|
inherited |
Preallocate a number of voices of a particular TSynthVoice to avoid doing realtime allocation.
Definition at line 1073 of file al_PolySynth.hpp.
|
inherited |
Preallocate a number of voices of a voice to avoid doing realtime allocation. The name must be registered using registerSynthClass()
|
inherited |
Insert an AudioCallback object at the end of the callback queue.
v | The AudioCallback object |
The callback provided is appended to the list of post processing callbacks. The post processing callbacks are run in sequence after the audio from all voices has been rendered. This can be useful for global effects, spatialization, etc.
|
inlineinherited |
|
inlineinherited |
|
inherited |
Get the first available voice with minimal checks.
forceAlloc |
This is a quick function with littl eoverhead for PolySynths that handle only one type of voice.
|
inlineinherited |
getFreeVoices
This function is unsafe and should be used with extreme care. Ensure that no allocation, voice insertion or removal takes place while working with these voices.
Definition at line 742 of file al_PolySynth.hpp.
|
inherited |
Get a reference to a voice.
forceAlloc | force allocation of voice even if maximum allowed polyphony is reached |
Returns a free voice from the internal dynamic allocated pool. You must call triggerVoice to put the voice back in the rendering chain after setting its properties, otherwise it will be lost.
Definition at line 1030 of file al_PolySynth.hpp.
|
inherited |
Get a reference to a free voice by voice type name.
forceAlloc | force allocation of voice even if maximum allowed polyphony is reached |
Returns a free voice from the internal dynamic allocated pool. If voice is not available. It will be allocated. Can return nullptr if the class name and creator have not been registered with registerSynthClass()
|
inherited |
Insert an AudioCallback object after another in the queue.
v | The AudioCallback object |
beforeThis | The callback that will come before v |
The callback provided is inserted into the list of post processing callbacks.
The post processing callbacks are run in sequence after the audio from all voices has been rendered. This can be useful for global effects, spatialization, etc.
If afterThis is not found v is prepended to the callback list
|
inherited |
Insert an AudioCallback object before another in the queue.
v | The AudioCallback object |
beforeThis | The callback that will come after v |
The callback provided is inserted into the list of post processing callbacks.
The post processing callbacks are run in sequence after the audio from all voices has been rendered. This can be useful for global effects, spatialization, etc.
If beforeThis is not found v is prepended to the callback list
|
inherited |
Use this function to insert a voice allocated externally into the free voice pool.
voice | the new voice to be added to the free voice pool |
You can also use this function to return to the polysynth a voice requested that will not be used.
|
inline |
The listener pose is used to determine both the graphic view and the audio spatialization.
Definition at line 251 of file al_DynamicScene.hpp.
|
inherited |
Remove voice from the free voice pool.
voice |
|
virtual |
Prepares internals for run.
io | The audio device AudioIO/AudioIOData object |
This function must be called before any render() calls as it allocates and resizes the internal AudioIOData objects that are passed to the voices in the chain. You should call setVoiceMaxOutputChannels() or setVoiceBusChannels() to set specific values if your voices use more than one output channel or you need to use buses.
Reimplemented from al::PolySynth.
|
inherited |
Insert an AudioCallback object at the head of the callback queue.
v | The AudioCallback object |
The callback provided is prepended to the list of post processing callbacks. The post processing callbacks are run in sequence after the audio from all voices has been rendered. This can be useful for global effects, spatialization, etc.
|
inlineinherited |
Check for voices marked as free and move them to the free voice pool.
You need to call this function only if you are in TIME_MASTER_FREE mode. In other modes it is called in the render() function for the domain.
Definition at line 898 of file al_PolySynth.hpp.
|
inlineinherited |
Add new voices to the chain.
You need to call this function only if you are in TIME_MASTER_FREE mode. In other modes it is called in the render() function for the domain.
Definition at line 804 of file al_PolySynth.hpp.
|
inlineinherited |
Check for voices that need trigger off and execute.
You need to call this function only if you are in TIME_MASTER_FREE mode. In other modes it is called in the render() function for the domain.
Definition at line 855 of file al_PolySynth.hpp.
|
inlineinherited |
Register a SynthVoice class to allow instantiating it by name
This is needed for remote instantiation and for text sequence playback.
Definition at line 690 of file al_PolySynth.hpp.
|
inherited |
Remove an AudioCallback object from the queue.
v | The AudioCallback object |
The callback provided is removed from the list of post processing callbacks.
If v is not found, this call has no effect.
|
finalvirtual |
render all the active voices into the audio buffers
io | AudioIOData containing buffers and audio I/O meta data |
Reimplemented from al::PolySynth.
|
inherited |
setBusRoutingCallback
cb | This function will be called after all voices have rendered their output and prior to the function call to process spatialization. Can be used to route signals to buses. |
|
inherited |
Set channel map for output.
channelMap | The index into the vector refers to the output channel in the voice buffer, the value is the channel index to write for audio output. This operation should be performed only when audio is not running. Channel mapping is ignored in DynamicScene and DistributedScene. |
|
inlineinherited |
Set the time in seconds to wait between sequencer updates when time master is CPU.
This has no effect if time master mode is not TIME_MASTER_CPU
Definition at line 794 of file al_PolySynth.hpp.
|
inlineinherited |
Set default user data to set to voices before the are returned by getVoice()
userData |
Definition at line 550 of file al_PolySynth.hpp.
|
inline |
Set a Spatializar to use.
sl | The Speaker layout to use |
If not called, the default is stereo panning over two speakers.
Definition at line 226 of file al_DynamicScene.hpp.
|
inherited |
Set time master context.
master | domain |
You should not call this function if any of the rendering domains are running.
|
inlineinherited |
Determines the number of buses for the internal AudioIOData objects.
channels | Always call prepare() after calling this function. The changes are only applied by prepare(). |
Definition at line 761 of file al_PolySynth.hpp.
|
inherited |
Determines the number of output channels allocated for the internal AudioIOData objects.
|
inline |
Stop all audio threads. No processing is possible after calling this function.
You might need to close all threads to have applications close neatly. Will only have effect if threading is enabled for simulation or audio
Definition at line 286 of file al_DynamicScene.hpp.
|
inherited |
trigger Puts voice in active voice lit and calls triggerOn() for it
voice | pointer to the voice to trigger |
You can use the id to identify the note for later triggerOff() calls. Always use a positive value for id, as negative ids have special treatment in classes like this one and SynthGUIManager
|
finalvirtual |
This function runs the simulation/update of internal states for each voice.
dt | The elapsed time since the previous call to this function |
Reimplemented from al::PolySynth.
|
protectedinherited |
Dynamic voices that are currently active. Only modified within the master domain (set by mMasterMode)
Definition at line 963 of file al_PolySynth.hpp.
|
protectedinherited |
Voices to be inserted in the realtime context. Internal voices are allocated in PolySynth and shared with the outside.
Definition at line 958 of file al_PolySynth.hpp.