forked from Bs0Dd/Coverett
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seplay.c
59 lines (53 loc) · 1.36 KB
/
seplay.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
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include "coverett.h"
#include "devices/sound.h"
int main(int argc, char* argv[]){
if (argc < 2){
puts("Sound Effects PLAYer");
puts("Usage: seplay [-f] <effect name or search query> [volume, pitch]");
puts(" -f - Get effects list by search query");
puts(" volume - [0, 1], pitch - [0.5, 2]");
return 0;
}
bus_t stdbus = openBus("/dev/hvc0");
device_t dev = findDev(stdbus, "sound");
if (!dev.exists){
fputs("This program requires a Sound Card.\n", stderr);
return -1;
}
char* lowarg;
if (strlen(argv[1]) > 1){
lowarg = strdup(argv[1]);
lowarg[1] = tolower(lowarg[1]);
}
if (strcmp(lowarg, "-f") == 0){
if (argc < 3){
fputs("No search query specified\n", stderr);
return -1;
}
list_t sounds = findSound(&dev, argv[2]);
if (sounds.type == CO_ERROR){
fprintf(stderr, "Error: %s\n", sounds.errString);
return -1;
}
int total;
char** names = getSoundsName(sounds, &total);
puts("Found effects:");
for (int i = 0; i < total; i++){
puts(names[i]);
}
}
else{
double volume = argc > 2 ? atof(argv[2]) : NAN;
double pitch = argc > 3 ? atof(argv[3]) : NAN;
result_t stat = playSound(&dev, argv[1], volume, pitch);
if (stat.type == CO_ERROR){
fprintf(stderr, "Error: %s\n", stat.errString);
return -1;
}
}
return 0;
}