Tuesday, 12 November 2013

What, exactly, is DSD? - II. Getting in Shape

Last week, we learned that by adopting a PCM format, we also constrain ourselves with the need to employ radical low-pass filtering in both the ADC and DAC stages in order to eliminate the fundamental problem of aliasing. Yesterday we learned that we can use oversampling and noise shaping to overcome some of the limitations imposed by Bit Depth in PCM systems. Taking both together, we learned that by increasing both the BitDepth and the Sample Rate we can make inroads into the audible effects of both of these limitations.

In practice, there is no point in extending the Bit Depth beyond 24 bits. This represents a dynamic range of 144dB, and no recording system we know of can can present analog waveforms with that level of dynamic range to the input of an ADC. On the other hand, even by extending the Sampling Rate out to 384kHz (the largest at which I have even seen any commercially available music made available), the brick-wall filter requirements are still within the territory where we would anticipate its effects to be audible. A 24/384 file is approximately 13 times the size of its 16/44.1 equivalent. That gets to be an awfully big file. In order for the filter requirements to be ameliorated to the point where we are no longer concerned with their sonic impact the sample rate needs to be out in the MHz range. But a 24-bit 2.82MHz file would be a whopping 100 times the size of its 16/44.1 counterpart. Clearly this is takes us places we don’t want to go.

But wait! Didn’t we just learn that by oversampling and Noise Shaping we can access dynamic range below the limitation imposed by the Bit Depth? Increasing the sample rate by a factor of 64 to 2.82MHz would mean that our audio frequencies (20Hz - 20kHz) are all going to be massively oversampled. Perhaps we can reduce the Bit Depth? Well, with oversampling alone, all we can do is shave a paltry 4-bits off our Bit depth. But do not get discouraged, with Noise Shaping it turns out we can reduce it all the way down to 1-bit. A 1-bit 2.82MHz file is only 4 times larger than its 16/44.1 equivalent, which is actually quite manageable. But really? Can we get more than 100dB of dynamic range from a 1-bit system just by sampling at 2.82MHz?

Yes, we can, but I am not going anywhere near the mathematics that spit out those numbers. That is the preserve of experts only. But here’s what we do. When we encode data with a 1-bit number, the quantization error is absolutely massive, and can be anywhere between +100% and -100% of the signal itself. Without any form of noise shaping, this quantization noise would in practice sit at a level of around -20dB (due to the effect of oversampling alone) but would extend all the way out to a frequency of 1.41MHz. But because of the massive amount of oversampling, we can attempt to use Noise Shaping to depress the quantization noise in the region of 0-20kHz, at the expense of increasing it at frequencies above, say 100kHz. In other words, we would “shape” it out of the audio band and up into the frequency range where we are confident no musical information lives, and plan on filtering it out later. We didn’t choose that sampling rate of 2.82MHz by accident. It turns out that is the lowest sample rate at which we can get the noise down well below 100dB over the entire audio frequency bandwidth.

To convert this signal back to analog, it turns out this format is much easier to implement than multi-bit PCM. Because we only encode 1-bit, we only have to create an output voltage of either Maximum or Minimum. We are not concerned with generating seriously accurate intermediate voltages. To generate this output, all we have to do is switch back and forth between Maximum and Minimum according to the bit stream. This switching can be done very accurately indeed. Then, having generated this binary waveform, all we have to do is pass it through a low pass filter. Job done.

This is a pretty interesting result. We have managed to eliminate the need for those nasty brick-wall filters at both the ACD and DAC, and at the same time capture a signal with exceptional dynamic range across the audio bandwidth. This, my friends, is DSD.

As with a lot of things, when you peek under the hood, things always get a little more complicated, and I will address some of those complications tomorrow.

Monday, 11 November 2013

What, exactly, is DSD? - I. Opinion Polls

Being strictly accurate, DSD (Direct Stream Digital) is a term coined by Sony and Phillips, and refers to a very specific audio protocol. It is a 1-bit Sigma-Delta Modulated data stream encoded at a sample rate of 2.8224MHz. However, the term has now been arbitrarily widened by the audio community at large, to the point where we find it employed to apply generically to an ever-widening family of Sigma-Delta Modulated audio data streams. We read the terms Double-DSD, Quadruple DSD, and “DSD-Wide” applied to various SDM-based audio formats, so that DSD has become a catch-all term somewhat like PCM. There are many flavours of it, and some are claimed to be better than others.

So, time to take a closer look at DSD in its broadest sense, and hopefully wrap some order around the confusion.

