Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
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 
35  PulseIn(BelaContext* context, unsigned int digitalInput, int direction=1){
36  init(context, digitalInput, direction);
37  };
38 
50  void init(BelaContext* context, unsigned int digitalInput, int direction=1);
51 
62  void check(BelaContext* context);
63 
71  int hasPulsed(BelaContext* context, int frame){//let's leave this in PulseIn.h to allow the compiler to optimize out the call.
72  if(_lastContext != context->audioFramesElapsed){ // check for pulses in the whole context and cache the result
73  check(context);
74  }
75  return _array[frame];
76  }
77  virtual ~PulseIn();
78 };
79 
80 #endif /* PULSEIN_H_ */
int hasPulsed(BelaContext *context, int frame)
Definition: PulseIn.h:71
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition: Bela.h:148
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:296
Main Bela public API.
PulseIn(BelaContext *context, unsigned int digitalInput, int direction=1)
Definition: PulseIn.h:35