-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcsoundplayer.cpp
89 lines (64 loc) · 1.59 KB
/
csoundplayer.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
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
79
80
81
82
83
84
85
86
87
88
#include "csoundplayer.h"
void CSoundPlayer::init( ) {
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16;
int audio_channels = 2;
int audio_buffers = 4096;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
printf("Unable to open audio!\n");
exit(1);
}
soundEffect[SOUND_TIKTIK] = NULL;
soundEffect[SOUND_GOAL_SCORED] = NULL;
music = NULL;
volume = 64;
return;
}
void CSoundPlayer::loadSoundEffect( int which_soundEffect, string path ) {
soundEffect[which_soundEffect] = Mix_LoadWAV( path.c_str() );
return;
}
void CSoundPlayer::loadMusic( string path ) {
music = Mix_LoadMUS( path.c_str() );
return;
}
void CSoundPlayer::haltAllSounds( ) {
Mix_HaltChannel( -1 );
Mix_HaltMusic( );
Mix_FreeMusic( music );
return;
}
void CSoundPlayer::playMusic( ) {
Mix_PlayMusic( music, -1 );
return;
}
void CSoundPlayer::playSoundEffect( int which_soundEffect ) {
Mix_HaltChannel( -1 );
Mix_PlayChannel( -1, soundEffect[which_soundEffect], 0 );
return;
}
void CSoundPlayer::quit( ) {
Mix_CloseAudio( );
return;
}
void CSoundPlayer::decrease_volume( ) {
volume -= 10;
if (volume < 0) {
volume = 0;
}
Mix_VolumeChunk( soundEffect[SOUND_TIKTIK], volume );
Mix_VolumeChunk( soundEffect[SOUND_GOAL_SCORED], volume );
Mix_VolumeMusic( volume );
return;
}
void CSoundPlayer::increase_volume( ) {
volume += 10;
if (volume > 128) {
volume = 128;
}
Mix_VolumeChunk( soundEffect[SOUND_TIKTIK], volume );
Mix_VolumeChunk( soundEffect[SOUND_GOAL_SCORED], volume );
Mix_VolumeMusic( volume );
return;
}