-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudioManager.cpp
40 lines (30 loc) · 899 Bytes
/
audioManager.cpp
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
#pragma once
#include <iostream>
#include <string>
#include "audioManager.h"
void init(audioManager* audioManager)
{
for (int i = 0; i < audioManager->sfxsLength; i++) {
init(audioManager->sfxs[i]);
}
}
void play(audioManager* audioManager, sfx* sfx) {
if (sfx->randomness <= 0) {
play(sfx->clip, sfx->volume * (*audioManager->appVolume));
}
else {
play(sfx->clip, sfx->volume * (*audioManager->appVolume), sfx->randomness * (*audioManager->appVolume));
}
}
void free(audioManager* audioManager) {
// Pause them all
Mix_Pause(-1);
//while (Mix_Playing(-1)) {
// // do nothing until audio finishes
// std::cout << "Waiting for finish playing sfx on channel " << Mix_Playing(-1) << std::endl;
//}
//std::cout << "Finished playing sfx and freeing sfx in audio manager" << std::endl;
for (int i = 0; i < audioManager->sfxsLength; i++) {
free(audioManager->sfxs[i]);
}
}