// Path: app/src/main/java/com/chrynan/android_guitar_tuner/tuner/config/AudioConfig.java
// public interface AudioConfig {
// 
//     /**
//      * The sample rate that the Audio Recorder is using, in hertz. Note that this value is device
//      * dependent.
//      *
//      * @return The sample rate of the audio recording.
//      */
//     int getSampleRate();
// 
//     /**
//      * The size of the underlying input waveform buffer array used by the Audio Recorder. This should be
//      * larger than the value returned by {@link #getReadSize()}. This value should only be used to
//      * create an instance of an Audio Recorder and when reading or performing operations on the
//      * waveform buffer array, {@link #getReadSize()} should be used. Note that an implementation of
//      * this method should return a valid value for the device.
//      *
//      * @return The size of the underlying waveform buffer array.
//      */
//     int getInputBufferSize();
// 
//     /**
//      * The size of the underlying output waveform buffer array used by the Audio Recorder. This should be
//      * larger than the value returned by {@link #getReadSize()}. This value should only be used to
//      * create an instance of an Audio Recorder and when reading or performing operations on the
//      * waveform buffer array, {@link #getReadSize()} should be used. Note that an implementation of
//      * this method should return a valid value for the device.
//      *
//      * @return The size of the underlying waveform buffer array.
//      */
//     int getOutputBufferSize();
// 
//     /**
//      * The size of the input array of data that should be read from the buffer. Use this value when
//      * processing the buffer of waveform data.
//      *
//      * @return The size of values read from the underlying waveform buffer array.
//      */
//     int getReadSize();
// 
//     /**
//      * The size of the array of data that should be written to the output buffer. Use this value when
//      * processing the buffer of waveform data.
//      *
//      * @return The size of values written to the underlying waveform buffer array.
//      */
//     int getWriteSize();
// 
//     /**
//      * The input channel to retrieve the input data.
//      *
//      * @return The input channel
//      */
//     int getInputChannel();
// 
//     /**
//      * The output channel to output the data. For example, a value representing Stereo.
//      *
//      * @return The output channel.
//      */
//     int getOutputChannel();
// 
//     /**
//      * The input audio format of the buffer array (ex: float or short).
//      *
//      * @return The format of the buffer array.
//      */
//     int getInputFormat();
// 
//     /**
//      * The output audio format of the buffer array (ex: float or short).
//      *
//      * @return The format of the buffer array.
//      */
//     int getOutputFormat();
// 
//     /**
//      * The amount of bytes to represent a single piece of output data. For instance, 16-bit PCM data
//      * can be represented by two bytes.
//      *
//      * @return The amount of bytes needed to represent the output data.
//      */
//     int getOutputFormatByteCount();
// 
//     /**
//      * The input source of the audio data.
//      *
//      * @return The input source.
//      */
//     int getInputSource();
// }
// 
// Path: app/src/main/java/com/chrynan/android_guitar_tuner/tuner/converter/ArrayConverter.java
// public interface ArrayConverter {
// 
//     /**
//      * Converts the provided byte array to a corresponding float array.
//      *
//      * @param array          The byte array to be converted.
//      * @param convertedArray The float array representing the original byte array but as float values.
//      */
//     void convert(final byte[] array, final float[] convertedArray);
// 
//     /**
//      * Converts the provided short array to a corresponding float array.
//      *
//      * @param array          The short array to be converted.
//      * @param convertedArray The float array representing the original short array but as float values.
//      */
//     void convert(final short[] array, final float[] convertedArray);
// }


import android.media.AudioRecord;
import android.os.Build;
import com.chrynan.android_guitar_tuner.tuner.config.AudioConfig;
import com.chrynan.android_guitar_tuner.tuner.converter.ArrayConverter;
package com.chrynan.android_guitar_tuner.tuner.recorder;



/**
 * An Android implementation of the {@link AudioRecorder} interface that works with the Android
 * {@link android.media.AudioRecord} object.
 */
public class AndroidAudioRecorder implements AudioRecorder {

