-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcSound.cpp
47 lines (41 loc) · 1.33 KB
/
cSound.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
41
42
43
44
45
46
47
// Copyright 2015 Kelvin Chandra, Software Laboratory Center, Binus University. All Rights Reserved.
#include "Globals.h"
#include "cSound.h"
cSound::cSound(void)
{
FMOD::System_Create(&system);// create an instance of the game engine
system->init(32, FMOD_INIT_NORMAL, 0);// initialise the game engine with 32 channels
}
cSound::~cSound(void)
{
for (int i = 0; i < NUM_SOUNDS; i++) sounds[i]->release();
system->release();
}
bool cSound::Load()
{
system->createStream("Sound/bg_music.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sounds[SOUND_AMBIENT1]);
system->createStream("Sound/explosion.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sounds[SOUND_AMBIENT2]);
return true;
}
void cSound::Play(int sound_id)
{
if (sound_id == SOUND_AMBIENT1) {
system->playSound(FMOD_CHANNEL_FREE, sounds[SOUND_AMBIENT1], false, &ambient1Channel);
ambient1Channel->setVolume(0.5f); //between 0 and 1
}
else if (sound_id == SOUND_AMBIENT2) {
system->playSound(FMOD_CHANNEL_FREE, sounds[SOUND_AMBIENT2], false, &ambient2Channel);
ambient2Channel->setVolume(0.5f); //between 0 and 1
}
else system->playSound(FMOD_CHANNEL_FREE, sounds[sound_id], false, 0);
}
void cSound::StopAll()
{
ambient1Channel->stop();
ambient2Channel->stop();
ambient3Channel->stop();
}
void cSound::Update()
{
system->update();
}