blob: 7142625342972865d2e2aac2f4a58ba9f9cbc5d1 (
plain)
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
|
#include <SDL2/SDL.h>
#include "audio.h"
namespace jin
{
namespace audio
{
shared Audio* Audio::audio = NULL;
bool Audio::init(const SettingBase* setting)
{
static bool result = _init(setting);
return result;
}
void Audio::quit()
{
CallOnce(_quit());
}
onlyonce bool Audio::_init(const SettingBase* s)
{
if (SDL_Init(SDL_INIT_AUDIO) < 0)
return false;
const AudioSetting* setting = (AudioSetting*)s;
SDL_AudioSpec wanted;
zero(wanted);
wanted.freq = setting->freq;
wanted.format = setting->format;
wanted.channels = setting->channels;
wanted.samples = setting->samples;
wanted.userdata = setting->userdata;
wanted.callback = setting->callback;
if (SDL_OpenAudio(&wanted, NULL) < 0)
{
return false;
}
// start audio
SDL_PauseAudio(0);
return true;
}
onlyonce void Audio::_quit()
{
SDL_CloseAudio();
delete audio;
}
shared void defaultCallback(void *udata, Uint8 *stream, int len)
{
}
}
}
|