Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on How to manage decibel meter?

Post

How to manage decibel meter?

+2
−0

I had build an application using following source code (following the steps).

package com.decibal.level;

import androidx.appcompat.app.AppCompatActivity;

import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView mStatusView;
    MediaRecorder mediaRecorder;
    Thread runner;
    private static double mEMA = 0.0;
    static final private double EMA_FILTER = 0.6;

    final Runnable updater = new Runnable() {
        @Override
        public void run() {
            updateTv();
        };
    };
    final Handler handler = new Handler();
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mStatusView = findViewById(R.id.statusView);

        if (runner == null){
            runner = new Thread(){
                public void run(){
                    while(runner!=null){
                        try{
                            Thread.sleep(1000);
                            Log.d("Noise","Tock");
                        }catch (InterruptedException e){
                            e.printStackTrace();
                        }
                        handler.post(updater);
                    }
                }
            };
            runner.start();
            Log.d("Noise","start runner()");
        }
    }

    public void onResume()
    {
        super.onResume();
        startRecorder();
    }

    public void onPause()
    {
        super.onPause();
        stopRecorder();
    }

    public void startRecorder(){
        if (mediaRecorder == null){
            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();
            }catch (java.io.IOException ioe){
                android.util.Log.e("[Monkey]", "IOException: " + android.util.Log.getStackTraceString(ioe));
            }catch (java.lang.SecurityException e){
                android.util.Log.e("[Monkey]", "SecurityException: " + android.util.Log.getStackTraceString(e));
            }
            try{
                mediaRecorder.start();
            }catch (java.lang.SecurityException e){
                android.util.Log.e("[Monkey]", "SecurityException: " + android.util.Log.getStackTraceString(e));
            }

            //mEMA = 0.0;
        }
    }

    public void stopRecorder(){
        if (mediaRecorder!=null){
            mediaRecorder.stop();
            mediaRecorder.release();
            mediaRecorder = null;
        }
    }

    public void updateTv(){
        mStatusView.setText(Double.toString((getAmplitudeEMA()))+"dB");
    }
    public double soundDb(double ampl){
        return 20 * Math.log10(getAmplitudeEMA()/ampl);
    }

    public double getAmplitudeEMA() {
        double amp =  getAmplitude();
        mEMA = EMA_FILTER * amp + (1.0 - EMA_FILTER) * mEMA;
        return mEMA;
    }
    public double getAmplitude() {
        if (mediaRecorder != null)
            return  (mediaRecorder.getMaxAmplitude());
        else
            return 0;

    }
}

I am listing decibel meter result below :

59.28dB
72.12480000000001dB
81.13996800000001dB
71.78239488000001dB
66.2051831808dB
73.232829308928dB
64.03725268942848dB
66.16596043030856dB
66.50655366884938dB

When I speak

101.3610485870159dB
354.1377677739226dB

When i don't speak anymore

56.662042843827614dB
9.06592685501242dB
1.4505482968019872dB

When I was trying to check decibel meter using the sound meter.

The meter was at 60-71(When I speak also). The source code is correct but, the equation is wrong(that's what I think). When I don't speak than, I just can hear fan rotation sound (noise) which is not too much. Phone can detect the sound also. But, I worry when I stop speaking than decibel meter drops. How can I manage the decibel meter?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (2 comments)
General comments
meriton‭ wrote over 3 years ago

I'm afraid I don't understand your question. First, why is a decibel meter dropping when you stop speaking cause for worry? Isn't that expected? Second, can you clarify what you mean by "manage" the decibel meter?

deleted user wrote over 3 years ago

@meriton When I wasn't speaking the meter was above 56. When I speak it(meter) was at 100. When I stop speaking than, it drops to 10. Which was awkward to me. Yes! It was expected but, when I stop speaking it should at 56 again. But, which didn't happen. I don't know why it is happening after answering the question also. Actually, I meant, the decibel level wasn't as I wanted. That's why I said,"how to manage it"