Strangely enough, the best place to start is via a detour into the topic of dither which I discussed a couple of weeks back. You will recall how I showed that a 16-bit audio signal with a maximum dynamic range of 96dB can, when appropriately dithered, be shown using Fourier Analysis to have a noise floor that can be as low as -120dB. I dismissed that as a digital party trick, which in that context it is. But this time it is apropos to elaborate on that.

The question is, can I actually encode a waveform that has an amplitude below -96dB using 16-bit data? Yes I can, but only if I take advantage of a process called “oversampling”. Oversampling works a bit like an opinion poll. If I ask your opinion on whether Joe or Fred will win the next election, your response may be right or may be wrong, but it has limited value as a predictor of outcome. However, if I ask 10,000 people, their collective opinions may prove to be a more reliable measure. What I have done in asking 10,000 people is to “oversample” the problem. The more people I poll, the more accurate the outcome should be. Additionally, instead of just predicting that Joe will win (sorry, Fred), I start to be able to predict exactly how many points he will win by, even though my pollster never even asked that question in the first place!

In digital audio, you will recall that I showed how an audio signal needs to be sampled at a frequency which is at least twice the highest frequency in the audio signal. I can, of course, sample it at any frequency higher than that. Sampling at a higher frequency than is strictly necessary is called “oversampling”. There is a corollary to this. All frequencies in the audio signal that are lower than the highest frequency are therefore inherently being oversampled. The lowest frequencies are being oversampled the most, and highest frequencies the least. Oversampling gives me “information space” I can use to encode a “sub-dynamic” (my term) signal. Here’s how…

At this point I wrote and then deleted three very dense and dry paragraphs which described, and illustrated with examples, the mathematics of how oversampling works. But I had to simplify it too much to make it readable, in which form it was too easy to misinterpret, so they had to go. Instead, I will somewhat bluntly present the end result: The higher the oversampling rate, the deeper we can go below the theoretical PCM limit. More precisely, each time we double the sample rate, we can encode an additional 3dB of dynamic range. But there’s no free lunch to be had. Simple information theory says we can’t encode something below the level of the Least Significant Bit (LSB), and yet that’s what we appear to have done. The extra “information” must be encoded elsewhere in the data, and it is. In this case it is encoded as high levels of harmonic distortion. The harmonic distortion is the mathematical price we pay for encoding our “sub-dynamic” signal. This is a specific example of a more general mathematical consequence, which says that if we use the magic of oversampling to encode signals below the level of the LSB, other signals - think of them as aliases if you like - are going to appear at higher frequencies, and there is nothing we can do about that.

Let’s go back again to dither, and consider a technique - Noise Shaping - that I mentioned in a previous post. Noise shaping relates to the fact that when we quantize a signal in a digital representation, the resultant quantization error looks like a noise signal added to the waveform. What is the spectrum of this noise signal? It turns out that we have a significant level of control over what it can look like. At lower frequencies we can squeeze that noise down to levels way below the value of the LSB, lower even than can be achieved by oversampling alone, but at the expense of huge amounts of additional noise popping up at higher frequencies. That high-frequency noise is the "aliases" of the sub-dynamic "low frequency" information that our Noise Shaping has encoded - even if that low frequency information is silence(!). This is what we mean by Noise Shaping - we “shape” the quantization noise so that it is lower at low frequencies and higher at high frequencies. For CD audio, those high frequencies must all be within the audio frequency range, and as a consequence, you have to be very careful in deciding where and when (and even whether) to use it, and what “shape” you want to employ. Remember - no free lunch.

But if we increase the sample rate we also increase the high frequency space above the limit of audibility. Perhaps we can use it as a place to park all that “shaped” high-frequency noise? Tomorrow, we’ll find out.

Wednesday, 6 November 2013

iTunes 11.1.3

I have been using iTunes 11.1.3 all day without encountering any problems.  It should be fine for BitPerfect users to download and install it.

iTunes 11.1.3 released

Today we are testing the latest iTunes update 11.1.3 for compatibility with BitPerfect.  I will post my findings later in the day.

Tuesday, 5 November 2013

To upsample or not to upsample; that is the question.

Back in late March, I posted some introductory comments here regarding how DACs actually function.  Anyway, following my recent posts on Sample Rate I thought it might be apropos to revisit that subject.

Today’s DACs, with a few very rare (and expensive) exceptions, all use a process called Sigma Delta Modulation (SDM, sometimes also written DSM) to generate their output signal.  A nice way to look at SDM DACs is to visualize them as upsampling their output to a massively high frequency - sometimes 64, 128 or 256 times 44.1kHz, but often higher than that - and taking advantage of the ability to use a very benign analog filter at the output.  That is a gross over-simplification, but for the purposes of the point I am trying to make today, it is good enough.

