Lossless digital volume control on a Mac?

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
Can somebody please explain to me if lossless digital volume control can be implemented on a Mac?

In practical terms all my sources are on my Mac Pro:
- YouTube and other online sites
- TV channels (I watch Freeview channels on my computer, no TV)
- iTunes (all my music is on an external hard disc)

My tube system is designed to have only the amplification I need, nothing more. So normal listening level is around 80% of maximum volume at a guess. If -6db means losing 1 bit, I'm probably not losing that much.

I'm interested in the idea of lossless digital volume controls, but I have no idea how to implement this on my computer since my mouse does all the volume control on whatever website or software I'm using.
 
A digital volume control (i.e. not operating an analog volume feature via some digital control channel) means simply dividing all sample values by some fixed number (or multiplying by a fixed float). Advanced algorithms (e.g. the aforementioned CamillaDSP) start the division on samples close to zero (so called zero-crossing) and/or slowly change from the previous ratio to the new ratio (to avoid audible clicks), some handle compression close to maximum value to avoid clipping (for amplification, not attenuation), but the actual volume control is always the same.

If your chain can resolve to analog domain all the lower digits created by the division, the operation is "lossless". E.g. if you have a 24bit DAC with real resolution of 22bits, then a 16bit track has a volume control headroom of 6 bits (-36dB) to keep the original 16bit resolution. A proper 24bit track has no volume control headroom. The division can be done in int32, float32, int64, float64, float128... but after truncating the intermediary samples down to 24bit for the actual DAC the resulting numbers will be identical as all the added precision is cut off.

A different question is whether the lost resolution is audible, especially for the quiter sound.
 
I may be able to shed a little light. Just looking at the Xcode developer docs...

For the main part - any format is converted to PCM by OSX internally. Core Audio and the monolith that is OSX then performs the volume function too. There's perception curves in audio that I believe may also be used. There's also the standard filters both via digital but also on the output hardware.

So assuming a pure source (another issue) by the time the audio reaches the audio jack it's been frappe'd to oblivion. If you use a DAC with a PCM output from the Mac.. that's not pure either.

In the OSX Kernel there's a class called IOAudioLevelControl. It allows you to set the scaling, including if it's linear.

useLinearScale
TRUE instructs CoreAudio to not apply a curve to the scaler representation of the volume, FALSE instructs CoreAudio to apply a curve, which is CoreAudio's default behavior.

Volume - directly is a signed 32 bit integer value, if you control using dB then it's a fixed point number (16.16bit).

So unless you have a separate mechanism - all the OSX integrated drivers/services and applications (ie any using the native Core Audio etc) will only work within the above limits.


This is the start (online nicer documentation): What Is Core Audio?

Reading a little more.. you can use AudioObjectGet/SetPropertyData() and then set the volume using the properties associated - this includes controlling channels and the master channel assuming the calling code has the right privileges.

Here you go: objective c - Change OS X system volume programmatically - Stack Overflow
 
Last edited:

TNT

Member
Joined 2003
Paid Member
"I find it quite laughable that the OP frets about a "lossless" volume control when the sources include stuff like "YouTube" and playback is via a tube amp! The source is already lossy and the amp is a euphonic distortion machine. Go figure."

You must do a lot of laughing with a mind like yours....

Please, defend the technical aspects brought forward... it makes no sense to worry about your volume control with such low quality sources.

How are you thinking here?

//
 
Please, defend the technical aspects brought forward... it makes no sense to worry about your volume control with such low quality sources. How are you thinking here?

I'm a musician. All my music files ripped from CD are in AIFF format. Besides which I'm a songwriter and I have other music files. My thinking is that if a digital volume control can be made less lossy it's worth implementing. I build tube equipment and digital is outside my knowledge base, so I was looking for some help here to understand what can and can't be done.

My objection to the original poster wasn't on the basis of the source material, which is a valid point, it was in his attitude and in calling tube equipment effects boxes. As a musician I don't have much patience with self-proclaimed experts with cloth ears. Even less for insensitive comments in the middle of a pandemic when some are living through very upsetting experiences.
 
"Please, defend the technical aspects brought forward... it makes no sense to worry about your volume control with such low quality sources. How are you thinking here?"

I'm a musician. All my music files ripped from CD are in AIFF format. Besides which I'm a songwriter and I have other music files. My thinking is that if a digital volume control can be made less lossy it's worth implementing. I build tube equipment and digital is outside my knowledge base, so I was looking for some help here to understand what can and can't be done.

My objection to the original poster wasn't on the basis of the source material, which is a valid point, it was in his attitude and in calling tube equipment effects boxes. As a musician I don't have much patience with self-proclaimed experts with cloth ears. Even less for insensitive comments in the middle of a pandemic when some are living through very upsetting experiences.

I apologize for my earlier snarky post, although I have to say that the sentiment still stands for me. Look, if you are looking into how to implement a high quality volume control I am all for that. But I think you need to forget about using buzzwords like "lossless" because they just do not really apply to the digital domain. From my engineering perspective, the problem is more about what level of degradation of the information content can be considered to be "doing no harm". In the analog domain the signal resolution can be considered infinite, and it is only the signal to noise ratio that is really limiting. So if you want to reduce the voltage by some factor, it is not the signal that will be limiting the information content. In the digital domain you have a different story. The information is already limited by the bit depth of the source. This is true no matter what format you are using. When you reduce the level of the digital signal you will be eliminating information at the lowest levels of detail, the lowest bit(s). Also, if a volume reduction factor is used that cannot be "fit" into a single bit, you also are introducing error into the signal because you must round up or down to the next bit and this introduces something that is like a low level noise component on a single bit level. One solution for that is to use dither, which largely cures this problem. This page has a good overview of the subject:
Dither and ecasound | Richard's Stuff

