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

Thread: AudioStream.cpp & AudioStream.h - BUGFIX

  1. #1
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    129

    AudioStream.cpp & AudioStream.h - BUGFIX

    ============
    Observed problem:
    ============

    Under high-load conditions, values returned by AudioProcessorUsage() & AudioProcessorUsageMax() suffer from "rollover" (values returned can't go all the way to 100%). For values greater than approximately 60.71, the returned values appear to start over at 0. Also, returns from AudioProcessorUsageMax() indicate values that both increase & decrease, where they should be expected to only increase.

    =================
    To reproduce the problem:
    =================

    TeensyMIDIPolySynth.zip
    MERRYG02.zip

    Arduino IDE 1.8.13 + Teensy Loader 1.53-beta1 (same with Arduino 1.8.12 + Teensy Loader 1.52)

    Arduino IDE Configuration:
    Tools/Board: "Teensy 4.0" or "Teensy 4.1"
    Tools/USB Type: "Serial + MIDI"
    Tools/CPU Speed: "600MHz"
    Tools/Optimize: "Fastest"
    Tools/Keyboard Layout: "US English"
    Tools/Port: "COMx Serial (Teensy 4.0)"

    1) Build, load, & run the included TeensyMIDIPolySynth sketch (NOTE: the ability to reproduce the problem requires a sketch that heavily loads the Teensy/Audio/MIDI capabilities. Lest I get my knuckles rapped for not providing a "simple sketch which reproduces the problem", my humble & respectful reply is that, although it may not be a simple sketch, I am able provide a "sketch which *consistently* reproduces the problem", where reproducing the problem is often much more difficult than fixing the problem !!)

    2) Play the included MEERYGO2.MID file on your preferred MIDI player, with the "Teensy16PolySynth vXXX" device selected for output

    3) In the serial monitor, note that before the MIDI file starts playing, the values returned by AudioProcessorUsage() & AudioProcessorUsageMax() hover just under 50%

    4) while playing the MIDI file, the values returned by AudioProcessorUsage() & AudioProcessorUsageMax() drop to around 4%, where they should be expected to increase to a value greater than 50%

    =====================
    Proposed modification/resolution:
    =====================

    In AudioStream.cpp, the following is currently found:

    Code:
    uint16_t AudioStream::cpu_cycles_total = 0;
    uint16_t AudioStream::cpu_cycles_total_max = 0;
    Change to the following:

    Code:
    uint32_t AudioStream::cpu_cycles_total = 0;
    uint32_t AudioStream::cpu_cycles_total_max = 0;
    Likewise, in AudioStream.h, the following is currently found:

    Code:
    	uint16_t cpu_cycles;
    	uint16_t cpu_cycles_max;
    	static uint16_t cpu_cycles_total;
    	static uint16_t cpu_cycles_total_max;
    Change to the following:

    Code:
    	uint32_t cpu_cycles;
    	uint32_t cpu_cycles_max;
    	static uint32_t cpu_cycles_total;
    	static uint32_t cpu_cycles_total_max;
    =======================
    Post-modification observed behavior:
    =======================

    - before the MIDI file starts playing, the values returned by AudioProcessorUsage() & AudioProcessorUsageMax() hover just under 50%

    - while playing the MIDI file, the values returned by AudioProcessorUsage() & AudioProcessorUsageMax() increase to around 65%

    Mark J Culross
    KD5RXT

    P.S. I'm not a github kind of guy, so I do not know how to do a proper PR for this. Any assistance and/or pointers would be appreciated. MJC

  2. #2

  3. #3
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    129
    Thanks Paul !! In the ranges that my TeensyMIDIPolySynth sketch loads the processor (50% - 65%), the change resolved the reported roll-over.

    Mark J Culross
    KD5RXT

Posting Permissions

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