Jump to content
  • The Computer Audiophile
    The Computer Audiophile

    Semi-Automatic Sample Rate Solution

    speaks.pngComputer Audiophile readers using Mac OS X are very familiar with the sample rate ritual required to play high resolution material through iTunes. In the near future Sonic Studio's Amarra hardware/software package will render this ritual obsolete. Amarra has built-in auto sample rate recognition, in addition to many other great features, that enables listeners to switch between sample rates without touching Audio Midi Setup or closing iTunes. The output from Amarra remains bit perfect at every sample rate up to 24/192. However, Amarra is still being refined before its official release date fairly soon. Plus, the current global economy has most people exercising restraint before shelling out money for items that don't keep the heat on or keep the roof over their head. In the spirit of saving money and increasing convenience I now present CA-SampleRate my semi-automatic sample rate solution. Did I mention it's free? <a href="http://en.wiktionary.org/wiki/free_as_in_beer">(As in beer)</a>

     

    [PRBREAK][/PRBREAK]

     

     

     

     

     

    <b>What's The Problem?</b>

     

    As I stated in the opening paragraph Mac OS X with iTunes has an issue with playing material of varying sample rates. Here is what a typical listening experience with iTunes on Mac and content with differing sample rates looks like.

     

    1. Open Audio Midi and set sample rate to 16/44.1.

    2. Open iTunes and play only 16/44.1 content bit perfect every time.

    3. Close iTunes.

    4. Change Audio Midi to 24/96.

    5. Open iTunes and play only 24/96 content bit perfect every time.

    6. Follow this pattern every time a sample rate change is required.

     

    As you can see switching sample rates is a process that takes a person out of the music listening state of mind. This process makes the Mac feel more like a computer than a music server that can take your mind anywhere the music drifts. Not only does the listener have to manually adjust the sample rate, but the listener also must close iTunes and reopen the application for it to output bit perfect audio. Simply changing the sample rate in Audio Midi without closing and reopening iTunes only degrades the sound. In layman's terms iTunes only cares about the sample rate at the time iTunes is opened. This whole process may not sound that bad, but it really gets old. As one collects more high resolution material this annoyance only gets bigger.

     

     

     

    <b>CA-SampleRate = Semi-Automatic</b>

     

    The other night I was thinking of a way to make this whole sample rate situation much more convenient. Knowing that I wasn't out to reinvent the Amarra wheel I focused on the Mac OS X Automator. After about one hour of trial and error with different methods I settled on what I believe is a really cool, convenient, and simple semi-automatic solution.I call it the CA-SampleRate application.

     

    Running this little application does the following:

     

    1. Closes iTunes, if open.

    2. Launches Audio Midi Setup.

    3. Pauses for eight seconds enabling a sample rate adjustments by the listener.

    4. Closes Audio Midi Setup automatically.

    5. Reopens iTunes

     

     

     

    Using CA-SampleRate in the aforementioned listening session would now look like this:

     

    1. Open Audio Midi and set sample rate to 16/44.1.

    2. Open iTunes and play only 16/44.1 content bit perfect every time.

     

    <s>3. Close iTunes.</s>

    <s>4. Change Audio Midi to 24/96.</s>

    <s>5. Open iTunes and play only 24/96 content bit perfect every time.</s>

    <s>6. Follow this pattern every time a sample rate change is required.</s>

     

    3. Click <b>CA-SampleRate</b> and select the correct sample rate when Audio Midi pops up.

    4. Continue listen to music at new sample rate.

     

     

     

     

    <b>Now What?</b>

     

    Simply download the zip file containing the CA-SampleRate application and unzip it to your applications folder. I recommend going one step further and dragging the application to the Dock so you have one-click access to this new simple semi-automatic solution. Then start listening in iTunes as usual and run the app whenever you need to change sample rates. The application does what it's supposed to do and then exits so there are no extra items running inthe background on your music server. Note: Please feel free to modify CA-SampleRate in any way that simplifies the process, then share your idea with the other Computer Audiophile readers. I'm also hoping that a reader can come up with an Apple script to change the sample rate as part of this Automator application. I spent a little time on this part, but wanted to get the application out the door before I really dug into the script. Here is a little video of CA-SampleRate in action, followed by a screenshot of the Automator actions and the zip file containing the actual application for all the Mac users. Enjoy :~)

     

     

     

     

     

    <center>

    <a href="http://files.computeraudiophile.com/2009/0218/CA-SampleRate.zip">Click here to download the CA-SampleRate application</a>

    </center>

     

     

     

     

     

    <center>CA-SampleRate Demonstration</center>

     

    <center>

    <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="210" width="320">

     

    <param name="src" value="http://video.computeraudiophile.com/2009/0218/CA-SampleRate.mov">

    <param name="autoplay" value="false">

    <param name="type" value="video/quicktime" height="210" width="320">

     

    <embed src="http://video.computeraudiophile.com/2009/0218/CA-SampleRate.mov" height="210" width="320" autoplay="false" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/">

     

    </object>

    </center>

     

     

     

     

     

    <center>

    <img src="http://images.computeraudiophile.com/graphics/2009/0218/CA-SampleRate-Settings.png">

    </center>

     

     

     

     




    User Feedback

    Recommended Comments



    hi Chris, i was just experimenting with various sample rate settings on my Mac (connected to a Berkeley Alpha DAC) & find the "96kHz audio midi setting" sounds *significantly* better than the "44kHz audio midi setting". this is regardless whether i'm playing 16/44 or 24/96 files.<br />

    <br />

    this seems unusual to me because i'd imagine the computer is having to upsample the 16/44 files. anyway, was just wondering why this might be so, & if this is consistent with other people's experience?

    Share this comment


    Link to comment
    Share on other sites

    Hello,<br />

    <br />

    This is already a great solution but there are several Apple Scripts online who try to tackle the same problem. GUI scripting (Apple Script executes commands that mimic user interactions) seems to be the way to achieve a one click solution. <br />

    <br />

    Here is one script that changes the audio source :<br />

    http://www.macosxhints.com/article.php?story=20050614171126634<br />

    <br />

    It should be possible to adopt the source to the sample rate change. <br />

    <br />

    With applications like Quicksilver or Butler you can then assign the scripts/apps to keyboard-shortcuts. What would be really amazing is to create an Iphone app that would trigger remotely this script. I think that it's feasible (even if not very elegant) but that's clearly out of my league .... <br />

    <br />

    Laurent

    Share this comment


    Link to comment
    Share on other sites

    I'm not an Apple eater so can't try this for myself, but could you make the script fully automatic for one particular sample rate and then have 2/3/4/ scripts, one for each sample rate you need? Name each script for its sample rate and just click the one you want?<br />

    <br />

    Just a thought.

    Share this comment


    Link to comment
    Share on other sites

    Hi guys, <br />

    <br />

    thanks for this Chris. I've been a lurker here for some time, soaking up all the useful info on offer!<br />

    <br />

    Just a quick heads-up for those using the iphone/ipod touch to control their iTunes and want to stay firmly planted to their sofa's. I noticed on the 'App store' a few cheap VNC clients which would allow the whole 'quit/midi/re-open' dance direct from the iphone/touch.<br />

    <br />

    Still the same dance but without the trip to the dance hall :)<br />

    <br />

    <br />

    Share this comment


    Link to comment
    Share on other sites

    The responses here are really col guys, thanks. I think we can accomplish the fully automatic one-click solution, but it's going to take a group effort. <br />

    <br />

    One question for the group - I investigated using keyboard commands to automatically change the sample rate but I could not get the cursor focused on the sample rate (it's not a tab stop that's for sure) without using a mouse. Once I used the mouse all bets were off for automating the operation because mouse recording is so rudimentary. It records the location on the screen that is clicked, not the actual item that was clicked etc ... I'm sure you all are well aware of this given the great technical details you've provided so far.<br />

    <br />

    <br />

    Based on the responses so far what do you guys think is the best path forward to get a one-click solution working for each sample rate? It would be cool to look at the most probably solution first etc... I'm very excited and energized by this one and think everyone will benefit if we can come up with a solution! Thanks guys!<br />

    <br />

    Share this comment


    Link to comment
    Share on other sites

    Use up & down arrows to select an item in the sample rate popup menu. For example, to select the second item, press option up arrow to move to the top of the popup menu, then down arrow (without the option key) to move to the second item, then press return key to select it.<br />

    <br />

    That's the method used in the example AppleScript I posted.

    Share this comment


    Link to comment
    Share on other sites

    This problem should be pretty easy to solve actually, now that you had the inspiration to try and solve the problem. I've written some AppleScript using UI scripting to automate the opening of multiple applications in sequence. The problem with Automator is it can only use commands that have been built into the application. A lot of applications don't have commands build in, therefore you have to rely on UI scripting, which is a bit clunky but once you've figured it out not that problematic.<br />

    <br />

    I'll have a play tonight and post some working code on the site. I would be surprised if someone else doesn't get there first though...

    Share this comment


    Link to comment
    Share on other sites

    So nice to see Apple programmers here. Thanks guys for this eventual little app! In the old days you had to apologize for owning a Mac :-)

    Share this comment


    Link to comment
    Share on other sites

    The command that opens the sample rate menu is:<br />

    tell combo box 1 to click button 1<br />

    <br />

    It's in my code directly under the comment "Sample rate (frequency) popup menu".

    Share this comment


    Link to comment
    Share on other sites

    Audio Midi Setup has no built-in AppleScript dictionary or Automator Actions, so you cannot do it via AppleScript or Automator commands.<br />

    <br />

    You can do it by scripting keystrokes using Apple's kludgy UI (User Interface) Scripting:<br />

    http://www.apple.com/applescript/uiscripting/<br />

    <br />

    If you want to play with UI scripting, save yourself some grief and buy Prefab UI Browser for $55:<br />

    http://prefabsoftware.com/uibrowser/<br />

    <br />

    A much easier solution than UI scripting is the nice interface of QuickKeys, $80:<br />

    http://www.startly.com/products/qkx.html<br />

    <br />

    I am not sure, but I do not believe the cheaper macro programs iKeys and Keyboard Maestro can control popup menus.<br />

    <br />

    To get you started, here's an AppleScript I created using Prefab UI Browser. If you paste it into a Script Editor window and save it, it will reformat with indentation to make it more readable:<br />

    <br />

    set PropertiesMenuDelta to {121, 144} --Offset of Properties button from Close button = {1342, 170} - {1221, 26} <br />

    set PropertiesMenuPos to {0, 0}<br />

    <br />

    set choice to button returned of (display dialog "Choose Sample Rate:" buttons {"44.1", "96", "Cancel"} cancel button "Cancel")<br />

    <br />

    activate application "Audio MIDI Setup"<br />

    tell application "System Events"<br />

    click menu item "Audio MIDI Setup" of menu 1 of menu bar item "Window" of menu bar 1 of process "Audio MIDI Setup" --Bring window to front, or else keystrokes fail.<br />

    <br />

    tell window "Audio MIDI Setup" of process "Audio MIDI Setup"<br />

    set CloseButtonPos to position of button 1<br />

    <br />

    -- Properties popup menu: --<br />

    repeat with i from 1 to 2<br />

    set item i of PropertiesMenuPos to (item i of CloseButtonPos) + (item i of PropertiesMenuDelta)<br />

    end repeat<br />

    tell tab group 1 to click (first pop up button whose position is PropertiesMenuPos)<br />

    <br />

    -- Select "Built-in Output" (last item in popup menu):<br />

    delay 0.5<br />

    key code 125 using option down -- jump to bottom of list<br />

    delay 0.5<br />

    key code 36 -- Return key works better than Enter.<br />

    delay 1 --Wait for window to redraw.<br />

    <br />

    <br />

    -- Sample rate (frequency) popup menu: --<br />

    <br />

    if choice is "44.1" then<br />

    -- Select "44.1" (first item in popup menu):<br />

    tell combo box 1 of tab group 1 to click button 1<br />

    delay 0.5<br />

    key code 126 using option down -- Opt-UpArrow jumps to top of list.<br />

    delay 0.5<br />

    key code 36 -- Return key. (Enter does nothing.)<br />

    --click button 1 -- Useless: reverts to original setting.<br />

    end if<br />

    <br />

    if choice is "96" then<br />

    --Select "96" (last item in popup menu):<br />

    tell combo box 1 of tab group 1 to click button 1<br />

    delay 0.5<br />

    key code 125 using option down -- Opt-DownArrow jumps to bottom of list.<br />

    delay 0.5<br />

    key code 36 -- Return key. (Enter does nothing.)<br />

    end if<br />

    end tell<br />

    end tell<br />

    --delay 1.5 --Wait for sample rate to change before next step.<br />

    <br />

    Share this comment


    Link to comment
    Share on other sites

    I edited the AppleScript I posted yesterday. The edits fix a problem in which Audio MIDI Setup did not come to the front; add a dialog allowing the user to choose between two sample rates; and eliminate two levels of nested Tell's to make it more understandable.<br />

    <br />

    Even if you don't know AppleScript, you can observe it in action by launching Script Editor (in Applications > AppleScript), pasting the script into an empty Script Editor window, saving it, and then clicking the Run button.

    Share this comment


    Link to comment
    Share on other sites

    Chris<br />

    <br />

    I've send an email to editor at computeraudiophile.com with an applescript. Try it out and let me know if it works for you. <br />

    <br />

    Edit 1; One of the problems with my script is that I think may be getting consistency across user's computers due to different options available in Audio Midi...i.e. different clicks do different things<br />

    <br />

    Edit 2; I see Bob has a solution for that; I'll try it tomorrow night and see if it works<br />

    <br />

    Fuel

    Share this comment


    Link to comment
    Share on other sites

    Unfortunately, CA-SampleRate doesn't appear to run under Mac OS X Tiger. :(<br />

    <br />

    I presume it's specifically for Leopard?<br />

    <br />

    --<br />

    djp

    Share this comment


    Link to comment
    Share on other sites

    Maybe not an OSX issue -- I get the message, "You cannot open the application "CA-SampleRate" because it is not supported on this architecture."<br />

    <br />

    This is on an aluminum Powerbook G4 1.67gHz running OSX 10.4.11.<br />

    <br />

    Darn!<br />

    <br />

    Applescript should work though.<br />

    <br />

    Question:<br />

    <br />

    Could the good samaritans posting the Applescript examples add script for changing to 24/176.4 and 24/192 as well as 24/96? Thanks!<br />

    <br />

    Steve Z

    Share this comment


    Link to comment
    Share on other sites

    Hi Steve - The CA app won't run on older software/hardware. Work continues on this whole thing offline and I hope to have something soon.

    Share this comment


    Link to comment
    Share on other sites

    Hi guys. Thanks Chris for this wonderful site. This is my first time. I'm sure I'll hang around on this forum a lot in the future.<br />

    Anyway, I was wandering what happens with sample rate when I play lossless compressed music. I have a m-audio firewire 410 DAC and I use play to listen to music. Let's say I have a 24/192 m4a file. I guess I have to set m-audio control panel to 192 khz to listen to the song in the right way, isn't it so? What happens if leaving the settings to 192 I play now a 44.1 song? Does it depends on the playback program and how it handles comversion of lossless files or is it irrelevant?<br />

    Isn't there a way to listen to compressed or even uncompressed files the right sample rate just by playing them in a particular program? I see that my DAC control panel doesn't change its settings the right way when I skip from a 44.1 to a 192 or 96 or any other sample rate file. Can the Songbird program be helpful in this in some way?<br />

    <br />

    Thank to anyone will try to make me understand...

    Share this comment


    Link to comment
    Share on other sites

    Chris,<br />

    <br />

    I'm externally clocking my Lynx card. When I change the frequency on my clock, the frequency in Audio Midi automatically changes to match. Would there be a way to create a script that reads this change, and closes/reopens iTunes?<br />

    <br />

    That would be "automatic" sample rate change in my book. . .<br />

    <br />

    Thanks,<br />

    <br />

    Bob

    Share this comment


    Link to comment
    Share on other sites

    Chris,<br />

    <br />

    I am talking to some Apple engineers to see if there is a command line ability to set Auido Midi. From reading the Core Audio stuff in the Apple developers site it should be doable. If the command line parameters exist it will be a very simple script to change settings. I should here something back this week.<br />

    <br />

    Chuck

    Share this comment


    Link to comment
    Share on other sites

    Hi Chuck - This sounds very cool! Now that I think about it, setting Audio Midi should be very doable through the command line because virtually all gui interfaces are just good looking tools to submit commands behind the scenes.

    Share this comment


    Link to comment
    Share on other sites

    Can't anybody answer to my question?

    Share this comment


    Link to comment
    Share on other sites

    Your Automator workflow is a big step forward Chris, but a full set-it-and-forget-it application/preference would put us on the mountaintop! :)<br />

    <br />

    It looked like there was some pretty good progress being made here in that direction, but it's been quiet for a while?

    Share this comment


    Link to comment
    Share on other sites




    Guest
    This is now closed for further comments




×
×
  • Create New...