NAP
bufferplayernode.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 // Std includes
8 #include <atomic>
9 
10 // Nap includes
11 #include <audio/utility/safeptr.h>
12 
13 // Audio includes
14 #include <audio/core/audionode.h>
15 #include <audio/core/audionodemanager.h>
16 
17 namespace nap
18 {
19  namespace audio
20  {
21 
25  class NAPAPI BufferPlayerNode : public Node
26  {
27  RTTI_ENABLE(Node)
28 
29  public:
30  BufferPlayerNode(NodeManager& manager) : Node(manager)
31  {}
32 
36  OutputPin audioOutput = {this};
37 
44  void play(int channel = 0, DiscreteTimeValue position = 0, ControllerValue speed = 1.);
45 
49  void stop();
50 
55  void setSpeed(ControllerValue speed);
56 
61  void setPosition(DiscreteTimeValue position);
62 
67  void setChannel(int channel);
68 
73  void setBuffer(SafePtr<MultiSampleBuffer> buffer);
74 
78  ControllerValue getSpeed() const { return mSpeed; }
79 
83  DiscreteTimeValue getPosition() const { return mPosition; }
84 
88  int getChannel() const { return mChannel; }
89 
90  private:
91  // Inherited from Node
92  void process() override;
93 
94  std::atomic<bool> mPlaying = {false}; // Indicates wether the node is currently playing.
95  std::atomic<int> mChannel = {0}; // The channel within the buffer that is being played bacl/
96  std::atomic<double> mPosition = {0}; // Current position of playback in samples within the source buffer.
97  std::atomic<ControllerValue> mSpeed = {1.f}; // Playback speed as a fraction of the original speed.
98  SafePtr<MultiSampleBuffer> mBuffer = nullptr; // Pointer to the buffer with audio material being played back.
99  };
100 
101  }
102 }
nap::audio::BufferPlayerNode::getPosition
DiscreteTimeValue getPosition() const
Definition: bufferplayernode.h:83
nap::audio::BufferPlayerNode::getChannel
int getChannel() const
Definition: bufferplayernode.h:88
nap::audio::BufferPlayerNode
Definition: bufferplayernode.h:25
nap::audio::NodeManager
Definition: audionodemanager.h:33
nap::audio::ControllerValue
float ControllerValue
Definition: audiotypes.h:113
nap::audio::OutputPin
Definition: audiopin.h:204
nap::audio::Node
Definition: audionode.h:33
nap::audio::DiscreteTimeValue
nap::uint64 DiscreteTimeValue
Definition: audiotypes.h:125
nap::audio::BufferPlayerNode::BufferPlayerNode
BufferPlayerNode(NodeManager &manager)
Definition: bufferplayernode.h:30
nap
Definition: templateapp.h:17
nap::audio::BufferPlayerNode::getSpeed
ControllerValue getSpeed() const
Definition: bufferplayernode.h:78
nap::audio::SafePtr
Definition: safeptr.h:28