Doing such high-order up-conversion utilizes a great deal of processing power, and providing that processing power adds cost.  Additionally, the manufacturers of the most commonly used DAC chipsets are very coy about their internal architectures, and don’t disclose the most significant details behind their approaches.  I would go so far as to say that some DAC manufacturers actually misunderstand how the DAC chipsets which they buy actually work, and publish misleading information (I have to assume this is not done intentionally) about how their product functions.  Much of this centres around cavalier usage of the terms ‘upsampling’ and ‘oversampling’.  Finally, some DAC manufacturers use DAC chipsets with prodigious on-chip DSP capability (such as the mighty ESS Sabre 9018), and then fail to make full use of it in their implementations.

Let’s study a hypothetical example.  We’ll take a 44.1kHz audio stream that our DAC chip needs to upsample by a factor of 64 to 2.88MHz, before passing it through its SDM.  The best way to do this would be using a no-holds-barred high-performance sample rate converter.  However, there are some quite simple alternatives, the simplest of which would be to just repeat each of the original 44.1kHz samples 64 times until the next sample comes along.  What this does is to encode the “stairstep” representation of digital audio we often have in mind, in fine detail.  This is acceptable, because, in truth, the 44.1kHz audio steam does not contain one jot of additional information.  Personally, I would refer to this as oversampling rather than upsampling, but you cannot rely on DAC manufacturers doing likewise.

If we are going to use this approach, though, it leads us down a certain path.  It results in the accurate recreation of the stairstep waveform at the output of the DAC.  Even though we have oversampled by a factor of 64 in our SDM process, the output of our DAC has been a faithful reproduction of a 44.1kHz sampled waveform.  This waveform, therefore needs to go through an analog brick-wall filter to strip out the aliases which are embedded within the stairstep.  This is exactly as we discussed in my last post on Sample Rates.

In principle, therefore, by upsampling (using proper Sample Rate Conversion) our 44.1kHz audio by a factor of 2 or 4 prior to sending it to the DAC, we can avail ourselves of the possibility that the DAC can instead implement a less aggressive, and better-sounding, brick-wall filter at its output.  That would be nice.  But that is not the way many (and maybe even most) DACs that use this approach are built.  Instead, they use the same analog brick-wall filter at high sample rates as they do at 44.1kHz (because switching analog filters in and out makes for complicated - read expensive - circuitry).  If your DAC does this you would not expect to hear anything at all in the way of sonic improvement by asking BitPerfect (or whatever other audio software you use) to upsample for you.

So let’s go back a couple of paragraphs, and instead of our DAC oversampling the incoming 44.1kHz waveform, suppose it actually upsamples it using a high quality SRC algorithm.  Bear in mind that all of the audio content up to 20kHz in a 44.1kHz audio stream is aliased within the frequency band from 24.1kHz to 44.1kHz.  If we are to upsample this, we should really strip the aliases out using a digital brick-wall filter.  Done this way, the result is a clean signal that we can pass into the SDM, and which is precisely regenerated, without the stairstep, at the DAC’s output.  So we no longer need that aggressive, sonically worrisome, analog brick-wall filter.

Let’s take another look at these last two scenarios.  One had an aggressive analog brick-wall filter at the output, but the other had essentially the same brick-wall filter implemented digitally at an intermediate processing stage.  If the two sound at all different, it can only be because the two filters sounded different.  Is this possible?  In fact, yes it is, and there are two reasons for that.  The first, as I mentioned in a previous post, is that an analog filter has sonic characteristics which derive from both its design, and from the sonic characteristics of the components with which it is constructed.  The digital equivalent - IF (a big IF) properly implemented - only has sonic consequences arising from its design.  There is a further point, which is that digital filters can be designed to have certain characteristics which their analog counterparts cannot, but that fact serves only as a distraction here.  The bottom line here is that, if properly designed, a diligent DAC designer ought to be able to achieve better sound with this ‘upsampling’ approach than with the previously discussed ‘oversampling’ approach (again, I must emphasize this is MY usage of those terminologies, and is not necessarily everybody else’s).

Using the ‘upsampling’ approach I have just described, it should once again make little difference whether you send your music to the DAC at its native sample rate, or if you upsample it first using BitPerfect (or whatever).  However, all this assumes that the upsampling algorithm used by the DAC is at least as good as the one used by BitPerfect.  There is no guarantee that this will be so, in which case you may find that you get improved results by using BitPerfect to upsample for you to the maximum supported by your DAC.  And you should use one of the SoX upsampling algorithms provided by BitPerfect, rather than CoreAudio.

