Просмотр исходного кода

Fix AudioProcessorUsage() on Teensy LC

teensy4-core
PaulStoffregen 4 лет назад
Родитель
Сommit
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))

Загрузка…
Отмена
Сохранить