AME.

How it works

For developers: trace the data path, controls and output boundaries by file.

Signal path

Apple Music handles media access and decoding. Hooks connect supported audio interfaces; decoded samples enter AMExclusive in Apple’s float32 P0 representation, then pass through a queue and mapper to device PCM.

Apple Music decoder → P0 float32 → ApplePcmTap → PcmQueue
→ QueuedPcmSource / sample mapper → WasapiExclusiveSink → DAC

Core files and responsibilities

Source fileResponsibility and entry points
mod/src/HookDll.cppHook installation and Apple audio entry points; search AudioConverterFillComplexBuffer and g_audioCoreRuntime.
mod/src/ApplePrivateOffsets.hVersion-specific private offsets; check alongside hook installation when adapting app versions.
mod/src/audio_v2/AudioCoreRuntime.hAudioCoreRuntime: joins converter/native-graph observations to the coordinator.
mod/src/audio_v2/ApplePcmOutput.hApplePcmFormatView / ApplePcmOutputView describe callback formats and buffers.
mod/src/audio_v2/ApplePcmTap.hApplePcmTap::BindActive, OnInterleaved and OnPlanar pass the bound converter’s samples to the coordinator.
mod/src/audio_v2/AudioCoreCoordinator.hEnable, PushP0Interleaved, PushP0Planar, OpenEndpoint and Start assemble capture and endpoint lifecycle.
mod/src/audio_v2/PcmQueue.hPcmQueue::TryPush / TryPushPlanar: preallocated SPSC queue, block splitting and planar normalization.
mod/src/audio_v2/QueuedPcmSource.hQueuedPcmSource / PcmMappingPolicy consume blocks and select exact-integer or local-float mapping.
mod/src/audio_v2/WasapiExclusiveSink.cppWasapiExclusiveSink::InitializeClient probes formats and opens exclusive output; GetBuffer / ReleaseBuffer bound endpoint submission.
mod/src/audio_v2/AudioCoreRuntime.cppAudioCoreRuntime implementation: format candidates, converter observations, P0 capture and coordination.
mod/src/audio_v2/AudioCoreConverterRegistry.hConverterRegistration and bounded converter registry: source precision, format and generation metadata.

Formats and real-time constraints

PcmTypes.h separates sample rate, channels, valid bits and container bits in PcmFormat. PcmBlock also carries mediaGeneration, sequence, firstFrame, discontinuity and endOfStream; preserve these boundaries alongside the samples.

The current types support stereo and up to 2048 frames per block. PcmQueue uses rigtorp/SPSCQueue. Apple callbacks perform bounded queue submission; avoid waits, file I/O or extra allocations there. Full queues and rejected formats are failure paths, not unlimited buffering.

Source fileResponsibility and entry points
mod/src/audio_v2/PcmTypes.hPcmFormat, PcmBlock, kSupportedChannels and kMaxBlockFrames.

WASAPI output

The output checks device format support with IsFormatSupported, then initializes AUDCLNT_SHAREMODE_EXCLUSIVE with EVENTCALLBACK. The render thread waits for the device event and writes PCM into the WASAPI buffer, bypassing the Windows shared mixer.

The output uses the source sample rate and integer PCM format, which the device and driver must support. The hardware-buffer setting controls the requested duration.

  • Validate unsupported formats, busy devices, driver rejection, pause/resume, track changes, seeking and exclusive toggles on real devices.
Source fileResponsibility and entry points
mod/src/audio_v2/WasapiExclusiveSink.cppInitializeClient: format checks, exclusive initialization, device events and buffer submission; start here for device/buffer changes.
mod/src/audio_v2/WasapiExclusiveSink.hWasapiSinkConfig and WasapiExclusiveSink: output configuration and lifecycle interfaces.
mod/src/audio_v2/AudioCoreCoordinator.cppCoordinates the PCM queue and endpoint startup/shutdown; review alongside output handoff changes.
mod/src/audio_v2/AudioCoreGate.hAudioCoreGate: Off, Armed, Capturing, Prebuffered, Active/Faulted phases; generation tokens constrain stale callbacks.
mod/src/audio_v2/AppleOutputGate.hAppleOutputGate::CommitCutover suppresses native output only after replacement startup; retirement clears the gate.
mod/src/audio_v2/NativeRenderGateProxy.hNative IAudioClient / IAudioRenderClient proxy declarations and internal-client bypass guard.

