aboutsummaryrefslogtreecommitdiff
path: root/test/02Audio/audiotest.cpp
blob: d4b8975ddfd9d76eee402f760b8b3b7ad915fb65 (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
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include "jin.h"

using namespace jin::core;
using namespace jin::graphics;
using namespace jin::input;
using namespace jin::audio;

void onEvent(jin::input::Event* e)
{
    static Game* game = Game::get();
    if (e->type == EventType::QUIT)
        game->stop();
}

void onUpdate(float dt)
{

}

void onDraw()
{

}

int main(int argc, char* argv[])
{
    Game* game = Game::get();
    Game::Setting setting;
    setting.eventHandler = onEvent;
    setting.updater = onUpdate;
    setting.drawer = onDraw;
    setting.loader = nullptr;
    game->init(&setting);

    Window* wnd = Window::get();
    Window::Setting wndSetting;
    wndSetting.width = 600;
    wndSetting.height = 512;
    wndSetting.title = "test";
    wndSetting.fps = 60;
    wndSetting.vsync = false;
    wndSetting.fullscreen = false;
    wndSetting.resizable = false;
    wnd->init(&wndSetting);

    SDLAudio* audio = SDLAudio::get();
    SDLAudio::Setting audioSetting;
    audioSetting.samplerate = 44100;
    audioSetting.samples = 44100;
    audio->init(&audioSetting);

    SDLSource* src = SDLSource::createSource("a.ogg");
    src->play();
    src->setLoop(false);

    SDLSource* src2 = SDLSource::createSource("a.wav");
    src2->setLoop(true);
    src2->play();

    audio->setVolume(0.7);

    game->run();

    game->quit();
    audio->quit();
    wnd->quit();

    return 0;
}