mirror of https://github.com/bjornbytes/lovr.git
Devices WIP
This commit is contained in:
parent
53d3568528
commit
ebcc5f51d7
|
@ -120,21 +120,20 @@ static int l_lovrAudioCapture(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrAudioSetCaptureDevice(lua_State *L) {
|
||||
//
|
||||
|
||||
return 0;
|
||||
static int l_lovrAudioGetDevices(lua_State *L) {
|
||||
AudioDevice *devices;
|
||||
size_t count;
|
||||
lovrAudioGetDevices(&devices, &count);
|
||||
for(int i = 0; i < count; i++) {
|
||||
lua_pushstring(L, devices[i].name);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static int l_lovrAudioGetCaptureDevice(lua_State *L) {
|
||||
//
|
||||
static int l_lovrUseDevice(lua_State *L) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
//lovrAudioUseDevice()
|
||||
|
||||
static int l_lovrAudioListCaptureDevices(lua_State *L) {
|
||||
//
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -148,9 +147,8 @@ static const luaL_Reg lovrAudio[] = {
|
|||
{ "setListenerPose", l_lovrAudioSetListenerPose },
|
||||
{ "capture", l_lovrAudioCapture },
|
||||
{ "getCaptureDuration", l_lovrAudioGetCaptureDuration },
|
||||
{ "setCaptureDevice", l_lovrAudioSetCaptureDevice },
|
||||
{ "getCaptureDevice", l_lovrAudioGetCaptureDevice },
|
||||
{ "listCaptureDevices", l_lovrAudioListCaptureDevices },
|
||||
{ "getDevices", l_lovrAudioGetDevices },
|
||||
{ "useDevice", l_lovrUseDevice },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -44,6 +44,8 @@ static struct {
|
|||
ma_pcm_rb captureRingbuffer;
|
||||
arr_t(ma_data_converter) converters;
|
||||
Spatializer* spatializer;
|
||||
|
||||
AudioDevice *deviceInfos;
|
||||
} state;
|
||||
|
||||
// Device callbacks
|
||||
|
@ -437,4 +439,22 @@ struct SoundData* lovrAudioCapture(uint32_t frameCount, SoundData *soundData, ui
|
|||
}
|
||||
|
||||
return soundData;
|
||||
}
|
||||
|
||||
void lovrAudioGetDevices(AudioDevice **outDevices, size_t *outCount) {
|
||||
if(state.deviceInfos)
|
||||
free(state.deviceInfos);
|
||||
|
||||
ma_result gettingStatus = ma_context_get_devices(&state.context, NULL, NULL, NULL, NULL);
|
||||
lovrAssert(gettingStatus == MA_SUCCESS, "Failed to enumerate audio devices: %d", gettingStatus);
|
||||
*outCount = state.context.playbackDeviceInfoCount + state.context.captureDeviceInfoCount;
|
||||
state.deviceInfos = calloc(*outCount, sizeof(AudioDevice));
|
||||
for(int i = 0; i < *outCount; i++) {
|
||||
ma_device_info *mainfo = &state.context.pDeviceInfos[i];
|
||||
AudioDevice *lovrInfo = &state.deviceInfos[i];
|
||||
lovrInfo->name = mainfo->name;
|
||||
lovrInfo->type = i < state.context.playbackDeviceInfoCount ? AUDIO_PLAYBACK : AUDIO_CAPTURE;
|
||||
lovrInfo->isDefault = mainfo->isDefault;
|
||||
lovrInfo->identifier = &mainfo->id;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -29,6 +30,13 @@ typedef struct {
|
|||
bool start;
|
||||
} AudioConfig;
|
||||
|
||||
typedef struct {
|
||||
AudioType type;
|
||||
const char *name;
|
||||
bool isDefault;
|
||||
void *identifier;
|
||||
} AudioDevice;
|
||||
|
||||
#ifndef LOVR_AUDIO_SAMPLE_RATE
|
||||
# define LOVR_AUDIO_SAMPLE_RATE 44100
|
||||
#endif
|
||||
|
@ -59,4 +67,7 @@ void lovrSourceSetTime(Source* source, uint32_t sample);
|
|||
struct SoundData* lovrSourceGetSoundData(Source* source);
|
||||
|
||||
uint32_t lovrAudioGetCaptureSampleCount();
|
||||
struct SoundData* lovrAudioCapture(uint32_t sampleCount, struct SoundData *soundData, uint32_t offset);
|
||||
struct SoundData* lovrAudioCapture(uint32_t sampleCount, struct SoundData *soundData, uint32_t offset);
|
||||
|
||||
void lovrAudioGetDevices(AudioDevice **outDevices, size_t *outCount);
|
||||
void lovrAudioUseDevice(void *identifier);
|
Loading…
Reference in New Issue