But getting back to what I originally posted. Is there a problem that you are trying to solve with your current system? That is what had me puzzled and, yes, laughing. Even if you use the naive volume adjustment in your Mac, the sonic penalty is probably not significant compared to the kind of compromises that the sources that you originally listed (YouTube, internet TV, etc.). I just didn't see a real reason to take any action there.

In any case, if you want to do the least harm, the best approach IMHO is to process the signal as a float, multiply by whatever factor you wish to adjust the level, and then convert back to a fixed number of bits using dither before sending the signal to your DAC. This can all be done using proper audio processing software. For example, I use Gstreamer, but there many other examples should be able to do the same thing.
 
Thank you Charlie for an extremely informative post. No hard feelings. This hits the nail squarely on the head in terms I can deal with, even with my scant digital knowledge. As you say, there isn't a real problem as such. In the spirit of optimising ones system, which isn't always logical, one investigates a variety of better solutions. I was clearly using the term "lossless" in a careless way when in practical terms I meant "the least lossy".

I have to look up terms like bit depth and float, but I do see the issue here. I would like to continue using my mouse for volume control, it's so much more practical with all my sources. So I'm looking for a solution in the computer, not between computer and DAC, hence posting here. My Mac Pro is 2009, upgrade to use Sierra. I have Audirvana though it's not currently enabled. So that's what I have available. I looked up Gstreamer and looks like it's not yet Mac-ready. One question is how much technical knowledge is required to set up such a solution. I could only follow clear instructions. But I'm open to suggestions.

This all came up after discussions on another forum about the degradation of audio signals through digital volume controls so I wanted to see if I could take any useful action on this. It probably isn't of too much consequence with TV channels. I don't know how much it degrades mp3 files. I don't know how much it degrades AIFF files which are ripped from CD in a claimed Apple lossless format. As I said, I do very little attenuation since my system is optimised for something like 80% of the signal at normal listening levels.

Any more insights and solutions would be very useful. Thanks, guys. I would have thought I'm not the only person who wants to know more about this issue.
 
Last edited:
I apologize for my earlier snarky post, although I have to say that the sentiment still stands for me. Look, if you are looking into how to implement a high quality volume control I am all for that. But I think you need to forget about using buzzwords like "lossless" because they just do not really apply to the digital domain. From my engineering perspective, the problem is more about what level of degradation of the information content can be considered to be "doing no harm". In the analog domain the signal resolution can be considered infinite, and it is only the signal to noise ratio that is really limiting. So if you want to reduce the voltage by some factor, it is not the signal that will be limiting the information content. In the digital domain you have a different story. The information is already limited by the bit depth of the source. This is true no matter what format you are using. When you reduce the level of the digital signal you will be eliminating information at the lowest levels of detail, the lowest bit(s). Also, if a volume reduction factor is used that cannot be "fit" into a single bit, you also are introducing error into the signal because you must round up or down to the next bit and this introduces something that is like a low level noise component on a single bit level. One solution for that is to use dither, which largely cures this problem. This page has a good overview of the subject:
Dither and ecasound | Richard's Stuff

But getting back to what I originally posted. Is there a problem that you are trying to solve with your current system? That is what had me puzzled and, yes, laughing. Even if you use the naive volume adjustment in your Mac, the sonic penalty is probably not significant compared to the kind of compromises that the sources that you originally listed (YouTube, internet TV, etc.). I just didn't see a real reason to take any action there.

In any case, if you want to do the least harm, the best approach IMHO is to process the signal as a float, multiply by whatever factor you wish to adjust the level, and then convert back to a fixed number of bits using dither before sending the signal to your DAC. This can all be done using proper audio processing software. For example, I use Gstreamer, but there many other examples should be able to do the same thing.

I used to use HQPlayer volume control, apparently 60-80bit precision - very good and you could also set maximum volume at start up, so no exploding speakers. However I found that playback through HQPlayer had a kind of white noise background to it, whereas playback through other software or Windows media play of all things didn't have this (it was also present using HQPlayer desktop in Windows). Anyhow I moved on from there.

I did like TPDF dither.

I would love a software based volume control, ideally at the system level - any options?

My motivation for this is that no-preamp so far seems to be the best for me (anything in the way of the Chord DAC seems to takes away some of it's magic). I have tried an excellent measuring Topping Pre90 (which was good, but not to my taste and very poor remote), I also own an Audio-gd Master 9, now this sounds really quite good, but has way more gain than I need and does blur the sound compare to running DAC direct. Best sounding solution is DAC direct to amp, but using 'lossy' windows volume control would you believe.

I am looking at passive solutions (LDR or Merzmarise B1 seem to be the ones I'm gravitating towards).
 
I used to use HQPlayer volume control, apparently 60-80bit precision

Audio samples at 24 bits, divided by a fixed number with 60bit precision, truncated or dithered to 24 bits of output signal, converted by a DAC with 22 bits of real resolution at most. What happened to the 60bit precision of the volume control? Exactly same samples would reach the DAC using a regular 32bit division +/-1LSB for the dither (below the DAC noise).
 
Last edited:
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.