3

I am working on a research project that involves recording community noise nuisances using an android device to perform some complex digital signal processing analysis and calculate some metrics.

My supervisor instructed me to calibrate the microphones of the android devices before distributing them in the community. I was wondering if there is a programmatic way of doing it.

Why the calibration?

An android devices' microphone's sensitivity may be different from another device. Even the manufacturers of the same company cannot comment on their sensitivities.

So it's quite possible, that an android device may record a sound at 60 dB and another device may record the sound at 70 dB at the same time under identical surroundings and conditions.

I was thinking on the following lines -> make a recording in a quite environment followed by a recording in a noisy environment. The gain can be adjusted as required. I am still not clear on this.

Is there any programmatic way of doing this?

Any help on this is greatly appreciated.

Aditya
  • 1,172
  • 11
  • 32
  • Possible duplicate of [How to calibrate an external microphone device?](http://stackoverflow.com/questions/38336768/how-to-calibrate-an-external-microphone-device) You just asked a nearly identical question. Maybe add some details from this one to the earlier one. – hotpaw2 Jul 13 '16 at 04:43
  • Yeah. The reason I posted this question is because it's about calibrating the microphone of an android smartphone. Since I have to write a script to automatically calibrate a microphone in an environment before making a recording, I feel that this question is different than the other one that I have asked. – Aditya Jul 13 '16 at 14:33

1 Answers1

0

After doing some research, I have finally found a way to calibrate the sensitivity of an Android phone's microphone.

Given below is the code to generate the amplitude as a dB values using the class MediaRecorder in android.

import android.media.MediaRecorder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

public class RecordingAudioThreshold extends AppCompatActivity {

    // This class generates the spectrogram of a wav file
    private MediaRecorder mediaRecorder = null;
    private Timer timerThread;
    private Button startRecording, stopRecording;
    private TextView recordingThreshold, recordingThresholdDB;
    int amplitude = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_generate_spectrogram);

        // Initialize the timer (used to cancel the thread if it's not running).
        timerThread = new Timer();

        // Method to calibrate the microphone
        startRecording = (Button) findViewById(R.id.button_startRecording);
        stopRecording = (Button) findViewById(R.id.button_stopRecording);
        recordingThreshold = (TextView) findViewById(R.id.textView_threshold);
        recordingThresholdDB = (TextView) findViewById(R.id.textView_thresholdDB);

        startRecording.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mediaRecorder = new MediaRecorder();
                mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                mediaRecorder.setOutputFile("/dev/null");

                try {
                    mediaRecorder.prepare();
                    mediaRecorder.start();
                    System.out.println("Started Recording using Media Recorder");
                } catch (IOException e) {
                    System.out.println("Exception while recording of type : " + e.toString());
                }

                // start the timer to print the recorded values
                timerThread.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        amplitude = mediaRecorder.getMaxAmplitude();
                        recordingThreshold.post(new Runnable() {
                            @Override
                            public void run() {
                                recordingThreshold.setText("The recorded value is : " + amplitude);
                            }
                        });
                        recordingThresholdDB.post(new Runnable() {
                            @Override
                            public void run() {
                                recordingThresholdDB.setText("The decibel value is : " + 20 * Math.log10(amplitude));
                            }
                        });
                    }
                }, 0, 500);
            }
        });

        stopRecording.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                timerThread.cancel();
                if (mediaRecorder != null) {
                    mediaRecorder.release();
                    mediaRecorder = null;
                }
                recordingThreshold.setText("Calibration complete.");
                recordingThresholdDB.setText("Calibration complete.");
            }
        });
    }
}

Now there are two ways to adjust the sensitivity of the microphone. One method is to use a Calibrated Audio Recording Equipment and the second method is to generate a sound of known value.

Measure the volume in dB measured by the phone's microphone and by the calibrated audio recording equipment and adjust the gain.

Produce a sound of known value and adjust the gain.

Both work really well, but I prefer using a recording equipment.

Aditya
  • 1,172
  • 11
  • 32
  • Nice! Note that the microphone may not be equally sensitive on all frequencies though. – nijoakim Dec 30 '19 at 19:08
  • That's a good point. Android device microphones are tailor made for frequencies which are humans are sensitive to. – Aditya Feb 07 '20 at 06:42
  • Well, mics can still miss some of the high or low pitch frequencies which humans can hear completely as well as be quite different around the other frequencies. Source http://blog.faberacoustical.com/2009/ios/iphone/iphone-microphone-frequency-response-comparison/ – nijoakim Feb 18 '20 at 14:31