Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <termios.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <linux/kd.h>
- #include <pthread.h>
- enum sound_names
- {
- c1,
- cis1,
- d1,
- dis1,
- e1,
- f1,
- fis1,
- g1,
- gis1,
- a1,
- ais1,
- h1,
- c2,
- cis2,
- d2,
- dis2,
- e2,
- f2,
- fis2,
- g2,
- gis2,
- a2,
- ais2,
- h2,
- c3,
- cis3,
- d3,
- dis3,
- e3,
- f3,
- fis3,
- g3,
- gis3,
- a3,
- ais3,
- h3
- };
- double sounds[36] =
- {
- 261.6,
- 277.2,
- 293.7,
- 311.1,
- 329.6,
- 349.6,
- 370.0,
- 391.9,
- 415.3,
- 440.0,
- 466.2,
- 493.9,
- 523.3,
- 554.4,
- 587.3,
- 622.3,
- 659.3,
- 698.5,
- 740.0,
- 784.0,
- 830.6,
- 880.0,
- 932.3,
- 987.8,
- 1046.5,
- 1108.7,
- 1174.6,
- 1244.5,
- 1318.5,
- 1396.9,
- 1479.9,
- 1567.9,
- 1661.2,
- 1760.0,
- 1864.6,
- 1975.5
- };
- int mygetch(void)
- {
- struct termios oldt,newt;
- int ch;
- tcgetattr( STDIN_FILENO, &oldt );
- newt = oldt;
- newt.c_lflag &= ~( ICANON | ECHO );
- tcsetattr( STDIN_FILENO, TCSANOW, &newt );
- ch = getchar();
- tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
- return ch;
- }
- void msleep(int sec)
- {
- usleep(sec*1000);
- }
- void play(int freq, int time)
- {
- int fd = open("/dev/tty10", O_RDONLY);
- ioctl(fd, KDMKTONE, ((time)<<16)+(1193180/(int)sounds[freq]));
- msleep(time);
- }
- int sound;
- void *keys()
- {
- while(1)
- {
- int key = mygetch();
- switch(key)
- {
- case 'z': { play(c1, 100); break; }
- case 'x': { play(d1, 100); break; }
- case 'c': { play(e1, 100); break; }
- case 'v': { play(f1, 100); break; }
- case 'b': { play(g1, 100); break; }
- case 'n': { play(a1, 100); break; }
- case 'm': { play(h1, 100); break; }
- case ',': { play(c2, 100); break; }
- case 's': { play(cis1, 100); break; }
- case 'd': { play(dis1, 100); break; }
- case 'g': { play(fis1, 100); break; }
- case 'h': { play(gis1, 100); break; }
- case 'j': { play(ais1, 100); break; }
- }
- }
- }
- int main(int argc, char *argv[])
- {
- pthread_t thread;
- pthread_create(&thread, NULL, keys, NULL);
- pthread_join(thread, NULL);
- /* play(c2, 220);
- play(e2, 180);
- msleep(40);
- play(e2, 180);
- msleep(40);
- play(e2, 180);
- msleep(40);
- play(e2, 180);
- msleep(40);
- play(e2, 220);
- play(d2, 220);
- msleep(220);
- play(d2, 220);
- play(e2, 180);
- msleep(40);
- play(e2, 180);
- msleep(40);
- play(e2, 180);
- play(d2, 180);
- msleep(40);
- play(d2, 220);
- msleep(440);
- play(h1, 220);
- play(d2, 220);
- play(h1, 220);
- play(d2, 220);
- play(h1, 220);
- play(d2, 220);
- play(h1, 240);
- play(g2, 440);
- play(fis2, 440);
- play(e2, 440);
- play(d2, 440);
- msleep(220);
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement