Automated Apple Music Lossless Sample Rate Switching for Audio Devices on Macs.

Overview

header image with app icon

LosslessSwitcher switches your current audio device's sample rate to match the currently playing lossless song on your Apple Music app, automatically.

Let's say if the next song that you are playing, is a Hi-Res Lossless track with a sample rate of 192kHz, LosslessSwitcher will switch your device to that sample rate as soon as possible.

The opposite happens, when the next track happens to have a lower sample rate.

Installation

Simply go to the Releases page of this repository. (Link to latest release)

Alternatively, try the beta! (link)

Drag the app to your Applications folder. If you wish to have it running when logging in, you should be able to add LosslessSwitcher in System Preferences:

> User & Groups > Login Items > Add LosslessSwitcher app

App details

There isn't much going on, when it comes to the UI of the app, as most of the logic is to:

  1. Read Apple Music's logs to know the song's sample rate.
  2. Set the sample rate to the device that you are currently playing to.

As such, the app lives on your menu bar. The screenshot above shows it's only UI component that it offers, which is to show the sample rate that it has parsed from Apple Music's logs.

app screenshot, with music note icon shown as UI button

If you wish, the sample rate can also be directly visible as the menu bar item.

app screenshot with sample rate shown as UI button

Do also note that:

  • There may be short interuptions to your audio playback, during the time where the app attempts to switch the sample rates.
  • Prolonged use on MacBooks may accelerate battery usages, due to the frequent querying of the latest sample rate.

Why make this?

Ever since Apple Music Lossless launched along with macOS 11.4, the app would never switch the sample rates according to the song that was playing. A trip down to the Audio MIDI Setup app was required. This still happens today, with macOS 12.3.1, despite iOS's Music app having such an ability.

I think this improvement might be well appreciated by many, hence this project is here, free and open source.

Prerequisites

Due to how the app works, this app is not, and cannot be sandboxed. It also has the following requirement, due to the use of OSLog API:

  • The user running LosslessSwitcher must be an admin. This is not tested and assumed due to this Apple Developer Forums thread.
  • Apple Music app must have Lossless mode on. (well, of course)

Other than that, it should run on any Mac running macOS 11.4 or later.

Disclaimer

By using LosslessSwitcher, you agree that under no circumstances will the developer or any contributors be held responsible or liable in any way for any claims, damages, losses, expenses, costs or liabilities whatsoever or any other consequences suffered by you or incurred by you directly or indirectly in connection with any form of usages of LosslessSwitcher.

Devices tested

