This commit is contained in:
bjorn 2021-02-08 08:05:29 -07:00 committed by Bjorn
parent 0877edf9d1
commit ccc53a10aa
17 changed files with 102 additions and 119 deletions

View File

@ -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

View File

@ -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

View File

@ -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[];

View File

@ -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;
}

View File

@ -116,7 +116,6 @@ StringEntry lovrPermission[] = {
{ 0 }
};
static LOVR_THREAD_LOCAL int pollRef;
void luax_checkvariant(lua_State* L, int index, Variant* variant) {

View File

@ -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);

View File

@ -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;
}

View File

@ -119,6 +119,6 @@ void lovrPlatformRequestPermission(Permission permission) {
//
}
void lovrPlatformOnPermissionEvent(permissionsCallback callback) {
void lovrPlatformOnPermissionEvent(permissionCallback callback) {
//
}

View File

@ -126,6 +126,6 @@ void lovrPlatformRequestPermission(Permission permission) {
//
}
void lovrPlatformOnPermissionEvent(permissionsCallback callback) {
void lovrPlatformOnPermissionEvent(permissionCallback callback) {
//
}

View File

@ -375,6 +375,6 @@ void lovrPlatformRequestPermission(Permission permission) {
//
}
void lovrPlatformOnPermissionEvent(permissionsCallback callback) {
void lovrPlatformOnPermissionEvent(permissionCallback callback) {
//
}

View File

@ -105,6 +105,6 @@ void lovrPlatformRequestPermission(Permission permission) {
//
}
void lovrPlatformOnPermissionEvent(permissionsCallback callback) {
void lovrPlatformOnPermissionEvent(permissionCallback callback) {
//
}

View File

@ -187,7 +187,7 @@ bool lovrAudioInit(const char* spatializer) {
SpatializerConfig spatializerConfig = {
.maxSourcesHint = MAX_SOURCES,
.fixedBuffer = BUFFER_SIZE,
.fixedBufferSize = BUFFER_SIZE,
.sampleRate = PLAYBACK_SAMPLE_RATE
};

View File

@ -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;

View File

@ -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

View File

@ -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 <stdlib.h>
//////// 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 <OVR_Audio.h>
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"
};

View File

@ -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"
};

View File

@ -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;
}