Jump to content
IGNORED

AppleScript to automatically change Sample Rate in Audio MIDI Setup


Bob Stern

Recommended Posts

According to the following article, Snow Leopard allows AppleScripts to access Cocoa frameworks. This hopefully will enable people who understand AppleScript, but who do not know Objective C, to write a script to automatically change the sample rate in Audio MIDI Setup to match the track currently playing in iTunes.

http://www.macworld.com/article/142455-16/2009/08/snow_leopard_tweaks.html

 

Links to several Macworld articles on Snow Leopard. See especially the first article, the main review:

http://www.macworld.com/article/142459/2009/08/snow_leopard.html

 

In another thread, Clay (cfmsp) linked to posts in Apple's Core Audio forum by several Apple engineers on 31 Jan 2008 (that's 2008, not 2009). iTunes engineer Stephen Davis said it was a bug that iTunes must be relaunched to recognize when the user changes the sample rate set in Audio MIDI Setup, so maybe the need to relaunch iTunes will get fixed eventually.

 

However, in the same thread, the Core Audio engineers said they had no plans to change the fact that Audio MIDI Setup does not automatically adapt to the sample rate of the music being played. Their rationale was that OS X is intended to permit multiple applications to simultaneously send audio to the same output device (in which case the outputs are summed), and that it would be improper for one application such as iTunes to automatically change the sample rate of the output device. The main reason was that some audio apps crash if the sample rate of the output device changes while the app is playing audio. It occurs to me that another reason is that there could be a contest among apps as to which one had precedence in controlling the sample rate.

 

HQPlayer (on 3.8 GHz 8-core i7 iMac 2020) > NAA (on 2012 Mac Mini i7) > RME ADI-2 v2 > Benchmark AHB-2 > Thiel 3.7

Link to comment

Hi Bob,

 

Regarding your last alinea - I agree 100% with that. There just would be no way of already playing software let change the sample rate and all. So, first this playback software already exists and doesn't anticipate on it (obviously), and second, if it has to be made / adapted to this, well, I wouldn't know I to do it.

 

People following the Exclusive Mode "discussion" a bit (in the Bel Canto review thread) may now better understand how this is to be solved. So, Microsoft said

 

a. Your incoming email must always be heard, so even when something is playing, the ding-dong comes through BUT will play on the sample rate currently going on (perfectly OK, because who cares about the (better) sample rate the ding-dong will receive);

 

b. If you are so ignorant to not want the ding-dong, you can tell the device it can be used in "Exclusive Mode", which tells as much that the ding-dong will be rejected at the time it wants to play.

 

So, this just avoids the sample rates to be mixed, and all is solved (because sample rates now can change at will as well).

 

Regarding your last sentence, that is solved by (indirectly) telling what is allowed to crash which.

 

Now, am I provocating Microsoft here ? h*ll no. Both MS and Apple are stupid to think we like ding-dongs. If they only could set aside that kind of thinking, all would be inherently bit perfect, and yes, everything would crash the other. But is that a problem ? no, because when I am listening to audio I don't have my email client running. What ? I didn't even install it on the audio PC.

 

Peter

 

Lush^3-e      Lush^2      Blaxius^2.5      Ethernet^3     HDMI^2     XLR^2

XXHighEnd (developer)

Phasure NOS1 24/768 Async USB DAC (manufacturer)

Phasure Mach III Audio PC with Linear PSU (manufacturer)

Orelino & Orelo MKII Speakers (designer/supplier)

Link to comment

Bob Stern commented... "In another thread, Clay (cfmsp) linked to posts in Apple's Core Audio forum by several Apple engineers on 31 Jan 2008 (that's 2008, not 2009). iTunes engineer Stephen Davis said it was a bug that iTunes must be relaunched to recognize when the user changes the sample rate set in Audio MIDI Setup, so maybe the need to relaunch iTunes will get fixed eventually."

So is this now cured? I've not heard if people have tested this recently but always assumed iTunes kept the original sample rate still and we got multiple levels of SRC if Audio Midi was changed while iTunes was loaded.

 

Eloise

 

Eloise

---

...in my opinion / experience...

While I agree "Everything may matter" working out what actually affects the sound is a trickier thing.

And I agree "Trust your ears" but equally don't allow them to fool you - trust them with a bit of skepticism.

keep your mind open... But mind your brain doesn't fall out.

Link to comment

