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;
|
||||
}
|
||||
|
||||
static int l_lovrUseDevice(lua_State *L) {
|
||||
static int l_lovrAudioUseDevice(lua_State *L) {
|
||||
AudioType type = luax_checkenum(L, 1, AudioType, "playback");
|
||||
const char *name = lua_tostring(L, 2);
|
||||
int sampleRate = lua_tointeger(L, 3);
|
||||
SampleFormat format = luax_checkenum(L, 4, SampleFormat, "invalid");
|
||||
lovrAudioUseDevice(type, name, sampleRate, format);
|
||||
lovrAudioUseDevice(type, name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -122,7 +127,8 @@ static const luaL_Reg lovrAudio[] = {
|
|||
{ "setListenerPose", l_lovrAudioSetListenerPose },
|
||||
{ "getCaptureStream", l_lovrAudioGetCaptureStream },
|
||||
{ "getDevices", l_lovrAudioGetDevices },
|
||||
{ "useDevice", l_lovrUseDevice },
|
||||
{ "useDevice", l_lovrAudioUseDevice },
|
||||
{ "setCaptureFormat", l_lovrAudioSetCaptureFormat },
|
||||
{ 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);
|
||||
}
|
||||
config.playback.channels = OUTPUT_CHANNELS;
|
||||
} else {
|
||||
} else { // if AUDIO_CAPTURE
|
||||
ma_device_type deviceType = ma_device_type_capture;
|
||||
config = ma_device_config_init(deviceType);
|
||||
|
||||
|
@ -444,13 +444,24 @@ void lovrAudioFreeDevices(AudioDeviceArr *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);
|
||||
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;
|
||||
if (previousState != MA_STATE_UNINITIALIZED && previousState != MA_STATE_STOPPED) {
|
||||
lovrAudioStop(type);
|
||||
|
|
|
@ -71,4 +71,5 @@ AudioDeviceArr* lovrAudioGetDevices(AudioType type);
|
|||
// free a list of devices returned from above call
|
||||
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