Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add sound locking API (for preventing sound lib collision)

  • Loading branch information...
commit fd6743d1a53ad528f67f744412e866169275d87e 1 parent 114cd04
@fincs authored
View
1  .gitignore
@@ -45,6 +45,7 @@ build/
!/sdk/userlib/libitcm/
!/sdk/userlib/md5/
!/sdk/userlib/coopgui/
+!/sdk/userlib/sndlock/
*.exe
*.nds
*.elf
View
36 sdk/userlib/sndlock/Makefile
@@ -0,0 +1,36 @@
+#---------------------------------------------------------------------------------
+.SUFFIXES:
+#---------------------------------------------------------------------------------
+
+ifeq ($(strip $(DEVKITPRO)),)
+$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPro")
+endif
+
+ifeq ($(strip $(DEVKITARM)),)
+$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
+endif
+
+ifeq ($(strip $(FEOSSDK)),)
+$(error "Please set FEOSSDK in your environment. export FEOSSDK=<path to>FeOS/sdk")
+endif
+
+FEOSMK = $(FEOSSDK)/mk
+
+#---------------------------------------------------------------------------------
+# TARGET is the name of the output
+# BUILD is the directory where object files & intermediate files will be placed
+# SOURCES is a list of directories containing source code
+# DATA is a list of directories containing data files
+# INCLUDES is a list of directories containing header files
+#---------------------------------------------------------------------------------
+TARGET := $(shell basename $(CURDIR))
+BUILD := build
+SOURCES := source
+DATA := data
+INCLUDES := include
+
+include $(FEOSMK)/dynlib.mk
+
+install: all
+ @mkdir -p $(FEOSDEST)/data/FeOS/lib
+ @cp $(TARGET).fx2 $(FEOSDEST)/data/FeOS/lib/$(TARGET).fx2
View
16 sdk/userlib/sndlock/include/sndlock.h
@@ -0,0 +1,16 @@
+#pragma once
+#include <feos.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef int sndlock_t;
+
+bool SndLock_Acquire(const char* name, sndlock_t* pLock);
+bool SndLock_Release(sndlock_t lock);
+const char* SndLock_GetName();
+
+#ifdef __cplusplus
+}
+#endif
View
41 sdk/userlib/sndlock/source/sndlock.c
@@ -0,0 +1,41 @@
+#include <sndlock.h>
+#include <time.h>
+
+static const char* g_lockName;
+static sndlock_t g_lock;
+static word_t g_ranSeed;
+
+// http://en.wikipedia.org/wiki/Lehmer_RNG#Sample_C99_code
+static word_t quickRand16()
+{
+ if (g_ranSeed == 0)
+ g_ranSeed = (word_t)time(NULL) ^ (word_t)&g_ranSeed;
+
+ g_ranSeed = (word_t)(((u64)g_ranSeed * 279470273UL) % 4294967291UL);
+ return g_ranSeed & 0xFFFF;
+}
+
+static word_t quickRand()
+{
+ return quickRand16() | (quickRand16() << 16);
+}
+
+FEOS_EXPORT bool SndLock_Acquire(const char* name, sndlock_t* pLock)
+{
+ if (g_lockName || !name || !pLock) return false;
+ g_lockName = name;
+ *pLock = (g_lock = quickRand());
+ return true;
+}
+
+FEOS_EXPORT bool SndLock_Release(sndlock_t lock)
+{
+ if (!g_lockName || g_lock != lock) return false;
+ g_lockName = NULL;
+ return true;
+}
+
+FEOS_EXPORT const char* SndLock_GetName()
+{
+ return g_lockName;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.