Monday, July 26, 2021

Expand your Horizons

This time, I want to have a look at what is possible using only open source software
and using only Linux.

I don't mean replacing your current OS or DAW, but rather adding to it, with things
like realtime processing, audio manipulation and extra features that are not available
in the more main stream software and plugins.

Many of you will use a DAW like PT or Logic in Mac or Windows.
Nothing wrong with that, but there are things that those apps are not designed to
do at all, or you have to use "kludges" and you have no way of changing the default
behaviour as it's all closed source.

The idea then, is to interface a modest Linux PC to your current DAW/mixer workflow.
Certain tasks can then be offloaded to this PC, but are available in near realtime
on your existing system, or can be accessed via a shared folder on a network.

Linux supports as many sound cards/interfaces as you need, and is limited only
by the resources available on your PC.
How you interface them, is entirely up to you, it can be via XLR/RCA (analog),
Firewire, USB, TCP/IP or Samba shares.

Furthermore, no hardware patch-bay is required, once multiple feeds are coming
in and out of a Linux PC, many software patch-bays are available and can be changed
in realtime.

Below, two scenarios I have created and patches can be saved and recalled at any time.




As can be seen then, the possibilities are almost endless.
There are also separate MIDI patches, but I don't use them.

Below, some actual applications that are available, been coded or modified and
recompiled by me.
In all cases, I used the same computer, which is an entry level Celeron with a 1.8GHz
CPU, 2 GB RAM and good old fashioned 500GB spinning drive.
The Linux I'm using is Debian 9,  64 bits.

For sound cards I'm using the internal one, an extra one on PCI and two on USB-2.
Hence I have in total, 4 stereo outputs (or 8 mono) and 4 stereo inputs plus 4 monos.

Inputs 1&2 connect to the AUX outputs of my Mackie mixer, 3 to the output of my Mac,
and input 4 is a general purpose stereo inputs to connect to the output of my FM tuner,
mobile phone or CD player.
These are selected by means of a hardware patch panel.

As for the outputs, 2 connect to the line inputs of my mixer, 2 to the FX returns and the
rest via a passive mixer to a pair of studio monitors.
These I use as "dry" monitoring channels.
Since no amplification or EQ is required on the monitoring channels, the passive mixer
is a simple lash-up of log sliders feeding a summing matrix.

So here we go, some real world (and realtime) applications.

1) Monitoring loudness and dynamic range of FM radio and CD's.

Have always been interested in how much FM stations compress and "manipulate"
the audio before broadcast.
Connected the audio outputs of my Pioneer FM tuner to a pair of inputs and analyzed
the output of two popular stations.
The first, plays predominantly modern music, note the LRA and frequency response.
(Note, I used a level of around -28 LUFS, to allow for plenty of headroom and range).



Each of the apps that you see, can be used together or individually, and all in realtime.
Further explanation as follows:

The top trace, is the audio waveform, this then allows visual inspection in case
there is any clipping.
The bottom waveforms (green is the left audio & purple is the right).
The one just above it (brownish/orange), is the average frequency response (last 3 secs).
Note the characteristic low cut at 15 KHZ.
All FM stations do this, so as to preserve the stereo pilot tone at 19 KHz & the suppressed 
carrier at 38 KHz.

Then we also have a readout of the time spent analyzing, the RMS value and the LUFS
plus overall LRA.

The bottom app, is just the patch settings.


As can be seen, to do all this in realtime, placed only a few percent CPU load and a
total latency of around 18 milliseconds.
Not bad at all for a Celeron computer with 2 GB RAM.

Let's then look at a FM talk only station:


Very Interesting results.

Let's analyze two different CD's.


A bit compressed, but expected of most of today's music.
At least it's not limited to 15 KHz like FM broadcasts or many streaming platforms.
The second one though, is just crazy, yes it's more dynamic, but just look at the clipping.
So much for standards.


