<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://www.aelius.com/njh/feed.xml" rel="self" type="application/atom+xml" /><link href="https://www.aelius.com/njh/" rel="alternate" type="text/html" /><updated>2025-06-22T08:44:06+01:00</updated><id>https://www.aelius.com/njh/feed.xml</id><title type="html">njh</title><subtitle>Nicholas Humfrey&apos;s Blog</subtitle><entry><title type="html">Receiving AES67 audio on the command line</title><link href="https://www.aelius.com/njh/posts/0002" rel="alternate" type="text/html" title="Receiving AES67 audio on the command line" /><published>2018-03-24T23:30:00+00:00</published><updated>2018-03-24T23:30:00+00:00</updated><id>https://www.aelius.com/njh/posts/0002</id><content type="html" xml:base="https://www.aelius.com/njh/posts/0002"><![CDATA[<style type="text/css">
  .screenshot {
    width: 80%;
    display: block;
    margin: 0 auto;
  }
</style>

<p>In this blog post I will describe how to record audio transmitted by an <a href="http://www.aes.org/publications/standards/search.cfm?docID=96">AES67</a> compatible device to disk of a computer, using Open Source command line tools.</p>

<p><a href="http://www.aes.org/publications/standards/search.cfm?docID=96">AES67</a> is a standard for sending high-quality audio over an IP network. Like many other professional audio standards, it is specified by the <a href="http://www.aes.org/">Audio Engineering Society</a>.</p>

<p>Rather than creating a whole new competing standard, <a href="http://www.aes.org/publications/standards/search.cfm?docID=96">AES67</a> specifies how existing internet standards can be used together in the context of professional audio. Some of the standards it is based upon are:</p>

<ul>
  <li>IP Multicast / IGMP - <a href="https://tools.ietf.org/html/rfc2236">RFC 2236</a></li>
  <li>Real-time Transport Protocol (RTP) - <a href="https://tools.ietf.org/html/rfc3550">RFC 3550</a></li>
  <li>Precision Time Protocol (PTP) - <a href="https://standards.ieee.org/findstds/standard/1588-2008.html">IEEE 1588-2008</a></li>
  <li>Session Description Protocol (SDP) - <a href="https://tools.ietf.org/html/rfc4566">RFC 4566</a></li>
  <li>DiffServ QoS - <a href="https://tools.ietf.org/html/rfc2474">RFC 2474</a></li>
</ul>

<p>While there is an ever-increasing number of commercial products that support AES67, there is not very much Open Source software or information. I am hoping to start changing that by writing about it.</p>

<h2 id="glensound-aoip44">Glensound AOIP44</h2>

<p>I decided to buy a <a href="http://www.glensound.co.uk/product-details/aoip44">Glensound AOIP44</a>, as a reference implementation for my open source <a href="http://www.aes.org/publications/standards/search.cfm?docID=96">AES67</a> experiments.</p>

<p>Features:</p>

<ul>
  <li>Audinate <a href="https://www.audinate.com/solutions/dante-overview">Dante</a> UltimoX4 chipset</li>
  <li>4 balanced audio input and output channels</li>
  <li>19” rack-mountable 1U enclosure</li>
  <li>Can be powered by PoE</li>
</ul>

<p><img src="https://www.aelius.com/njh/images/0002-glensond-aoip44-rear.jpg" alt="Glensound AOIP44 Rear" /></p>

<p>So why did I choose to buy the <a href="http://www.glensound.co.uk/product-details/aoip44">Glensound AOIP44</a> over other products?</p>

<ul>
  <li><a href="https://www.audinate.com/solutions/dante-overview">Dante</a> has become one of the most common implementations of Audio over IP</li>
  <li>Although expensive for a personal purchase, it was cheaper than other options</li>
  <li>Glensound are based in the UK and have a reputation for building solid, reliable hardware</li>
  <li>Glensound design and build equipment for use in broadcast - which is my area of interest</li>
</ul>

<p><strong>Note: not all Dante devices support AES67 - double check before purchasing.</strong></p>

<h2 id="configuring-aes67">Configuring AES67</h2>

<p>By default, Dante devices use a proprietary protocol and can only communicate with other Dante devices. However, on newer devices, it is possible to enable 
AES67. The following steps are what is required to set up an AES67 multicast stream.</p>

<h3 id="step-1">Step 1</h3>

