// Path: android/WALT/app/src/main/java/org/chromium/latency/walt/Utils.java
// static int getIntPreference(Context context, @StringRes int keyId, int defaultValue) {
//     SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
//     return preferences.getInt(context.getString(keyId), defaultValue);
// }


import android.content.Context;
import android.media.AudioManager;
import android.os.Handler;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
import static org.chromium.latency.walt.Utils.getIntPreference;

    // Audio out
    private int requestedBeeps;
    private int recordingRepetitions;
    private static int recorderSyncAfterRepetitions = 10;
    private final int threshold;

    ArrayList<Double> deltas_mic = new ArrayList<>();
    private ArrayList<Double> deltas_play2queue = new ArrayList<>();
    ArrayList<Double> deltas_queue2wire = new ArrayList<>();
    private ArrayList<Double> deltasJ2N = new ArrayList<>();

    long lastBeepTime;

    public static native long playTone();
    public static native void startWarmTest();
    public static native void stopTests();
    public static native void createEngine();
    public static native void destroyEngine();
    public static native void createBufferQueueAudioPlayer(int frameRate, int framesPerBuffer);

    public static native void startRecording();
    public static native void createAudioRecorder(int frameRate, int framesToRecord);
    public static native short[] getRecordedWave();
    public static native long getTeRec();
    public static native long getTcRec();
    public static native long getTePlay();

    AudioTest(Context context) {
        super(context);
// Path: android/WALT/app/src/main/java/org/chromium/latency/walt/Utils.java
// static int getIntPreference(Context context, @StringRes int keyId, int defaultValue) {
//     SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
//     return preferences.getInt(context.getString(keyId), defaultValue);
// }


// Path: android/WALT/app/src/main/java/org/chromium/latency/walt/AudioTest.java
import android.content.Context;
import android.media.AudioManager;
import android.os.Handler;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
import static org.chromium.latency.walt.Utils.getIntPreference;


    // Audio out
    private int requestedBeeps;
    private int recordingRepetitions;
    private static int recorderSyncAfterRepetitions = 10;
    private final int threshold;

    ArrayList<Double> deltas_mic = new ArrayList<>();
    private ArrayList<Double> deltas_play2queue = new ArrayList<>();
    ArrayList<Double> deltas_queue2wire = new ArrayList<>();
    private ArrayList<Double> deltasJ2N = new ArrayList<>();

    long lastBeepTime;

    public static native long playTone();
    public static native void startWarmTest();
    public static native void stopTests();
    public static native void createEngine();
    public static native void destroyEngine();
    public static native void createBufferQueueAudioPlayer(int frameRate, int framesPerBuffer);

    public static native void startRecording();
    public static native void createAudioRecorder(int frameRate, int framesToRecord);
    public static native short[] getRecordedWave();
    public static native long getTeRec();
    public static native long getTcRec();
    public static native long getTePlay();

    AudioTest(Context context) {
        super(context);
        playbackRepetitions = getIntPreference(context, R.string.preference_audio_out_reps, 10);