Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: CPU Cycle Counter Formula in AudioStream

  1. #1
    Senior Member
    Join Date
    Oct 2015
    Location
    Vermont, USA
    Posts
    257

    CPU Cycle Counter Formula in AudioStream

    I love how the Audio library lets you see what fraction of the processor is being consumed by different blocks in your audio processing chain. But, in looking at the formula, I don't understand how the calculation is done...

    From AudioStream.h, I see this formula:

    #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))

    I understand the scaling by the sample rate and block size. The part that I don't understand is the bit in red. Why is there this additive term?

    Chip

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,658
    Quote Originally Posted by chipaudette View Post
    Why is there this additive term?
    It rounds to the nearest integer. Or at least it did in the days when AUDIO_SAMPLE_RATE was expressed as an integer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •