diff --git a/CMakeLists.txt b/CMakeLists.txt index a9414df4..f2b74bd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -309,7 +309,7 @@ target_link_libraries(lovr if(LOVR_ENABLE_AUDIO) target_sources(lovr PRIVATE src/modules/audio/audio.c - src/modules/audio/spatializers/simple_spatializer.c + src/modules/audio/spatializers/spatializer_simple.c src/api/l_audio.c src/api/l_audio_source.c src/lib/miniaudio/miniaudio.c @@ -341,7 +341,7 @@ if(LOVR_ENABLE_AUDIO) set(LOVR_OCULUS_AUDIO OculusAudio) add_definitions(-DLOVR_ENABLE_OCULUS_AUDIO) - target_sources(lovr PRIVATE src/modules/audio/spatializers/oculus_spatializer.c) + target_sources(lovr PRIVATE src/modules/audio/spatializers/spatializer_oculus.c) target_link_libraries(lovr ${LOVR_OCULUS_AUDIO}) # TODO: Reorder? endif() else() @@ -649,10 +649,6 @@ elseif(ANDROID) set(ANDROID_APKSIGNER_KEYSTORE_PASS --ks-pass) endif() - if (ANDROID_EXTRAPACKAGES) # Only pass --extra-packages if var is set - set(ANDROID_EXTRAPACKAGES --extra-packages ${ANDROID_EXTRAPACKAGES}) - endif() - # Make an apk add_custom_target( buildAPK ALL @@ -669,7 +665,6 @@ elseif(ANDROID) -M AndroidManifest.xml -I ${ANDROID_JAR} -F lovr.unaligned.apk - ${ANDROID_EXTRAPACKAGES} ${ANDROID_ASSETS} raw COMMAND ${ANDROID_TOOLS}/zipalign -f -p 4 lovr.unaligned.apk lovr.unsigned.apk diff --git a/Tupfile b/Tupfile index 848fbcf5..fa9b206f 100644 --- a/Tupfile +++ b/Tupfile @@ -16,7 +16,7 @@ SRC += src/core/util.c SRC += src/core/zip.c # modules -SRC_@(AUDIO) += src/modules/audio/audio.c src/modules/audio/spatializers/simple_spatializer.c +SRC_@(AUDIO) += src/modules/audio/*.c src/modules/audio/spatializers/spatializer_simple.c SRC_@(DATA) += src/modules/data/*.c SRC_@(EVENT) += src/modules/event/*.c SRC_@(FILESYSTEM) += src/modules/filesystem/*.c diff --git a/src/api/api.h b/src/api/api.h index 1c8bf95c..8b08993e 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -96,13 +96,14 @@ extern StringEntry lovrJointType[]; extern StringEntry lovrMaterialColor[]; extern StringEntry lovrMaterialScalar[]; extern StringEntry lovrMaterialTexture[]; +extern StringEntry lovrPermission[]; +extern StringEntry lovrSampleFormat[]; extern StringEntry lovrShaderType[]; extern StringEntry lovrShapeType[]; extern StringEntry lovrStencilAction[]; extern StringEntry lovrTextureFormat[]; extern StringEntry lovrTextureType[]; extern StringEntry lovrTimeUnit[]; -extern StringEntry lovrSampleFormat[]; extern StringEntry lovrUniformAccess[]; extern StringEntry lovrVerticalAlign[]; extern StringEntry lovrWinding[]; diff --git a/src/api/l_audio.c b/src/api/l_audio.c index 58d277f9..39772713 100644 --- a/src/api/l_audio.c +++ b/src/api/l_audio.c @@ -118,9 +118,16 @@ static int l_lovrAudioGetCaptureStream(lua_State* L) { } static int l_lovrAudioNewSource(lua_State* L) { - Source* source = NULL; SoundData* soundData = luax_totype(L, 1, SoundData); + if (!soundData) { + Blob* blob = luax_readblob(L, 1, "Source"); + soundData = lovrSoundDataCreateFromFile(blob, false); + lovrRelease(Blob, blob); + } else { + lovrRetain(soundData); + } + bool spatial = true; if (lua_istable(L, 2)) { lua_getfield(L, 2, "spatial"); @@ -128,18 +135,9 @@ static int l_lovrAudioNewSource(lua_State* L) { lua_pop(L, 1); } - if (soundData) { - source = lovrSourceCreate(soundData, spatial); - } else { - Blob* blob = luax_readblob(L, 1, "Source"); - soundData = lovrSoundDataCreateFromFile(blob, false); - lovrRelease(Blob, blob); - - source = lovrSourceCreate(soundData, spatial); - lovrRelease(SoundData, soundData); - } - + Source* source = lovrSourceCreate(soundData, spatial); luax_pushtype(L, Source, source); + lovrRelease(SoundData, soundData); lovrRelease(Source, source); return 1; } diff --git a/src/api/l_event.c b/src/api/l_event.c index 86ecc2fc..d559f498 100644 --- a/src/api/l_event.c +++ b/src/api/l_event.c @@ -116,7 +116,6 @@ StringEntry lovrPermission[] = { { 0 } }; - static LOVR_THREAD_LOCAL int pollRef; void luax_checkvariant(lua_State* L, int index, Variant* variant) { diff --git a/src/core/os.h b/src/core/os.h index eaf3b86a..7884bec7 100644 --- a/src/core/os.h +++ b/src/core/os.h @@ -130,7 +130,7 @@ typedef enum { } ButtonAction; typedef enum { - AUDIO_CAPTURE_PERMISSION, + AUDIO_CAPTURE_PERMISSION } Permission; typedef void (*quitCallback)(void); @@ -139,7 +139,7 @@ typedef void (*windowResizeCallback)(int width, int height); typedef void (*mouseButtonCallback)(MouseButton button, ButtonAction action); typedef void (*keyboardCallback)(ButtonAction action, KeyboardKey key, uint32_t scancode, bool repeat); typedef void (*textCallback)(uint32_t codepoint); -typedef void (*permissionsCallback)(Permission permission, bool granted); +typedef void (*permissionCallback)(Permission permission, bool granted); bool lovrPlatformInit(void); void lovrPlatformDestroy(void); @@ -172,4 +172,4 @@ void lovrPlatformSetMouseMode(MouseMode mode); bool lovrPlatformIsMouseDown(MouseButton button); bool lovrPlatformIsKeyDown(KeyboardKey key); void lovrPlatformRequestPermission(Permission permission); -void lovrPlatformOnPermissionEvent(permissionsCallback callback); +void lovrPlatformOnPermissionEvent(permissionCallback callback); diff --git a/src/core/os_android.c b/src/core/os_android.c index 5280388d..e37c0159 100644 --- a/src/core/os_android.c +++ b/src/core/os_android.c @@ -22,7 +22,7 @@ static struct { quitCallback onQuit; keyboardCallback onKeyboardEvent; textCallback onTextEvent; - permissionsCallback onPermissionEvent; + permissionCallback onPermissionEvent; } state; static void onAppCmd(struct android_app* app, int32_t cmd) { @@ -471,7 +471,7 @@ bool lovrPlatformIsKeyDown(KeyboardKey key) { return false; } -// permissions +// Permissions void lovrPlatformRequestPermission(Permission permission) { if (permission == AUDIO_CAPTURE_PERMISSION) { @@ -480,7 +480,7 @@ void lovrPlatformRequestPermission(Permission permission) { jmethodID requestAudioCapturePermission = (*state.jni)->GetMethodID(state.jni, class, "requestAudioCapturePermission", "()V"); if (!requestAudioCapturePermission) { (*state.jni)->DeleteLocalRef(state.jni, class); - if(state.onPermissionEvent) state.onPermissionEvent(AUDIO_CAPTURE_PERMISSION, false); + if (state.onPermissionEvent) state.onPermissionEvent(AUDIO_CAPTURE_PERMISSION, false); return; } @@ -488,7 +488,7 @@ void lovrPlatformRequestPermission(Permission permission) { } } -void lovrPlatformOnPermissionEvent(permissionsCallback callback) { +void lovrPlatformOnPermissionEvent(permissionCallback callback) { state.onPermissionEvent = callback; } diff --git a/src/core/os_linux.c b/src/core/os_linux.c index b786c7e8..56a88e57 100644 --- a/src/core/os_linux.c +++ b/src/core/os_linux.c @@ -119,6 +119,6 @@ void lovrPlatformRequestPermission(Permission permission) { // } -void lovrPlatformOnPermissionEvent(permissionsCallback callback) { +void lovrPlatformOnPermissionEvent(permissionCallback callback) { // } diff --git a/src/core/os_macos.c b/src/core/os_macos.c index 62f500d7..49153044 100644 --- a/src/core/os_macos.c +++ b/src/core/os_macos.c @@ -126,6 +126,6 @@ void lovrPlatformRequestPermission(Permission permission) { // } -void lovrPlatformOnPermissionEvent(permissionsCallback callback) { +void lovrPlatformOnPermissionEvent(permissionCallback callback) { // } diff --git a/src/core/os_web.c b/src/core/os_web.c index 6ec398e2..412bde43 100644 --- a/src/core/os_web.c +++ b/src/core/os_web.c @@ -375,6 +375,6 @@ void lovrPlatformRequestPermission(Permission permission) { // } -void lovrPlatformOnPermissionEvent(permissionsCallback callback) { +void lovrPlatformOnPermissionEvent(permissionCallback callback) { // } diff --git a/src/core/os_win32.c b/src/core/os_win32.c index e94d616a..1fe23a9b 100644 --- a/src/core/os_win32.c +++ b/src/core/os_win32.c @@ -105,6 +105,6 @@ void lovrPlatformRequestPermission(Permission permission) { // } -void lovrPlatformOnPermissionEvent(permissionsCallback callback) { +void lovrPlatformOnPermissionEvent(permissionCallback callback) { // } diff --git a/src/modules/audio/audio.c b/src/modules/audio/audio.c index d0c4b41b..53cf51ef 100644 --- a/src/modules/audio/audio.c +++ b/src/modules/audio/audio.c @@ -187,7 +187,7 @@ bool lovrAudioInit(const char* spatializer) { SpatializerConfig spatializerConfig = { .maxSourcesHint = MAX_SOURCES, - .fixedBuffer = BUFFER_SIZE, + .fixedBufferSize = BUFFER_SIZE, .sampleRate = PLAYBACK_SAMPLE_RATE }; diff --git a/src/modules/audio/spatializer.h b/src/modules/audio/spatializer.h index fa3c0700..d58bf74c 100644 --- a/src/modules/audio/spatializer.h +++ b/src/modules/audio/spatializer.h @@ -1,17 +1,15 @@ #include "audio.h" -#include "core/maf.h" typedef struct { - int maxSourcesHint; - int fixedBuffer; - int sampleRate; + uint32_t maxSourcesHint; + uint32_t fixedBufferSize; + uint32_t sampleRate; } SpatializerConfig; typedef struct { // return true on success bool (*init)(SpatializerConfig config); void (*destroy)(void); - // input is mono, output is interleaved stereo, framesIn is mono frames, framesOut is stereo frames. // Safe to assume framesIn == framesOut unless spatializer requests needFixedBuffer. // Return value is number of samples written into output. @@ -20,13 +18,9 @@ typedef struct { // output is stereo, frames is stereo frames, scratch is a buffer the length of output (in case that helps) // return value is number of stereo frames written. uint32_t (*tail)(float* scratch, float* output, uint32_t frames); - void (*setListenerPose)(float position[4], float orientation[4]); - void (*sourceCreate)(Source* source); void (*sourceDestroy)(Source* source); - - bool buffered; const char* name; } Spatializer; diff --git a/src/modules/audio/spatializers/oculus_spatializer_math_shim.h b/src/modules/audio/spatializers/oculus_spatializer_math_shim.h deleted file mode 100644 index 09fe3946..00000000 --- a/src/modules/audio/spatializers/oculus_spatializer_math_shim.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef OVR_CAPI_h -#define OVR_CAPI_h - -// Just the definition of a pose from OVR_CAPI.h. Lets OVR_Audio work right. - -#if !defined(OVR_UNUSED_STRUCT_PAD) - #define OVR_UNUSED_STRUCT_PAD(padName, size) char padName[size]; -#endif - -#if !defined(OVR_ALIGNAS) - #if defined(__GNUC__) || defined(__clang__) - #define OVR_ALIGNAS(n) __attribute__((aligned(n))) - #elif defined(_MSC_VER) || defined(__INTEL_COMPILER) - #define OVR_ALIGNAS(n) __declspec(align(n)) - #elif defined(__CC_ARM) - #define OVR_ALIGNAS(n) __align(n) - #else - #error Need to define OVR_ALIGNAS - #endif -#endif - -/// A quaternion rotation. -typedef struct OVR_ALIGNAS(4) ovrQuatf_ -{ - float x, y, z, w; -} ovrQuatf; - -/// A 2D vector with float components. -typedef struct OVR_ALIGNAS(4) ovrVector2f_ -{ - float x, y; -} ovrVector2f; - -/// A 3D vector with float components. -typedef struct OVR_ALIGNAS(4) ovrVector3f_ -{ - float x, y, z; -} ovrVector3f; - -/// A 4x4 matrix with float elements. -typedef struct OVR_ALIGNAS(4) ovrMatrix4f_ -{ - float M[4][4]; -} ovrMatrix4f; - - -/// Position and orientation together. -typedef struct OVR_ALIGNAS(4) ovrPosef_ -{ - ovrQuatf Orientation; - ovrVector3f Position; -} ovrPosef; - -/// A full pose (rigid body) configuration with first and second derivatives. -/// -/// Body refers to any object for which ovrPoseStatef is providing data. -/// It can be the HMD, Touch controller, sensor or something else. The context -/// depends on the usage of the struct. -typedef struct OVR_ALIGNAS(8) ovrPoseStatef_ -{ - ovrPosef ThePose; ///< Position and orientation. - ovrVector3f AngularVelocity; ///< Angular velocity in radians per second. - ovrVector3f LinearVelocity; ///< Velocity in meters per second. - ovrVector3f AngularAcceleration; ///< Angular acceleration in radians per second per second. - ovrVector3f LinearAcceleration; ///< Acceleration in meters per second per second. - OVR_UNUSED_STRUCT_PAD(pad0, 4) ///< \internal struct pad. - double TimeInSeconds; ///< Absolute time that this pose refers to. \see ovr_GetTimeInSeconds -} ovrPoseStatef; - -#endif \ No newline at end of file diff --git a/src/modules/audio/spatializers/oculus_spatializer.c b/src/modules/audio/spatializers/spatializer_oculus.c similarity index 76% rename from src/modules/audio/spatializers/oculus_spatializer.c rename to src/modules/audio/spatializers/spatializer_oculus.c index c7410196..b2b21ad5 100644 --- a/src/modules/audio/spatializers/oculus_spatializer.c +++ b/src/modules/audio/spatializers/spatializer_oculus.c @@ -1,10 +1,77 @@ #include "audio/audio.h" #include "audio/spatializer.h" #include "lib/miniaudio/miniaudio.h" -#include "oculus_spatializer_math_shim.h" -#include "OVR_Audio.h" #include +//////// Just the definition of a pose from OVR_CAPI.h. Lets OVR_Audio work right. +#ifndef OVR_CAPI_h +#define OVR_CAPI_h +#if !defined(OVR_UNUSED_STRUCT_PAD) + #define OVR_UNUSED_STRUCT_PAD(padName, size) char padName[size]; +#endif + +#if !defined(OVR_ALIGNAS) + #if defined(__GNUC__) || defined(__clang__) + #define OVR_ALIGNAS(n) __attribute__((aligned(n))) + #elif defined(_MSC_VER) || defined(__INTEL_COMPILER) + #define OVR_ALIGNAS(n) __declspec(align(n)) + #elif defined(__CC_ARM) + #define OVR_ALIGNAS(n) __align(n) + #else + #error Need to define OVR_ALIGNAS + #endif +#endif + +/// A quaternion rotation. +typedef struct OVR_ALIGNAS(4) ovrQuatf_ +{ + float x, y, z, w; +} ovrQuatf; + +/// A 2D vector with float components. +typedef struct OVR_ALIGNAS(4) ovrVector2f_ +{ + float x, y; +} ovrVector2f; + +/// A 3D vector with float components. +typedef struct OVR_ALIGNAS(4) ovrVector3f_ +{ + float x, y, z; +} ovrVector3f; + +/// A 4x4 matrix with float elements. +typedef struct OVR_ALIGNAS(4) ovrMatrix4f_ +{ + float M[4][4]; +} ovrMatrix4f; + + +/// Position and orientation together. +typedef struct OVR_ALIGNAS(4) ovrPosef_ +{ + ovrQuatf Orientation; + ovrVector3f Position; +} ovrPosef; + +/// A full pose (rigid body) configuration with first and second derivatives. +/// +/// Body refers to any object for which ovrPoseStatef is providing data. +/// It can be the HMD, Touch controller, sensor or something else. The context +/// depends on the usage of the struct. +typedef struct OVR_ALIGNAS(8) ovrPoseStatef_ +{ + ovrPosef ThePose; ///< Position and orientation. + ovrVector3f AngularVelocity; ///< Angular velocity in radians per second. + ovrVector3f LinearVelocity; ///< Velocity in meters per second. + ovrVector3f AngularAcceleration; ///< Angular acceleration in radians per second per second. + ovrVector3f LinearAcceleration; ///< Acceleration in meters per second per second. + OVR_UNUSED_STRUCT_PAD(pad0, 4) ///< \internal struct pad. + double TimeInSeconds; ///< Absolute time that this pose refers to. \see ovr_GetTimeInSeconds +} ovrPoseStatef; +#endif //////// end OVR_CAPI_h +#include + typedef struct { Source* source; bool usedSourceThisPlayback; // If true source was non-NULL at some point between midPlayback going high and tail() @@ -232,6 +299,5 @@ Spatializer oculusSpatializer = { .setListenerPose = oculus_spatializer_setListenerPose, .sourceCreate = oculus_spatializer_source_create, .sourceDestroy = oculus_spatializer_source_destroy, // Need noop - .buffered = true, .name = "oculus" }; diff --git a/src/modules/audio/spatializers/simple_spatializer.c b/src/modules/audio/spatializers/spatializer_simple.c similarity index 99% rename from src/modules/audio/spatializers/simple_spatializer.c rename to src/modules/audio/spatializers/spatializer_simple.c index 7f652db3..c0062bea 100644 --- a/src/modules/audio/spatializers/simple_spatializer.c +++ b/src/modules/audio/spatializers/spatializer_simple.c @@ -1,4 +1,5 @@ #include "../spatializer.h" +#include "core/maf.h" #include "core/util.h" static struct { @@ -66,6 +67,5 @@ Spatializer simpleSpatializer = { .setListenerPose = simple_spatializer_setListenerPose, .sourceCreate = simple_spatializer_source_create, .sourceDestroy = simple_spatializer_source_destroy, - .buffered = false, .name = "simple" }; diff --git a/src/modules/headset/headset_pico.c b/src/modules/headset/headset_pico.c index d9f80e18..70ececca 100644 --- a/src/modules/headset/headset_pico.c +++ b/src/modules/headset/headset_pico.c @@ -224,7 +224,7 @@ static struct { arr_t(NativeCanvas) canvases; void (*renderCallback)(void*); void* renderUserdata; - permissionsCallback onPermissionEvent; + permissionCallback onPermissionEvent; } state; static bool pico_init(float supersample, float offset, uint32_t msaa) { @@ -419,7 +419,7 @@ void lovrPlatformRequestPermission(Permission permission) { // todo } -void lovrPlatformOnPermissionEvent(permissionsCallback callback) { +void lovrPlatformOnPermissionEvent(permissionCallback callback) { state.onPermissionEvent = callback; }