2023-01-18 17:18:19 +00:00
|
|
|
/* Copyright (C) 2022-2023 Salvatore Sanfilippo -- All Rights Reserved
|
|
|
|
* See the LICENSE file for information about the license. */
|
|
|
|
|
|
|
|
/* Our circular buffer of raw samples, used in order to display
|
|
|
|
* the signal. */
|
|
|
|
|
2023-01-18 19:25:39 +00:00
|
|
|
#define RAW_SAMPLES_NUM \
|
|
|
|
2048 /* Use a power of two: we take the modulo
|
2023-01-18 17:18:19 +00:00
|
|
|
of the index quite often to normalize inside
|
|
|
|
the range, and division is slow. */
|
|
|
|
typedef struct RawSamplesBuffer {
|
2023-01-18 19:25:39 +00:00
|
|
|
FuriMutex* mutex;
|
2023-01-18 17:18:19 +00:00
|
|
|
struct {
|
2023-01-18 19:25:39 +00:00
|
|
|
uint16_t level : 1;
|
|
|
|
uint16_t dur : 15;
|
2023-01-18 17:18:19 +00:00
|
|
|
} samples[RAW_SAMPLES_NUM];
|
2023-01-18 19:25:39 +00:00
|
|
|
uint32_t idx; /* Current idx (next to write). */
|
2023-01-18 17:18:19 +00:00
|
|
|
uint32_t total; /* Total samples: same as RAW_SAMPLES_NUM, we provide
|
|
|
|
this field for a cleaner interface with the user, but
|
|
|
|
we always use RAW_SAMPLES_NUM when taking the modulo so
|
|
|
|
the compiler can optimize % as bit masking. */
|
|
|
|
/* Signal features. */
|
|
|
|
uint32_t short_pulse_dur; /* Duration of the shortest pulse. */
|
|
|
|
} RawSamplesBuffer;
|
|
|
|
|
2023-01-18 19:25:39 +00:00
|
|
|
RawSamplesBuffer* raw_samples_alloc(void);
|
|
|
|
void raw_samples_reset(RawSamplesBuffer* s);
|
|
|
|
void raw_samples_center(RawSamplesBuffer* s, uint32_t offset);
|
|
|
|
void raw_samples_add(RawSamplesBuffer* s, bool level, uint32_t dur);
|
2023-02-02 10:54:14 +00:00
|
|
|
void raw_samples_add_or_update(RawSamplesBuffer* s, bool level, uint32_t dur);
|
2023-01-18 19:25:39 +00:00
|
|
|
void raw_samples_get(RawSamplesBuffer* s, uint32_t idx, bool* level, uint32_t* dur);
|
|
|
|
void raw_samples_copy(RawSamplesBuffer* dst, RawSamplesBuffer* src);
|
|
|
|
void raw_samples_free(RawSamplesBuffer* s);
|