mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-03 04:53:35 +00:00
lovrAudioUseDevice
This commit is contained in:
parent
9381e2027d
commit
e46079b368
|
@ -150,9 +150,8 @@ static int l_lovrAudioGetDevices(lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_lovrUseDevice(lua_State *L) {
|
static int l_lovrUseDevice(lua_State *L) {
|
||||||
|
AudioDeviceIdentifier ident = lua_touserdata(L, 1);
|
||||||
//lovrAudioUseDevice()
|
lovrAudioUseDevice(ident);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,9 @@ bool lovrAudioInitDevice(AudioType type) {
|
||||||
ma_device_config config = ma_device_config_init(deviceType);
|
ma_device_config config = ma_device_config_init(deviceType);
|
||||||
config.sampleRate = LOVR_AUDIO_SAMPLE_RATE;
|
config.sampleRate = LOVR_AUDIO_SAMPLE_RATE;
|
||||||
config.playback.format = miniAudioFormatFromLovr[OUTPUT_FORMAT];
|
config.playback.format = miniAudioFormatFromLovr[OUTPUT_FORMAT];
|
||||||
|
config.playback.pDeviceID = state.config[AUDIO_PLAYBACK].device;
|
||||||
config.capture.format = miniAudioFormatFromLovr[OUTPUT_FORMAT];
|
config.capture.format = miniAudioFormatFromLovr[OUTPUT_FORMAT];
|
||||||
|
config.playback.pDeviceID = state.config[AUDIO_CAPTURE].device;
|
||||||
config.playback.channels = OUTPUT_CHANNELS;
|
config.playback.channels = OUTPUT_CHANNELS;
|
||||||
config.capture.channels = CAPTURE_CHANNELS;
|
config.capture.channels = CAPTURE_CHANNELS;
|
||||||
config.dataCallback = callbacks[type];
|
config.dataCallback = callbacks[type];
|
||||||
|
@ -460,3 +462,22 @@ void lovrAudioGetDevices(AudioDevice **outDevices, size_t *outCount) {
|
||||||
lovrInfo->maxChannels = mainfo->maxChannels;
|
lovrInfo->maxChannels = mainfo->maxChannels;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lovrAudioUseDevice(AudioDeviceIdentifier identifier) {
|
||||||
|
int deviceCount = state.context.playbackDeviceInfoCount + state.context.captureDeviceInfoCount;
|
||||||
|
for(int i = 0; i < deviceCount; i++) {
|
||||||
|
if (identifier == &state.context.pDeviceInfos[i].id) {
|
||||||
|
AudioType type = i < state.context.playbackDeviceInfoCount ? AUDIO_PLAYBACK : AUDIO_CAPTURE;
|
||||||
|
state.config[type].device = identifier;
|
||||||
|
lovrLog(LOG_INFO, "audio", "Switching to %s device %s (%p)", type?"capture":"playback", state.context.pDeviceInfos[i].name, identifier);
|
||||||
|
ma_device_uninit(&state.devices[type]);
|
||||||
|
if(state.config[type].enable)
|
||||||
|
lovrAudioInitDevice(type);
|
||||||
|
if(state.config[type].start)
|
||||||
|
ma_device_start(&state.devices[type]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lovrAssert(false, "Couldn't find the given identifier");
|
||||||
|
}
|
|
@ -25,16 +25,19 @@ typedef enum {
|
||||||
UNIT_SAMPLES
|
UNIT_SAMPLES
|
||||||
} TimeUnit;
|
} TimeUnit;
|
||||||
|
|
||||||
|
typedef void* AudioDeviceIdentifier;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool enable;
|
bool enable;
|
||||||
bool start;
|
bool start;
|
||||||
|
AudioDeviceIdentifier device;
|
||||||
} AudioConfig;
|
} AudioConfig;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
AudioType type;
|
AudioType type;
|
||||||
const char *name;
|
const char *name;
|
||||||
bool isDefault;
|
bool isDefault;
|
||||||
void *identifier;
|
AudioDeviceIdentifier identifier;
|
||||||
int minChannels, maxChannels;
|
int minChannels, maxChannels;
|
||||||
} AudioDevice;
|
} AudioDevice;
|
||||||
|
|
||||||
|
@ -71,4 +74,4 @@ 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 lovrAudioGetDevices(AudioDevice **outDevices, size_t *outCount);
|
||||||
void lovrAudioUseDevice(void *identifier);
|
void lovrAudioUseDevice(AudioDeviceIdentifier identifier);
|
Loading…
Reference in a new issue