0

here buffer.data is Uint8List pcm data which mean the range will be 0-255

 var data = buffer.data as List<int>;
         var sum = 0;
         for(var i = 0; i<  data.length;i++){
           sum+= data[i] * data[i];
         }
         var mean = sum/data.length;
         var rms = math.sqrt(mean);
         var db = 20*math.log(rms/255)/math.ln10;
         print(db);

now when I calculate this I get values around -2 to -7 which I think is too nominal for silence and some noise with when I'm speaking.

So is this correct way?

Pokaboom
  • 1,110
  • 9
  • 28
  • It's very rare to have PCM audio in 8 bit values (unless encoded in G.711 mu Law or A law), and wouldn't ever be in unsigned values (otherwise how would negative values be encoded?) You could try subtracting 128 from each `data[i]` value just in case they really are signed bytes, but that seems very unlikely. Does `data.length` represent the size you expect? If you have 1 second of audio at 16kHz sample rate - do you see exactly 16,000 bytes? – Richard Heap Feb 18 '22 at 13:48
  • Based on your earlier question you had PCM16, which of course you should be interpreting as `Int16List` – Richard Heap Feb 18 '22 at 13:51
  • @RichardHeap as you in my previous question I did all you said but wasn't getting the proper decibels. Today I tried a different library and I was getting values in floating points. Now the current library java based and second library I tried is kotlin based. – Pokaboom Feb 18 '22 at 17:15
  • Actually, I'm trying to implement a waveform plugin and now I'm thinking the previous library is giving some wrong output because both provide decibels already but newer one looks accurate. And I'm thinking of trying more library test all values and your question, I have 16k sampling rate in 1 second but I am not getting that much – Pokaboom Feb 18 '22 at 17:17

0 Answers0