summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/pcmbuf.c50
-rw-r--r--firmware/export/thread.h1
-rw-r--r--firmware/thread.c5
3 files changed, 38 insertions, 18 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index e2b1d7f87b..91b9f1329b 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -104,6 +104,8 @@ static size_t pcmbuf_mix_sample IDATA_ATTR;
104static bool low_latency_mode = false; 104static bool low_latency_mode = false;
105static bool pcmbuf_flush; 105static bool pcmbuf_flush;
106 106
107static int codec_thread_priority = 0;
108
107extern struct thread_entry *codec_thread_p; 109extern struct thread_entry *codec_thread_p;
108 110
109/* Helpful macros for use in conditionals this assumes some of the above 111/* Helpful macros for use in conditionals this assumes some of the above
@@ -235,30 +237,37 @@ static inline void pcmbuf_add_chunk(void)
235 audiobuffer_fillpos = 0; 237 audiobuffer_fillpos = 0;
236} 238}
237 239
238static void pcmbuf_under_watermark(void)
239{
240#ifdef HAVE_PRIORITY_SCHEDULING 240#ifdef HAVE_PRIORITY_SCHEDULING
241 static int old_priority = 0; 241static void boost_codec_thread(bool boost)
242 242{
243 if (LOW_DATA(2) && pcm_is_playing()) 243 if (boost)
244 { 244 {
245 if (!old_priority) 245 if (codec_thread_priority == 0)
246 { 246 codec_thread_priority = thread_set_priority(
247 /* Buffer is critically low so override UI priority. */ 247 codec_thread_p, PRIORITY_REALTIME);
248 old_priority = thread_set_priority(codec_thread_p,
249 PRIORITY_REALTIME);
250 }
251 } 248 }
252 else if (old_priority) 249 else if (codec_thread_priority != 0)
253 { 250 {
254 /* Set back the original priority. */ 251 thread_set_priority(codec_thread_p, codec_thread_priority);
255 thread_set_priority(codec_thread_p, old_priority); 252 codec_thread_priority = 0;
256 old_priority = 0;
257 } 253 }
258#endif 254}
255#endif /* HAVE_PRIORITY_SCHEDULING */
259 256
260 /* Fill audio buffer by boosting cpu */ 257static void pcmbuf_under_watermark(void)
261 trigger_cpu_boost(); 258{
259 /* Only codec thread initiates boost - voice boosts the cpu when playing
260 a clip */
261 if (thread_get_current() == codec_thread_p)
262 {
263#ifdef HAVE_PRIORITY_SCHEDULING
264 /* If buffer is critically low, override UI priority, else
265 set back to the original priority. */
266 boost_codec_thread(LOW_DATA(2) && pcm_is_playing());
267#endif
268 /* Fill audio buffer by boosting cpu */
269 trigger_cpu_boost();
270 }
262 271
263 /* Disable crossfade if < .5s of audio */ 272 /* Disable crossfade if < .5s of audio */
264 if (LOW_DATA(2)) 273 if (LOW_DATA(2))
@@ -364,6 +373,11 @@ void pcmbuf_play_stop(void)
364 crossfade_init = false; 373 crossfade_init = false;
365 crossfade_active = false; 374 crossfade_active = false;
366 pcmbuf_flush = false; 375 pcmbuf_flush = false;
376
377#ifdef HAVE_PRIORITY_SCHEDULING
378 /* Can unboost the codec thread here no matter who's calling */
379 boost_codec_thread(false);
380#endif
367} 381}
368 382
369int pcmbuf_used_descs(void) { 383int pcmbuf_used_descs(void) {
diff --git a/firmware/export/thread.h b/firmware/export/thread.h
index 2ff4694159..3a979722b9 100644
--- a/firmware/export/thread.h
+++ b/firmware/export/thread.h
@@ -150,6 +150,7 @@ void wakeup_thread(struct thread_entry **thread);
150int thread_set_priority(struct thread_entry *thread, int priority); 150int thread_set_priority(struct thread_entry *thread, int priority);
151int thread_get_priority(struct thread_entry *thread); 151int thread_get_priority(struct thread_entry *thread);
152#endif 152#endif
153struct thread_entry * thread_get_current(void);
153void init_threads(void); 154void init_threads(void);
154int thread_stack_usage(const struct thread_entry *thread); 155int thread_stack_usage(const struct thread_entry *thread);
155int thread_get_status(const struct thread_entry *thread); 156int thread_get_status(const struct thread_entry *thread);
diff --git a/firmware/thread.c b/firmware/thread.c
index 281ab0fa54..614286c422 100644
--- a/firmware/thread.c
+++ b/firmware/thread.c
@@ -776,6 +776,11 @@ int thread_get_priority(struct thread_entry *thread)
776} 776}
777#endif 777#endif
778 778
779struct thread_entry * thread_get_current(void)
780{
781 return cores[CURRENT_CORE].running;
782}
783
779void init_threads(void) 784void init_threads(void)
780{ 785{
781 unsigned int core = CURRENT_CORE; 786 unsigned int core = CURRENT_CORE;