app_buffer.h 1.2 KB

1234567891011121314151617181920212223242526
  1. /* Our circular buffer of raw samples, used in order to display
  2. * the signal. */
  3. #define RAW_SAMPLES_NUM 1024 /* Use a power of two: we take the modulo
  4. of the index quite often to normalize inside
  5. the range, and division is slow. */
  6. typedef struct RawSamplesBuffer {
  7. FuriMutex *mutex;
  8. uint8_t level[RAW_SAMPLES_NUM];
  9. uint32_t dur[RAW_SAMPLES_NUM];
  10. uint32_t idx; /* Current idx (next to write). */
  11. uint32_t total; /* Total samples: same as RAW_SAMPLES_NUM, we provide
  12. this field for a cleaner interface with the user, but
  13. we always use RAW_SAMPLES_NUM when taking the modulo so
  14. the compiler can optimize % as bit masking. */
  15. /* Signal features. */
  16. uint32_t short_pulse_dur; /* Duration of the shortest pulse. */
  17. } RawSamplesBuffer;
  18. RawSamplesBuffer *raw_samples_alloc(void);
  19. void raw_samples_reset(RawSamplesBuffer *s);
  20. void raw_samples_add(RawSamplesBuffer *s, bool level, uint32_t dur);
  21. void raw_samples_get(RawSamplesBuffer *s, uint32_t idx, bool *level, uint32_t *dur);
  22. void raw_samples_copy(RawSamplesBuffer *dst, RawSamplesBuffer *src);
  23. void raw_samples_free(RawSamplesBuffer *s);