Skip to content

Commit fba220c

Browse files
committed
Add Redbox (CA) to menu, apply ./fbt format
1 parent 6006c9f commit fba220c

12 files changed

+224
-213
lines changed

dtmf_dolphin.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ static void app_free(DTMFDolphinApp* app) {
7878
free(app);
7979
}
8080

81-
int32_t dtmf_dolphin_app(void *p) {
81+
int32_t dtmf_dolphin_app(void* p) {
8282
UNUSED(p);
8383
DTMFDolphinApp* app = app_alloc();
84-
84+
8585
view_dispatcher_run(app->view_dispatcher);
8686

8787
app_free(app);

dtmf_dolphin_audio.c

+49-43
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "dtmf_dolphin_audio.h"
22

3-
DTMFDolphinAudio *current_player;
3+
DTMFDolphinAudio* current_player;
44

55
static void dtmf_dolphin_audio_dma_isr(void* ctx) {
6-
FuriMessageQueue *event_queue = ctx;
6+
FuriMessageQueue* event_queue = ctx;
77

8-
if (LL_DMA_IsActiveFlag_HT1(DMA1)) {
8+
if(LL_DMA_IsActiveFlag_HT1(DMA1)) {
99
LL_DMA_ClearFlag_HT1(DMA1);
1010

1111
DTMFDolphinCustomEvent event = {.type = DTMFDolphinEventDMAHalfTransfer};
@@ -21,13 +21,13 @@ static void dtmf_dolphin_audio_dma_isr(void* ctx) {
2121
}
2222

2323
void dtmf_dolphin_audio_clear_samples(DTMFDolphinAudio* player) {
24-
for (size_t i = 0; i < player->buffer_length; i++) {
24+
for(size_t i = 0; i < player->buffer_length; i++) {
2525
player->sample_buffer[i] = 0;
2626
}
2727
}
2828

2929
DTMFDolphinOsc* dtmf_dolphin_osc_alloc() {
30-
DTMFDolphinOsc *osc = malloc(sizeof(DTMFDolphinOsc));
30+
DTMFDolphinOsc* osc = malloc(sizeof(DTMFDolphinOsc));
3131
osc->cached_freq = 0;
3232
osc->offset = 0;
3333
osc->period = 0;
@@ -36,7 +36,7 @@ DTMFDolphinOsc* dtmf_dolphin_osc_alloc() {
3636
}
3737

3838
DTMFDolphinPulseFilter* dtmf_dolphin_pulse_filter_alloc() {
39-
DTMFDolphinPulseFilter *pf = malloc(sizeof(DTMFDolphinPulseFilter));
39+
DTMFDolphinPulseFilter* pf = malloc(sizeof(DTMFDolphinPulseFilter));
4040
pf->duration = 0;
4141
pf->period = 0;
4242
pf->offset = 0;
@@ -45,7 +45,7 @@ DTMFDolphinPulseFilter* dtmf_dolphin_pulse_filter_alloc() {
4545
}
4646

4747
DTMFDolphinAudio* dtmf_dolphin_audio_alloc() {
48-
DTMFDolphinAudio *player = malloc(sizeof(DTMFDolphinAudio));
48+
DTMFDolphinAudio* player = malloc(sizeof(DTMFDolphinAudio));
4949
player->buffer_length = SAMPLE_BUFFER_LENGTH;
5050
player->half_buffer_length = SAMPLE_BUFFER_LENGTH / 2;
5151
player->sample_buffer = malloc(sizeof(uint16_t) * player->buffer_length);
@@ -61,64 +61,66 @@ DTMFDolphinAudio* dtmf_dolphin_audio_alloc() {
6161
}
6262

6363
size_t calc_waveform_period(float freq) {
64-
if (!freq) {
64+
if(!freq) {
6565
return 0;
6666
}
6767
// DMA Rate calculation, thanks to Dr_Zlo
68-
float dma_rate = CPU_CLOCK_FREQ \
69-
/ 2 \
70-
/ DTMF_DOLPHIN_HAL_DMA_PRESCALER \
71-
/ (DTMF_DOLPHIN_HAL_DMA_AUTORELOAD + 1);
68+
float dma_rate = CPU_CLOCK_FREQ / 2 / DTMF_DOLPHIN_HAL_DMA_PRESCALER /
69+
(DTMF_DOLPHIN_HAL_DMA_AUTORELOAD + 1);
7270

7371
// Using a constant scaling modifier, which likely represents
7472
// the combined system overhead and isr latency.
75-
return (uint16_t) dma_rate * 2 / freq * 0.801923;
73+
return (uint16_t)dma_rate * 2 / freq * 0.801923;
7674
}
7775

7876
void osc_generate_lookup_table(DTMFDolphinOsc* osc, float freq) {
79-
if (osc->lookup_table != NULL) {
77+
if(osc->lookup_table != NULL) {
8078
free(osc->lookup_table);
8179
}
8280
osc->offset = 0;
8381
osc->cached_freq = freq;
8482
osc->period = calc_waveform_period(freq);
85-
if (!osc->period) {
83+
if(!osc->period) {
8684
osc->lookup_table = NULL;
8785
return;
8886
}
8987
osc->lookup_table = malloc(sizeof(float) * osc->period);
9088

91-
for (size_t i = 0; i < osc->period; i++) {
89+
for(size_t i = 0; i < osc->period; i++) {
9290
osc->lookup_table[i] = sin(i * PERIOD_2_PI / osc->period) + 1;
9391
}
9492
}
9593

96-
void filter_generate_lookup_table(DTMFDolphinPulseFilter* pf, uint16_t pulses, uint16_t pulse_ms, uint16_t gap_ms) {
97-
if (pf->lookup_table != NULL) {
94+
void filter_generate_lookup_table(
95+
DTMFDolphinPulseFilter* pf,
96+
uint16_t pulses,
97+
uint16_t pulse_ms,
98+
uint16_t gap_ms) {
99+
if(pf->lookup_table != NULL) {
98100
free(pf->lookup_table);
99101
}
100102
pf->offset = 0;
101103

102-
uint16_t gap_period = calc_waveform_period(1000 / (float) gap_ms);
103-
uint16_t pulse_period = calc_waveform_period(1000 / (float) pulse_ms);
104+
uint16_t gap_period = calc_waveform_period(1000 / (float)gap_ms);
105+
uint16_t pulse_period = calc_waveform_period(1000 / (float)pulse_ms);
104106
pf->period = pulse_period + gap_period;
105107

106-
if (!pf->period) {
108+
if(!pf->period) {
107109
pf->lookup_table = NULL;
108110
return;
109111
}
110112
pf->duration = pf->period * pulses;
111113
pf->lookup_table = malloc(sizeof(bool) * pf->duration);
112114

113-
for (size_t i = 0; i < pf->duration; i++) {
115+
for(size_t i = 0; i < pf->duration; i++) {
114116
pf->lookup_table[i] = i % pf->period < pulse_period;
115117
}
116118
}
117119

118120
float sample_frame(DTMFDolphinOsc* osc) {
119121
float frame = 0.0;
120122

121-
if (osc->period) {
123+
if(osc->period) {
122124
frame = osc->lookup_table[osc->offset];
123125
osc->offset = (osc->offset + 1) % osc->period;
124126
}
@@ -129,8 +131,8 @@ float sample_frame(DTMFDolphinOsc* osc) {
129131
bool sample_filter(DTMFDolphinPulseFilter* pf) {
130132
bool frame = true;
131133

132-
if (pf->duration) {
133-
if (pf->offset < pf->duration) {
134+
if(pf->duration) {
135+
if(pf->offset < pf->duration) {
134136
frame = pf->lookup_table[pf->offset];
135137
pf->offset = pf->offset + 1;
136138
} else {
@@ -142,14 +144,14 @@ bool sample_filter(DTMFDolphinPulseFilter* pf) {
142144
}
143145

144146
void dtmf_dolphin_osc_free(DTMFDolphinOsc* osc) {
145-
if (osc->lookup_table != NULL) {
147+
if(osc->lookup_table != NULL) {
146148
free(osc->lookup_table);
147149
}
148150
free(osc);
149151
}
150152

151153
void dtmf_dolphin_filter_free(DTMFDolphinPulseFilter* pf) {
152-
if (pf->lookup_table != NULL) {
154+
if(pf->lookup_table != NULL) {
153155
free(pf->lookup_table);
154156
}
155157
free(pf);
@@ -165,22 +167,19 @@ void dtmf_dolphin_audio_free(DTMFDolphinAudio* player) {
165167
current_player = NULL;
166168
}
167169

168-
169170
bool generate_waveform(DTMFDolphinAudio* player, uint16_t buffer_index) {
170171
uint16_t* sample_buffer_start = &player->sample_buffer[buffer_index];
171172

172-
for (size_t i = 0; i < player->half_buffer_length; i++) {
173+
for(size_t i = 0; i < player->half_buffer_length; i++) {
173174
float data = 0;
174-
if (player->osc2->period) {
175-
data = \
176-
(sample_frame(player->osc1) / 2) + \
177-
(sample_frame(player->osc2) / 2);
175+
if(player->osc2->period) {
176+
data = (sample_frame(player->osc1) / 2) + (sample_frame(player->osc2) / 2);
178177
} else {
179178
data = (sample_frame(player->osc1));
180179
}
181180
data *= sample_filter(player->filter) ? player->volume : 0.0;
182-
data *= UINT8_MAX / 2; // scale -128..127
183-
data += UINT8_MAX / 2; // to unsigned
181+
data *= UINT8_MAX / 2; // scale -128..127
182+
data += UINT8_MAX / 2; // to unsigned
184183

185184
if(data < 0) {
186185
data = 0;
@@ -196,8 +195,13 @@ bool generate_waveform(DTMFDolphinAudio* player, uint16_t buffer_index) {
196195
return true;
197196
}
198197

199-
bool dtmf_dolphin_audio_play_tones(float freq1, float freq2, uint16_t pulses, uint16_t pulse_ms, uint16_t gap_ms) {
200-
if (current_player != NULL && current_player->playing) {
198+
bool dtmf_dolphin_audio_play_tones(
199+
float freq1,
200+
float freq2,
201+
uint16_t pulses,
202+
uint16_t pulse_ms,
203+
uint16_t gap_ms) {
204+
if(current_player != NULL && current_player->playing) {
201205
// Cannot start playing while still playing something else
202206
return false;
203207
}
@@ -213,7 +217,8 @@ bool dtmf_dolphin_audio_play_tones(float freq1, float freq2, uint16_t pulses, ui
213217
dtmf_dolphin_speaker_init();
214218
dtmf_dolphin_dma_init((uint32_t)current_player->sample_buffer, current_player->buffer_length);
215219

216-
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, dtmf_dolphin_audio_dma_isr, current_player->queue);
220+
furi_hal_interrupt_set_isr(
221+
FuriHalInterruptIdDma1Ch1, dtmf_dolphin_audio_dma_isr, current_player->queue);
217222

218223
dtmf_dolphin_dma_start();
219224
dtmf_dolphin_speaker_start();
@@ -222,11 +227,12 @@ bool dtmf_dolphin_audio_play_tones(float freq1, float freq2, uint16_t pulses, ui
222227
}
223228

224229
bool dtmf_dolphin_audio_stop_tones() {
225-
if (current_player != NULL && !current_player->playing) {
230+
if(current_player != NULL && !current_player->playing) {
226231
// Can't stop a player that isn't playing.
227232
return false;
228233
}
229-
while(current_player->filter->offset > 0 && current_player->filter->offset < current_player->filter->duration) {
234+
while(current_player->filter->offset > 0 &&
235+
current_player->filter->offset < current_player->filter->duration) {
230236
// run remaining ticks if needed to complete filter sequence
231237
dtmf_dolphin_audio_handle_tick();
232238
}
@@ -236,20 +242,20 @@ bool dtmf_dolphin_audio_stop_tones() {
236242
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, NULL, NULL);
237243

238244
dtmf_dolphin_audio_free(current_player);
239-
245+
240246
return true;
241247
}
242248

243249
bool dtmf_dolphin_audio_handle_tick() {
244250
bool handled = false;
245251

246-
if (current_player) {
252+
if(current_player) {
247253
DTMFDolphinCustomEvent event;
248254
if(furi_message_queue_get(current_player->queue, &event, 250) == FuriStatusOk) {
249255
if(event.type == DTMFDolphinEventDMAHalfTransfer) {
250256
generate_waveform(current_player, 0);
251257
handled = true;
252-
} else if (event.type == DTMFDolphinEventDMAFullTransfer) {
258+
} else if(event.type == DTMFDolphinEventDMAFullTransfer) {
253259
generate_waveform(current_player, current_player->half_buffer_length);
254260
handled = true;
255261
}

dtmf_dolphin_audio.h

+12-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ typedef struct {
2424
typedef struct {
2525
size_t buffer_length;
2626
size_t half_buffer_length;
27-
uint8_t *buffer_buffer;
28-
uint16_t *sample_buffer;
27+
uint8_t* buffer_buffer;
28+
uint16_t* sample_buffer;
2929
float volume;
30-
FuriMessageQueue *queue;
31-
DTMFDolphinOsc *osc1;
32-
DTMFDolphinOsc *osc2;
33-
DTMFDolphinPulseFilter *filter;
30+
FuriMessageQueue* queue;
31+
DTMFDolphinOsc* osc1;
32+
DTMFDolphinOsc* osc2;
33+
DTMFDolphinPulseFilter* filter;
3434
bool playing;
3535
} DTMFDolphinAudio;
3636

@@ -42,7 +42,12 @@ void dtmf_dolphin_audio_free(DTMFDolphinAudio* player);
4242

4343
void dtmf_dolphin_osc_free(DTMFDolphinOsc* osc);
4444

45-
bool dtmf_dolphin_audio_play_tones(float freq1, float freq2, uint16_t pulses, uint16_t pulse_ms, uint16_t gap_ms);
45+
bool dtmf_dolphin_audio_play_tones(
46+
float freq1,
47+
float freq2,
48+
uint16_t pulses,
49+
uint16_t pulse_ms,
50+
uint16_t gap_ms);
4651

4752
bool dtmf_dolphin_audio_stop_tones();
4853

0 commit comments

Comments
 (0)