PulseIn.h
1 /*
2  * PulseIn.h
3  *
4  * Created on: 4 Feb 2016
5  * Author: giulio
6  */
7 
8 #ifndef PULSEIN_H_
9 #define PULSEIN_H_
10 
11 #include <Bela.h>
12 #include <vector>
13 class PulseIn {
14 private:
15  std::vector<int> _array;
16  int _pulseOnState;
17  int _digitalInput;
18  bool _pulseIsOn;
19  uint64_t _pulseStart;
20  uint64_t _lastContext;
21 public:
22  PulseIn(){
23  _digitalInput = -1;
24  };
25 
26  PulseIn(BelaContext* context, unsigned int digitalInput, int direction=1){
27  init(context, digitalInput, direction);
28  };
39  void init(BelaContext* context, unsigned int digitalInput, int direction=1);
40 
51  void check(BelaContext* context);
52 
60  int hasPulsed(BelaContext* context, int frame){//let's leave this in PulseIn.h to allow the compiler to optimize out the call.
61  if(_lastContext != context->audioFramesElapsed){ // check for pulses in the whole context and cache the result
62  check(context);
63  }
64  return _array[frame];
65  }
66  virtual ~PulseIn();
67 };
68 
69 #endif /* PULSEIN_H_ */
int hasPulsed(BelaContext *context, int frame)
Definition: PulseIn.h:60
Structure holding current audio and sensor settings and pointers to data buffers. ...
Definition: Bela.h:190
void init(BelaContext *context, unsigned int digitalInput, int direction=1)
Definition: PulseIn.h:13
void check(BelaContext *context)
const uint64_t audioFramesElapsed
Number of elapsed audio frames since the start of rendering.
Definition: Bela.h:271
Main Bela public API.