Overte C++ Documentation
PositionalAudioStream.h
1 //
2 // PositionalAudioStream.h
3 // libraries/audio/src
4 //
5 // Created by Stephen Birarda on 6/5/13.
6 // Copyright 2013 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_PositionalAudioStream_h
13 #define hifi_PositionalAudioStream_h
14 
15 #include <glm/gtx/quaternion.hpp>
16 #include <AABox.h>
17 
18 #include "InboundAudioStream.h"
19 
20 const int AUDIOMIXER_INBOUND_RING_BUFFER_FRAME_CAPACITY = 100;
21 
22 using StreamID = QUuid;
23 const int NUM_STREAM_ID_BYTES = NUM_BYTES_RFC4122_UUID;
24 
25 struct NodeIDStreamID {
26  QUuid nodeID;
27  Node::LocalID nodeLocalID;
28  StreamID streamID;
29 
30  NodeIDStreamID(QUuid nodeID, Node::LocalID nodeLocalID, StreamID streamID)
31  : nodeID(nodeID), nodeLocalID(nodeLocalID), streamID(streamID) {};
32 
33  bool operator==(const NodeIDStreamID& other) const {
34  return (nodeLocalID == other.nodeLocalID || nodeID == other.nodeID) && streamID == other.streamID;
35  }
36 };
37 
38 using ChannelFlag = quint8;
39 
40 class PositionalAudioStream : public InboundAudioStream {
41  Q_OBJECT
42 public:
43  enum Type {
44  Microphone,
45  Injector
46  };
47 
48  PositionalAudioStream(PositionalAudioStream::Type type, bool isStereo, int numStaticJitterFrames = -1);
49 
50  const QUuid DEFAULT_STREAM_IDENTIFIER = QUuid();
51  virtual const StreamID& getStreamIdentifier() const { return DEFAULT_STREAM_IDENTIFIER; }
52 
53  virtual void resetStats() override;
54 
55  virtual AudioStreamStats getAudioStreamStats() const override;
56 
57  void updateLastPopOutputLoudnessAndTrailingLoudness();
58  float getLastPopOutputTrailingLoudness() const { return _lastPopOutputTrailingLoudness; }
59  float getLastPopOutputLoudness() const { return _lastPopOutputLoudness; }
60  float getQuietestFrameLoudness() const { return _quietestFrameLoudness; }
61 
62  bool shouldLoopbackForNode() const { return _shouldLoopbackForNode; }
63  bool isStereo() const { return _isStereo; }
64 
65  PositionalAudioStream::Type getType() const { return _type; }
66 
67  const glm::vec3& getPosition() const { return _position; }
68  const glm::quat& getOrientation() const { return _orientation; }
69  const glm::vec3& getAvatarBoundingBoxCorner() const { return _avatarBoundingBoxCorner; }
70  const glm::vec3& getAvatarBoundingBoxScale() const { return _avatarBoundingBoxScale; }
71 
72  using IgnoreBox = AABox;
73 
74  // called from single AudioMixerSlave while processing packets for node
75  void enableIgnoreBox();
76  void disableIgnoreBox() { _isIgnoreBoxEnabled = false; }
77 
78  // thread-safe, called from AudioMixerSlave(s) while preparing mixes
79  bool isIgnoreBoxEnabled() const { return _isIgnoreBoxEnabled; }
80  const IgnoreBox& getIgnoreBox() const { return _ignoreBox; }
81 
82 protected:
83  // disallow copying of PositionalAudioStream objects
84  PositionalAudioStream(const PositionalAudioStream&);
85  PositionalAudioStream& operator= (const PositionalAudioStream&);
86 
87  int parsePositionalData(const QByteArray& positionalByteArray);
88 
89 protected:
90  void calculateIgnoreBox();
91 
92  Type _type;
93  glm::vec3 _position;
94  glm::quat _orientation;
95 
96  glm::vec3 _avatarBoundingBoxCorner;
97  glm::vec3 _avatarBoundingBoxScale;
98 
99  bool _shouldLoopbackForNode;
100  bool _isStereo;
101  // Ignore penumbra filter
102  bool _ignorePenumbra;
103 
104  float _lastPopOutputTrailingLoudness;
105  float _lastPopOutputLoudness;
106  float _quietestTrailingFrameLoudness;
107  float _quietestFrameLoudness;
108  int _frameCounter;
109 
110  bool _isIgnoreBoxEnabled { false };
111  IgnoreBox _ignoreBox;
112 };
113 
114 #endif // hifi_PositionalAudioStream_h