-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioOutput.c
86 lines (79 loc) · 1.68 KB
/
AudioOutput.c
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
#include<stdio.h>
#include<windows.h>
#define T32 3200
#define T24 2400
#define T16 1600
#define T12 1200
#define T8 800
#define T6 600
#define T4 400
#define T2 200
#define T1 100
#define D1 349
#define D2 392
#define D3 440
#define D4 466
#define D5 523
#define D6 587
#define D7 659
#define Z1 698
#define Z2 784
#define Z3 880
#define Z4 988
#define Z5 1046
#define Z6 1175
#define Z7 1318
#define G1 1397
#define I 20
#define R 340
void birthday_song() {
// note array
int notes[] = {
D5, D5, D6, D5, Z1, D7,
D5, D5, D6, D5, Z2, Z1,
D5, D5, Z5, Z3, Z1, D7,
Z4, Z4, Z3, Z1, Z2, Z1
};
// duration array
int durations[] = {
T4, T4, T8, T8, T8, T16,
T4, T4, T8, T8, T8, T16,
T4, T4, T8, T8, T8, T16,
T4, T4, T8, T8, T8, T16
};
// loop to play
for(int i = 0; i < sizeof(notes)/sizeof(notes[0]); i++) {
Beep(notes[i], durations[i]);
}
}
void play_audio(){
long hz,t;
system("mode con cp select=65001");
printf("Input the sound frequency;sound time(';'separated)");
scanf("%d;%d",&hz,&t);
Beep(hz,t);
}
void menu() {
while (1) {
printf("[Other Options] Exit Program\n"
"[1] Play Birthday Song\n"
"[2] Custom Audio\n");
int choice;
scanf("%d", &choice);
while (getchar() != '\n'); // Clear the input buffer
switch(choice) {
case 1:
birthday_song();
break;
case 2:
play_audio();
break;
default:
printf("Exit Program\n");
return;
}
}
}
void main() {
menu();
}