NAP
audioservice.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Audio includes
8 #include <audio/core/audionodemanager.h>
9 #include <audio/utility/safeptr.h>
10 
11 // Nap includes
12 #include <nap/service.h>
13 #include <utility/threading.h>
14 
15 namespace nap
16 {
17  namespace audio
18  {
19  // Forward declarations
20  class AudioService;
21 
26  class NAPAPI AudioService final : public Service
27  {
28  RTTI_ENABLE(nap::Service)
29 
30  public:
31  AudioService(ServiceConfiguration* configuration);
32 
33  ~AudioService() = default;
34 
38  bool init(nap::utility::ErrorState& errorState) override;
39 
43  void shutdown() override;
44 
48  NodeManager& getNodeManager();
49 
57  void onAudioCallback(float** inputBuffer, float** outputBuffer, unsigned long framesPerBuffer);
58 
62  void enqueueTask(TaskQueue::Task task) { mNodeManager.enqueueTask(task); }
63 
64  private:
65  /*
66  * Checks wether certain atomic types that are used within the library are lockfree and gives a warning if not.
67  */
68  void checkLockfreeTypes();
69 
70  private:
71  NodeManager mNodeManager; // The node manager that performs the audio processing.
72  bool mMpg123Initialized = false; // If mpg123 is initialized
73 
74  // DeletionQueue with nodes that are no longer used and that can be cleared and destructed safely on the next audio callback.
75  // Clearing is performed on the audio callback to make sure the node can not be destructed while it is being processed.
76  DeletionQueue mDeletionQueue;
77  };
78  }
79 }
nap::audio::DeletionQueue
Definition: safeptr.h:74
nap::audio::AudioService::enqueueTask
void enqueueTask(TaskQueue::Task task)
Definition: audioservice.h:62
nap::utility::ErrorState
Definition: errorstate.h:19
nap::ServiceConfiguration
Definition: service.h:28
nap::audio::AudioService
Definition: audioservice.h:26
nap::audio::NodeManager
Definition: audionodemanager.h:33
nap::Service
Definition: templateservice.h:8
nap::TaskQueue::Task
std::function< void()> Task
Definition: threading.h:26
nap
Definition: templateapp.h:17