3 ms·
It's much nicer Said every developer who has ever applied floats where scaled integers would be just as effective. I attribute this to pocket calculators whic
by jqpabc123 4y ago
It's much nicer
Said every developer who has ever applied floats where scaled integers would be just as effective.
I attribute this to pocket calculators which have shaped most people's thinking.
I've even had developers try to tell me it can't be done any other way --- until I show them.
All that said, if floats are needed to interface with other software, you may not have much choice in the matter.
- tialaramex 4y agoNot for developers, it's much nicer for the users. There's a phrase "infinite headroom" which might make this a bit sharper. With a conventional analogue recording medium, the medium has physical properties which impact the precision with which it can record audio. For example maybe the reel-to-reel tape recorders in a studio can do about 12-bit precision. At the bottom, the precision is cut off by noise, mechanical noise in the equipment and eventually even quantum mechanical noise in our universe which is unavoidable. At the top it's cut off by practical engineering limits - the magnetic field strengths are limited. A good analogue engineer ensures that there's "headroom" where if the recording is a little louder than expected it doesn't bump into that upper limit, when Aretha hits that note 6dB louder than anticipated, you had 10dB of headroom so it's captured OK. But to do this you're sacrificing that precision at the other end of the scale, listeners can't hear her turning the lyrics sheet in the background of the song even though you'd have heard that if you were in the room. In digital integer space, we can have lots of precision, 14-bit happened early, 16-bit was soon common place, and today 24-bit is widely available (although you need to squint to see 24 actual bits, don't think about it too hard). But, the integers are brick walls at the edges of that range. If you set things up to use all your (say) 16-bits and it comes out hotter than expected, your data is trashed because it saturates † producing a harsh clipping. So you need to carefully set the headroom to give you as much space at the top as you need, but without wasting too much. Stressful. With floats you get infinite headroom. Conventionally PCM audio is represented as -1.0 to 1.0, but in float space if you're "too hot" by a factor of literally 1000, it's no problem at all, floating point numbers can go from -1000.0 to 1000.0 just fine, and when you're ready to actually listen to it, just multiply them by 0.001 (this is called "gain" in audio). † Or, if the programmer doesn't understand what they're doing, it wraps and sounds like complete nonsense. This is common on 1980s home computer audio setups.
- jqpabc123 4y agoDon't get me wrong --- there are perfectly valid use cases for floats --- and it sounds like you may have one. But these valid uses are a lot less than what I see in a lot of software.
- ttoinou 4y agoSaid every developer who has ever applied floats where scaled integers would be just as effective. Floats are great to prototype quickly and get a good result. Once the algorithm is found, you can spend more time fine tuning with improvements such as others kinds of ways to represent fractional numbers