6666
6767Display display;
6868FIX_FFT fft;
69- RainbowFFT effect (display, fft);
7069
70+ std::vector<Effect *> effects;
71+
72+ #ifdef EFFECTS_ON_CORE1
7173constexpr int core1_stack_len = 512 ;
7274uint32_t core1_stack[512 ];
75+ int16_t effect_buf[SAMPLE_COUNT] = {0 };
76+ #endif
7377
7478static constexpr unsigned int BUFFERS_PER_FFT_SAMPLE = 2 ;
7579static constexpr unsigned int SAMPLES_PER_AUDIO_BUFFER = SAMPLE_COUNT / BUFFERS_PER_FFT_SAMPLE;
@@ -94,15 +98,15 @@ static uint8_t btstack_last_sample_idx;
9498
9599auto_init_mutex (core1_effect_update);
96100
97- int16_t effect_buf[SAMPLE_COUNT] = {0 };
98-
101+ #ifdef EFFECTS_ON_CORE1
99102void core1_entry () {
100103 while (1 ) {
101104 mutex_enter_blocking (&core1_effect_update);
102- effect. update (effect_buf, SAMPLE_COUNT);
105+ effects[ 0 ]-> update (effect_buf, SAMPLE_COUNT);
103106 mutex_exit (&core1_effect_update);
104107 }
105108}
109+ #endif
106110
107111static audio_buffer_pool_t *init_audio (uint32_t sample_frequency, uint8_t channel_count) {
108112
@@ -140,12 +144,19 @@ static audio_buffer_pool_t *init_audio(uint32_t sample_frequency, uint8_t channe
140144 assert (ok);
141145 (void )ok;
142146
143- effect.init (sample_frequency);
147+ effects.push_back (new RainbowFFT (display, fft));
148+ effects.push_back (new ClassicFFT (display, fft));
149+
150+ for (auto &effect : effects) {
151+ effect->init (sample_frequency);
152+ }
144153
145154 display.init ();
146155 display.clear ();
147156
148- // multicore_launch_core1_with_stack(core1_entry, core1_stack, core1_stack_len);
157+ #ifdef EFFECTS_ON_CORE1
158+ multicore_launch_core1_with_stack (core1_entry, core1_stack, core1_stack_len);
159+ #endif
149160
150161 return producer_pool;
151162}
@@ -160,14 +171,22 @@ static void btstack_audio_pico_sink_fill_buffers(void){
160171 int16_t * buffer16 = (int16_t *) audio_buffer->buffer ->bytes ;
161172 (*playback_callback)(buffer16, audio_buffer->max_sample_count );
162173
163- effect.update (buffer16, SAMPLE_COUNT);
174+ #ifndef EFFECTS_ON_CORE1
175+ effects[0 ]->update (buffer16, SAMPLE_COUNT);
176+ #endif
164177
165- // mutex_enter_blocking(&core1_effect_update);
178+ #ifdef EFFECTS_ON_CORE1
179+ mutex_enter_blocking (&core1_effect_update);
180+ #endif
166181 for (auto i = 0u ; i < SAMPLE_COUNT; i++) {
167- // effect_buf[i] = buffer16[i];
182+ #ifdef EFFECTS_ON_CORE1
183+ effect_buf[i] = buffer16[i];
184+ #endif
168185 buffer16[i] = (int32_t (buffer16[i]) * int32_t (btstack_volume)) >> 8 ;
169186 }
170- // mutex_exit(&core1_effect_update);
187+ #ifdef EFFECTS_ON_CORE1
188+ mutex_exit (&core1_effect_update);
189+ #endif
171190
172191 // duplicate samples for mono
173192 if (btstack_audio_pico_channel_count == 1 ){
0 commit comments