<p>Open Dante Controller and select the <em>Device View</em> menu item from the <em>Device</em> menu:</p>

<p><img src="https://www.aelius.com/njh/images/0002-aoip44-aes67-config-step1.png" alt="Dante Controller - Device View Menu" class="screenshot" /></p>

<h3 id="step-2">Step 2</h3>

<p>Select the <em>AES67 Config</em> tab and change the AES67 mode to <em>Enabled</em>. You will need to press the <em>Reboot</em> button after enabling it.</p>

<p><img src="https://www.aelius.com/njh/images/0002-aoip44-aes67-config-step2.png" alt="Dante Controller - AES67 Config" class="screenshot" /></p>

<h3 id="step-3">Step 3</h3>

<p>After the device has finished rebooting, the next step is to create a Multicast Flow. This can be done by selecting the <em>Create Multicast Flow</em> menu item in the <em>Device</em> menu.</p>

<p><img src="https://www.aelius.com/njh/images/0002-aoip44-aes67-config-step3.png" alt="Dante Controller - Create Multicast Flow" class="screenshot" /></p>

<h3 id="step-4">Step 4</h3>

<p>A dialogue box will pop-up, allowing you to choose the Channels that you would like to add to the Multicast Flow. You must also tick the checkbox to make it an AES67 flow.</p>

<p><img src="https://www.aelius.com/njh/images/0002-aoip44-aes67-config-step4.png" alt="Dante Controller - Configure Multicast Flow" class="screenshot" /></p>

<p>At this point, the RTP audio packets will start being sent out of the network port. If you have a dumb switch (that doesn’t support IGMP snooping), then those packets will be being sent to every other port on the switch.</p>

<h3 id="step-5">Step 5</h3>

<p>Under the <em>Transmit</em> tab, you should now be able to see the Multicast Flows that have been set up. Make a note of the multicast IP address that the AES67 flow is being sent to (it will be in the format 239.x.x.x). We will use this when recording the stream.</p>

<p><img src="https://www.aelius.com/njh/images/0002-aoip44-aes67-config-step5.png" alt="Dante Controller - Viewing Multicast Flows" class="screenshot" /></p>

<h2 id="recording-the-stream">Recording the stream</h2>

<p>We are going to use two different command line tools to record the RTP stream:</p>

<ul>
  <li>rtpdump (part of <a href="http://www.cs.columbia.edu/irt/software/rtptools/">RTP Tools</a>)</li>
  <li><a href="http://sox.sourceforge.net/">SoX</a> (aka the Swiss Army knife of sound processing)</li>
</ul>

<p>Both these tools can be installed on Mac OS using <a href="http://brew.sh/">Homebrew</a>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>brew install rtptools sox
</code></pre></div></div>

<p>Sox can be installed on Debian/Ubuntu using:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>apt-get install sox
</code></pre></div></div>

<p>RTP Tools for other operating systems are listed on the <a href="http://www.cs.columbia.edu/irt/software/rtptools/download/">downloads page</a>.</p>

<p>First we are going to verify that we are receiving the stream correctly. <code class="language-plaintext highlighter-rouge">rtpdump</code> will print a very rapid stream of output, displaying one line showing the parameters for each RTP packet received:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ rtpdump 239.65.125.63/5004
1521848203.141443 RTP len=300 from=169.254.98.63:61440 v=2 p=0 x=0 cc=0 m=0 pt=97 (????,0,0) seq=46327 ts=1526026162 ssrc=0xfe7df7a7 
1521848203.141529 RTP len=300 from=169.254.98.63:61440 v=2 p=0 x=0 cc=0 m=0 pt=97 (????,0,0) seq=46328 ts=1526026210 ssrc=0xfe7df7a7 
1521848203.141543 RTP len=300 from=169.254.98.63:61440 v=2 p=0 x=0 cc=0 m=0 pt=97 (????,0,0) seq=46329 ts=1526026258 ssrc=0xfe7df7a7 
1521848203.141970 RTP len=300 from=169.254.98.63:61440 v=2 p=0 x=0 cc=0 m=0 pt=97 (????,0,0) seq=46330 ts=1526026306 ssrc=0xfe7df7a7 
1521848203.142924 RTP len=300 from=169.254.98.63:61440 v=2 p=0 x=0 cc=0 m=0 pt=97 (????,0,0) seq=46331 ts=1526026354 ssrc=0xfe7df7a7 
</code></pre></div></div>

