You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DetectorImpl.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.feemers.android.fftdrawer.SignalProcessing;
  2. import java.util.ArrayList;
  3. public class DetectorImpl implements IDetector {
  4. protected ArrayList<Double> m_buffer;
  5. protected int m_buffer_SIZE; //TODO: Make this this dependent to the sampleRate
  6. protected double m_sampleRate;
  7. protected ThresholdCalculator m_thresholdCalculator;
  8. protected double m_threshold;
  9. protected Notifier m_Notifier;
  10. public DetectorImpl(int windowSize)
  11. {
  12. m_buffer = new ArrayList<>();
  13. m_buffer_SIZE = 128; //TODO later: Change this hardcoded value and calculate it during runtime -> depending on sampleRate
  14. m_sampleRate = 0;
  15. m_thresholdCalculator = new ThresholdCalculator(windowSize);
  16. m_threshold = m_thresholdCalculator.getThreshold();
  17. }
  18. @Override
  19. public void onNewSample(double sample) {
  20. m_thresholdCalculator.onNewSample(sample);
  21. m_threshold = m_thresholdCalculator.getThreshold();
  22. }
  23. @Override
  24. public void setSampleRate(double sampleRate) {
  25. m_sampleRate = sampleRate;
  26. }
  27. @Override
  28. public void setThreshold(double threshold) {
  29. // Call this to set the constant part of the threshold determined by the user
  30. m_thresholdCalculator.setConstantThresholdPart(threshold);
  31. }
  32. public void connectNotifier(Notifier notifier){
  33. if(notifier == null){
  34. throw new AssertionError("Notifier is null");
  35. }
  36. m_Notifier = notifier;
  37. }
  38. }