Of course, the same setup could be used to monitor and analyze the audio from TV broadcasts.
You may have also noticed that on the last three tests, I used yet another app, a level histogram.
this is very useful is showing the "spread" or loudness range.

Keep in mind that is was all done in realtime.

2) Getting perceptional loudness and song EQ's:

Those that make and record music or do final mix on music, will know that each genre
of music, has some "established" EQ's or what they sound like.

Once it's time to final mix your song, you may want to make it sound more like a similar
commercial song.
No problem, simply play the commercial song you want to "emulate" through the apps above,
take some screenshots during the intro, chorus, etc and you will have a much better picture.

Some of you will also know that, humans do not perceive all sounds (pitch) at the same level
or intensity.
There has been many studies done on this, and the LUFS system also takes this into account.
There are algorithms available so we can easily make an app to see what a specific mix
will sound like.

Below is the response of some music, with relation to this.
It's a 3 second average of how it will be perceived, it's not a frequency response in the 
traditional sense, but intensity of frequencies as they will be perceived by the average person.

I have also added a LUFS meter, plus another very handy app, an instant recorder.
By clicking on the big green icon, it will record the audio and time stamp it for later reference.



These apps alone are worth having to monitor your mix from your DAW on a daily basis.

3) Auto Normalizing audio files in a watch folder.

Another use could be to get the computer to auto normalize (to -23 or any other level)
all files that are placed in a special watch folder.
For each file, a screenshot of the finished product can also be automatically generated.



4) Some effects

Yet another use, is to create effects for TV or radio shows.
One effect that is quite difficult to achieve, is the realistic simulation of a cellphone or
other digital call that is breaking up.
Normally it involves reducing the sample rate and some EQ.
However, this is not that realistic, to get that mangled sound, one should ideally feed
the audio through a real digital channel and create the break up or decimation there.

Again, open source to the rescue, there are uLAW, GSM and other codecs available
that can be manipulated to adjust the "break-down".

To that, just add some EQ and some compression to replicate those conversations.

The settings I used for GSM "mangling":


I have full control of level, phase and simulated bit error rate.
On top of this, some compression and more "envelope mangling":


The results?

Before and after:




5) Silence detection & reporting.

In situations like broadcasting, streaming and others, realtime monitoring
of silence (or drop-outs) is extremely important.

Since we can analyze audio in realtime, it then becomes a simple matter
to set up a circular buffer sampling an audio input or inputs.
The buffer size determines the sample rate and period we must sample
for the resulting silence (or another level) that is then treated as an 
alarm condition and acted upon.

The action that is automatically taken can be programmed in a script.
It can range from a simple audible alarm, to an email or even activating
a pin on a hardware port, which in turn can activate another piece of kit.

Over and above, a log in an excel compatible spreadsheet can also be
automatically created.

The opposite is also possible, automatic recording only when there is
audio above a certain level available.
This is very handy for situations where the audio may be periodic or
even sporadic.
No reason to fill up a hard drive with hours and hours of silence.

I have created an app that can record (with no silences) to one long
audio file, or separate audio files each with their time & date as file names.

As can be seen, loads of possibilities which are only limited by your
needs and imagination.
Each of the above examples can of course be tailored to many other
applications and uses.
Since I have all the source code, any changes can be quickly applied with
no need for an update from a company.

In conclusion, I hope that this blog has given you some ideas to try out new things,
ideas and concepts.

Will leave you with one final idea:
Get some audio transformers from old, un-used equipment and wire them inline
with you inputs and outputs of you new Linux computer.
It will help get some of that old, analog sound to your mixes.




Don't be scared to experiment, it will help you expand your horizons and possibilities.




Thursday, July 1, 2021

What lurks beneath

 No, it's not a horror movie, but it may well turn into a horror story if you're not careful.

I'm of course talking about audio interference, not the type you can hear, not immediately anyway.
We hear audio as longitudinal waves, i.e. the compression of air molecules,
but.....much more exists as electromagnetic (RF) waves.