<p>The multicast address <code class="language-plaintext highlighter-rouge">239.65.125.63</code> is the address that the audio is being sent to. This is the address shown in Dante Controller under the Transmit Tab of the Device View. The port <code class="language-plaintext highlighter-rouge">5004</code> is the default port to send RTP packets to and is recommended as part of AES67. I had trouble recording with my laptop because it had two network interfaces. Disabling Wifi allowed me to receive the multicast stream.</p>

<p>Next, we are going to record the RTP stream to disk:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>rtpdump -F payload -o radio4.raw 239.65.125.63/5004
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">-F payload</code> option specifies that only the payload part of the RTP packets (the audio) is written to the output file. <code class="language-plaintext highlighter-rouge">-o</code> specifies the filename to write the audio to.</p>

<p>The output file is just the raw audio, with no wrapper/metadata to explain to other software the format of the audio. We are going to use the <code class="language-plaintext highlighter-rouge">sox</code> to command to convert the raw audio into a Wav file:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sox -t s24 -B -r 48000 -c 2 radio4.raw radio4.wav
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">-t s24</code> option specifies that the input audio is in L24 format (signed integer linear 24-bit PCM samples). The <code class="language-plaintext highlighter-rouge">-B</code> option specifies that the samples are ‘Big Endian’, also known as Network Byte Order. The <code class="language-plaintext highlighter-rouge">-r 48000</code> option specifies the sample rate of the audio and finally <code class="language-plaintext highlighter-rouge">-c 2</code> specifies that there are two channels (stereo).</p>

<p>Rather than running the commands separately, you can instead combine both commands together using a Unix pipe and write directly to a Wav file:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>rtpdump -F payload 239.65.125.63/5004 | \
  sox -t s24 -r 48000 -c 2 -B - recording.wav
</code></pre></div></div>

<p>Or you can play the stream through your local sound card using:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>rtpdump -F payload 239.65.125.63/5004 | \
  play -t s24 -r 48000 -c 2 -B -
</code></pre></div></div>

<h2 id="whats-next">Whats Next?</h2>

<p>Over a decade ago I was working on a <a href="https://github.com/njh/mast">Multicast Audio Streaming Toolkit</a> (MAST). It would be fantastic to bring it up to date and working with AES67.</p>

<p>I have also written an <a href="https://gist.github.com/njh/c9196c465ea33ae9f97db782870464ef">AES67 Open Source Software Wishlist</a>.</p>]]></content><author><name></name></author><category term="AES67" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Controlling lighting using RS Pro Logic / Genie NX</title><link href="https://www.aelius.com/njh/posts/0001" rel="alternate" type="text/html" title="Controlling lighting using RS Pro Logic / Genie NX" /><published>2018-01-21T12:00:00+00:00</published><updated>2018-01-21T12:00:00+00:00</updated><id>https://www.aelius.com/njh/posts/0001</id><content type="html" xml:base="https://www.aelius.com/njh/posts/0001"><![CDATA[<p>For a few years, I have been looking into different ways of controlling home lighting. The goal is to be able to turn lights on and off using a computer interface, enabling lights various types of remote control and automation:</p>
<ul>
  <li>Turned on at sunset and off at midnight</li>
  <li>Using a remote control, or mobile phone</li>
  <li>Voice control using Alexa or Google Home</li>
  <li>Switch off all the lights in a room at once</li>
</ul>

<p>However, I am also keen to ensure that lights can still be turned on and off using a light switch, as normal, even if part of the system fails.</p>

<p><img src="https://www.aelius.com/njh/images/0001-marmitek-ad10.jpg" alt="RS Pro Logic 110v-240v no LCD" /></p>

<p>The first home automation system I tried was <a href="https://en.wikipedia.org/wiki/X10_(industry_standard)">X10</a>. I had a <a href="https://www.uk-automation.co.uk/marmitek-x10-din-rail-switch/">Marmitek AD10</a> connected to the landing lights. What was great about this is that it worked really well with the existing home lighting wiring. It had two control inputs:</p>

<ul>
  <li>Input 1 responds to a change of state, so can be used with a normal light
switch (switching the circuit on or off will toggle the light).</li>
  <li>Input 2 toggles between on/off when it receives a pulse - so can be used
with a retractive switch (that springs back like a doorbell).</li>
</ul>

