# How do I set audio output bit depth, or why can't I?

**URL:** <https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543>\
**Category:** General JUCE discussion\
**Created:** [April 29, 2016, 1:06am UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543 "2016-04-29T01:06:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![0joshuaolson1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/0joshuaolson1/32/706_2.png) [@0joshuaolson1](https://forum.juce.com/u/0joshuaolson1)\
**Post date:** [April 29, 2016, 1:06am UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/1 "2016-04-29T01:06:09Z")

</div>

Years ago someone asked the [same question](https://forum.juce.com/t/audiodevicemanager-set-bitdepth/3768). The answer at the time was that JUCE autoselects the best format for the relevant audio device. There’s still no setBitDepth.

I know my external usb dac/amp works with 24 bit data at best, but if I recall from some ALSA experimentation it ‘accepts’ 32bit floats, which means the truncating would happen somehow (I’d rather do it myself) or there’d be unnecessary downconversion. What does JUCE do here and what should I?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 29, 2016, 7:52am UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/2 "2016-04-29T07:52:25Z")

</div>

TBH you can just ignore the bit depth. Only a tiny number of audio APIs actually let you change it, and even fewer devices support different depths. The JUCE classes will always use the highest bit depth if possible, and since you send the data as floats anyway it shouldn’t matter. (And nobody can actually tell the difference, of course…)

---

<div class="post-metadata">

**Author:** ![0joshuaolson1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/0joshuaolson1/32/706_2.png) [@0joshuaolson1](https://forum.juce.com/u/0joshuaolson1)\
**Post date:** [April 30, 2016, 2:12pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/3 "2016-04-30T14:12:49Z")

</div>

I can understand the usefulness of floats for processing, but how are they truncated and how do I control dithering?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 30, 2016, 3:17pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/4 "2016-04-30T15:17:33Z")

</div>

This stuff very rarely matters. What’s you actual reason for wanting to do this?

---

<div class="post-metadata">

**Author:** ![0joshuaolson1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/0joshuaolson1/32/706_2.png) [@0joshuaolson1](https://forum.juce.com/u/0joshuaolson1)\
**Post date:** [April 30, 2016, 3:59pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/5 "2016-04-30T15:59:51Z")

</div>

I want a synthesis/composition program for me. Dithering most certainly matters for writing audio files, but then bit perfect music players need to know the bit depth of the sound card too, don’t they?

Again, how are floats truncated?

Thanks for trying to help.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 30, 2016, 4:49pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/6 "2016-04-30T16:49:41Z")

</div>

> [@Zeno\_X](#):
>
> bit perfect music players need to know the bit depth of the sound card too, don’t they?

No, why would they?

The conversion either happens in the audio driver, and almost all drivers will probably just truncate to 16/24 bits. In juce code where we have to do this, we also just truncate it, because no human can tell the difference.

If you want to add extra dithering, you can do that yourself before writing the buffers, but honestly, it’s a waste of effort.

---

<div class="post-metadata">

**Author:** ![0joshuaolson1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/0joshuaolson1/32/706_2.png) [@0joshuaolson1](https://forum.juce.com/u/0joshuaolson1)\
**Post date:** [April 30, 2016, 4:52pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/7 "2016-04-30T16:52:19Z")

</div>

The only processing an audio driver should be doing in a pro audio setting is either mixing (conversion is necessary if the inputs are different bit rates or depths) or uncompressing a lossless audio stream. What does bit perfect mean to you?

---

<div class="post-metadata">

**Author:** ![0joshuaolson1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/0joshuaolson1/32/706_2.png) [@0joshuaolson1](https://forum.juce.com/u/0joshuaolson1)\
**Post date:** [April 30, 2016, 4:57pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/8 "2016-04-30T16:57:54Z")

</div>

**How** are floats truncated? Do I need to care about endianness? From a performance perspective now, knowing which bits are unused is great for minimizing branching in loops (phasers, for example), and critical for getting fixed point or integer-like processing right (correctness perspective).

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 30, 2016, 6:15pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/9 "2016-04-30T18:15:27Z")

</div>

Seriously, none of the things you’re asking about matter at all.

Just focus on writing good pure-floating-point algorithms and don’t waste your time thinking about implementation details below the driver level.

---

<div class="post-metadata">

**Author:** ![0joshuaolson1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/0joshuaolson1/32/706_2.png) [@0joshuaolson1](https://forum.juce.com/u/0joshuaolson1)\
**Post date:** [April 30, 2016, 6:20pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/10 "2016-04-30T18:20:40Z")

</div>

So is your answer that floats are 32 bit IEEE-754 and the lowest 8 or 16 logical bits in the significand are truncated? Is this how JUCE handles it?

EDIT: Sorry, not 752. Significand, not mantissa.

---

<div class="post-metadata">

**Author:** ![0joshuaolson1](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/0joshuaolson1/32/706_2.png) [@0joshuaolson1](https://forum.juce.com/u/0joshuaolson1)\
**Post date:** [April 30, 2016, 6:52pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/11 "2016-04-30T18:52:28Z")

</div>

I will add that Csound doesn’t emphasize the dithering strategy either.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 30, 2016, 6:55pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/12 "2016-04-30T18:55:52Z")

</div>

> [@Zeno\_X](#):
>
> So is your answer that floats are 32 bit IEEE-754 and the lowest 8 or 16 logical bits in the significand are truncated?

Nope. My answer is that I couldn’t give a rat’s arse about how floats get truncated. And I’ve never heard of an expert in the field ever suggesting it was of the slightest importance.

In the places where JUCE does it, we use plain old C++ float-to-int conversion, which is probably best defined as “whatever your compiler and CPU happen to do”.

---

<div class="post-metadata">

**Author:** ![TypeWriter](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/typewriter/32/14323_2.png) [@TypeWriter](https://forum.juce.com/u/TypeWriter)\
**Post date:** [May 19, 2022, 6:07am UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/13 "2022-05-19T06:07:44Z")

</div>

I actually think you can hear the difference. Someone much smarter than me could probably give a better reason on why or why this is or is not…

Upon implementing a delay line with all floats versus doubles I noticed a difference. This was when I first started years ago… which led me to my rule… if audio goes through a variable it must be a double, user params can be floats.

However, here is my attempt at a defense. The “noise floor” or that white noise at negative whatever db is technically not in the recording. I assume with perfect interpolation there would be zero or no noise.

Which leads me to my point that it is the error in playback causing a higher noise floor and thus lower quality. I found this thread wondering what would be a good decimal size to implement with custom variable types to replace my “dull” floats? 8,16,50,100!!!

I leave you with a play on words why “truncating” is a problem which is the same problem with words…

I asked a sample, how it was doing it said “bad”

I asked a sample, how it was doing it said “not good”

I asked a sample, how it was doing it said “ok”

I asked a sample, how it was doing it said “not bad”

I asked a sample, how it was doing it said “good”

Every statement “means” the same as the previous “statement” but somehow it doesn’t? Nah mean? Idk just programmed 18 hours straight. Night fellas.

---

<div class="post-metadata">

**Author:** ![TypeWriter](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/typewriter/32/14323_2.png) [@TypeWriter](https://forum.juce.com/u/TypeWriter)\
**Post date:** [May 19, 2022, 6:13am UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/14 "2022-05-19T06:13:20Z")

</div>

Also this too,

> **[32-Bit Float Files Explained - Sound Devices](https://www.sounddevices.com/32-bit-float-files-explained/)**
>
> The MixPre II models introduce the ability to record 32-bit floating point WAV files.  For ultra-high-dynamic-range recording, 32-bit float is an ideal recording format. The primary benefit of these files is their ability to record signals...

Encase anyone else didn’t know what in the hell IEEE-754 is like me. I also learned what truncating is today. I always called it chopping off. lol

Ok, for real my day is truncating goodnight 😂

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 19, 2022, 8:04am UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/15 "2022-05-19T08:04:58Z")

</div>

IMHO there was no need to necro this thread. All we need to know is here:

> [@jules](#):
>
> The JUCE classes will always use the highest bit depth if possible,

You can design your code to use double processing, that is no problem.

I am torn if there is a need to have the AudioIODeviceCallback to accept doubles in a special mode similar to the AudioProcessor::isDoubleProcessingSupported() flag.

Adding dither noise is probably best added in your floating point domain anyway, i.e. float or double as you like it.

If you want to write to audio files, it will be discretised into the target format by the AudioFormatWriter depending on how you set that up. Truncating will then happen in the discrete domain quite naturally.

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [May 19, 2022, 9:40am UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/16 "2022-05-19T09:40:22Z")

</div>

> [@daniel](#):
>
> IMHO there was no need to necro this thread

perhaps there is an argument that the forum could be set up to lock threads that are older than some arbitrary cut off (6-12 months?). If someone wants to continue the discussion they can start a new thread and reference the old one with a link. eg.

```auto
I found [this thread](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543)
but I have further questions...

```

I’m pretty sure the old thread will forward reference to the new one at the bottom of it, and we then avoid necro-ing potentially useless/defunct replies in the original, and will go a long way to stopping potential noise replies on long dead threads.

Something for the JUCE team to consider…

---

<div class="post-metadata">

**Author:** ![nicolasdanet](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nicolasdanet/32/56_2.png) [@nicolasdanet](https://forum.juce.com/u/nicolasdanet)\
**Post date:** [May 19, 2022, 10:44am UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/17 "2022-05-19T10:44:10Z")

</div>

Already discussed in the thread below ; you should probably necro it! 🤣

> [@Auto-close threads after 12 months](https://forum.juce.com/t/auto-close-threads-after-12-months/45773):
>
> Since technical problems after a year need usually be looked into with a new perspective I wanted to suggest to auto-close threads after 12 months. That way users would write their problem. Given that the codebase is changing constantly, I don’t think it makes sense to ask a couple of years about “having the same problem” without new information. The user can still reference the old thread if they believe it is relevant. Exception would be the Feature Requests, since they will be closed once …

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [May 19, 2022, 11:09am UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/18 "2022-05-19T11:09:22Z")

</div>

haha, yeah I won’t do that. Some good arguments against there, maybe 6-12 months is too hasty, but still think there is an argument that beyond 24 months there is very likely no good justification for reviving a thread. But, that’s like, just my opinion, man… 😃

---

<div class="post-metadata">

**Author:** ![TypeWriter](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/typewriter/32/14323_2.png) [@TypeWriter](https://forum.juce.com/u/TypeWriter)\
**Post date:** [May 19, 2022, 4:01pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/19 "2022-05-19T16:01:51Z")

</div>

woke up and found this

> **[GitHub - invadergir/juce-double-precision-poc: Juce Easy Double-Precision POC...](https://github.com/invadergir/juce-double-precision-poc)**
>
> Juce Easy Double-Precision POC (Proof of Concept / Experiment) - GitHub - invadergir/juce-double-precision-poc: Juce Easy Double-Precision POC (Proof of Concept / Experiment)

---

<div class="post-metadata">

**Author:** ![TypeWriter](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/typewriter/32/14323_2.png) [@TypeWriter](https://forum.juce.com/u/TypeWriter)\
**Post date:** [May 19, 2022, 4:26pm UTC](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543/20 "2022-05-19T16:26:05Z")

</div>

I’ve been trying to do the math, of the exact decimals needed for losses processing. However, I did find initializing a long double to 0.45 might render 0.45000000000123469234. -[Note] boost has a decimal variable class with as many variables as you would like…

I think at this point in time … a double buffer is absolutely necessary and I even thought I saw that Flag at one point.

I was talking to a buddy who is a pretty talented mastering engineer and he was telling me how he measures his plugins, to see if they cut off bits.

I’ve heard many people say we can’t tell the different between 16 bit wavs and 24 bit/32 bit. Which you absolutely can, although sample rate plays more into that… shrug

Flip slide… I had a friend studying signal processing tell me, the dolby digital lossless has an incredibly high sample rate and is only 1 bit or 6 bit because it creates an amplified envelope because of the sample rate whatever, that means. (sampleRate is a double but not &buffer???)

To anyone wondering, I believe 24 bit 96Hz is the most effective format for sessions and only work in that. As a programmer I also believe a float is too grainy for professional audio, and long doubles may cause too many errors because of library support limitations at this time. So use doubles. Maybe even long doubles for digital summing…

Lastly I think the answer is here. Would you want a 4 bit chip processor in an analogue project, or a 8 bit processor? Thanks for reading this far!

[Next page](https://forum.juce.com/t/how-do-i-set-audio-output-bit-depth-or-why-cant-i/17543.md?page=2)
