forked from berthubert/googerteller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
teller.cc
61 lines (54 loc) · 1.3 KB
/
teller.cc
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
#include <iostream>
#include <vector>
#include <math.h>
#include <unistd.h>
#include <thread>
#include <atomic>
#include <pcaudiolib/audio.h>
using namespace std;
int main()
{
audio_object* ao;
ao=create_audio_device_object(0, "teller", "");
if(!ao) {
cerr<<"Unable to open audio file "<<endl;
return 0;
}
int res = audio_object_open(ao, AUDIO_OBJECT_FORMAT_S16LE, 44100, 1);
if(res < 0) {
cerr<<"Error opening audio: "<<audio_object_strerror(ao, res)<<endl;
}
std::atomic<int64_t> counter = 0;
auto player = [&]() {
vector<int16_t> data;
int ourcounter=0;
data.reserve(44100);
while(counter >= 0) {
data.clear();
if(ourcounter < counter) {
for(int n=0; n < 250; ++n) {
int16_t val = 20000 * sin((n/44100.0) * 500 * 2 * M_PI);
data.push_back(val);
}
ourcounter++;
if(counter - ourcounter > 1000)
ourcounter = counter;
}
else {
for(int n=0; n < 150; ++n) {
data.push_back(0);
}
}
audio_object_write(ao, &data[0], data.size() * sizeof(decltype(data)::value_type));
// audio_object_flush(ao);
}
};
std::thread athread(player);
string line;
while(getline(cin, line)) {
counter++;
}
counter = -1;
athread.join();
sleep(1);
}