Add Coreaudio ID to Portaudio device index mapping - #1165
Open
douglasheld2 wants to merge 2 commits into
Open
Conversation
It is sometimes useful to be able to correlate a coreaudio device to a Portaudio device, especially when multiple coreaudio devices have the same name and need to be differentiated by their ID numbers.
After compiling in this extra function, the IDs can be correlated with the following function in python:
from cffi import FFI
_pa_extra_ffi = FFI()
_pa_extra_ffi.cdef("""
int PaMacCore_GetDeviceIndexForAudioDeviceID(unsigned int id);
""")
_pa_extra_lib = _pa_extra_ffi.dlopen(
"/Users/doug/Library/Python/3.12/lib/python/site-packages/_sounddevice_data/portaudio-binaries/libportaudio.dylib"
)
def get_portaudio_index_from_coreaudio_id(target_core_id):
"""
Convert a macOS CoreAudio AudioDeviceID into a PortAudio/sounddevice index.
"""
index = _pa_extra_lib.PaMacCore_GetDeviceIndexForAudioDeviceID(target_core_id)
if index < 0:
return None
return index
RossBencina
reviewed
Jul 25, 2026
Co-authored-by: Ross Bencina <rossb@audiomulch.com>
RossBencina
reviewed
Jul 31, 2026
Collaborator
There was a problem hiding this comment.
Phil and I have reviewed this PR and have decided to reject the approach taken here. We would accept a new PR for the inverse function:
AudioDeviceId PaMacCore_DeviceIndexToAudioDeviceID(PaDeviceIndex index)
This would return kAudioDeviceUnknown for any lookup failures. Note that the implementation can use PaUtil_DeviceIndexToHostApiDeviceIndex to get the index into the devIds array but be sure to check for errors.
We would prefer this approach because:
- The implementation would be simpler
- It facilitates lookup both ways (client code can implement the search that your PR implements)
- It is consistent with other PortAudio host API extension functions
Collaborator
|
CI is failing with whitespace errors: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It is sometimes useful to be able to correlate a coreaudio device to a Portaudio device, especially when multiple coreaudio devices have the same name and need to be differentiated by their ID numbers.
After compiling in this extra function, the IDs can be correlated with the following function in python:
I have also removed two unused variables
iin unrelated parts of the file.