-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey_cap.cpp
More file actions
129 lines (106 loc) · 2.6 KB
/
key_cap.cpp
File metadata and controls
129 lines (106 loc) · 2.6 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <stdio.h>
#include <ncurses.h>
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <map>
#include <thread>
#define WIDTH 30
#define HEIGHT 10
#define MAXNOTES 8
int startx = 0;
int starty = 0;
const double R=8000; // sample rate (samples per second)
//const double C=261.625565; // frequency of middle-C (hertz)
//double C = 200;
//double D = 240;
const double V=127; // a volume constant
std::map<int, double> code2freq = {{122, 261.625565}, {120, 293.66}, {99, 329.63}, {118, 349.23}, {98, 392.00}};
double freq = 0;
void audio_loop()
{
for ( int t=0; ; t++ )
{
//uint8_t temp = (sin(t*2*M_PI/R*freq)+1)*V;
//int vol = V / (sizeof(codes)/sizeof(codes[0]));
/*for (int code : codes)
{
if (code == 0) { break; }
std::cout << code;
/*double freq = code2freq.at(code);
temp += (sin(t*2*M_PI/R*freq)+1)*vol; // pure middle C sine wave
}*/
//uint8_t temp = t/F*C; // middle C saw wave (bytebeat style)
//uint8_t temp = (t*5&t>>1)|(t*3&t>>1); // viznut bytebeat composition
}
return;
}
int main()
{
//WINDOW *menu_win;
/*int highlight = 1;
int choice = 0;*/
int c;
initscr();
noecho();
cbreak();
nodelay(stdscr, TRUE);
/* Line buffering disabled. pass on everything */
//startx = (80 - WIDTH) / 2;
//starty = (24 - HEIGHT) / 2;
//menu_win = newwin(HEIGHT, WIDTH, starty, startx);
//keypad(menu_win, TRUE);
//std::thread audio (audio_loop); //Start audio loop
while(1)
{
while((c = getch()))
{
try
{
freq = code2freq.at(c);
std::cout<< freq <<std::endl;
//codes[p++] = c;
}
catch(const std::out_of_range& oor)
{
freq = 0;
}
}
/*while(p < MAXNOTES)
{
codes[p++] = 0;
}
if (codes[0] != 0){
std::cout << codes[0] << std::endl;
}*/
//audio_loop();
clrtoeol();
refresh();
//print_menu(menu_win, highlight);
//if(choice != 0) /* User did a choice come out of the infinite loop */
//break;
}
//mvprintw(23, 0, "You chose choice %d with choice string %s\n", choice, choices[choice - 1]);
clrtoeol();
refresh();
endwin();
return 0;
}
/*void print_menu(WINDOW *menu_win, int highlight)
{
int x, y, i;
x = 2;
y = 2;
box(menu_win, 0, 0);
for(i = 0; i < n_choices; ++i)
{ if(highlight == i + 1) // High light the present choice
{ wattron(menu_win, A_REVERSE);
mvwprintw(menu_win, y, x, "%s", choices[i]);
wattroff(menu_win, A_REVERSE);
}
else
mvwprintw(menu_win, y, x, "%s", choices[i]);
++y;
}
wrefresh(menu_win);
}*/