Modified Microphone implementation to handle only one device at a time (WIP)
This commit is contained in:
committed by
Saracen
parent
76fd9d215c
commit
061358d838
@ -73,42 +73,6 @@ void AudioDriver::update_mix_time(int p_frames) {
|
||||
_last_mix_time = OS::get_singleton()->get_ticks_usec();
|
||||
}
|
||||
|
||||
void AudioDriver::update_microphone_default(StringName p_device_name) {
|
||||
if (default_microphone_device_output != NULL) {
|
||||
MicrophoneDeviceOutput *output = default_microphone_device_output->owner;
|
||||
output->remove_reciever(default_microphone_device_output);
|
||||
|
||||
while (output != NULL) {
|
||||
MicrophoneDeviceOutput *owner = output->owner;
|
||||
if (output->recievers.size() == 0) {
|
||||
if (owner == NULL) {
|
||||
if (output->active == true) {
|
||||
capture_device_stop(output->name);
|
||||
output->active == false;
|
||||
}
|
||||
} else {
|
||||
owner->remove_reciever(output);
|
||||
memdelete(output);
|
||||
}
|
||||
output = owner;
|
||||
}
|
||||
}
|
||||
|
||||
if (microphone_device_output_map.has(p_device_name)) {
|
||||
|
||||
Map<StringName, MicrophoneDeviceOutput *>::Element *e = microphone_device_output_map.find(p_device_name);
|
||||
MicrophoneDeviceOutput *new_output = e->get();
|
||||
new_output->add_reciever(default_microphone_device_output);
|
||||
if (new_output->active == false) {
|
||||
capture_device_start(p_device_name);
|
||||
new_output->active = true;
|
||||
}
|
||||
}
|
||||
|
||||
output = default_microphone_device_output->owner;
|
||||
}
|
||||
}
|
||||
|
||||
double AudioDriver::get_mix_time() const {
|
||||
|
||||
double total = (OS::get_singleton()->get_ticks_usec() - _last_mix_time) / 1000000.0;
|
||||
@ -138,74 +102,6 @@ int AudioDriver::get_total_channels_by_speaker_mode(AudioDriver::SpeakerMode p_m
|
||||
ERR_FAIL_V(2);
|
||||
}
|
||||
|
||||
AudioDriver::MicrophoneReciever *AudioDriver::create_microphone_reciever(const StringName &p_device_name) {
|
||||
|
||||
MicrophoneReciever *microphone_reciever = NULL;
|
||||
MicrophoneDeviceOutput *reciever_output = NULL;
|
||||
MicrophoneDeviceOutput *device_output = NULL;
|
||||
|
||||
StringName device_name = capture_device_get_default_name();
|
||||
|
||||
if (microphone_device_output_map.has(device_name)) {
|
||||
|
||||
Map<StringName, MicrophoneDeviceOutput *>::Element *e = microphone_device_output_map.find(device_name);
|
||||
device_output = e->get();
|
||||
}
|
||||
|
||||
if (device_output) {
|
||||
if (p_device_name == "") {
|
||||
if (default_microphone_device_output != NULL) {
|
||||
reciever_output = default_microphone_device_output;
|
||||
} else {
|
||||
// Default reciever does not exist, create it and connect it
|
||||
default_microphone_device_output = memnew(MicrophoneDeviceOutputIndirect);
|
||||
reciever_output = default_microphone_device_output;
|
||||
device_output->add_reciever(reciever_output);
|
||||
}
|
||||
} else {
|
||||
if (microphone_device_output_map.has(p_device_name)) {
|
||||
reciever_output = device_output;
|
||||
}
|
||||
}
|
||||
|
||||
if (reciever_output) {
|
||||
microphone_reciever = memnew(MicrophoneReciever);
|
||||
reciever_output->add_reciever(microphone_reciever);
|
||||
if (device_output->active == false) {
|
||||
capture_device_start(device_name);
|
||||
device_output->active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return microphone_reciever;
|
||||
}
|
||||
|
||||
void AudioDriver::destroy_microphone_reciever(AudioDriver::MicrophoneReciever *p_microphone_reciever) {
|
||||
|
||||
if (p_microphone_reciever != NULL) {
|
||||
MicrophoneDeviceOutput *output = p_microphone_reciever->owner;
|
||||
output->remove_reciever(p_microphone_reciever);
|
||||
|
||||
while (output != NULL) {
|
||||
MicrophoneDeviceOutput *owner = output->owner;
|
||||
if (output->recievers.size() == 0) {
|
||||
if (owner == NULL) {
|
||||
if (output->active == true) {
|
||||
capture_device_stop(output->name);
|
||||
output->active == false;
|
||||
}
|
||||
} else {
|
||||
owner->remove_reciever(output);
|
||||
memdelete(output);
|
||||
}
|
||||
output = owner;
|
||||
}
|
||||
}
|
||||
memdelete(p_microphone_reciever);
|
||||
}
|
||||
}
|
||||
|
||||
Array AudioDriver::get_device_list() {
|
||||
Array list;
|
||||
|
||||
@ -218,13 +114,19 @@ String AudioDriver::get_device() {
|
||||
return "Default";
|
||||
}
|
||||
|
||||
Array AudioDriver::capture_get_device_list() {
|
||||
Array list;
|
||||
|
||||
list.push_back("Default");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
AudioDriver::AudioDriver() {
|
||||
|
||||
_last_mix_time = 0;
|
||||
_mix_amount = 0;
|
||||
|
||||
default_microphone_device_output = NULL;
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
prof_time = 0;
|
||||
#endif
|
||||
@ -1308,32 +1210,19 @@ void AudioServer::set_device(String device) {
|
||||
AudioDriver::get_singleton()->set_device(device);
|
||||
}
|
||||
|
||||
PoolStringArray AudioServer::audio_in_get_device_names() {
|
||||
Array AudioServer::capture_get_device_list() {
|
||||
|
||||
lock();
|
||||
PoolStringArray device_names = AudioDriver::get_singleton()->capture_device_get_names();
|
||||
unlock();
|
||||
|
||||
return device_names;
|
||||
return AudioDriver::get_singleton()->capture_get_device_list();
|
||||
}
|
||||
|
||||
AudioDriver::MicrophoneReciever *AudioServer::create_microphone_reciever(const StringName &p_device_name) {
|
||||
AudioDriver::MicrophoneReciever *microphone_reciever = NULL;
|
||||
StringName AudioServer::capture_get_device() {
|
||||
|
||||
lock();
|
||||
microphone_reciever = AudioDriver::get_singleton()->create_microphone_reciever(p_device_name);
|
||||
unlock();
|
||||
|
||||
return microphone_reciever;
|
||||
return AudioDriver::get_singleton()->capture_get_device();
|
||||
}
|
||||
|
||||
void AudioServer::destroy_microphone_reciever(AudioDriver::MicrophoneReciever *p_microphone_reciever) {
|
||||
lock();
|
||||
AudioDriver::get_singleton()->destroy_microphone_reciever(p_microphone_reciever);
|
||||
unlock();
|
||||
}
|
||||
void AudioServer::capture_set_device(StringName device) {
|
||||
|
||||
void AudioServer::_change_default_device(StringName p_recording_device_default_name) {
|
||||
AudioDriver::get_singleton()->capture_set_device(device);
|
||||
}
|
||||
|
||||
void AudioServer::_bind_methods() {
|
||||
|
||||
Reference in New Issue
Block a user