I accidentally discovered that I can send audio streams with +/- 1.4 peaks to [dac~] and it doesn't clip on either my 01V96i or MOTU ultralite 4, although the analog output levels are different. I always thought +/- 1 was full scale. What's going on? The mixer can be connected via S/PDIF or USB and the MOTU via USB, so I'm guessing those links can handle numbers > 1 and < -1 (what's the maximum?), and the fact that my converters produce different output levels for the same numbers means there's no standard? And 1.4 suggests that the actual limit might be 1.4142 = sqrt(2) = pow(cos(pi/4), -1). If true, what's the significance?
-
Not clipping! (?) OMG, MY BAD, NEVERMIND
-
@jameslo @jameslo Not gospel...... because there are so many unknowns.
The values sent will not actually be between -1 and +1 but will be (probably signed) integers between -32768 (?) and 32767 for 16bit.
Pd processes at 32bit floating point.... so much bigger integers.. and can write those values to files.
But usually a stream will be 16 or 24bit.
Maybe the Pd value of 1 represents 32767..... a safe(ish) value for a 16bit stream for the computer internal soundcard.But your usb soundcards are probably 24bit and so can accept much higher values without an integer overflow.
SPDIF 20bit or sometimes 24bit.
I don't know whether the bit depth is negotiated and the integer range scaled at the output from Pd, but maybe not.Right from the birth of digital audio there was no standard for the ADC circuit.... sometimes it would accept 0dBu, often +18, or something else.
The numbers are streamed out of Pd to the OS, routed by the drivers..etc.
What happens to the numbers after that, or even during that process?
What do individual manufacturers do to keep their idiot customers happy?As long as there are no integer overflows, and they arrive at the DAC within its range, there will be no clipping.
David. -
@whale-av I'd be curious if anyone sees analog output clipping at +/- 1.1 and if anyone doesn't see clipping at +/- 2. That 1.4142 thing seems too...um...spooky. Happy Halloween.
-
My understanding (based on educated guesswork) is that the audio chain remains floating point until the last possible moment. It does not make sense for the OS's audio-mixing framework to convert incoming streams to integer before mixing because then you would lose the ability to prevent clipping by turning down the master volume. Even Windows is not that stupid.
So this... "The values sent will not actually be between -1 and +1 but will be (probably signed) integers between -32768 (?) and 32767 for 16bit"... is true at the hardware driver level but not at the OS mixer level.
Pd must be outputting floats.
I would have assumed that the OS (or JACK etc) would map +/- 1.0 onto the integer samples' full scale. But I suppose there is no guarantee of that. There's nothing really to stop the OS mixer from attenuating before providing the integer samples to the driver. We assume that it isn't doing this, and assume that it's spooky otherwise, but... I never read anywhere that there's an ironclad promise not to.
Incidentally sqrt(2) is very very close to +3 dB -- 10 ** (3/20) == 1.4125375446228, sqrt(2) == 1.4142135623731. 3 dB isn't an arbitrary value in audio engineering
So one explanation could be that something in between Pd's audio output and the hardware driver is attenuating by 3 dB. What that might be, I've no idea.
hjh
-
@jameslo I know MacOS limits the output but I thought that was only for the built-in sound.. but maybe some OSes also limit going to external dacs
-
@seb-harmonik.ar I just tested the line out of my 2012 MacBook Pro 10.14.6 and it goes up to 1.4 without clipping too! Puny signal though.
-
@jameslo Since the "loudness wars" the EBU R 128 spec recommends a maximum of -3dB as lossy codecs will often clip at just above. I know that at least one pci soundcard card adjusts its metering for that spec, even though it is a broadcast spec, as it has madi output with aes/ebu.
I cannot find anything that points to whether Miller or the computer industry decided on your 1.4.
Only that devices are different..... i.e. old ios didn't use floating point because it couldn't do the maths fast enough.You need high impedance headphones with most laptops as their voltage rails are 3.3V nowadays. Even when they were 5V audio out was puny. The MacBook pro only delivers 3V RMS to the headphone socket.
And 32bit floating point has a dynamic range of 1528dB....! ... be careful out there...!...
David. -
@whale-av said:
And 32bit floating point has a dynamic range of 1528dB....! ... be careful out there...!...
That's a joke, right?
Let's do a thought experiment. Let's say you have binary floating-point samples where the maximum exponent is 4 and you have 2 bits below the point. Then the maximum value is 1.11 * 2^4 = 11100 = 28. If you had all the bits of precision, the maximum would be 31 (the largest integer less than 2^(4+1)). So the maximum quantization error due to the limited precision of the mantissa is 3 = 2 ^ (max exponent - mantissa bits) - 1.
If we increase the maximum exponent to 5, the same holds: max possible value = 111111 = 63, max encodable = 111000, max error = 7.
If we increase the maximum exponent to 127 (max allowed in single precision), and allow 23 bits below the point, then the error is 2 ^ (127 - 23) - 1 = 2 ^ 104 - 1, or on the order of 2 * 10^31.
This is the noise part of signal-to-noise ratio. It's the maximum noise. The overall noise level is the integral of the quantization error function (which is the absolute value of the difference between y and quantized y, where quantized y is a piecewise function) divided by the x range (something like that) and this will be lower than the max.
Of course, if you have an audio signal scaled up to 2^127, then some samples might reach the peak, but many will be lower amplitude, and their quantization error will be lower. So the overall SNR should be higher than the worst case at the top of the range. But quantization error must integrate over the absolute value, so the lower error at small amplitudes does not cancel out the astronomical error at high amplitudes.
Yes, I've seen the articles producing that bogus 1528 dB figure. The mistake they make is to assume that quantization error is equally distributed throughout the range, and that the magnitude of this quantization error is proportional to the smallest representable value. This is a fundamental reasoning error. To understand how to think properly about quantization error, read https://www.analog.com/media/en/training-seminars/tutorials/MT-229.pdf .
I'm quite bothered by this, actually. Some marketing bros use faulty math to claim that "our soundcard can give you 1528 dB dynamic range!!1!1!!" and then this goes to the top of search results, and gets repeated as folklore. But it's nonsense. It needs to be stopped.
hjh
-
@ddw_music True... of course no soundcard is going to give such a range... but the lies in audio marketing are legion and "musician" and "space" nearly synonyms.
I thought we (but probably just me) were discussing internal IEEE standard processing wrt 32bit floating point. Anyway its a bit more complex than that. A better read on the subject of quantization error imhb...... https://www.analog.com/en/technical-articles/relationship-data-word-size-dynamic-range.html
David. -
@whale-av said:
I thought we (but probably just me) were discussing internal IEEE standard processing wrt 32bit floating point.
Sure, and no dispute. Audio software generally assumes that floating point +/- 1.0 is full scale, and indeed I always assumed that. But if something in the chain is reducing by 3 dB then Pd wouldn't have any control over that.
In any case, I mainly wanted to note that this is one case where Google doesn't help.
Incidentally there were some extensive debates in SuperCollider land over whether SC should or should not clip to +/-1.0. Apparently in Mac, there might not be any limiting or clipping within CoreAudio before applying the system volume control. If something blows up, you might get a 700 dB signal out of SC, which would be attenuated by up to just a few dozen dB at the system volume control = full range distorted signal into your earphones, call your doctor. So pd isn't the only place where signals beyond full scale got passed through.
A better read on the subject of quantization error imhb...... https://www.analog.com/en/technical-articles/relationship-data-word-size-dynamic-range.html
One thing this article doesn't do is to calculate the 32 bit float SNR (unless I overlooked it), probably because the answer depends partly on signal amplitude.
hjh
-
this is why using abstractions to wrap/clip output before
[dac~]
are good practice imo.. I have[outputc~]
in shadylib that also has a volume slider and the option to record. -
I sometimes use my mixer as a lazy loopback device: I output to it via S/PDIF and then take input via USB. If I send signals that step outside of -1..1 I get clipping! So so far I only see that 3dB of headroom on the analog outputs.
-
@jameslo said:
So far I only see that 3dB of headroom on the analog outputs.
Just occurred to me: If an equal-power stereo panner's gain is 0 dB at the sides, then the gain will be sqrt(1/2) in the center (both with sinusoidal and sqrt laws).
So here's a common audio operation that would drop 3 dB with default settings, which a driver or OS-mixer author might consider a good idea to include in the chain. (Also, this would be unlikely to be applied to mono inputs.)
hjh
-
@ddw_music That's it!!! I was ignoring my panner, which when panned to the middle is down 3dB on both L & R. And for that last test with my lazy man's loopback, I just wrote something from scratch and omitted the panner. Crap, I wish I could delete this whole thread so as not to mislead anyone else. -1..1 is the full range, period. Sorry to waste everyone's time
-
@jameslo The time was not wasted.... we all learnt something... and a great quantity of head scratching will probably save me money for shampoo...
David.