"So is this now cured?"

 

Eloise, as near as I can tell, this is not a bug, but a feature, at last with regards to OS X doing anything about this with Snow Leopard.

 

EDIT: I just re-read and I notice that Eloise was referring to the need to re-start iTunes for a change in AMS to take effect. The comments I posted below are in response to auto-changing the sampling rate (by the OS). Apologies for any confusion.

 

Here's a small portion (of a long thread) about sampling rates on the Metric Halo MIO Forum. This post is by Brian Willoughby (who is very highly regarded there).

 

It's an email list, so I couldn't just provide a link:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

Q: "It would be good if there was an option for playback at file's native rate without having to visit AMS each time. Will things be any different with QT 10 and Snow Leopard, just a few days way now?"

 

Brian: No. What you suggest runs completely contrary to the overall design of CoreAudio and Mac OS X.

 

An audio interface is a shared resource that OSX deems to be "owned" by the user of the computer. An audio interface can only have one sample rate and bit depth at a time, but it can play several audio files at once, and can even have multiple audio programs running at the same time. Therefore, most consumer audio software is supposed to follow Apple's recommendation that the global CoreAudio settings be used as-is, without monkeying with the interface settings every time you play a file.

 

What you're asking for seems like the right thing to do, but only if the entire operating system only allowed one program to play one file at a time. Even then, though, there would be hardware glitches between consecutive files of different rates. Since you ideally want to play two copies of the same file to two interfaces, with each at a different sample rate, you're going to need something more advanced. [note: this last sentence refers to Questioner's earlier specific example]

 

Logic Pro is an exception to this because it is professional software. Logic Pro takes over the audio interface and sets the sample rate and bit depth every time you load or switch focus between songs. You can try to makes changes in AMS, but Logic registers for change notifications and will reset things immediately. Other applications can do this, but it would interfere with Apple's consumer model, and thus the behavior should ideally be limited to professional applications."

 

Clay

 

 

Link to comment

a computer based music server is built on an OS that has to keep in mind that Itunes is not the only audio source.

 

The answer to this issue seems to be right there as well. Apple should develop some sort of hook that allows iTunes to use Logicc Pro's audio engine. Problem solved. Of course we'd have to pay for that, but for people with multi-resolution iTunes libraries, that cost may be small considering the absolute benefit; bit perfect audio nirvana from your 44.1, 96, and 192 audio files, all on the fly.

 

I see another hardware based solution: A new Apple Airport Express Extreme. This new device would play 24/192 and all other file formats. Sample rate would switch on the fly, outside of the computer. The device would probably have to lose it wireless capability because I gather that sending 24/192 over wireless would be an extreme engineering challenge, unless you use microwaves. I can imagine enjoying some nice hi rez jazz while my brain fries:)

 

CD

 

Link to comment

This new device would play 24/192 and all other file formats. Sample rate would switch on the fly, outside of the computer.

 

How do you see this working at pertaining our all ever goal : bit perfect ? or better in this case : no sample rate conversion ?

 

Lush^3-e      Lush^2      Blaxius^2.5      Ethernet^3     HDMI^2     XLR^2

XXHighEnd (developer)

Phasure NOS1 24/768 Async USB DAC (manufacturer)

Phasure Mach III Audio PC with Linear PSU (manufacturer)

Orelino & Orelo MKII Speakers (designer/supplier)

Link to comment

As I understnd it, iTunes, when connecting to an airport express, is really just a delivery truck, sending the audio files as straight data, like a word document, to the express. The express takes care of SPDIFing the data and streaming it to a DAC.

 

Correct me if I'm wrong, though, just my layman's observations.

 

CD

 

Link to comment
  • 4 weeks later...

Fuel, does your script rely on GUI scripting to simulate mouse actions in Audio MIDI Setup? I don't think there is any other way to do it in Tiger or Leopard.

 

In Snow Leopard, AppleScript can directly modify the sample rate parameters in the Core Audio Cocoa Frameworks, and thereby avoid the need for GUI scripting. However, I haven't had time to figure out how to do it.

 

I also don't know whether such an AppleScript developed in Snow Leopard would run in Tiger or Leopard.

 

HQPlayer (on 3.8 GHz 8-core i7 iMac 2020) > NAA (on 2012 Mac Mini i7) > RME ADI-2 v2 > Benchmark AHB-2 > Thiel 3.7

Link to comment
  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...