package com.feemers.android.fftdrawer.SignalProcessing; import java.util.ArrayList; public class DetectorImpl implements IDetector { protected ArrayList m_buffer; protected int m_buffer_SIZE; //TODO: Make this this dependent to the sampleRate protected double m_sampleRate; protected ThresholdCalculator m_thresholdCalculator; protected double m_threshold; protected Notifier m_Notifier; public DetectorImpl(int windowSize) { m_buffer = new ArrayList<>(); m_buffer_SIZE = 128; //TODO later: Change this hardcoded value and calculate it during runtime -> depending on sampleRate m_sampleRate = 0; m_thresholdCalculator = new ThresholdCalculator(windowSize); m_threshold = m_thresholdCalculator.getThreshold(); } @Override public void onNewSample(double sample) { m_thresholdCalculator.onNewSample(sample); m_threshold = m_thresholdCalculator.getThreshold(); } @Override public void setSampleRate(double sampleRate) { m_sampleRate = sampleRate; } @Override public void setThreshold(double threshold) { // Call this to set the constant part of the threshold determined by the user m_thresholdCalculator.setConstantThresholdPart(threshold); } public void connectNotifier(Notifier notifier){ if(notifier == null){ throw new AssertionError("Notifier is null"); } m_Notifier = notifier; } }