aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Audio/je_source.cpp
blob: e20cd6945e151ad82a745e47d9c4b3f067a73bbb (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
#include "../core/je_configuration.h"
#if LIBJIN_MODULES_AUDIO

#include <cstring>

#include "je_source.h"

namespace jin
{
	namespace audio
	{

		static int check_header(const void *data, int size, const char *str, int offset) {
			int len = strlen(str);
			return (size >= offset + len) && !memcmp((char*)data + offset, str, len);
		}

		SourceType Source::getType(const void* mem, int size)
		{
			if(check_header(mem, size, "WAVE", 8))
				return SourceType::WAV;
			if(check_header(mem, size, "OggS", 0))
				return SourceType::OGG;
			return SourceType::INVALID;
		}

	} // namespace audio
} // namespace jin

#endif // LIBJIN_MODULES_AUDIO