-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSoundBank.cpp
More file actions
44 lines (37 loc) · 761 Bytes
/
Copy pathSoundBank.cpp
File metadata and controls
44 lines (37 loc) · 761 Bytes
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
#include "SoundBank.h"
//static accessor
SoundBank SoundBank::SoundControl;
unsigned int SoundBank::LoadSoundFile(const std::string& filename)
{
Mix_Chunk* tempSound = 0;
if((tempSound = Mix_LoadWAV(filename.c_str())) == 0)
{
return -1;
}
m_sounds.push_back(tempSound);
return (m_sounds.size() - 1);
}
void SoundBank::Play(unsigned int soundId)
{
if(soundId >= m_sounds.size())
{
return;
}
if(m_sounds[soundId] == 0)
{
return;
}
Mix_PlayChannel(-1, m_sounds[soundId], 0);
}
SoundBank::SoundBank()
{
//Do nothing
}
SoundBank::~SoundBank()
{
for(unsigned int i = 0;i < m_sounds.size();++i)
{
Mix_FreeChunk(m_sounds[i]);
}
Mix_CloseAudio();
}