forked from fedetft/miosix-kernel
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (45 loc) · 1.47 KB
/
Copy pathmain.cpp
File metadata and controls
56 lines (45 loc) · 1.47 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
#include "miosix.h"
#include "drivers/common/audio.h"
#include "audio/audio_processor.h"
#include "audio/audio_buffer.h"
#include "audio/audio_math.h"
#include "midi/midi.h"
#include "tests/midi_test_data.h"
#include "containers/circular_buffer.h"
#include <functional>
#include <algorithm>
#include <math.h>
#include <cstdint>
using namespace miosix;
using namespace std;
// testing an implementation of an AudioProcessor
class AudioProcessorTest : public AudioProcessor {
public:
AudioProcessorTest(AudioDriver &audioDriver) :
AudioProcessor(audioDriver),
sineLUT([](float x) { return std::sin(x); }, 0, 2 * M_PI,
AudioMath::LookupTableEdges::PERIODIC) {}
void process() override {
auto &buffer = getBuffer();
float *left = buffer.getWritePointer(0);
float *right = buffer.getWritePointer(1);
for (uint32_t i = 0; i < getBufferSize(); i += 1) {
left[i] = 0.8 * sineLUT(phase);
right[i] = left[i];
phase += phaseDelta;
if (phase >= 2 * M_PI) phase -= 2 * M_PI;
}
}
AudioMath::LookupTable<128> sineLUT;
float phase = 0;
float phaseDelta = 440 * 2 * M_PI / 44100.0;
};
int main() {
// initializing the audio driver
AudioDriver audioDriver;
audioDriver.getBuffer();
AudioProcessorTest audioProcessorTest(audioDriver);
audioDriver.init();
audioDriver.setAudioProcessable(audioProcessorTest);
audioDriver.start();
}