2 #ifndef AL_DYNAMICSCENE_HPP
3 #define AL_DYNAMICSCENE_HPP
47 #include <condition_variable>
52 #include "al/math/al_Vec.hpp"
53 #include "al/scene/al_SynthSequencer.hpp"
54 #include "al/sound/al_Speaker.hpp"
55 #include "al/sound/al_StereoPanner.hpp"
56 #include "al/spatial/al_DistAtten.hpp"
57 #include "al/spatial/al_Pose.hpp"
72 const Pose pose() {
return mPose.
get(); }
74 float size() {
return mSize.
get(); }
76 void setPose(
Pose pose) { mPose.
set(pose); }
78 void setSize(
float size) { mSize.
set(size); }
82 Parameter ¶meterSize() {
return mSize; }
84 bool useDistanceAttenuation() {
return mUseDistAtten; }
85 void useDistanceAttenuation(
bool atten) { mUseDistAtten = atten; }
87 std::vector<Vec3f> &audioOutOffsets() {
return mAudioOutPositionOffsets; }
94 mAudioOutPositionOffsets = offsets;
115 bool noCalls =
false)
override;
123 bool noCalls =
false)
override;
131 pFields.reserve(pFields.size() + 8);
132 Pose currentPose = pose();
133 pFields.insert(pFields.end(), currentPose.
vec().begin(),
134 currentPose.
vec().end());
138 pFields.push_back(*comps++);
139 pFields.push_back(*comps++);
140 pFields.push_back(*comps++);
141 pFields.push_back(*comps);
143 pFields.push_back(mSize.
get());
154 Parameter mSize{
"_size",
"", 1.0};
158 mAudioOutPositionOffsets;
162 bool mUseDistAtten{
true};
163 bool mIsReplica{
false};
176 ThreadPool(
unsigned int n = std::thread::hardware_concurrency());
179 void waitForProcessingDone();
182 size_t size() {
return workers.size(); }
187 std::vector<std::thread> workers;
191 std::mutex queue_mutex;
192 std::condition_variable cv_task;
193 std::condition_variable cv_finished;
201 std::unique_lock<std::mutex> lock(queue_mutex);
204 cv_task.notify_one();
214 TimeMasterMode masterMode = TimeMasterMode::TIME_MASTER_AUDIO);
225 template <
class TSpatializer>
227 mSpatializer = std::make_shared<TSpatializer>(sl);
228 mSpatializer->compile();
229 return std::static_pointer_cast<TSpatializer>(mSpatializer);
244 virtual void cleanup() {}
263 virtual void update(
double dt = 0) final;
265 void setUpdateThreaded(
bool threaded) { mThreadedUpdate = threaded; }
266 void setAudioThreaded(
bool threaded) { mThreadedAudio = threaded; }
268 DistAtten<> &distanceAttenuation() {
return mDistAtten; }
270 void print(std::ostream &stream = std::cout);
272 void showWorldMarker(
bool show =
true) { mDrawWorldMarker = show; }
287 mSynthRunning =
false;
288 mThreadTrigger.notify_all();
289 for (
auto &thr : mAudioThreads) {
292 mAudioThreads.clear();
298 std::shared_ptr<Spatializer> mSpatializer;
303 bool mSortDrawingByDistance{
false};
305 std::unique_ptr<ThreadPool> mWorkerThreads;
306 bool mThreadedUpdate{
true};
309 bool mThreadedAudio{
false};
310 std::vector<std::thread> mAudioThreads;
311 std::vector<AudioIOData> mThreadedAudioData;
312 std::map<int, std::vector<int>>
315 std::condition_variable mThreadTrigger;
316 std::condition_variable mAudioThreadDone;
317 std::mutex mSpatializerLock;
321 std::mutex mThreadTriggerLock;
322 bool mSynthRunning{
true};
323 unsigned int mAudioBusy = 0;
325 static void updateThreadFunc(UpdateThreadFuncData data);
327 static void audioThreadFunc(DynamicScene *scene,
int id);
330 bool mDrawWorldMarker{
false};
std::shared_ptr< TSpatializer > setSpatializer(Speakers &sl)
Set a Spatializar to use.
Pose & listenerPose()
The listener pose is used to determine both the graphic view and the audio spatialization.
virtual void render(AudioIOData &io) final
render all the active voices into the audio buffers
virtual void update(double dt=0) final
This function runs the simulation/update of internal states for each voice.
void stopAudioThreads()
Stop all audio threads. No processing is possible after calling this function.
void prepare(AudioIOData &io)
Prepares internals for run.
void sortDrawingByDistance(bool sort=true)
Enables/disables sorting by distance to listener on graphics render.
virtual void render(Graphics &g) final
render graphics for all active voices
Interface for loading fonts and rendering text.
virtual float get() override
get the parameter's value
virtual void set(float value, ValueSource *src=nullptr) override
set the parameter's value
virtual ParameterType get()
get the parameter's value
virtual void set(ParameterType value, ValueSource *src=nullptr)
set the parameter's value
A PolySynth manages polyphony and rendering of SynthVoice instances.
A local coordinate frame.
Vec3d & vec()
Get vector component.
Quatd & quat()
Get quaternion component (represents orientation)
A PositionedVoice is a rendering class that can have a position and size.
void markAsReplica()
Set voice as part of a replica distributed scene.
virtual bool setTriggerParams(float *pFields, int numFields=-1) override
For PositionedVoice, the pose (7 floats) and the size are appended to the pfields.
void audioOutOffsets(const std::vector< Vec3f > &offsets)
Set the position offset for each of the audio outputs for this voice.
virtual bool setTriggerParams(std::vector< float > &pFields, bool noCalls=false) override
Set parameter values.
virtual void preProcess(Graphics &)
Override this function to apply transformations after the internal transformations of the voice has b...
virtual std::vector< ParameterField > getTriggerParams() override
For PositionedVoice, the pose (7 floats) and the size are appended to the pfields.
virtual bool setTriggerParams(std::vector< ParameterField > pFields, bool noCalls=false) override
Set parameter values.
T components[4]
component vector
virtual std::vector< ParameterField > getTriggerParams()
Get this instance's parameter fields.
void sort(T &value1, T &value2)
std::vector< Speaker > Speakers
A set of speakers.