-
Notifications
You must be signed in to change notification settings - Fork 0
/
audioRec.cpp
112 lines (91 loc) · 2.16 KB
/
audioRec.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "audioRec.h"
ReSpeaker respeaker;
AudioInputTDMslave tdm1(8);
AudioRecordQueue queue1;
AudioRecordQueue queue3;
AudioRecordQueue queue5;
AudioRecordQueue queue7;
AudioConnection patchCord9(tdm1, 0, queue1, 0);
AudioConnection patchCord2(tdm1, 1, queue3, 0);
AudioConnection patchCord5(tdm1, 2, queue5, 0);
AudioConnection patchCord7(tdm1, 3, queue7, 0);
int16_t tmp[128];
int blkcnt = 0;
bool initOK;
float curVol = 0;
bool recordingInitialized() {
return initOK;
}
void setupRec() {
if (respeaker.i2cOK()) {
initOK = true;
respeaker.initBoard();
delay(1000);
respeaker.startCapture22();
delay(1000);
AudioMemory(64);
AudioInterrupts();
queue1.begin();
queue3.begin();
queue5.begin();
queue7.begin();
if (respeaker.captureStarted()) {
Serial.println("started recording");
} else {
Serial.println("recording failed");
}
} else {
initOK = false;
Serial.println("I2C error");
}
}
void audioRecPause() {
queue1.end();
queue3.end();
queue5.end();
queue7.end();
}
void audioRecResume() {
queue1.begin();
queue3.begin();
queue5.begin();
queue7.begin();
}
void clearBuffer() {
queue1.clear();
queue3.clear();
queue5.clear();
queue7.clear();
}
void freeBuffer() {
queue1.freeBuffer();
queue3.freeBuffer();
queue5.freeBuffer();
queue7.freeBuffer();
}
float getMicVolume() {
return curVol;
}
void setMicVolume(float vol) {
curVol = vol;
uint8_t v = (uint8_t)(vol*255.0f);
respeaker.setVolume(v);
}
int readAudio(objects *objs) {
const int rd = HOP_SIZE;
int avail = 0;
avail = queue7.available();
int16_t * b;
if (avail > 0) {
memcpy(tmp, queue1.readBuffer(), rd*2); //16 Bit int = 2 byte
//ToDo: do something with tmp
memcpy(tmp, queue3.readBuffer(), rd*2); //16 Bit int = 2 byte
//ToDo: do something with tmp
memcpy(tmp, queue5.readBuffer(), rd*2); //16 Bit int = 2 byte
//ToDo: do something with tmp
memcpy(tmp, queue7.readBuffer(), rd*2); //16 Bit int = 2 byte
//ToDo: do something with tmp
freeBuffer();
}
return avail;
}