-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMixer.cpp
More file actions
64 lines (49 loc) · 1.41 KB
/
Copy pathMixer.cpp
File metadata and controls
64 lines (49 loc) · 1.41 KB
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
55
56
57
58
59
60
61
62
63
64
/* Dependencies */
#include <stdint.h>
#include "Mixer.h"
#include "AmplitudeModulator.h"
namespace CheapTune {
Mixer::Mixer(Amplitude_t globalAmplitude) :
_channels(), /*_filter(),*/ _globalAmplitude(globalAmplitude) {
}
void Mixer::setGlobalAmplitude(Amplitude_t globalAmplitude) {
_globalAmplitude = globalAmplitude;
}
Sample_t Mixer::mixTwoSamples(Sample_t _A, Sample_t _B) {
int32_t Z, A = _A, B = _B;
if (A < 0 && B < 0)
Z = (A + B) - ((A * B) / SAMPLE_VMIN);
else if ((A > 0) & (B > 0))
Z = (A + B) - ((A * B) / SAMPLE_VMAX);
else
Z = A + B;
return Z;
}
Sample_t Mixer::getSample() {
/* Get the first channel sample */
Sample_t sample = _channels[0].getSample();
/* Get all other channels samples */
for (unsigned char i = 1; i < CHANNELS_COUNT; ++i) {
/* Get channel sample and mix them with the previous sample */
sample = mixTwoSamples(sample, _channels[i].getSample());
}
/* Pass the resulting sample into the filter */
//sample = _filter.computeSample(sample);
/* Amplitude modulate the sample */
sample = AmplitudeModulator::compute(sample, _globalAmplitude);
/* Return the final sample value */
return sample;
}
void Mixer::reset() {
for (unsigned char i = 0; i < CHANNELS_COUNT; ++i)
_channels[i].reset();
//_filter.reset();
_globalAmplitude = 255;
}
Channel& Mixer::channel(unsigned char index) {
return _channels[index];
}
/*Filter& Mixer::filter() {
return _filter;
}*/
}