瀏覽代碼

Fix AudioProcessorUsage() on Teensy LC

main
PaulStoffregen 4 年之前
父節點
當前提交
d0d1177153
共有 2 個文件被更改,包括 13 次插入1 次删除
  1. +9
    -1
      teensy3/AudioStream.cpp
  2. +4
    -0
      teensy3/AudioStream.h

+ 9
- 1
teensy3/AudioStream.cpp 查看文件

@@ -320,9 +320,13 @@ void software_isr(void) // AudioStream::update_all()
{
AudioStream *p;

#if defined(KINETISK)
ARM_DEMCR |= ARM_DEMCR_TRCENA;
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA;
uint32_t totalcycles = ARM_DWT_CYCCNT;
#elif defined(KINETISL)
uint32_t totalcycles = micros();
#endif
//digitalWriteFast(2, HIGH);
for (p = AudioStream::first_update; p; p = p->next_update) {
if (p->active) {
@@ -336,7 +340,11 @@ void software_isr(void) // AudioStream::update_all()
}
}
//digitalWriteFast(2, LOW);
totalcycles = (ARM_DWT_CYCCNT - totalcycles) >> 4;;
#if defined(KINETISK)
totalcycles = (ARM_DWT_CYCCNT - totalcycles) >> 4;
#elif defined(KINETISL)
totalcycles = micros() - totalcycles;
#endif
AudioStream::cpu_cycles_total = totalcycles;
if (totalcycles > AudioStream::cpu_cycles_total_max)
AudioStream::cpu_cycles_total_max = totalcycles;

+ 4
- 0
teensy3/AudioStream.h 查看文件

@@ -114,7 +114,11 @@ protected:
AudioStream::initialize_memory(data, num); \
})

#if defined(KINETISK)
#define CYCLE_COUNTER_APPROX_PERCENT(n) (((n) + (F_CPU / 32 / AUDIO_SAMPLE_RATE * AUDIO_BLOCK_SAMPLES / 100)) / (F_CPU / 16 / AUDIO_SAMPLE_RATE * AUDIO_BLOCK_SAMPLES / 100))
#elif defined(KINETISL)
#define CYCLE_COUNTER_APPROX_PERCENT(n) ((n) * (int)(AUDIO_SAMPLE_RATE) + (int)(AUDIO_SAMPLE_RATE/2)) / (AUDIO_BLOCK_SAMPLES * 10000)
#endif

#define AudioProcessorUsage() (CYCLE_COUNTER_APPROX_PERCENT(AudioStream::cpu_cycles_total))
#define AudioProcessorUsageMax() (CYCLE_COUNTER_APPROX_PERCENT(AudioStream::cpu_cycles_total_max))

Loading…
取消
儲存