Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AudioAnalyzeRMS_F32 and control_sgtl5000_32bit #15

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/AudioAnalyzeRMS_F32.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* Audio Library for Teensy 3.X
* Copyright (c) 2014, Paul Stoffregen, [email protected]
* Modified to floating point by Oyvind Mjanger.
*
* Development of this audio library was funded by PJRC.COM, LLC by sales of
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
* open source software by purchasing Teensy or other PJRC products.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


#include "AudioAnalyzeRMS_F32.h"
#include "utility/dspinst.h"

void AudioAnalyzeRMS_F32::update(void)
{
audio_block_f32_t *block = receiveReadOnly_f32();
if (!block) {
count++;
return;
}
#if defined(KINETISK)
float32_t *p = (float32_t *)(block->data);
float32_t *end = p + AUDIO_BLOCK_SAMPLES;
float64_t sum = accum;
float32_t in; // Temporary variable to store input value

do {
in = *p++;
sum += in * in;
in = *p++;
sum += in * in;
in = *p++;
sum += in * in;
in = *p++;
sum += in * in;
} while (p < end);
accum = sum;
count++;
#else
float32_t *p = block->data;
float32_t *end = p + AUDIO_BLOCK_SAMPLES;
float64_t sum = accum;
do {
float32_t n = *p++;
sum += n * n;
} while (p < end);
accum = sum;
count++;
#endif
release(block);
}

float AudioAnalyzeRMS_F32::read(void)
{
__disable_irq();
float64_t sum = accum;
accum = 0;
float32_t num = count;
count = 0;
__enable_irq();
float32_t meansq = sum / (num * AUDIO_BLOCK_SAMPLES);
return sqrtf(meansq);
}

56 changes: 56 additions & 0 deletions src/AudioAnalyzeRMS_F32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Audio Library for Teensy 3.X
* Copyright (c) 2014, Paul Stoffregen, [email protected]
* Modified to floating point by Oyvind Mjanger.
*
* Development of this audio library was funded by PJRC.COM, LLC by sales of
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
* open source software by purchasing Teensy or other PJRC products.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef analyze_rms_F32_h_
#define analyze_rms_F32_h_

#include "Arduino.h"
#include "AudioStream_F32.h"
#include <arm_math.h> //ARM DSP extensions. for speed!


class AudioAnalyzeRMS_F32 : public AudioStream_F32
{
private:
audio_block_f32_t *inputQueueArray_F32[1];
float64_t accum;
float32_t count;

public:
AudioAnalyzeRMS_F32(void) : AudioStream_F32(1, inputQueueArray_F32) {
accum = 0;
count = 0;
}
bool available(void) {
return count > 0;
}
float read(void);
virtual void update(void);
};

#endif

2 changes: 2 additions & 0 deletions src/Tympan_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "AudioStream_F32.h"
#include "BTNRH_WDRC_Types.h"
#include "control_tlv320aic3206.h"
#include "control_sgtl5000_32bit.h"
#include "AudioAnalyzeRMS_F32.h"
#include "AudioCalcEnvelope_F32.h"
#include "AudioCalcGainWDRC_F32.h"
#include "AudioCalcLevel_F32.h"
Expand Down
Loading