-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathOscilloscope.h
79 lines (72 loc) · 1.92 KB
/
Oscilloscope.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef Oscilloscope_h_
#define Oscilloscope_h_
#include "AudioStream.h"
#include "ST7735_t3.h"
#define NO_OF_BLOCKS 2
class Oscilloscope : public AudioStream {
public:
Oscilloscope(void) : AudioStream(1, inputQueueArray) {
}
virtual void update(void);
void ScreenSetup(ST7735_t3*);
void Display(void);
void AddtoBuffer(int16_t*);
private:
audio_block_t *inputQueueArray[1];
ST7735_t3 *display;
int16_t buffer[AUDIO_BLOCK_SAMPLES * NO_OF_BLOCKS];
int16_t old_val[AUDIO_BLOCK_SAMPLES];
uint32_t count = 0;
};
#endif
void Oscilloscope::ScreenSetup(ST7735_t3 *screen) {
__disable_irq();
display = screen;
__enable_irq();
}
void Oscilloscope::Display() {
__disable_irq();
boolean crossing = false;
int16_t pixel_x = 0;
uint32_t i = 0;
do {
int16_t wave_data = buffer[i];
if (crossing || wave_data > 0) {
i++;
wave_data = buffer[i];
if (crossing || wave_data <0 ) {
crossing = true;
int16_t pixel_y = map(wave_data, 32767, -32768, -100, 100) + 62;
display->drawPixel(pixel_x + 15, old_val[pixel_x], 0);//Remove previous pixel
display->drawPixel(pixel_x + 15, pixel_y, 0x07B0);//New pixel
old_val[pixel_x] = {pixel_y};
pixel_x++;
}
}
i++;
} while (i < AUDIO_BLOCK_SAMPLES * NO_OF_BLOCKS);
__enable_irq();
}
void Oscilloscope::AddtoBuffer(int16_t *audio) {
const int16_t *begin = audio;
const int16_t *end = audio + AUDIO_BLOCK_SAMPLES;
__disable_irq();
do {
buffer[count++] = *audio;
audio++;
} while (audio < end);
if(count > (AUDIO_BLOCK_SAMPLES * NO_OF_BLOCKS) -1){
count = 0;
Display();
}
__enable_irq();
}
void Oscilloscope::update(void) {
if (!display) return;
audio_block_t *block;
block = receiveReadOnly(0);
if (block) {
AddtoBuffer(block->data);
release(block);
}
}