mirror of https://github.com/bjornbytes/lovr.git
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) {
|
||||
|
||||
//lovrAudioUseDevice()
|
||||
|
||||
AudioDeviceIdentifier ident = lua_touserdata(L, 1);
|
||||
lovrAudioUseDevice(ident);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -203,7 +203,9 @@ bool lovrAudioInitDevice(AudioType type) {
|
|||
ma_device_config config = ma_device_config_init(deviceType);
|
||||
config.sampleRate = LOVR_AUDIO_SAMPLE_RATE;
|
||||
config.playback.format = miniAudioFormatFromLovr[OUTPUT_FORMAT];
|
||||
config.playback.pDeviceID = state.config[AUDIO_PLAYBACK].device;
|
||||
config.capture.format = miniAudioFormatFromLovr[OUTPUT_FORMAT];
|
||||
config.playback.pDeviceID = state.config[AUDIO_CAPTURE].device;
|
||||
config.playback.channels = OUTPUT_CHANNELS;
|
||||
config.capture.channels = CAPTURE_CHANNELS;
|
||||
config.dataCallback = callbacks[type];
|
||||
|
@ -460,3 +462,22 @@ void lovrAudioGetDevices(AudioDevice **outDevices, size_t *outCount) {
|
|||
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
|
||||
} TimeUnit;
|
||||
|
||||
typedef void* AudioDeviceIdentifier;
|
||||
|
||||
typedef struct {
|
||||
bool enable;
|
||||
bool start;
|
||||
AudioDeviceIdentifier device;
|
||||
} AudioConfig;
|
||||
|
||||
typedef struct {
|
||||
AudioType type;
|
||||
const char *name;
|
||||
bool isDefault;
|
||||
void *identifier;
|
||||
AudioDeviceIdentifier identifier;
|
||||
int minChannels, maxChannels;
|
||||
} AudioDevice;
|
||||
|
||||
|
@ -71,4 +74,4 @@ uint32_t lovrAudioGetCaptureSampleCount();
|
|||
struct SoundData* lovrAudioCapture(uint32_t sampleCount, struct SoundData *soundData, uint32_t offset);
|
||||
|
||||
void lovrAudioGetDevices(AudioDevice **outDevices, size_t *outCount);
|
||||
void lovrAudioUseDevice(void *identifier);
|
||||
void lovrAudioUseDevice(AudioDeviceIdentifier identifier);
|
Loading…
Reference in New Issue