-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudio.cpp
More file actions
62 lines (51 loc) · 2.01 KB
/
Audio.cpp
File metadata and controls
62 lines (51 loc) · 2.01 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
#include "Audio.h"
void loadSound(ALLEGRO_SAMPLE * &sound, std::string directory) {
ALLEGRO_PATH * path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(path, "Resources");
al_append_path_component(path, "Sounds");
al_change_directory(al_path_cstr(path, '/'));
al_destroy_path(path);
sound = al_load_sample(directory.c_str());
}
void loadSong(ALLEGRO_SAMPLE * &song, std::string directory, ALLEGRO_SAMPLE_INSTANCE * &songInstance, playmodeType playmode) {
ALLEGRO_PLAYMODE al_playmode;
ALLEGRO_PATH * path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(path, "Resources");
al_append_path_component(path, "Music");
al_change_directory(al_path_cstr(path, '/'));
al_destroy_path(path);
switch (playmode) {
case once: al_playmode = ALLEGRO_PLAYMODE_ONCE; break;
case loop: al_playmode = ALLEGRO_PLAYMODE_LOOP; break;
case bidir: al_playmode = ALLEGRO_PLAYMODE_BIDIR;
}
song = al_load_sample(directory.c_str());
songInstance = al_create_sample_instance(song);
al_set_sample_instance_playmode(songInstance, al_playmode);
al_attach_sample_instance_to_mixer(songInstance, al_get_default_mixer());
}
void playSound(ALLEGRO_SAMPLE *sound, playmodeType playmode, float volume, float pan, float speed) {
ALLEGRO_PLAYMODE al_playmode;
switch (playmode) {
case once: al_playmode = ALLEGRO_PLAYMODE_ONCE; break;
case loop: al_playmode = ALLEGRO_PLAYMODE_LOOP; break;
case bidir: al_playmode = ALLEGRO_PLAYMODE_BIDIR;
}
al_play_sample(sound, volume, pan, speed, al_playmode, 0);
}
void playSong(ALLEGRO_SAMPLE_INSTANCE *songInstance) {
al_play_sample_instance(songInstance);
}
void stopSong(ALLEGRO_SAMPLE_INSTANCE *songInstance) {
al_stop_sample_instance(songInstance);
}
void destroySound(ALLEGRO_SAMPLE * &soundeffect) {
al_destroy_sample(soundeffect);
soundeffect = nullptr;
}
void destroySong(ALLEGRO_SAMPLE * &song, ALLEGRO_SAMPLE_INSTANCE * &songInstance) {
al_destroy_sample(song);
al_destroy_sample_instance(songInstance);
song = nullptr;
songInstance = nullptr;
}