mirror of https://github.com/bjornbytes/lovr.git
lovrAudioSetCaptureFormat
instead of mixing up using device with using format
This commit is contained in:
parent
49288b7547
commit
2719eba1ba
|
@ -104,12 +104,17 @@ static int l_lovrAudioGetDevices(lua_State *L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_lovrUseDevice(lua_State *L) {
|
static int l_lovrAudioUseDevice(lua_State *L) {
|
||||||
AudioType type = luax_checkenum(L, 1, AudioType, "playback");
|
AudioType type = luax_checkenum(L, 1, AudioType, "playback");
|
||||||
const char *name = lua_tostring(L, 2);
|
const char *name = lua_tostring(L, 2);
|
||||||
int sampleRate = lua_tointeger(L, 3);
|
lovrAudioUseDevice(type, name);
|
||||||
SampleFormat format = luax_checkenum(L, 4, SampleFormat, "invalid");
|
return 0;
|
||||||
lovrAudioUseDevice(type, name, sampleRate, format);
|
}
|
||||||
|
|
||||||
|
static int l_lovrAudioSetCaptureFormat(lua_State *L) {
|
||||||
|
SampleFormat format = luax_checkenum(L, 1, SampleFormat, "invalid");
|
||||||
|
int sampleRate = lua_tointeger(L, 2);
|
||||||
|
lovrAudioSetCaptureFormat(format, sampleRate);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +127,8 @@ static const luaL_Reg lovrAudio[] = {
|
||||||
{ "setListenerPose", l_lovrAudioSetListenerPose },
|
{ "setListenerPose", l_lovrAudioSetListenerPose },
|
||||||
{ "getCaptureStream", l_lovrAudioGetCaptureStream },
|
{ "getCaptureStream", l_lovrAudioGetCaptureStream },
|
||||||
{ "getDevices", l_lovrAudioGetDevices },
|
{ "getDevices", l_lovrAudioGetDevices },
|
||||||
{ "useDevice", l_lovrUseDevice },
|
{ "useDevice", l_lovrAudioUseDevice },
|
||||||
|
{ "setCaptureFormat", l_lovrAudioSetCaptureFormat },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,7 @@ bool lovrAudioInitDevice(AudioType type) {
|
||||||
lovrLog(LOG_WARN, "audio", "No audio playback device called '%s'; falling back to default.", state.config[AUDIO_PLAYBACK].deviceName);
|
lovrLog(LOG_WARN, "audio", "No audio playback device called '%s'; falling back to default.", state.config[AUDIO_PLAYBACK].deviceName);
|
||||||
}
|
}
|
||||||
config.playback.channels = OUTPUT_CHANNELS;
|
config.playback.channels = OUTPUT_CHANNELS;
|
||||||
} else {
|
} else { // if AUDIO_CAPTURE
|
||||||
ma_device_type deviceType = ma_device_type_capture;
|
ma_device_type deviceType = ma_device_type_capture;
|
||||||
config = ma_device_config_init(deviceType);
|
config = ma_device_config_init(deviceType);
|
||||||
|
|
||||||
|
@ -444,13 +444,24 @@ void lovrAudioFreeDevices(AudioDeviceArr *devices) {
|
||||||
arr_free(devices);
|
arr_free(devices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrAudioUseDevice(AudioType type, const char *deviceName, int sampleRate, SampleFormat format) {
|
void lovrAudioSetCaptureFormat(SampleFormat format, int sampleRate)
|
||||||
|
{
|
||||||
|
if (sampleRate) state.config[AUDIO_CAPTURE].sampleRate = sampleRate;
|
||||||
|
if (format != SAMPLE_INVALID) state.config[AUDIO_CAPTURE].format = format;
|
||||||
|
|
||||||
|
// restart device if needed
|
||||||
|
ma_uint32 previousState = state.devices[AUDIO_CAPTURE].state;
|
||||||
|
if (previousState != MA_STATE_UNINITIALIZED && previousState != MA_STATE_STOPPED) {
|
||||||
|
lovrAudioStop(AUDIO_CAPTURE);
|
||||||
|
lovrAudioStart(AUDIO_CAPTURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrAudioUseDevice(AudioType type, const char *deviceName) {
|
||||||
free(state.config[type].deviceName);
|
free(state.config[type].deviceName);
|
||||||
state.config[type].deviceName = strdup(deviceName);
|
state.config[type].deviceName = strdup(deviceName);
|
||||||
if (sampleRate) state.config[type].sampleRate = sampleRate;
|
|
||||||
if (format != SAMPLE_INVALID) state.config[type].format = format;
|
|
||||||
|
|
||||||
|
|
||||||
|
// restart device if needed
|
||||||
ma_uint32 previousState = state.devices[type].state;
|
ma_uint32 previousState = state.devices[type].state;
|
||||||
if (previousState != MA_STATE_UNINITIALIZED && previousState != MA_STATE_STOPPED) {
|
if (previousState != MA_STATE_UNINITIALIZED && previousState != MA_STATE_STOPPED) {
|
||||||
lovrAudioStop(type);
|
lovrAudioStop(type);
|
||||||
|
|
|
@ -71,4 +71,5 @@ AudioDeviceArr* lovrAudioGetDevices(AudioType type);
|
||||||
// free a list of devices returned from above call
|
// free a list of devices returned from above call
|
||||||
void lovrAudioFreeDevices(AudioDeviceArr *devices);
|
void lovrAudioFreeDevices(AudioDeviceArr *devices);
|
||||||
|
|
||||||
void lovrAudioUseDevice(AudioType type, const char *deviceName, int sampleRate, SampleFormat format);
|
void lovrAudioSetCaptureFormat(SampleFormat format, int sampleRate);
|
||||||
|
void lovrAudioUseDevice(AudioType type, const char *deviceName);
|
||||||
|
|
Loading…
Reference in New Issue