0

I am calculating a dBFS value from a 16-bit wave file sample (-32768 to +32767) using c# as follows:

int sampleValue = -32700;

double dBFSvalue = 20 * Math.Log10(Math.Abs(sampleValue) / 32768);

But when I try to print the dBFS value, a sampleValue of 32768 results in "0" as it should, but any other value of sampleValue results in "-infinity".

MessageBox.Show($"Result: {dBFSvalue}dBFS");

Is this something to do with the displaying of type Double? How should I convert the number to display it properly in the form of "-60.5 dBFS"?

Thanks.

VC.One
  • 14,790
  • 4
  • 25
  • 57
Quantum_Kernel
  • 303
  • 1
  • 7
  • 19
  • https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx –  Jul 14 '16 at 07:40

1 Answers1

3

Replace your second line of code by

double dBFSvalue = 20 * Math.Log10(Math.Abs(sampleValue) / 32768.0);

You need the .0 to calculate it as floating point number. Otherwise it is calculated as integer and the term in the brackets is evaluated as 0.

Fratyx
  • 5,717
  • 1
  • 12
  • 22