Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sound meter android

Tags:

android

audio

I'm trying to implement a sound meter in dB in android but I haven't found the way to start yet. I have gone over androids API and haven't found anything that I think is suitable. Can anyone help me please?

like image 936
Laurence Nicolaou Avatar asked Jul 02 '26 06:07

Laurence Nicolaou


2 Answers

This isn't possible in general because of the confusion between the different meanings of 'dB' and the fact that you can't measure physical Sound Pressure Level (which is generally what people mean when they talk about 'sound meters') without calibrated devices. See my previous answers to similar questions:

  • Audio output level in a form that can be converted to decibel
  • Calculate A-weighted (or B or C) SPL decibel iOS
like image 197
the_mandrill Avatar answered Jul 04 '26 19:07

the_mandrill


Try using AudioRecord to record the audio to a buffer, then measure the dB's from the raw PCM data.

To initialize AudioRecord

AudioRecord record = new AudioRecord(AudioSource.MIC, SAMPLING_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);

To read a sample from MIC

short[] buff = new short[8000];
record.read(buff, 0, buff.length); 
like image 31
DMK Avatar answered Jul 04 '26 19:07

DMK