<p>Sadly there are a couple of reasons why I stopped using <a href="https://en.wikipedia.org/wiki/X10_(industry_standard)">X10</a>:</p>
<ol>
  <li>The main reason is that while the system worked fine for a few months, some
kind of power line interference meant that it stopped working reliably.</li>
  <li>The modules seemed to have a short life expectancy and I had a couple
completely stop working. Replacing them got expensive.</li>
  <li>As is typical of X10, the module only responds to commands and does not
broadcast its status. This means that if someone operates the switch, it is
not possible for a computer to know if the lights are currently on or off.</li>
</ol>

<h2 id="rs-pro-logic">RS Pro Logic</h2>

<p>I have been aware of the <a href="https://en.wikipedia.org/wiki/Modbus">Modbus</a> control protocol for a while but never tried it out partly due expense. Modbus is typically used in industrial control and automation applications to control <a href="https://en.wikipedia.org/wiki/Programmable_logic_controller">Programmable Logic Controllers</a>. At its most basic, it allows you to send messages to multiple devices connected to a serial port bus, switching on and off outputs and reading inputs.</p>

<p>While searching the RS website, I found they had an own-brand range of <a href="https://en.wikipedia.org/wiki/Programmable_logic_controller">Programmable Logic Controllers</a>, under the brand name <a href="https://uk.rs-online.com/web/generalDisplay.html?id=footer1/release/160712_rs_pro_logic_controllers_uk">RS Pro Logic</a>.</p>

<p><img src="https://www.aelius.com/njh/images/0001-rs-pro-logic.jpg" alt="RS Pro Logic 110v-240v no LCD" /></p>

<p>There are four different versions of the RS Pro Logic available:</p>

<ul>
  <li><a href="https://uk.rs-online.com/web/p/logic-modules/9176370/">12v-24v with LCD</a> (£78.97)</li>
  <li><a href="https://uk.rs-online.com/web/p/logic-modules/9176370/">110v-240v with LCD</a> (£78.97)</li>
  <li><a href="https://uk.rs-online.com/web/p/logic-modules/9176377/">12v-24v no LCD</a> (£62.86)</li>
  <li><a href="https://uk.rs-online.com/web/p/logic-modules/9176373/">110v-240v no LCD</a> (£62.86)</li>
  <li><a href="https://uk.rs-online.com/web/p/plc-accessories/9176395/">USB Adaptor</a> (£13.79)</li>
</ul>

<p>(Prices correct at time of publishing)</p>

<p>There are also expansion modules (extra IO), RS-485 adaptors and memory cards available in the range.</p>

<p>While not cheap, they are cheaper than I was expecting. And while you can only control a single output with the X10 module, you can control 4 outputs with the RS Pro Logic module.</p>

<p>There is surprisingly little documentation about the RS Pro Logic module on the RS website. All they provide is a datasheet and software download. When I asked for a manual, they sent me a copy of the manual for the <a href="http://gicindia.com/products/logic-controllers.html">Genie NX</a> - so it is clearly a re-branded/white-label version of that.</p>

<p>Apart from the supplier’s website, there isn’t a lot of information about the <a href="http://gicindia.com/products/logic-controllers.html">Genie NX</a> on the Internet. Although I did find that Mark Empson has done some <a href="http://www.smart-relay.co.nz/g-soft%20programming.php">YouTube Videos</a> about programming them using the Windows control software.</p>

<h2 id="getting-set-up">Getting Set Up</h2>

<p>I decided to buy the ‘110v-240v with no LCD’ version of the module. I liked the idea of keeping the mains voltages contained within a properly designed enclosure. Keeping those mains voltages away from anything I was making myself  makes me feel a lot safer. Because it takes in 230v in, it also doesn’t need a separate power supply. As it was going to be hidden away somewhere I didn’t see the need for an LCD and it brought the price down a bit.</p>

<p>To test the <a href="https://uk.rs-online.com/web/generalDisplay.html?id=footer1/release/160712_rs_pro_logic_controllers_uk">RS Pro Logic</a> module, I built a test rig, with one input (a retractive switch) and one output (a 13-amp socket).</p>

<p><img src="https://www.aelius.com/njh/images/0001-test-rig.jpg" alt="My Test Rig" /></p>

<p>By default, the module does nothing when you first switch it on (apart from responding to Modbus commands). To do anything autonomously then you need to programme it using the free <a href="http://download.designspark.info/RS_Logic_Module.zip">RS Logic Pro Windows Software</a>.</p>