Float32 and integer-source mapping

Float32 decoded from an integer source must still lie on the original PCM lattice. ExactSampleMapper.h::MapP0Sample checks finite values, range and precision, then maps exactly into left-aligned PCM32. Fractional results or invalid padding bits are rejected rather than rounded.

LocalFloatIntegerizer.h::IntegerizeLocalFloatSample separately quantizes native local float sources and records clipping. Do not relax ExactSampleMapper to accommodate float sources; the two paths have different guarantees.

  • For format/sample changes, review PcmTypes.h, QueuedPcmSource.h and both mappers; do not change only the WASAPI format declaration.
Source fileResponsibility and entry points
mod/src/audio_v2/ExactSampleMapper.hMapP0Sample: exact integer-source mapping.
mod/src/audio_v2/LocalFloatIntegerizer.hIntegerizeLocalFloatSample: local-float conversion.
mod/src/AudioFormatPolicy.hApplePcmFormat and format policy: source-format parsing, precision and local PCM candidates.
mod/src/audio_v2/BitPerfectVerifier.hBitPerfectVerifier compares submitted integer samples with exact mapping of the same P0 block and records mismatches.
mod/src/AudioErrors.hProject-owned HRESULTs and IsPlaybackRejection unify audio rejection reasons.
mod/src/SampleConversion.hEmpty placeholder in the public repository; actual sample conversion is implemented in the two mappers.

Lossless selection

Quality selection is separate from exclusive output. The policy retains the highest eligible lossless rate for the item; bandwidth reevaluation cannot admit a lower-rate candidate. Playback may wait for the best stream. Lossy-only tracks cannot become lossless.

  • Check lossless availability, unavailable best streams and reduced bandwidth; keep quality policy separate from the exclusive output toggle.
Source fileResponsibility and entry points
mod/src/LosslessQualityPolicy.hSelection::Observe / Accept: tracks the highest candidate rate and enforces admission.
mod/src/LosslessQualityLock.cppQuality-lock hooks and candidate filtering; review callers alongside policy changes.
mod/src/LosslessQualityLock.hInstall, SetEnabled and CreateStrictLosslessFilter expose the quality lock to callers.

Controls, UI and quality policy

  • Start UI changes in UiAdapter.cpp; protocol changes must update IpcProtocol.h, Broker.cpp and HookDll.cpp together.
Source fileResponsibility and entry points
mod/src/Broker.cppCompanion entry point, target Apple Music process management and configuration coordination.
mod/src/UiAdapter.cppExclusive toggle and buffer controls; start here for presentation, validation and interactions.
mod/src/IpcProtocol.hMessageType and Message communication contract; update both peers when changing messages.
mod/src/IpcTransport.cppIPC transport implementation; read with protocol and callers.
mod/src/LosslessQualityLock.cppQuality-lock hooks and candidate filtering.
mod/src/LosslessQualityPolicy.hSelection::Observe / Accept track the highest candidate rate and enforce admission.
mod/src/audio_v2/NativeRenderGateProxy.cppNative rendering proxies and handoff; review coordinator and lifecycle gates alongside changes.
mod/src/IpcTransport.hReadMessage / WriteMessage transport interfaces and PipeSecurity.
mod/src/MediaSessionControl.cppWindows.Media.Control session control and recovery logging; entry point for the media_control tool.
mod/src/BoundedLog.hBounded logging and rotation helpers used by broker, hooks and media control.