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

Thread: Audiolib RMS/PEAK value range

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    11

    Audiolib RMS/PEAK value range

    Hello everyone,

    with the AudioLib I get a value range from 0.0 to 1.0 for PEAK and RMS - ok.
    But I need the range -1.0 to 1.0.
    How do I get this range?

    Thanks,
    Bruno

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    398
    Quote Originally Posted by DIYLAB View Post
    Hello everyone,

    with the AudioLib I get a value range from 0.0 to 1.0 for PEAK and RMS - ok.
    But I need the range -1.0 to 1.0.
    How do I get this range?

    Thanks,
    Bruno
    RMS is by definition non-negative.

    The AudioAnalyzePeak class has read() and readPeakToPeak() methods - however read returns the maximum of
    the two polarities of peak, so you can't distinquish a (-0.3..+0.8) signal from a (-0.8..+0.3) signal as they both
    return 0.7 peak and 1.1 p2p.

    You'd need a modified version of AudioAnalyzePeak for this I think.

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Posts
    11
    Quote Originally Posted by MarkT View Post
    RMS is by definition non-negative.
    You'd need a modified version of AudioAnalyzePeak for this I think.
    I think so too.
    I need the negative values for a correlation display and a goniometer.
    As a desktop version in C# and NAudio it works fine, but the implementation for the Teensy gives me difficulties.

    Unfortunately I wouldn't know how to modify or better extend the AudioAnalyzePeak in my project. Because the original should already remain unchanged.

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    398
    Quote Originally Posted by DIYLAB View Post
    I think so too.
    I need the negative values for a correlation display and a goniometer.
    As a desktop version in C# and NAudio it works fine, but the implementation for the Teensy gives me difficulties.

    Unfortunately I wouldn't know how to modify or better extend the AudioAnalyzePeak in my project. Because the original should already remain unchanged.
    Well the existing read() method in Audio/analyze_peak.h is:
    Code:
    	float read(void) {
    		__disable_irq();
    		int min = min_sample;
    		int max = max_sample;
    		min_sample = 32767;
    		max_sample = -32768;
    		__enable_irq();
    		min = abs(min);
    		max = abs(max);
    		if (min > max) max = min;
    		return (float)max / 32767.0f;
    	}
    You could add two similar methods called readMax and readMin I'm sure...

  5. #5
    Junior Member
    Join Date
    Jun 2020
    Posts
    11
    Quote Originally Posted by MarkT View Post
    Well the existing read() method in Audio/analyze_peak.h is:
    You could add two similar methods called readMax and readMin I'm sure...
    Of course I can, but then I change the original files and the changes are lost with every Teensyduino update.
    How could I implement the additional methods in my own project?

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    398
    Create a pull-request from the Audio lib repo?

    I can do this if you like, I'm all setup.

Posting Permissions

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