package com.ifpdos.audiotest;

import android.media.MediaRecorder;
import android.util.Log;
import java.io.File;
import java.io.IOException;

/* JADX INFO: compiled from: RecordModel.java */
/* JADX INFO: loaded from: classes.dex */
public class h {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static h f1934a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private boolean f1935b = false;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private MediaRecorder f1936c;

    private h() {
    }

    private void a() {
        MediaRecorder mediaRecorder = this.f1936c;
        if (mediaRecorder != null) {
            this.f1935b = false;
            try {
                mediaRecorder.stop();
                this.f1936c.release();
                this.f1936c = null;
            } catch (Exception e2) {
                Log.e("RecordModel", "", e2);
            }
        }
    }

    private void b() {
        MediaRecorder mediaRecorder = new MediaRecorder();
        this.f1936c = mediaRecorder;
        mediaRecorder.setAudioSource(1);
        this.f1936c.setOutputFormat(0);
        this.f1936c.setAudioEncoder(0);
        this.f1936c.setMaxDuration(f());
        File file = new File(d());
        if (file.exists()) {
            file.delete();
        }
        this.f1936c.setOutputFile(d());
    }

    public static synchronized h e() {
        if (f1934a == null) {
            f1934a = new h();
        }
        return f1934a;
    }

    public int c() {
        int maxAmplitude = this.f1936c.getMaxAmplitude();
        if (maxAmplitude == 0) {
            return 0;
        }
        return (int) (Math.log10(maxAmplitude) * 20.0d);
    }

    public String d() {
        return "/tmp/tmp.aac";
    }

    public int f() {
        return 20000;
    }

    public boolean g() {
        return this.f1935b;
    }

    public boolean h() {
        if (this.f1935b) {
            return false;
        }
        if (this.f1936c == null) {
            b();
        }
        try {
            this.f1936c.prepare();
            this.f1936c.start();
            this.f1935b = true;
            return true;
        } catch (IOException e2) {
            Log.e("RecordModel", "startRecord: ", e2);
            return false;
        }
    }

    public void i() {
        a();
    }
}
