-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoundList.cpp
More file actions
78 lines (62 loc) · 1.35 KB
/
Copy pathSoundList.cpp
File metadata and controls
78 lines (62 loc) · 1.35 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <unistd.h>
#include "SoundList.h"
#include "SDLAudio.h"
#include "inifile.h"
#define _MAX_PATH 256
CSoundList* CSoundList::m_pThis = NULL;
CSoundList* CSoundList::GetInstance()
{
if(m_pThis == NULL)
{
m_pThis = new CSoundList();
}
return m_pThis;
}
CSoundList::CSoundList()
{
m_pAppSettings = new INIReader(INIPATH);
m_iIndex = -1;
m_bShutDown = false;
}
CSoundList::~CSoundList()
{
m_bShutDown = true;
CSDLAudio::GetInstance()->StopPlayback(-1);
delete m_pAppSettings;
}
void CSoundList::SampleFinished()
{
printf("soundList sample finished\n");
if(!m_bShutDown)
{
NextSound();
}
}
void CSoundList::SetVolume(int iVol)
{
if(m_iIndex != -1)
{
Mix_Volume(m_iCurrentChannel, iVol);
}
}
void CSoundList::NextSound()
{
std::string sound;
m_iIndex++;
do
{
char rgcSoundKey[128];
sprintf(rgcSoundKey,BACKGROUNDSAMPLE_KEY,m_iIndex);
sound = m_pAppSettings->Get(std::string(BACKGROUNDSAMPLE_SEC),std::string(rgcSoundKey),std::string(""));
if(sound.length() == 0)
{
m_iIndex = 0;
}
} while(!sound.length());
if(access(sound.c_str(), F_OK) == -1)
{
printf("Failed to open sample %s\n", sound.c_str());
}
printf("Playing background sample %s\n",sound.c_str());
m_iCurrentChannel = CSDLAudio::GetInstance()->PlaySample(sound.c_str(), this);
}