-
Notifications
You must be signed in to change notification settings - Fork 6
/
GUIAudio.cpp
63 lines (43 loc) · 1.39 KB
/
GUIAudio.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
#include "GUIAudio.h"
#include "GUIUtility.h"
using std::string;
#include <iostream>
using std::cout; using std::endl;
namespace GUI {
Music::Music(string filename)
{
music_impl = Mix_LoadMUS(filename.c_str());
if (music_impl == NULL)
throw Error("Could not initialize GUIMusic with file: " + filename);
}
Music::~Music(){
Mix_FreeMusic(music_impl);
}
Sound_clip::Sound_clip(string filename)
{
sound_clip_impl = Mix_LoadWAV("audio/scratch.wav");
if (!sound_clip_impl)
throw Error("Could not initialize GUISound_clip with file: audio/scratch.wav");
}
Sound_clip::~Sound_clip(){
if (sound_clip_impl)
Mix_FreeChunk(sound_clip_impl);
}
void Sound_clip::play(int vol, int delay, int pan, int pitch){
cout << "playing"<<endl;
if( Mix_PlayChannel( -1, sound_clip_impl, 0 ) == -1 ) {
throw Error("Could not play GUISound_clip! " + std::string(SDL_GetError()));
}
printf("%d channels are playing\n", Mix_Playing(-1));
}
void initAudio(int flags){
// int initted=Mix_Init(flags);
// if((initted&flags) != flags) {
// throw Error("Unable to init SDL_mixer Audio: \n" + std::string(SDL_GetError()));
// }
if (Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ){
throw Error("Unable to init SDL_mixer Audio: \n" + std::string(SDL_GetError()));
}
atexit(Mix_Quit);
}
} // namespace GUI