    private final ArrayConverter converter;
    private final AudioRecord audioRecorder;
    private final int readSize;
    private final short[] buffer;
    private final float[] floatBuffer;

// Path: app/src/main/java/com/chrynan/android_guitar_tuner/tuner/config/AudioConfig.java
// public interface AudioConfig {
// 
//     /**
//      * The sample rate that the Audio Recorder is using, in hertz. Note that this value is device
//      * dependent.
//      *
//      * @return The sample rate of the audio recording.
//      */
//     int getSampleRate();
// 
//     /**
//      * The size of the underlying input waveform buffer array used by the Audio Recorder. This should be
//      * larger than the value returned by {@link #getReadSize()}. This value should only be used to
//      * create an instance of an Audio Recorder and when reading or performing operations on the
//      * waveform buffer array, {@link #getReadSize()} should be used. Note that an implementation of
//      * this method should return a valid value for the device.
//      *
//      * @return The size of the underlying waveform buffer array.
//      */
//     int getInputBufferSize();
// 
//     /**
//      * The size of the underlying output waveform buffer array used by the Audio Recorder. This should be
//      * larger than the value returned by {@link #getReadSize()}. This value should only be used to
//      * create an instance of an Audio Recorder and when reading or performing operations on the
//      * waveform buffer array, {@link #getReadSize()} should be used. Note that an implementation of
//      * this method should return a valid value for the device.
//      *
//      * @return The size of the underlying waveform buffer array.
//      */
//     int getOutputBufferSize();
// 
//     /**
//      * The size of the input array of data that should be read from the buffer. Use this value when
//      * processing the buffer of waveform data.
//      *
//      * @return The size of values read from the underlying waveform buffer array.
//      */
//     int getReadSize();
// 
//     /**
//      * The size of the array of data that should be written to the output buffer. Use this value when
//      * processing the buffer of waveform data.
//      *
//      * @return The size of values written to the underlying waveform buffer array.
//      */
//     int getWriteSize();
// 
//     /**
//      * The input channel to retrieve the input data.
//      *
//      * @return The input channel
//      */
//     int getInputChannel();
// 
//     /**
//      * The output channel to output the data. For example, a value representing Stereo.
//      *
//      * @return The output channel.
//      */
//     int getOutputChannel();
// 
//     /**
//      * The input audio format of the buffer array (ex: float or short).
//      *
//      * @return The format of the buffer array.
//      */
//     int getInputFormat();
// 
//     /**
//      * The output audio format of the buffer array (ex: float or short).
//      *
//      * @return The format of the buffer array.
//      */
//     int getOutputFormat();
// 
//     /**
//      * The amount of bytes to represent a single piece of output data. For instance, 16-bit PCM data
//      * can be represented by two bytes.
//      *
//      * @return The amount of bytes needed to represent the output data.
//      */
//     int getOutputFormatByteCount();
// 
//     /**
//      * The input source of the audio data.
//      *
//      * @return The input source.
//      */
//     int getInputSource();
// }
// 
// Path: app/src/main/java/com/chrynan/android_guitar_tuner/tuner/converter/ArrayConverter.java
// public interface ArrayConverter {
// 
//     /**
//      * Converts the provided byte array to a corresponding float array.
//      *
//      * @param array          The byte array to be converted.
//      * @param convertedArray The float array representing the original byte array but as float values.
//      */
//     void convert(final byte[] array, final float[] convertedArray);
// 
//     /**
//      * Converts the provided short array to a corresponding float array.
//      *
//      * @param array          The short array to be converted.
//      * @param convertedArray The float array representing the original short array but as float values.
//      */
//     void convert(final short[] array, final float[] convertedArray);
// }


// Path: app/src/main/java/com/chrynan/android_guitar_tuner/tuner/recorder/AndroidAudioRecorder.java
import android.media.AudioRecord;
import android.os.Build;
import com.chrynan.android_guitar_tuner.tuner.config.AudioConfig;
import com.chrynan.android_guitar_tuner.tuner.converter.ArrayConverter;

package com.chrynan.android_guitar_tuner.tuner.recorder;



/**
 * An Android implementation of the {@link AudioRecorder} interface that works with the Android
 * {@link android.media.AudioRecord} object.
 */
public class AndroidAudioRecorder implements AudioRecorder {

    private final ArrayConverter converter;
    private final AudioRecord audioRecorder;
    private final int readSize;
    private final short[] buffer;
    private final float[] floatBuffer;

    public AndroidAudioRecorder(final AudioConfig audioConfig, final ArrayConverter converter) {