<p>As a non-Windows User, this was a major detractor to buying an RS Logic Pro. Thankfully, it is possible to download a free copy of Windows 7 as a Virtual Machine from <a href="http://modern.ie/">modern.ie</a>. After running Windows in the <a href="https://www.virtualbox.org/">VirtualBox</a> hypervisor, I was able to install the RS Pro Logic software easily.</p>

<p><img src="https://www.aelius.com/njh/images/0001-screenshot-simple.png" alt="Simple Configuration Screenshot" /></p>

<p>The screenshot above demonstrations one of the simplest configurations it is possible to set up:</p>
<ul>
  <li><code class="language-plaintext highlighter-rouge">I1</code> (Input 1) is connected to <code class="language-plaintext highlighter-rouge">Q1</code> (Output 1)</li>
  <li>When <code class="language-plaintext highlighter-rouge">I1</code> is turned on and off, <code class="language-plaintext highlighter-rouge">Q1</code> will be turned on and off.</li>
</ul>

<h2 id="performing-state-toggle">Performing state toggle</h2>

<p>Switching an output <em>high</em> when an input is <em>high</em> is very straightforward, but I found setting up an input to toggle an output a bit more complex:</p>

<p><img src="https://www.aelius.com/njh/images/0001-screenshot-toggle.png" alt="Toggle Configuration Screenshot" /></p>

<p>The programme file, shown in the screenshot, can be download here:
<a href="https://www.aelius.com/njh/files/toggle.h53">toggle.h53</a>.</p>

<p>This is a description of each of the 4 rows in the ladder:</p>

<ol>
  <li><code class="language-plaintext highlighter-rouge">I1</code> (Input 1) is connected to <code class="language-plaintext highlighter-rouge">T1</code> (Timer 1). <code class="language-plaintext highlighter-rouge">T1</code> is configured to emit a
0.1s ‘Single Pulse’ - Mode C. This means that however long the input button 
is pressed, <code class="language-plaintext highlighter-rouge">T1</code> will only emit a 100ms pulse.</li>
  <li>The current state of <code class="language-plaintext highlighter-rouge">Q1</code> (Output Relay 1) is connected to <code class="language-plaintext highlighter-rouge">T2</code>. 
<code class="language-plaintext highlighter-rouge">T2</code> is in ‘Single On/Off’ - Mode M. This delays the current state of the 
relay by 500ms.</li>
  <li>Row 3 checks for a pulse from <code class="language-plaintext highlighter-rouge">T1</code>. If <code class="language-plaintext highlighter-rouge">T1</code> is <em>high</em> and the former state
of the relay (<code class="language-plaintext highlighter-rouge">T2</code>) is <em>low</em>, then it sets the relay to <em>high</em>.</li>
  <li>Row 4 does the opposite. If <code class="language-plaintext highlighter-rouge">T1</code> is <em>high</em> and the former state of
the relay is <em>high</em>, then it sets the relay to <em>low</em>.</li>
</ol>

<p>The reason for the timers is because the module behaves like electronic logic gates. Rather than executing a sequence of commands, as software would, the logic is instantaneous. So setting <code class="language-plaintext highlighter-rouge">Q1</code> to the inverse of <code class="language-plaintext highlighter-rouge">Q1</code> results in nothing happening, rather than rapidly turning it on and off.</p>

<p>This solution seems a little over-complex for the simplicity of the problem. Please let me know if you think there is a better way of doing this.</p>

<p>In <em>Part 2</em> of my blog post, I will explore how to control the <a href="https://uk.rs-online.com/web/generalDisplay.html?id=footer1/release/160712_rs_pro_logic_controllers_uk">RS Pro Logic</a> using the <a href="https://en.wikipedia.org/wiki/Modbus">Modbus</a> protocol from <a href="https://nodered.org/">Node-RED</a>.</p>]]></content><author><name></name></author><category term="Home" /><category term="Automation" /><summary type="html"><![CDATA[For a few years, I have been looking into different ways of controlling home lighting. The goal is to be able to turn lights on and off using a computer interface, enabling lights various types of remote control and automation: Turned on at sunset and off at midnight Using a remote control, or mobile phone Voice control using Alexa or Google Home Switch off all the lights in a room at once]]></summary></entry></feed>