-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound.cc
71 lines (63 loc) · 1.51 KB
/
sound.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
62
63
64
65
66
67
68
69
70
71
#include "main.hh"
#include "utils.hh"
using namespace rl;
#include <cstdio>
#include <cstring>
#include <map>
static std::map<hash_t, Sound> sounds;
static inline void load_sound(const char *name)
{
hash_t h = hash(name);
if (sounds.count(h) > 0) {
puts("Collision!");
return;
}
size_t l = strlen(name) + 9;
char *path = new char[l];
snprintf(path, l, "res/%s.ogg", name);
Sound snd = LoadSound(path);
delete[] path;
sounds[h] = snd;
}
void sound::init()
{
load_sound("bellflower_pop_ord");
load_sound("bellflower_pop_zero_0");
load_sound("bellflower_pop_zero_1");
load_sound("bellflower_pop_zero_2");
load_sound("bellflower_pop_zero_3");
load_sound("bellflower_pop_zero_4");
load_sound("puzzle_solved");
load_sound("hint");
}
void sound::play(const char *name, float pan)
{
auto p = sounds.find(hash(name));
if (p == sounds.end()) {
puts("Unknown sound");
return;
}
// Raylib 4.1 ensures that each instance has its own panning value
SetSoundPan(p->second, pan);
PlaySoundMulti(p->second);
}
float sound::bellflowers_pan(float x, float x_cen)
{
float span = (x - x_cen) / 5;
if (span > 1) span = 1;
if (span < -1) span = -1;
return 0.5 - span * 0.2;
}
const char *sound::bellflower_pop_zero(int cur, int total)
{
static char name[] = "bellflower_pop_zero_?";
size_t len = strlen(name);
static const char table[4][4] = {
{1},
{1, 3},
{1, 2, 4},
{1, 2, 3, 4},
};
name[len - 1] = '0' + table[total - 1][cur - 1];
return (const char *)name;
}