The bottom line here is that you should expect your DAC to sound better (or at least as good) with your music sent to it at its native sample rate than with it upsampled by BitPerfect.  And if it doesn’t, the difference is probably down to BitPerfect’s upsampling algorithm sounding better than the one implemented in your DAC’s DSP firmware.

So, in summary, in light of all the above, our recommendation here at BitPerfect is that you do NOT use BitPerfect to upsample for you, unless you have conducted some extensive listening tests and determined that upsampling sounds better in your system.  These tests should include serious auditioning of BitPerfect’s three SoX algorithms.

Monday, 4 November 2013

Masterchef Junior

I confess to having a weakness for good food and good wine, as well as good sound.  I enjoy cooking, and am not too bad at it, although I offer no pretensions to being any sort of chef.  So it is not surprising that I also get a kick out of watching the TV show Masterchef.

If you don’t know the premise of the show, it goes like this.  Two dozen of the best (amateur) home cooks in America are set cooking challenges by three top celebrity chefs, headed up by the fearsome Gordon Ramsey.  Each week one of them gets eliminated.  At the end of it all, the surviving chef wins the big prize.  The thing is, the challenges these amateur chefs get set are quite mind-blowingly difficult, and in addition they have to compete under very serious time pressures.  Watching the show, I always find myself thinking that the best 24 professional chefs in the country - and certainly ANY of the contestants in Ramsey’s companion show “Hell’s Kitchen” - would find the competition no less challenging.

So, to my astonishment, the producers at Masterchef came up with the notion of Masterchef Junior, where the same format would instead be opened to the 24 best chefs in America, but this time in the age range 10-13 years old.  The challenges faced by these junior chefs would be no less formidable than those faced by the adults.

Here’s the thing, though.  If you had pitched that idea to me before I had seen the show, I would have laughed and said that Masterchef Junior would be of marginal interest, and then only to Soccer Moms.  The reality turned out to be rather different.

Instead we were treated to the sight of 10-year-olds cooking stunningly (and I mean stunningly - things I couldn’t begin to imagine taking on) complex foods, with no preparation, under the very same pressure-cooker time constraints, and held accountable to the same unyielding standards, as their adult counterparts.  It blows my mind.  Imagine being dined in the most expensive restaurant you know of, having a great meal, and being introduced to the chef only to find that he or she is still at elementary school.  And, cynical as I am regarding the so-called “unscripted” nature of TV reality shows, I find it hard to believe that all of this is not very real.

I happen to believe that the current generation of children growing up in North America is doing so with the greatest sense of entitlement of any generation that has ever lived, coupled with the least intention of developing the skills necessary to make good on those expectations.

That said, I now know that there are at least 24 kids out there who, in whatever direction their lives and careers will eventually take them, have truly enormous - dare I say unlimited - potential.


Masterchef Junior

Sunday, 3 November 2013

Sample Rate Matters - II.

In yesterday’s post we found ourselves wondering whether a high-rez recording needs to expand its high frequency limit beyond 20kHz, and whether squeezing a brick-wall filter into the gap between 20kHz and 22.05kHz is really that good of an idea.  Today we will look at what we might be able to do about those things.

First, lets ignore the extension of the audio bandwidth above 20kHz and look at the simple expedient of doubling the sample rate from 44.1kHz to 88.2kHz.  Our Nyquist Frequency will now go up from 22.05kHz to 44.1kHz.  Two things are going to happen, which are quite interesting.  To understand these we must look back at the two brick-wall filters we introduced yesterday, one protecting the A-to-D converter (ADC) from receiving input signals above the Nyquist Frequency, and the other protecting the output of the D-to-A converter (DAC) from generating aliased components of the audio signal at frequencies above the Nyquist Frequency.  They were, to all intent and purpose, identical filters.  In reality, not so, and at double the sample rate it becomes evident that they have slightly different jobs to do.

We start by looking at the filter protecting the input to the ADC.  That filter still has to provide no attenuation at all at 20kHz and below, but now the 96dB attenuation it must provide need only happen at 44.1kHz and above.  That requirement used to be 22.05kHz and above.  The distance between the highest signal frequency and the Nyquist Frequency (the roll-over band) is now over 10 times wider than it was before!  That is a big improvement.  But let’s not get carried away by that - it is still a significant filter, one having a roll-off rate of nearly 100dB per octave.  By comparison, a simple RC filter has a roll-off rate of only 6dB per octave.