So we can't hear them as they are electromagnetic, but they can, and do at times, wreak havoc
with our audio recordings.

So how do these electromagnetic waves get into our audio paths?

There are two main ways, both via capacitive or inductive coupling.
(Basically, as a result of poor shielding and isolation of circuits and cables).

1) Waves that are higher than the audio spectrum, but are picked up, rectified and the 
modulation of the main carrier, which is in the audio spectrum, is then heard.
We have all heard cellphone interference on audio equipment.
The actual carrier can be anywhere from 900 - 2200 MHz, definitely not audible,
however, the digital modulation will be heard after rectification.

Keep in mind that ANY semiconductor junction in electronic devices,
can act as a rectifier.
To make it worse, modern audio equipment has a combination of analog and digital
gain circuits, which makes equipment much more prone to interference if not
adequately shielded or fed with inferior cables.

2) The other type of potential interference, is from electromagnetic waves which are
in the audible range but are not heard as they are RF and not longitudinal waves.
Unheard of course, until our equipment picks it up, amplifies it and ruins our recording.
Rectification is not even required as they are already in the 20 Hz - 20 KHz range.

An example of this, is 50 Hz (mains) pickup.

To illustrate this, I built a RF adapter for my cellphone.
So it does not record using a microphone, but rather by picking up electromagnetic
waves that are in the range of 20 Hz and 20 KHz, actually up to 22 KHz.

First up, mains interference.
This was recorded 2 meters away from any wall plug and the antenna was a short piece
of wire.
Again, no microphone was used, this is purely an electromagnetic (RF) recording.




The fundamental at 50 Hz is clearly visible (and audible when recorded), plus
harmonics going all the way up to around 1 KHz.

So what else is lurking, just waiting to ruin your recordings?

A quick scan around the house, quickly revealed some candidates.
First off, the spark igniters on the gas stove.



The aerial is just a short screwdriver, this is what was picked up:



Those peaks are the sparks being created.
Zooming in, we see that they last for around 6 samples (@44.1 KHz sample freq.)
which puts them at 7.439 KHz.
The repetition rate is 3 sparks/second.


Since I'm sampling at 44.1 KHz, can "see" signals up to half of that (Nyquist rule),
so let's look at what harmonics it produces.
We can see the 2nd harmonic (at 14.698 KHz), the 3rd will be of no consequence as it's
pretty much on the edge of what someone with good ears will hear.



Nasty, and it manifests itself as short, sharp clicks.

Let's take another example, the garden.
Surely, other than the audible (with our ears), there is not much else.
Let's find out.
First, let's record with the built-in cellphone's mic.

Other than some birds and wind noise, not much else.
Aha, that is what you think, let's switch to RF mode:



What the ??
Let's look at what it is, it's frequency and spectrum plot.







So, it's clicking pulses with most of the energy concentrated at around 10 KHz
and just look at the level.
Yep, it's my electric fence.

This was recorded in the middle of my garden, with the "antenna" being a 50 cm 
piece of wire and about 4 meters away from the fence.
This then, simulates a crappy audio cable quite well.

I was lucky that it's not on my microphone recording as it was done all with the cellphone.
No cables, no external mixers, etc.
Had I being doing an outside broadcast or other recording with lots of external cables
and equipment, almost sure some of that fence energy would be on that audio recording.

I hope that by now, you are more aware of things that can catch you out,
and there are plenty more.
Electric motors (without suppression), geysers and other high current appliances switching
on and off.

Let's not forget about lights, light dimmers, ...........

The list is a long one, but by always using good quality shielded cables, as short as possible
and properly shielded equipment, you decrease your chances of being affected 
by what lurks beneath, unseen and unheard until it's too late.

This RF adapter is actually a rather handy thing, maybe I'll start making a few and selling them.

Expand your Horizons

This time, I want to have a look at what is possible using only open source software and using only Linux. I don't mean replacing your c...