I did not test on any Macs running macOS 11, or any Apple Silicon based Macs (I don't have one 😢 ) Use at your own risk.

UPDATE: A reddit user has updated to me that LosslessSwitcher is working on Apple Silicon Macs! Thanks!

CPU Mac Model macOS Version Audio Device
Intel Mac Mini (2018) 12.2 Denon PMA-50
Intel MacBook Pro 13 inch (2018) 12.3.1 Denon PMA-50
Intel MacBook Pro 13 inch, four Thunderbolt 3 ports (2016) 12.3.1 Topping DX7 Pro

You can add to this list by modifying this README and opening a new pull request!

License

LosslessSwitcher is licensed under GPL-3.0.

Love the idea of this?

If you appreciate the development of this application, feel free to spread the word around so more people get to know about LosslessSwitcher. You can also show your support by sponsoring this project!

Dependencies

  • Sweep, by @JohnSundell, a easy to use Swift String scanner.
  • SimplyCoreAudio, by @rnine, a framework that makes CoreAudio so much easier to use.
Comments
  • request: allow to choose multiple devices to set the sample rate

    request: allow to choose multiple devices to set the sample rate

    Thank you for release this amazing app to solve sample rate problem for Apple Music.

    I'm now using BlackHole to loopback audio to AudioUnit Host app like AULab and Hosting AU to use batter EQ plug-in and send the sound to USB DAC,but at now time LosslessSwitcher can only change one device's sample rate at one time, can you add multiple devices sample rate change function ?

    opened by MDGSC 5
  • Doesn't sync bit depth

    Doesn't sync bit depth

    Hi!

    I don't even know if this is a bug, or simply an omission, but the app doesn't sync bit depth, only sample rate. So for example, if some song is 24/96, it syncs as 16/96.

    opened by tomekbuszewski 1
  • Why do I need this app?

    Why do I need this app?

    I am using Chord Mojo DAC/Amp. Doesn't macOS Monterey (version 12.3.1) and Apple Music app support automatic switching of sample rates for device as per the song sample rate?

    Thanks

    opened by anildigital 1
  • Apple Music app keeps opening automatically (in the background) while LosslessSwitcher is running

    Apple Music app keeps opening automatically (in the background) while LosslessSwitcher is running

    With LosslessSwitcher running, with the latest couple of (beta) versions, the Apple Music app opens in the background on its own. Even when you then quit the Music app, it will open in the background again (and you can see the dot in the dock indicating that the app is running). This does not happen with the current "stable" version of LosslessSwitcher, I've noticed it with the latest beta releases...

    opened by markojurkovic 2
  • Opening YouTube in Safari changes Sample Rate

    Opening YouTube in Safari changes Sample Rate

    Seems like Beta 6, build 11 has this issue -

    • if I'm playing music on music app on my Macbook air, then I open Safari and go to YouTube.com - it seems like losslesswitcher is reading YouTube somehow and changing the sample rate. Even if I have Safari completely muted. So not sure if it's just YouTube or there are certain situations where losslesswitcher is reading music/sound from places other than the music app.
    • I could also see someone actually liking this feature if they play YouTube and losslessswitcher is reading YouTube sample rate correctly (I'm not sure if it is or not).
    • Suggestion: Allow for Music App and YouTube to have separate sample rate reading capabilities where you can have them both on at same time (switches correctly) or only have one on at a time. For example: Option 1) both Music App and YouTube Sample Rate changes automatically when you go back and forth. Option 2) Music App on, YouTube off. Option 3) YouTube on, Music app off.
    opened by DeckHeadFi 4
  • Manual sample rate override in menu

    Manual sample rate override in menu

    Discussed in https://github.com/vincentneo/LosslessSwitcher/discussions/26

    Originally posted by Justinwang677 July 6, 2022 Some app don't change automatically so it would be a good idea to add a sample rate changing directly in the drop down menu and also bit depth option too

    enhancement 
    opened by vincentneo 0
  • limit max sample rate

    limit max sample rate

    Discussed in https://github.com/vincentneo/LosslessSwitcher/discussions/39

    Originally posted by 7enso November 8, 2022 My audio device is capable of playing at 192 kHz or more, my speakers are as well (digital in). Due to cable length issues the SPDIF signals get distorted above 96 kHz. So if the sample rate switches above 96 kHz I get distorted audio.

    Therefore it would be VERY useful to limit the maximum sample rate to a specific value - al least for me.

    I mplementation of that feature would be great!Thanks for the great work already :)

    enhancement 
    opened by vincentneo 0
  • LosslessSwitcher needs admin privileges?

    LosslessSwitcher needs admin privileges?

    I use Foobar2000 on an M1 MacMini under Ventura 13.0 I want to get an bit-perfect output - but Foobar2000 use the Mac Audio-MIDI-Settings.

    I got an hint from Foobar2000 forum to use the LosslessSwitcher.

    But I get this message: "LosslessSwitcher requires Administrator privileges in order to detect each song's lossless sample rate in the Music app."

    My working user on the Mac have no Administrator privileges, I do that for better security.

    What should I do?

    Have anyone tested LosslessSwitcher on an M1 ARM CPU Mac too?

    question 
    opened by macuserguru 3
