Spektrum - How-to Speedily Scan RF Noise in band 24MHz ~ 1800MHz

Build Spektrum on MacOS/x86_64

First of all, thanks for this great guide! I have been kind of obsessed with Spektrum since I read abcd567's mention from back when, because a $35 spectrum analyzer had never appeared even in my wildest dreams. A GHz analyzer. What?!

I don't have easy access to a WinTel or LinTel device. Besides Raspberry Pi, my main workstations are MacTel. Whereas ARM is still giving me segment fault, I finally managed a Mac/x86 build after patching pavels' source. Specifically, the "build" part focuses on his rtl-sdr fork.

Prerequisites

  • JRE (Java runtime environment), obviously. Pre-Big Sur, this would be a no-brainer because MacOS comes with one Java preinstalled. But if you use Big Sur (MacOS 11) or later, you are on your own.

    In my test, I didn't install OpenJDK because I ran into some complexities in my work prior to this. Instead, I let Processing deal with Java licensing, because prepackaged Processing, like prepackaged Spektrum, comes with JRE, and I already had Processing installed..

    *If you do use OpenJDK, make sure to delete accessibility.properties.

  • cmake. I was able to build from source, but it takes up too much disk so I replaced it with prebuilt package. (Whereas http://sdr.osmocom.org/trac/wiki/rtl-sdr describes autoreconf as an alternative, I found it troublesome on some platforms; in fact there doesn't seem to be a Mac port for it. Although automake is supposed to be an alternative to autoreconf, I didn't have time to try it.)
  • libusb 1.0. I used MacPorts to install a prebuilt package, although you can also build from source. (I know that Homebrew is all the rage; in fact libusb only officially recognize Homebrew. But I already use XCode command lines from App Store. Installing another XCode command line tool feels like calling for trouble to me. (Homebrew forces you to download XCode CLT from their custom site.)
    sudo /opt/local/bin/port install libusb
    One caveat with MacPorts is that it installs everything (including itself) under /opt file system instead of the traditional /usr.
    • Theoretically the installer should add /opt/local/bin to your PATH. But if you already have .profile in your home directory, it won't. So you may want to add to PATH yourself; otherwise you need to invoke the full path.
    • In addition to PATH, many build systems also do not include the more modern /opt paths. This is why I had to patch pavels' code. (The patch is already merged back so it now works with both MacPorts and HomeBrew.)

    Downloads

    • Spektrum Linux tarball.
      curl -Ospektrum-linux64.tar.gz https://github.com/pavels/spektrum/releases/download/2.1.0/spektrum-linux64.tar.gz
    • pavels’ rtl-sdr fork.
      git clone https://github.com/pavels/rtl-sdr
    • Compile and insall

      In this section, I shall assume that you only want to install into your own home directory so everything is done as your own user. Also assume that the tarball as well as rtl-sdr git source are both directly under the home directory.

      1. Install Spektrum Linux tarball.
        cd # return to $HOME
        tar xzf spektrum-linux64.tar.gz
        
      2. Compile librtlsdr and librtlpower.
        cd ~/rtl-sdr
        mkdir build
        cd build
        /Applications/CMake.app/Contents/bin/cmake ../
        make
        
        • /Applications/CMake.app/Contents/bin/cmake is the path used by cmake installer. If you install cmake by some other method or compile it from source, adjust path accordingly.
        • CMake’s Mac port also has a GUI for you to use. I am just too lazy to learn.
      3. (Continue from previous step. You are still in ~/rtl-sdr/build/) Install librtlsdr and librtlpower.
        for name in sdr power; do cp -p src/lib$name.dylib ~/spektrum/lib/; done
        
      4. Update spektrum script.
        cat <<EOM>~/spektrum/specktrum
        #!/bin/sh
        # This is a MacOS hack specific to "borrow" preinstalled Processing 3.5.4
        JRE_HOME=$HOME/Applications/Processing.app/Contents/PlugIns/jdk1.8.0_202.jdk/Contents/Home/jre
        APPDIR=$(dirname "$0")
        
        $JRE_HOME/bin/java -Djna.nosys=true -Djava.ext.dirs="$JRE_HOME/ext" -Djava.library.path="$APPDIR:$APPDIR/lib" -cp "$APPDIR:$APPDIR/lib/spektrum.jar:$APPDIR/lib/core.jar:$APPDIR/lib/jogl-all.jar:$APPDIR/lib/gluegen-rt.jar:$APPDIR/lib/jogl-all-natives-linux-amd64.jar:$APPDIR/lib/gluegen-rt-natives-linux-amd64.jar:$APPDIR/lib/controlP5.jar:$APPDIR/lib/bridj.jar:$APPDIR/lib/rtlspektrum.jar:$APPDIR/lib/serial.jar:$APPDIR/lib/jssc.jar" spektrum "$@“
        EOM
        ^D
        
        • In the above, ^D means to press “control” and “D” keys together.
        • The JRE_HOME is specific to pre-installed Processing 3.5.4 that includes jdk1.8.0_202. If you use another JRE, use its appropriate path. (If you installed any Java, OpenJDK or Oracle, there are many Internet documents to help you find the JRE_HOME. That is where all the “fun” begins.)

      Run spektrum

      From terminal,
      ~/spektrum/spektrum
      
      See this thread for sample scans.
2 Likes