Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename references to audio device, capture_device to output_device, input_device respectively #69120

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions doc/classes/AudioServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
Adds an [AudioEffect] effect to the bus [param bus_idx] at [param at_position].
</description>
</method>
<method name="capture_get_device_list">
<return type="PackedStringArray" />
<description>
Returns the names of all audio input devices detected on the system.
[b]Note:[/b] [member ProjectSettings.audio/driver/enable_input] must be [code]true[/code] for audio input to work. See also that setting's description for caveats related to permissions and operating system privacy settings.
</description>
</method>
<method name="generate_bus_layout" qualifiers="const">
<return type="AudioBusLayout" />
<description>
Expand Down Expand Up @@ -117,10 +110,11 @@
Returns the volume of the bus at index [param bus_idx] in dB.
</description>
</method>
<method name="get_device_list">
<method name="get_input_device_list">
<return type="PackedStringArray" />
<description>
Returns the names of all audio devices detected on the system.
Returns the names of all audio input devices detected on the system.
[b]Note:[/b] [member ProjectSettings.audio/driver/enable_input] must be [code]true[/code] for audio input to work. See also that setting's description for caveats related to permissions and operating system privacy settings.
</description>
</method>
<method name="get_mix_rate" qualifiers="const">
Expand All @@ -129,6 +123,12 @@
Returns the sample rate at the output of the [AudioServer].
</description>
</method>
<method name="get_output_device_list">
<return type="PackedStringArray" />
<description>
Returns the names of all audio output devices detected on the system.
</description>
</method>
<method name="get_output_latency" qualifiers="const">
<return type="float" />
<description>
Expand Down Expand Up @@ -302,12 +302,12 @@
<member name="bus_count" type="int" setter="set_bus_count" getter="get_bus_count" default="1">
Number of available audio buses.
</member>
<member name="capture_device" type="String" setter="capture_set_device" getter="capture_get_device" default="&quot;Default&quot;">
Name of the current device for audio input (see [method capture_get_device_list]). On systems with multiple audio inputs (such as analog, USB and HDMI audio), this can be used to select the audio input device. The value [code]"Default"[/code] will record audio on the system-wide default audio input. If an invalid device name is set, the value will be reverted back to [code]"Default"[/code].
<member name="input_device" type="String" setter="set_input_device" getter="get_input_device" default="&quot;Default&quot;">
Name of the current device for audio input (see [method get_input_device_list]). On systems with multiple audio inputs (such as analog, USB and HDMI audio), this can be used to select the audio input device. The value [code]"Default"[/code] will record audio on the system-wide default audio input. If an invalid device name is set, the value will be reverted back to [code]"Default"[/code].
[b]Note:[/b] [member ProjectSettings.audio/driver/enable_input] must be [code]true[/code] for audio input to work. See also that setting's description for caveats related to permissions and operating system privacy settings.
</member>
<member name="device" type="String" setter="set_device" getter="get_device" default="&quot;Default&quot;">
Name of the current device for audio output (see [method get_device_list]). On systems with multiple audio outputs (such as analog, USB and HDMI audio), this can be used to select the audio output device. The value [code]"Default"[/code] will play audio on the system-wide default audio output. If an invalid device name is set, the value will be reverted back to [code]"Default"[/code].
<member name="output_device" type="String" setter="set_output_device" getter="get_output_device" default="&quot;Default&quot;">
Name of the current device for audio output (see [method get_output_device_list]). On systems with multiple audio outputs (such as analog, USB and HDMI audio), this can be used to select the audio output device. The value [code]"Default"[/code] will play audio on the system-wide default audio output. If an invalid device name is set, the value will be reverted back to [code]"Default"[/code].
</member>
<member name="playback_speed_scale" type="float" setter="set_playback_speed_scale" getter="get_playback_speed_scale" default="1.0">
Scales the rate at which audio is played (i.e. setting it to [code]0.5[/code] will make the audio be played at half its speed).
Expand Down
54 changes: 27 additions & 27 deletions drivers/coreaudio/audio_driver_coreaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ OSStatus AudioDriverCoreAudio::input_device_address_cb(AudioObjectID inObjectID,
void *inClientData) {
AudioDriverCoreAudio *driver = static_cast<AudioDriverCoreAudio *>(inClientData);

// If our selected device is the Default call set_device to update the
// If our selected input device is the Default, call set_input_device to update the
// kAudioOutputUnitProperty_CurrentDevice property
if (driver->capture_device_name == "Default") {
driver->capture_set_device("Default");
if (driver->input_device_name == "Default") {
driver->set_input_device("Default");
}

return noErr;
Expand All @@ -58,10 +58,10 @@ OSStatus AudioDriverCoreAudio::output_device_address_cb(AudioObjectID inObjectID
void *inClientData) {
AudioDriverCoreAudio *driver = static_cast<AudioDriverCoreAudio *>(inClientData);

// If our selected device is the Default call set_device to update the
// If our selected output device is the Default call set_output_device to update the
// kAudioOutputUnitProperty_CurrentDevice property
if (driver->device_name == "Default") {
driver->set_device("Default");
if (driver->output_device_name == "Default") {
driver->set_output_device("Default");
}

return noErr;
Expand Down Expand Up @@ -495,7 +495,7 @@ Error AudioDriverCoreAudio::capture_stop() {

#ifdef MACOS_ENABLED

PackedStringArray AudioDriverCoreAudio::_get_device_list(bool capture) {
PackedStringArray AudioDriverCoreAudio::_get_device_list(bool input) {
PackedStringArray list;

list.push_back("Default");
Expand All @@ -514,7 +514,7 @@ PackedStringArray AudioDriverCoreAudio::_get_device_list(bool capture) {

UInt32 deviceCount = size / sizeof(AudioDeviceID);
for (UInt32 i = 0; i < deviceCount; i++) {
prop.mScope = capture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
prop.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
prop.mSelector = kAudioDevicePropertyStreamConfiguration;

AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, nullptr, &size);
Expand Down Expand Up @@ -555,10 +555,10 @@ PackedStringArray AudioDriverCoreAudio::_get_device_list(bool capture) {
return list;
}

void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
void AudioDriverCoreAudio::_set_device(const String &output_device, bool input) {
AudioDeviceID deviceId;
bool found = false;
if (device != "Default") {
if (output_device != "Default") {
AudioObjectPropertyAddress prop;

prop.mSelector = kAudioHardwarePropertyDevices;
Expand All @@ -573,7 +573,7 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {

UInt32 deviceCount = size / sizeof(AudioDeviceID);
for (UInt32 i = 0; i < deviceCount && !found; i++) {
prop.mScope = capture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
prop.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
prop.mSelector = kAudioDevicePropertyStreamConfiguration;

AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, nullptr, &size);
Expand Down Expand Up @@ -602,7 +602,7 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
ERR_FAIL_NULL_MSG(buffer, "Out of memory.");
if (CFStringGetCString(cfname, buffer, maxSize, kCFStringEncodingUTF8)) {
String name = String::utf8(buffer) + " (" + itos(audioDevices[i]) + ")";
if (name == device) {
if (name == output_device) {
deviceId = audioDevices[i];
found = true;
}
Expand All @@ -618,7 +618,7 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
if (!found) {
// If we haven't found the desired device get the system default one
UInt32 size = sizeof(AudioDeviceID);
UInt32 elem = capture ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
UInt32 elem = input ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
AudioObjectPropertyAddress property = { elem, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };

OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &property, 0, nullptr, &size, &deviceId);
Expand All @@ -628,45 +628,45 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
}

if (found) {
OSStatus result = AudioUnitSetProperty(capture ? input_unit : audio_unit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &deviceId, sizeof(AudioDeviceID));
OSStatus result = AudioUnitSetProperty(input ? input_unit : audio_unit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &deviceId, sizeof(AudioDeviceID));
ERR_FAIL_COND(result != noErr);

if (capture) {
if (input) {
// Reset audio input to keep synchronization.
input_position = 0;
input_size = 0;
}
}
}

PackedStringArray AudioDriverCoreAudio::get_device_list() {
PackedStringArray AudioDriverCoreAudio::get_output_device_list() {
return _get_device_list();
}

String AudioDriverCoreAudio::get_device() {
return device_name;
String AudioDriverCoreAudio::get_output_device() {
return output_device_name;
}

void AudioDriverCoreAudio::set_device(String device) {
device_name = device;
void AudioDriverCoreAudio::set_output_device(String output_device) {
output_device_name = output_device;
if (active) {
_set_device(device_name);
_set_device(output_device_name);
}
}

void AudioDriverCoreAudio::capture_set_device(const String &p_name) {
capture_device_name = p_name;
void AudioDriverCoreAudio::set_input_device(const String &p_name) {
input_device_name = p_name;
if (active) {
_set_device(capture_device_name, true);
_set_device(input_device_name, true);
}
}

PackedStringArray AudioDriverCoreAudio::capture_get_device_list() {
PackedStringArray AudioDriverCoreAudio::get_input_device_list() {
return _get_device_list(true);
}

String AudioDriverCoreAudio::capture_get_device() {
return capture_device_name;
String AudioDriverCoreAudio::get_input_device() {
return input_device_name;
}

#endif
Expand Down
18 changes: 9 additions & 9 deletions drivers/coreaudio/audio_driver_coreaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class AudioDriverCoreAudio : public AudioDriver {
bool active = false;
Mutex mutex;

String device_name = "Default";
String capture_device_name = "Default";
String output_device_name = "Default";
String input_device_name = "Default";

int mix_rate = 0;
unsigned int channels = 2;
Expand All @@ -60,7 +60,7 @@ class AudioDriverCoreAudio : public AudioDriver {

#ifdef MACOS_ENABLED
PackedStringArray _get_device_list(bool capture = false);
void _set_device(const String &device, bool capture = false);
void _set_device(const String &output_device, bool capture = false);

static OSStatus input_device_address_cb(AudioObjectID inObjectID,
UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses,
Expand Down Expand Up @@ -107,13 +107,13 @@ class AudioDriverCoreAudio : public AudioDriver {
void stop();

#ifdef MACOS_ENABLED
virtual PackedStringArray get_device_list();
virtual String get_device();
virtual void set_device(String device);
virtual PackedStringArray get_output_device_list();
virtual String get_output_device();
virtual void set_output_device(String output_device);

virtual PackedStringArray capture_get_device_list();
virtual void capture_set_device(const String &p_name);
virtual String capture_get_device();
virtual PackedStringArray get_input_device_list();
virtual void set_input_device(const String &p_name);
virtual String get_input_device();
#endif

AudioDriverCoreAudio();
Expand Down
Loading