aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/3rdparty/wav/wav.c80
-rw-r--r--src/3rdparty/wav/wav.h35
-rw-r--r--src/libjin/audio/audio.h2
-rw-r--r--src/libjin/audio/sdl/source.h5
-rw-r--r--src/libjin/common/data.h15
-rw-r--r--src/libjin/common/subsystem.h5
-rw-r--r--src/libjin/render/window.h2
-rw-r--r--src/libjin/utils/utils.h2
8 files changed, 139 insertions, 7 deletions
diff --git a/src/3rdparty/wav/wav.c b/src/3rdparty/wav/wav.c
new file mode 100644
index 0000000..bfe7a41
--- /dev/null
+++ b/src/3rdparty/wav/wav.c
@@ -0,0 +1,80 @@
+/**
+* Copyright (c) 2015 rxi
+*
+* This library is free software; you can redistribute it and/or modify it
+* under the terms of the MIT license. See LICENSE for details.
+*/
+
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+#include "wav.h"
+
+typedef unsigned short Uint16;
+typedef unsigned int Uint32;
+
+static const char *findSubChunk(
+ const char *data, size_t len, const char *id, size_t *size
+) {
+ /* TODO : Error handling on malformed wav file */
+ size_t idLen = strlen(id);
+ const char *p = data + 12;
+next:
+ *size = *((Uint32*)(p + 4));
+ if (memcmp(p, id, idLen)) {
+ p += 8 + *size;
+ if (p > data + len) return NULL;
+ goto next;
+ }
+ return p + 8;
+}
+
+int wav_read(wav_t *w, const void *data, size_t len) {
+ int bitdepth, channels, samplerate, format;
+ size_t sz;
+ const char *p = (const char*)data;
+ memset(w, 0, sizeof(*w));
+ /* Check header */
+ if (memcmp(p, "RIFF", 4) || memcmp(p + 8, "WAVE", 4)) {
+ return WAV_EBADHEADER;
+ }
+ /* Find fmt subchunk */
+ p = findSubChunk((const char*)data, len, "fmt", &sz);
+ if (!p) return WAV_ENOFMT;
+ /* Load fmt info */
+ format = *((Uint16*)(p));
+ channels = *((Uint16*)(p + 2));
+ samplerate = *((Uint32*)(p + 4));
+ bitdepth = *((Uint16*)(p + 14));
+ if (format != 1) {
+ return WAV_ENOSUPPORT;
+ }
+ if (channels == 0 || samplerate == 0 || bitdepth == 0) {
+ return WAV_EBADFMT;
+ }
+ /* Find data subchunk */
+ p = findSubChunk((const char*)data, len, "data", &sz);
+ if (!p) return WAV_ENODATA;
+ /* Init wav_t struct */
+ w->data = p;
+ w->samplerate = samplerate;
+ w->channels = channels;
+ w->length = (sz / (bitdepth / 8)) / channels;
+ w->bitdepth = bitdepth;
+ /* Done! */
+ return WAV_ESUCCESS;
+}
+
+const char *wav_strerror(int err) {
+ switch (err) {
+ case WAV_ESUCCESS: return "success";
+ case WAV_EFAILURE: return "failure";
+ case WAV_EBADHEADER: return "bad header data";
+ case WAV_EBADFMT: return "bad fmt data";
+ case WAV_ENOFMT: return "missing 'fmt' subchunk";
+ case WAV_ENODATA: return "missing 'data' subchunk";
+ case WAV_ENOSUPPORT: return "unsupported format; "
+ "expected uncompressed PCM";
+ }
+ return "unknown error";
+}
diff --git a/src/3rdparty/wav/wav.h b/src/3rdparty/wav/wav.h
new file mode 100644
index 0000000..888e522
--- /dev/null
+++ b/src/3rdparty/wav/wav.h
@@ -0,0 +1,35 @@
+/**
+* Copyright (c) 2015 rxi
+*
+* This library is free software; you can redistribute it and/or modify it
+* under the terms of the MIT license. See LICENSE for details.
+*/
+
+#ifndef WAV_H
+#define WAV_H
+
+#include <stdlib.h>
+#include <stdint.h>
+
+typedef struct {
+ const void *data;
+ int bitdepth;
+ int samplerate;
+ int channels;
+ size_t length;
+} wav_t;
+
+enum {
+ WAV_ESUCCESS = 0,
+ WAV_EFAILURE = -1,
+ WAV_EBADHEADER = -2,
+ WAV_EBADFMT = -3,
+ WAV_ENOFMT = -4,
+ WAV_ENODATA = -5,
+ WAV_ENOSUPPORT = -6
+};
+
+int wav_read(wav_t *w, const void *data, size_t len);
+const char *wav_strerror(int err);
+
+#endif
diff --git a/src/libjin/audio/audio.h b/src/libjin/audio/audio.h
index 6d57cd2..c0b0e1e 100644
--- a/src/libjin/audio/audio.h
+++ b/src/libjin/audio/audio.h
@@ -29,7 +29,7 @@ namespace audio
};
- class Audio : public common::Subsystem, IAudio
+ class Audio : public Subsystem, IAudio
{
public:
diff --git a/src/libjin/audio/sdl/source.h b/src/libjin/audio/sdl/source.h
index 5ea2cf2..0c8e938 100644
--- a/src/libjin/audio/sdl/source.h
+++ b/src/libjin/audio/sdl/source.h
@@ -1,6 +1,11 @@
#ifndef __JIN_SOURCE_SDL_H
#define __JIN_SOURCE_SDL_H
+#include "3rdparty/wav/wav.h"
+#define STB_VORBIS_HEADER_ONLY
+#include "3rdparty/stb/stb_vorbis.c"
+#undef STB_VORBIS_HEADER_ONLY
+
#include "../source.h"
namespace jin
diff --git a/src/libjin/common/data.h b/src/libjin/common/data.h
new file mode 100644
index 0000000..51a3252
--- /dev/null
+++ b/src/libjin/common/data.h
@@ -0,0 +1,15 @@
+#ifndef __JIN_COMMON_DATA_H
+#define __JIN_COMMON_DATA_H
+
+namespace jin
+{
+
+ struct Data
+ {
+ void* data;
+ int len;
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/src/libjin/common/subsystem.h b/src/libjin/common/subsystem.h
index ca4b33d..8c1b59b 100644
--- a/src/libjin/common/subsystem.h
+++ b/src/libjin/common/subsystem.h
@@ -5,9 +5,7 @@
namespace jin
{
-namespace common
-{
-
+
class Subsystem
{
@@ -32,6 +30,5 @@ namespace common
};
}
-}
#endif \ No newline at end of file
diff --git a/src/libjin/render/window.h b/src/libjin/render/window.h
index 1aabfa0..54fff47 100644
--- a/src/libjin/render/window.h
+++ b/src/libjin/render/window.h
@@ -9,7 +9,7 @@ namespace jin
namespace render
{
- class Window : public common::Subsystem
+ class Window : public Subsystem
{
public:
diff --git a/src/libjin/utils/utils.h b/src/libjin/utils/utils.h
index d597c83..3b8e9dd 100644
--- a/src/libjin/utils/utils.h
+++ b/src/libjin/utils/utils.h
@@ -5,6 +5,6 @@
#include "macros.h"
#include "endian.h"
-#define UNITTEST 1
+#define UNITTEST 0
#endif \ No newline at end of file