app_buffer.h 1.4 KB

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