Now we’ll look at the filter that removes the aliasing components from the output of the DAC.  Those components are aliases of the signal frequencies that are all below 20kHz.  As described in Part I, those aliases will be generated within the band of frequencies that lies between 68.2kHz and 88.2kHz.  If there is no signal above 20kHz, then there will be no aliasing components below 68.2kHz.  Therefore the requirements for the DAC’s anti-aliasing filter are a tad easier still.  We still need our brick wall filter to be flat below 20kHz, but now it can afford to roll over more slowly, and only needs to reach 96dB at 68.2kHz.

Doubling the sample rate yet again gives us more of the same.  The sample rate is now 176.4kHz and its Nyquist Frequency is 88.2kHz.  The DAC filter does not need to roll off until 156.4kHz!  These filters are significantly more benign.  In fact, you can argue that since the aliasing components will all be above 156.4kHz they will be completely inaudible anyway - and might not in fact even be reproducible by your loudspeakers!  Some DAC designs therefore do away entirely with the anti-aliasing filters when the sample rate is high enough.

You can keep on increasing the sample rate, and make further similar gains.

Obviously, the higher sample rates also give us the option of encoding audio signals with a correspondingly higher bandwidth.  Equally obviously, that advantage comes at the expense of some of the filter gains, which vanish completely once the desired audio frequency bandwidth is extended all the way out to the new Nyquist Frequency.  But even so, by extending the high frequency limit of the audio signal out to 30kHz, little is given up in filter performance, particularly with a sample rate of 176.4kHz.

So far I have only mentioned sample rates which are multiples of 44.1kHz, whereas we know that 96kHz and 192kHz are popular choices also.  From the point of view of the above arguments concerning brick-wall filters, 96kHz vs 88.2kHz (for example) makes no difference whatsoever.  However, there are other factors which come into play when you talk about the 48kHz family of sample rates vs the 44.1kHz family.  These are all related to what we call Sample Rate Conversion (SRC).

If you want to double the sample rate, one simple way to look at it is that you can keep all your original data, and just interpolate one additional data point between each existing data point.  However, if you convert from one sample rate to another which is not a convenient multiple of the first, then very very few - in fact, in some cases none - of the sample points in the original data will coincide with the required sample points for the new data.  Therefore more of the data - and in extreme cases all of the data - has to be interpolated.  Now, don’t get me wrong here.  There is nothing fundamentally wrong with interpolating.  But, without wanting to get overly mathematical, high quality interpolation requires a high quality algorithm, astutely implemented.  It is not too hard to make one of lesser quality, or to take a good one and implement it poorly.

Downconverting - going from a high sample rate to a lower one - is fraught with even more perils.  For example, going from 88.2kHz sample rate to 44.1kHz sounds easy.  We just delete every second data point.  You wouldn’t believe how many people do that, because it is easy.  But by doing so you make a HUGE assumption.  You see, 88.2kHz data has a Nyquist Frequency of 44.1kHz and therefore has the capability to encode signals at any frequency up to 44.1kHz.  However, music with a sample rate of 44.1kHz can only encode signals up to 22.05kHz.  Any signals above this frequency will be irrecoverably aliased down into the audio band.  Therefore, when converting from any sample rate to any lower sample rate, it is necessary to perform brick-wall filtering - this time in the digital domain - to eliminate frequency content above the Nyquist Frequency of the target sample rate.  This makes down-conversion a more challenging task than up-conversion if high quality is paramount.

Time to summarize the salient points regarding sample rates.

1.  Higher sample rates are not fundamentally (i.e mathematically) necessary to encode the best quality sound, but they can ameliorate (or even eliminate) the need for brick-wall filters which can be quite bad for sound quality.

2.  Higher sample rates can encode higher frequencies than lower sample rates.  Emerging studies suggest that human perception may extend to frequencies higher than can be captured by CD’s 44.1kHz sample rate standard.

3.  Chances are that a high sample rate music track was produced by transcoding from an original which may have been at some other sample rate.  There is absolutely no way of knowing what the original was by examining the file, although pointers can be suggestive.

4.  There is no fundamental reason why 96kHz music cannot be as good as 88.2kHz music.  Likewise 192kHz and 176.4kHz.  However, since almost all music is derived from masters using a sample rate which is a multiple of 44.1kHz, if you purchase 24/96 or 24/192 music your hope is that high quality SRC algorithms were used to prepare them.

5.  Try to bear in mind, if your high-res downloads are being offered at 96kHz and 192kHz, it means your music vendor is maybe being run by people who pay more attention to their Marketing department than their Engineering department.  That’s not an infallible rule of thumb, but it’s a reasonable one.  (Incidentally, that is what happened to Blackberry.  It’s why they are close to bankruptcy.)