Releases(1.1.0-beta7)
  • 1.1.0-beta7(Nov 28, 2022)

    A few (minor) changes for this update.

    Changes

    1. Console messages have now been restricted to the Music process only. This is to fix #51. Since the app's core purpose is to serve Apple Music users, there are no guarantees that I would lift this restriction in the future.
    2. Minor UI fix.
    3. Toggle "Detect Local Track Rates" option is added. This option can be used to enable or disable AppleScript-based detection. Enabling it will use AppleScript to get sample rate for local tracks / playlist tracks, but disabling might be good if experienced issue #30.

    About AppleScript Support

    With the introduction of the toggle as mentioned in the above section, third point, users should be able to decide this for themselves, rather than fixating towards using a particular build.

    Source code(tar.gz)
    Source code(zip)
    LosslessSwitcher-beta7-build12.app.zip(661.40 KB)
  • 1.1.0-beta6(Nov 16, 2022)

    This is just a small update that aims to target issue #32.

    To test

    1. Explicitly select the device that you want to playback (not the auto "default device" selection).
    2. Check if device will continue to stick to your selected device, even in circumstances such as EQ / virtual device.
    3. (extra) Check if device will revert to previously selected device after plugging and unplugging said device.

    Known issues

    App device selection menu may glitch out showing 2 checkmarks on app restart, but that should just be a cosmetic issue right now, and should not impact usability. (will fix in future)

    About AppleScript Support

    • Only build 9 contains the AppleScript changes introduced in beta 5.
    • Builds 10 and 11 will not work for local file sample rate switching as a result.
    • This is due to issue #30.
    Source code(tar.gz)
    Source code(zip)
    LosslessSwitcher-beta6-build10.app.zip(656.08 KB)
    LosslessSwitcher-beta6-build11.app.zip(656.35 KB)
    LosslessSwitcher-beta6-build9.app.zip(657.30 KB)
  • 1.1.0-beta5(Sep 1, 2022)

  • 1.1.0-beta4(Jun 26, 2022)

    There is now an option to select the audio device, overriding the default audio device currently selected. The addition of this release, hence, should solve issue #13.

    Release includes everything else introduced in v1.1 build 6/beta 3.

    A big thank you especially for @hatemosphere for the recent sponsor! Also thanks to sponsors @ckortekaas, @luisrjr and an anonymous sponsor for sponsoring this project earlier!

    Thanks for all your support!

    Source code(tar.gz)
    Source code(zip)
    LosslessSwitcher.v1.1-build7-beta4.zip(658.51 KB)
  • 1.1.0-beta3(Jun 26, 2022)

    This release (v1.1, build6, beta3) brings back interval checking from v1.0, and is combined with the audio track change check introduced in earlier betas.

    This hybrid approach should hopefully clear some issues with the audio track change detection method. Interval checking stops after about 10s after track change.

    In addition, a temporary cache should keep the sample rates of recently played tracks, in hopes that when previous tracks are played, if messages did not emit, at least the app can get the data from the cache.

    Sample rate should not change if system detects a new sample rate that is lower than the current one, if track is same.

    May help resolve issues in #17, #10, #8, #3

    A big thank you especially for @hatemosphere for the recent sponsor! Also thanks to sponsors @ckortekaas, @luisrjr and an anonymous sponsor for sponsoring this project earlier!

    Thanks for all your support!

    Source code(tar.gz)
    Source code(zip)
    LosslessSwitcher.v1.1-build6-beta3.zip(652.71 KB)
  • 1.1.0-beta2(May 3, 2022)

    • An additional detection route via Core Media messages have been implemented.
      • aimed at 192kHz/96kHz switching to 48kHz issue
      • there was an earlier iteration with Core Audio messages instead (build 4), but omitted due to message only showing up for 192kHz but not any lower sample rates.
    • abandoned pause/play issue due to #9 side effect
    • App now shows version and build to hopefully make releases less ambiguous?
      • build 3 = v1.1 beta 1
      • build 5 = v1.1 beta 2
      • build 4 = not released in binary form, but can be compiled if wished to (86edbda0710cf2e4078686cb81159e8a1f97d714)

    Failure to trigger may still occur.

    What to test: see if high sample rate audio like 192kHz ones are either switching correctly or not switching (i.e. no 48kHz sightings)

    Source code(tar.gz)
    Source code(zip)
    LosslessSwitcher-v1.1build5.zip(644.49 KB)
  • 1.1.0-beta1(May 1, 2022)

    • now uses private API 😨 (MediaRemote)
    • instead of timer based periodic checking, it should now only check console every time theres a play/pause event (still buggy. some times it doesn't trigger)
    • bug fix (#6, #5, #3, #1)

    Please do expect that sometimes the sample rate may not switch. The new checking method is still rather flaky.

    What to test: if audio above 48 kHz (such as 96/192kHz) correctly switches + that it shouldn't drop back to 48 kHz.

    Source code(tar.gz)
    Source code(zip)
    LosslessSwitcher.zip(642.31 KB)
  • 1.0.0(Apr 23, 2022)

Owner
Vincent Neo
Self-learnt programming initially, with Swift 2.2, now a student, and Apple WWDC20 & WWDC21 Swift Student Challenge Winner. Enjoys Coding and Photography 😊
Vincent Neo
Swift-music - swift-music is a swift package that provides an easy-to-use API for music related developments.

?? swift-music Introduction swift-music is a swift package that provides an easy-to-use API for music related developments. Currently available module

Jin Zhang 4 Feb 8, 2022
Simple command line utility for switching audio inputs and outputs on macOS

Switch Audio Simple command line utility for switching audio inputs and outputs

Daniel Hladík 3 Nov 22, 2022
Classical music front-end for Apple Music: iOS app

concertino_ios Concertino is a classical music front-end for Apple Music. It's splitted in several projects. This one provides only the iOS app. (Ther

Open Opus 107 Dec 22, 2022
A pure Swift Spotify Music App in Apple Music style

HBMusic A pure Swift Spotify Music App in Apple Music style. How to run pod inst

haoboxuxu 6 Dec 29, 2021
The Amazing Audio Engine is a sophisticated framework for iOS audio applications, built so you don't have to.

Important Notice: The Amazing Audio Engine has been retired. See the announcement here The Amazing Audio Engine The Amazing Audio Engine is a sophisti

null 523 Nov 12, 2022
AudiosPlugin is a Godot iOS Audio Plugin that resolves the audio recording issue in iOS for Godot Engine.

This plugin solves the Godot game engine audio recording and playback issue in iOS devices. Please open the Audios Plugin XCode Project and compile the project. You can also use the libaudios_plugin.a binary in your project.

null 3 Dec 22, 2022
YiVideoEditor is a library for rotating, cropping, adding layers (watermark) and as well as adding audio (music) to the videos.

YiVideoEditor YiVideoEditor is a library for rotating, cropping, adding layers (watermark) and as well as adding audio (music) to the videos. YiVideoE

coderyi 97 Dec 14, 2022
iOS music player app that downloads music from the internet, even YouTube

About YouTag is an iOS music player app that downloads music from the internet, even YouTube, and manages it in a local library. Music videos can also

null 263 Jan 8, 2023
An automated insulin delivery app template for iOS, built on LoopKit

Loop for iOS Loop is an app template for building an automated insulin delivery system. It is a stone resting on the boulders of work done by many oth

null 1.1k Jan 4, 2023
This app demonstrates how to use the Google Cloud Speech API and Apple on-device Speech library to recognize speech in live recorded audio.

SpeechRecognitionIOS This app demonstrates how to use Google Cloud Speech API and Apple on-device Speech library to recognize speech in live audio rec

Josh Uvi 0 Mar 11, 2022
🎶 Control Apple Music right from your macOS menu bar.

About Music Bar is macOS application that places music controls right in your menu bar. Installation Download and unzip the latest release. Drag the a

Musa 202 Jan 4, 2023
A small project written with SwiftUI achieves a scrolling effect similar to Apple Music lyrics.

Music Lyrics scrolling animation effect Since the iOS/iPadOS 13 update, Apple has brought a new scrolling lyrics feature to Apple Music. The album im

Huang Runhua 18 Nov 9, 2022
AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS, and tvOS.

AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit 9.5k Dec 31, 2022
AudioPlayer is syntax and feature sugar over AVPlayer. It plays your audio files (local & remote).

AudioPlayer AudioPlayer is a wrapper around AVPlayer. It also offers cool features such as: Quality control based on number of interruption (buffering

Kevin Delannoy 676 Dec 25, 2022
AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

AudioPlayer AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

Tom Baranes 260 Nov 27, 2022
Beethoven is an audio processing Swift library

Beethoven is an audio processing Swift library that provides an easy-to-use interface to solve an age-old problem of pitch detection of musical signals.

Vadym Markov 735 Dec 24, 2022
FDWaveformView is an easy way to display an audio waveform in your app

FDWaveformView is an easy way to display an audio waveform in your app. It is a nice visualization to show a playing audio file or to select a position in a file.

William Entriken 1.1k Dec 21, 2022
SwiftAudioPlayer - Swift-based audio player with AVAudioEngine as its base

SwiftAudioPlayer Swift-based audio player with AVAudioEngine as its base. Allows for: streaming online audio, playing local file, changing audio speed

null 417 Jan 7, 2023
Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS

AudioKit AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit 8.7k Sep 30, 2021