Browse Source

Fix AudioProcessorUsage() on Teensy LC

teensy4-core
PaulStoffregen 4 years ago
parent
commit
d0d1177153
2 changed files with 13 additions and 1 deletions
  1. +9
    -1
      teensy3/AudioStream.cpp
  2. +4
    -0
      teensy3/AudioStream.h

+ 9
- 1
teensy3/AudioStream.cpp View File

{ {
AudioStream *p; AudioStream *p;


#if defined(KINETISK)
ARM_DEMCR |= ARM_DEMCR_TRCENA; ARM_DEMCR |= ARM_DEMCR_TRCENA;
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA;
uint32_t totalcycles = ARM_DWT_CYCCNT; uint32_t totalcycles = ARM_DWT_CYCCNT;
#elif defined(KINETISL)
uint32_t totalcycles = micros();
#endif
//digitalWriteFast(2, HIGH); //digitalWriteFast(2, HIGH);
for (p = AudioStream::first_update; p; p = p->next_update) { for (p = AudioStream::first_update; p; p = p->next_update) {
if (p->active) { if (p->active) {
} }
} }
//digitalWriteFast(2, LOW); //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; AudioStream::cpu_cycles_total = totalcycles;
if (totalcycles > AudioStream::cpu_cycles_total_max) if (totalcycles > AudioStream::cpu_cycles_total_max)
AudioStream::cpu_cycles_total_max = totalcycles; AudioStream::cpu_cycles_total_max = totalcycles;

+ 4
- 0
teensy3/AudioStream.h View File

AudioStream::initialize_memory(data, num); \ 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)) #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 AudioProcessorUsage() (CYCLE_COUNTER_APPROX_PERCENT(AudioStream::cpu_cycles_total))
#define AudioProcessorUsageMax() (CYCLE_COUNTER_APPROX_PERCENT(AudioStream::cpu_cycles_total_max)) #define AudioProcessorUsageMax() (CYCLE_COUNTER_APPROX_PERCENT(AudioStream::cpu_cycles_total_max))

Loading…
Cancel
Save