AudioManager.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 #ifndef H_DC_AUDIO_MANAGER_INCLUDED
34 #define H_DC_AUDIO_MANAGER_INCLUDED
35 
36 // handles the nitty-gritty of audio.
37 // THe AudioManager must continuously process any pushed data.
38 // Under most implementations, a threaded approach would be most appropriate.
39 
40 #include <string>
41 #include <vector>
42 #include <Dynacoe/Backends/Backend.h>
43 namespace Dynacoe {
44 class AudioManager : public Backend {
45  public:
46  virtual ~AudioManager(){}
47 
48  // In the case that not enough new data is being
49  // fed to the AudioManager, underruns will occur.
50  // These routines tell the AudioManager how to fill the gap
51  enum class UnderrunHandlerRoutine {
52  Silence, // replace it with silence. Can lead to clicking
53  Ring, // playback some amount of previous data until more data is fed
54  Taper, // similar to ring, but fades in and out to samples to soften clickint
55 
56  };
57 
58  // Makes the connection to hardware to attempt to
59  // bring the backend to a usable state. Returns whether or
60  // not the connection was successfully made. Else,
61  // it is recommended to try again.
62  virtual bool Connect() = 0;
63 
64  // Sets the number of samples second.
65  // The default is 44100.
66  virtual void SetSampleRate(uint32_t) = 0;
67 
68  // returns the current sample rate in kHz
69  virtual uint32_t GetSampleRate() = 0;
70 
71  // Queues data to be interpreted by the AudioManager. The format is in
72  // 2 channel, interleaved form, meaning that the samples should be organized
73  // in an interleaved channel format. In most device setups, the
74  // odd samples are for the left speaker, and the
75  // even samples are for the right speaker
76  // each sample is a floating point number
77  // and expected to be normalized between -1 and 1.
78  virtual void PushData(float * data, uint32_t numSamples) = 0;
79 
80 
81  // returns the number of samples pending to be consumed
82  virtual uint32_t PendingSamplesCount() = 0;
83 
84 
85 
86  // Returns whether or not the AudioManager is in an underrun state
87  virtual bool Underrun() = 0;
88 
89  // Enables or disables output
90  virtual void EnableOutput(bool doIt) = 0;
91 
92 
93  // Set and Get the volume multipler. This value
94  // is clamped to 0 and 1 and represents a scale
95  // applied to all samples before interpretation.
96  // the default is .5;
97  virtual void SetVolumeMultiplier(float) = 0;
98  virtual float GetVolumeMultiplier() = 0;
99 
100 
101  virtual float GetCurrentOutputSample() = 0;
102 
103 };
104 }
105 
106 #endif
Definition: AssetID.h:37