RtAudio_Multi.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #if(defined DC_BACKENDS_RTAUDIO_ALSA || defined DC_BACKENDS_RTAUDIO_OSS || defined DC_BACKENDS_RTAUDIO_WIN32)
34 
35 #ifndef H_DC_RTAUDIO_MULTI_INCLUDED
36 #define H_DC_RTAUDIO_MULTI_INCLUDED
37 
38 
39 #include <Dynacoe/Backends/AudioManager/AudioManager.h>
40 #include <../srcs/Dynacoe/Backends/AudioManager/RtAudio/RtAudio.h>
41 #include <queue>
42 #ifdef DC_OS_WINDOWS
43  #include <mutex>
44 #else
45  #include <mutex>
46 #endif
47 #include <cstring>
48 
49 namespace Dynacoe {
50 class StreamBuffer;
51 class RtAudioManager : public AudioManager {
52  public:
53  // standard interface
54  bool Connect();
55  void SetSampleRate(uint32_t);
56  uint32_t GetSampleRate();
57  void PushData(float * data, uint32_t numSamples);
58  uint32_t PendingSamplesCount();
59  bool Underrun();
60  void EnableOutput(bool doIt);
61  void SetVolumeMultiplier(float);
62  float GetVolumeMultiplier();
63  float GetCurrentOutputSample();
64 
65  std::string Name();
66  std::string Version();
67  bool Valid();
68 
69 
70  RtAudioManager();
71  ~RtAudioManager();
72 
73  private:
74 
75 
76 
77 
78  int inputBuffer;
79 
80 
81  StreamBuffer * streamQueue;
82 
83 
84 
85  RtAudio * rtAudio;
86  RtAudio::StreamParameters rtParams;
87  RtAudio::StreamOptions rtOpts;
88 
89 
90  /* Attributes */
91  uint32_t sampleRate;
92  bool enabled;
93  bool connected;
94  bool isUnderrun;
95  float volume;
96  float lastSample;
97 
98 
99 
100  float GetUnderrunSample();
101  void OpenStream();
102  void CloseStream();
103  void StartStream();
104  void StopStream();
105  static int StreamCallback(void * buffer, void *, unsigned int, double, RtAudioStreamStatus, void *);
106 
107 
108  std::recursive_mutex bufferMutex; // attempt to stop the bad
109 
110 
111 };
112 }
113 
114 #endif
115 #endif
Definition: AssetID.h:37