-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathVolume.cpp
54 lines (44 loc) · 1.26 KB
/
Volume.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/** Volume
*
* Demonstrates reading a knob to adjust the level of audio
* passing through the module.
*
* The Mix knob is used to adjust the volume of the signal.
*/
#include "aurora.h"
using namespace daisy;
using namespace aurora;
/** Our global hardware object */
Hardware hw;
void AudioCallback(AudioHandle::InputBuffer in, AudioHandle::OutputBuffer out, size_t size)
{
/** This filters, and prepares all of the module's controls for us. */
hw.ProcessAllControls();
/** Read the Mix knob value into a variable called "volume". */
float volume = hw.GetKnobValue(KNOB_MIX);
/** Loop through each sample of audio */
for (size_t i = 0; i < size; i++)
{
/** Now for both left and right channels of audio, we'll multiply the input
* by the volume to turn down the output signal.
*
* With Mix all the way down, this will result in silence.
* With Mix all the way up, the audio should pass through at the normal level.
*/
/** Left Channel */
out[0][i] = in[0][i] * volume;
/** Right Channel */
out[1][i] = in[1][i] * volume;
}
}
int main(void)
{
/** Initialize the Hardware */
hw.Init();
/** Start the audio engine calling the function defined above periodically */
hw.StartAudio(AudioCallback);
/** Infinite Loop */
while (1)
{
}
}