Overte C++ Documentation
AudioMixerSlave.h
1 //
2 // AudioMixerSlave.h
3 // assignment-client/src/audio
4 //
5 // Created by Zach Pomerantz on 11/22/16.
6 // Copyright 2016 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_AudioMixerSlave_h
13 #define hifi_AudioMixerSlave_h
14 
15 #if !defined(Q_MOC_RUN)
16 // Work around https://bugreports.qt.io/browse/QTBUG-80990
17 #include <tbb/concurrent_vector.h>
18 #endif
19 
20 #include <AABox.h>
21 #include <AudioHRTF.h>
22 #include <AudioRingBuffer.h>
23 #include <ThreadedAssignment.h>
24 #include <UUIDHasher.h>
25 #include <NodeList.h>
26 #include <PositionalAudioStream.h>
27 
28 #include "AudioMixerClientData.h"
29 #include "AudioMixerStats.h"
30 
31 class AvatarAudioStream;
32 class AudioHRTF;
33 
34 class AudioMixerSlave {
35 public:
36  using ConstIter = NodeList::const_iterator;
37 
38  struct SharedData {
39  AudioMixerClientData::ConcurrentAddedStreams addedStreams;
40  std::vector<Node::LocalID> removedNodes;
41  std::vector<NodeIDStreamID> removedStreams;
42  };
43 
44  AudioMixerSlave(SharedData& sharedData) : _sharedData(sharedData) {};
45 
46  // process packets for a given node (requires no configuration)
47  void processPackets(const SharedNodePointer& node);
48 
49  // configure a round of mixing
50  void configureMix(ConstIter begin, ConstIter end, unsigned int frame, int numToRetain);
51 
52  // mix and broadcast non-ignored streams to the node (requires configuration using configureMix, above)
53  // returns true if a mixed packet was sent to the node
54  void mix(const SharedNodePointer& node);
55 
56  AudioMixerStats stats;
57 
58 private:
59  // create mix, returns true if mix has audio
60  bool prepareMix(const SharedNodePointer& listener);
61  void addStream(AudioMixerClientData::MixableStream& mixableStream,
62  AvatarAudioStream& listeningNodeStream,
63  float masterAvatarGain,
64  float masterInjectorGain,
65  bool isSoloing);
66  void updateHRTFParameters(AudioMixerClientData::MixableStream& mixableStream,
67  AvatarAudioStream& listeningNodeStream,
68  float masterAvatarGain,
69  float masterInjectorGain);
70  void resetHRTFState(AudioMixerClientData::MixableStream& mixableStream);
71 
72  void addStreams(Node& listener, AudioMixerClientData& listenerData);
73 
74  // mixing buffers
75  float _mixSamples[AudioConstants::NETWORK_FRAME_SAMPLES_STEREO];
76  int16_t _bufferSamples[AudioConstants::NETWORK_FRAME_SAMPLES_STEREO];
77 
78  // frame state
79  ConstIter _begin;
80  ConstIter _end;
81  unsigned int _frame { 0 };
82  int _numToRetain { -1 };
83 
84  SharedData& _sharedData;
85 };
86 
87 #endif // hifi_AudioMixerSlave_h