Skip to content

Conversation

@tomoyanonymous
Copy link
Contributor

@tomoyanonymous tomoyanonymous commented Nov 12, 2024

On MacOS, Device::supported_output/input_configs returns multiple configs and they are the same values except for min_samplerate and max_samplerate. However, the pair of samplerates are always the same value like min_samplerate:44100, max_samplerate:44100 and min_samplerate:48000, max_samplerate:48000.

With this PR, Device::supported_output/input_configs now returns a combined SupportedStreamConfig. I found this problem when I tried to reorder the available streamconfigs depending on the parameter in my application.

On MacOS, Device::default_input/output_config does not use cmp_default_heuristics (I guess wasapi&asio are the same), but I hope this could be used in every platform ideally (though this PR does not address the implementation of the default config-related method).

Tested on: M1 Macbook Air(2020), macOS 15.0.1

Copy link
Member

@roderickvd roderickvd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your (much) earlier contribution. We're breathing new life into cpal and we're going through the backlog.

@roderickvd roderickvd requested a review from Copilot August 4, 2025 20:59

This comment was marked as outdated.

@roderickvd
Copy link
Member

Thanks for the quick update after all this time! I like the approach.

Going into a further review, I solicited some feedback from Copilot if you want to take a look if any of that makes sense.

It you would also include an entry in the changelog?

@tomoyanonymous tomoyanonymous force-pushed the fix-coreaudio-srrange branch from b6aaf23 to 77c0d91 Compare August 5, 2025 06:25
@tomoyanonymous
Copy link
Contributor Author

rebased the branch on recent master to resolve conflict in changelog.

@roderickvd roderickvd requested a review from Copilot August 5, 2025 09:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue on macOS where Device::supported_output/input_configs was returning redundant configuration entries with identical min/max sample rates. The change consolidates these duplicate entries into a single configuration that spans the full available sample rate range.

  • Adds logic to detect when all sample rate ranges have identical min/max values
  • Returns a single consolidated config when all ranges are identical, or individual ranges when they differ
  • Updates changelog to document the behavior change

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/host/coreaudio/macos/mod.rs Implements the consolidation logic for sample rate ranges and adds explanatory comments
CHANGELOG.md Documents the new behavior for CoreAudio's supported_configs method

@roderickvd
Copy link
Member

enumerate example output before:

Supported hosts:
  [CoreAudio]
Available hosts:
  [CoreAudio]
CoreAudio
  Default Input Device:
    Some("MacBook Air Microphone")
  Default Output Device:
    Some("MacBook Air Speakers")
  Devices: 
  1. "MacBook Air Microphone"
    Default input stream config:
      SupportedStreamConfig { channels: 1, sample_rate: SampleRate(44100), buffer_size: Range { min: 14, max: 4096 }, sample_format: F32 }
    All supported input stream configs:
      1.1. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(44100), max_sample_rate: SampleRate(44100), buffer_size: Range { min: 14, max: 4096 }, sample_format: F32 }
      1.2. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(48000), max_sample_rate: SampleRate(48000), buffer_size: Range { min: 14, max: 4096 }, sample_format: F32 }
      1.3. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(88200), max_sample_rate: SampleRate(88200), buffer_size: Range { min: 14, max: 4096 }, sample_format: F32 }
      1.4. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(96000), max_sample_rate: SampleRate(96000), buffer_size: Range { min: 14, max: 4096 }, sample_format: F32 }
  2. "MacBook Air Speakers"
    Default output stream config:
      SupportedStreamConfig { channels: 2, sample_rate: SampleRate(96000), buffer_size: Range { min: 29, max: 4096 }, sample_format: F32 }
    All supported output stream configs:
      2.1. SupportedStreamConfigRange { channels: 2, min_sample_rate: SampleRate(44100), max_sample_rate: SampleRate(44100), buffer_size: Range { min: 29, max: 4096 }, sample_format: F32 }
      2.2. SupportedStreamConfigRange { channels: 2, min_sample_rate: SampleRate(48000), max_sample_rate: SampleRate(48000), buffer_size: Range { min: 29, max: 4096 }, sample_format: F32 }
      2.3. SupportedStreamConfigRange { channels: 2, min_sample_rate: SampleRate(88200), max_sample_rate: SampleRate(88200), buffer_size: Range { min: 29, max: 4096 }, sample_format: F32 }
      2.4. SupportedStreamConfigRange { channels: 2, min_sample_rate: SampleRate(96000), max_sample_rate: SampleRate(96000), buffer_size: Range { min: 29, max: 4096 }, sample_format: F32 }
  3. "Microsoft Teams Audio"
    Default input stream config:
      SupportedStreamConfig { channels: 1, sample_rate: SampleRate(48000), buffer_size: Range { min: 15, max: 4096 }, sample_format: F32 }
    All supported input stream configs:
      3.1. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(48000), max_sample_rate: SampleRate(48000), buffer_size: Range { min: 15, max: 4096 }, sample_format: F32 }
    Default output stream config:
      SupportedStreamConfig { channels: 1, sample_rate: SampleRate(48000), buffer_size: Range { min: 15, max: 4096 }, sample_format: F32 }
    All supported output stream configs:
      3.1. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(48000), max_sample_rate: SampleRate(48000), buffer_size: Range { min: 15, max: 4096 }, sample_format: F32 }

enumerate example output with this PR:

Supported hosts:
  [CoreAudio]
Available hosts:
  [CoreAudio]
CoreAudio
  Default Input Device:
    Some("MacBook Air Microphone")
  Default Output Device:
    Some("MacBook Air Speakers")
  Devices: 
  1. "MacBook Air Microphone"
    Default input stream config:
      SupportedStreamConfig { channels: 1, sample_rate: SampleRate(44100), buffer_size: Range { min: 14, max: 4096 }, sample_format: F32 }
    All supported input stream configs:
      1.1. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(44100), max_sample_rate: SampleRate(96000), buffer_size: Range { min: 14, max: 4096 }, sample_format: F32 }
  2. "MacBook Air Speakers"
    Default output stream config:
      SupportedStreamConfig { channels: 2, sample_rate: SampleRate(96000), buffer_size: Range { min: 29, max: 4096 }, sample_format: F32 }
    All supported output stream configs:
      2.1. SupportedStreamConfigRange { channels: 2, min_sample_rate: SampleRate(44100), max_sample_rate: SampleRate(96000), buffer_size: Range { min: 29, max: 4096 }, sample_format: F32 }
  3. "Microsoft Teams Audio"
    Default input stream config:
      SupportedStreamConfig { channels: 1, sample_rate: SampleRate(48000), buffer_size: Range { min: 15, max: 4096 }, sample_format: F32 }
    All supported input stream configs:
      3.1. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(48000), max_sample_rate: SampleRate(48000), buffer_size: Range { min: 15, max: 4096 }, sample_format: F32 }
    Default output stream config:
      SupportedStreamConfig { channels: 1, sample_rate: SampleRate(48000), buffer_size: Range { min: 15, max: 4096 }, sample_format: F32 }
    All supported output stream configs:
      3.1. SupportedStreamConfigRange { channels: 1, min_sample_rate: SampleRate(48000), max_sample_rate: SampleRate(48000), buffer_size: Range { min: 15, max: 4096 }, sample_format: F32 }

LGTM! I'm gonna help you out with these into_iter / iter calls - I see you've granted write access - and am going to merge this.

Thanks a lot, this is a good enhancement to also consider for the other hosts.

@roderickvd roderickvd merged commit 512a611 into RustAudio:master Aug 5, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants