aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/utils/unittest.cpp
blob: 4ab598af859abd723bd106fc7317b218fce7cb8a (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "utils.h"
#if UNITTEST

#include <iostream>
#include <stdio.h>
#include <fstream>
#include "../audio/sdl/source.h"
#include "../audio/sdl/audio.h"

using namespace JinEngine::audio;
using namespace std;

int main(int argc, char* argv[])
{
	SDLAudio* audio = SDLAudio::get();
	audio->init(0);
	SDLSource* source = SDLSource::createSource("a.ogg");
	SDLSource* source2 = SDLSource::createSource("a.wav");
	//source->play();
	source2->play();
	source->setLoop(true);
	source2->setLoop(true);
	int i = 0;
	while (true)
	{
		SDL_Delay(1000);
	}
	audio->quit();
	return 0;
}

/*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL2/SDL.h"

#include <3rdparty/cmixer/cmixer.h>

static SDL_mutex* audio_mutex;

static void lock_handler(cm_Event *e) {
	if (e->type == CM_EVENT_LOCK) {
		SDL_LockMutex(audio_mutex);
	}
	if (e->type == CM_EVENT_UNLOCK) {
		SDL_UnlockMutex(audio_mutex);
	}
}


static void audio_callback(void *udata, Uint8 *stream, int size) {
	cm_process((cm_Int16*)stream, size / 2);
}


int main(int argc, char **argv) {
	SDL_AudioDeviceID dev;
	SDL_AudioSpec fmt, got;
	cm_Source *src;
	cm_Source* src2;


	SDL_Init(SDL_INIT_AUDIO);
	audio_mutex = SDL_CreateMutex();

	memset(&fmt, 0, sizeof(fmt));
	fmt.freq = 44100;
	fmt.format = AUDIO_S16;
	fmt.channels = 2;
	fmt.samples = 1024;
	fmt.callback = audio_callback;

	dev = SDL_OpenAudioDevice(NULL, 0, &fmt, &got, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
	if (dev == 0) {
		fprintf(stderr, "Error: failed to open audio device '%s'\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}

	cm_init(got.freq);
	cm_set_lock(lock_handler);
	cm_set_master_gain(0.5);

	SDL_PauseAudioDevice(dev, 0);

	src = cm_new_source_from_file("a.ogg");
	src2 = cm_new_source_from_file("loop.wav");
	if (!src) {
		fprintf(stderr, "Error: failed to create source '%s'\n", cm_get_error());
		exit(EXIT_FAILURE);
	}
	cm_set_loop(src2, 1);

	cm_play(src);
	cm_play(src2);

	printf("Press [return] to exit\n");
	getchar();

	cm_destroy_source(src);
	SDL_CloseAudioDevice(dev);
	SDL_Quit();

	return EXIT_SUCCESS;
}
*/

#endif