Audio Management

EarTrumpet's core functionality revolves around its sophisticated management of audio devices and application audio sessions. It uses the native Windows Multimedia Device API (MMDevice API) to provide functionality beyond the standard Windows mixer.

Core Abstractions

The audio management system is built on a set of interfaces defined in the EarTrumpet.DataModel.Audio namespace:

  • IAudioDeviceManager: Manages an observable collection of all active audio devices (e.g., speakers, headphones). It keeps track of the default device and notifies the application of any changes, such as a device being added or removed.

  • IAudioDevice: Represents a single audio device. It contains a collection of all application audio sessions that are currently outputting sound to it.

  • IAudioDeviceSession: Represents a single application's audio stream. This is the level at which individual application volumes are controlled.

The concrete implementation of these interfaces for Windows is located in the EarTrumpet.DataModel.WindowsAudio namespace.

Audio Metering (Peak Values)

To provide real-time visual feedback of audio levels, EarTrumpet samples the peak values for each audio session. To ensure good performance and avoid overwhelming the UI thread, this process is handled efficiently:

  1. Audio metering is sampled on a dedicated background thread.
  2. The peak values are collected in a batch.
  3. The batch of updated values is then dispatched to the foreground (UI) thread for rendering.

This approach ensures a smooth and responsive user interface, even with many applications playing audio simultaneously.

Persisted Output Devices Workaround

Windows allows users to set a preferred audio output device on a per-application basis. However, this setting is not always reliably applied when an application starts up, particularly with UWP applications.

EarTrumpet mitigates this issue for the user. When an application session is created, EarTrumpet checks for a user-persisted playback device. If the application is not currently on its designated device, EarTrumpet manually moves the audio session to the correct one, ensuring a consistent user experience.