Unity Float to db

hi! As you all know, i hope, Unity has a function where you can read the … let’s call it “volume” of every sample of an audio file. the problem is: its given in float -1 to +1.
I found some sites where they convert float to db. But only 0 to +1 floats. what to do with negative floats?
Is there any “unity-compatible” conversion from float to db?

The data you get from Unity are PCM samples which are by nature positive and negative. In a wave file they are stored as an unsigned integer but represent the same information, just shifted into the positive range (like xortrox mentioned above).

Not sure why you want it in decibel but the conversion for volume is usually:

float db = 20f * Mathf.Log10(amplidude);

amplitude should be between 0 and 1. You get that by taking the absolute value of each sample (Mathf.Abs()).

Note that decibel is just a relation compared to a reference value. Depending on the usage a db value could mean totally different things. See Decibel.

I think you’re misunderstanding the meaning of “float”. A float is a kind of number the computer recognizes that takes up a certain amount of memory in the computer, where as db is just a name for the number. I assume that however they measure the decibels in an audio file at one time, it is stored either as a float, or something else that can handle decimals. The name of a VARIABLE is probably db, but the variable is an object the computer calls a “float”. Does that make sense?