Procházet zdrojové kódy

Change peak detect API to conform to library conventions

dds
PaulStoffregen před 10 roky
rodič
revize
5bc41358b6
5 změnil soubory, kde provedl 72 přidání a 60 odebrání
  1. +1
    -1
      Audio.h
  2. +10
    -21
      analyze_peak.cpp
  3. +22
    -11
      analyze_peak.h
  4. +15
    -13
      examples/Analysis/MonoPeakMeterAnalog/MonoPeakMeterAnalog.ino
  5. +24
    -14
      examples/Analysis/StereoPeakMeter/StereoPeakMeter.ino

+ 1
- 1
Audio.h Zobrazit soubor

@@ -55,7 +55,7 @@
#include "analyze_fft1024.h"
#include "analyze_print.h"
#include "analyze_tonedetect.h"
#include "analyze_peakdetect.h"
#include "analyze_peak.h"
#include "control_sgtl5000.h"
#include "control_wm8731.h"
#include "effect_chorus.h"

analyze_peakdetect.cpp → analyze_peak.cpp Zobrazit soubor

@@ -24,41 +24,30 @@
* THE SOFTWARE.
*/

#include "analyze_peakdetect.h"
#include "analyze_peak.h"

void AudioAnalyzePeak::update(void)
{
audio_block_t *block;
const int16_t *p, *end;
int32_t min, max;

block = receiveReadOnly();
if (!block) {
return;
}
if (!m_enabled) {
release(block);
return;
}
p = block->data;
end = p + AUDIO_BLOCK_SAMPLES;
min = min_sample;
max = max_sample;
do {
int16_t d=*p++;
if(d<min) min=d;
if(d>max) max=d;
if (d<min) min=d;
if (d>max) max=d;
} while (p < end);
min_sample = min;
max_sample = max;
new_output = true;
release(block);
}

void AudioAnalyzePeak::begin(bool noReset)
{
if(!noReset)
{
min=32767;
max=-32767;
}
m_enabled=true;
}
uint16_t AudioAnalyzePeak::Dpp(void)
{
if(max>min) return max-min; else return 0;
}


analyze_peakdetect.h → analyze_peak.h Zobrazit soubor

@@ -29,23 +29,34 @@

#include "AudioStream.h"

// TODO: this needs to be renamed to AudioAnalyzePeak
class AudioAnalyzePeak : public AudioStream
{
public:
AudioAnalyzePeak(void) : AudioStream(1, inputQueueArray) { }

AudioAnalyzePeak(void) : AudioStream(1, inputQueueArray) {
min_sample = 32767;
max_sample = -32768;
}
bool available(void) {
__disable_irq();
bool flag = new_output;
if (flag) new_output = false;
__enable_irq();
return flag;
}
float read(void) {
__disable_irq();
int diff = max_sample - min_sample;
min_sample = 32767;
max_sample = -32768;
__enable_irq();
return diff / 65535.0;
}
virtual void update(void);

void begin(bool noReset);
void begin(void) { begin(false); }
void stop(void) { m_enabled=false; }
uint16_t Dpp(void);
private:
audio_block_t *inputQueueArray[1];
bool m_enabled;
int16_t max;
int16_t min;
volatile bool new_output;
int16_t min_sample;
int16_t max_sample;
};

#endif

+ 15
- 13
examples/Analysis/MonoPeakMeterAnalog/MonoPeakMeterAnalog.ino Zobrazit soubor

@@ -11,30 +11,32 @@ This example code is in the public domain
#include <SPI.h>
#include <SD.h>

const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

AudioInputAnalog audioInput(A0); // A0 is pin 14, feel free to change.
AudioAnalyzePeak peak_M;
AudioAnalyzePeak peak;
AudioOutputAnalog audioOutput; // DAC pin.

AudioConnection c1(audioInput,peak_M);
AudioConnection c1(audioInput,peak);
AudioConnection c2(audioInput,audioOutput);

void setup() {
AudioMemory(4);
Serial.begin(Serial.baud());
Serial.begin(9600);
}

// for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can.

elapsedMillis fps;

void loop() {
if(fps>24) { // for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can.
Serial.println();
fps=0;
uint8_t monoPeak=peak_M.Dpp()/2184.5321;
Serial.print("|");
for(uint8_t cnt=0;cnt<monoPeak;cnt++) Serial.print(">");
peak_M.begin();
if (fps > 24) {
if (peak.available()) {
fps = 0;
uint8_t monoPeak = peak.read() * 30.0;
Serial.print("|");
for (uint8_t cnt=0;cnt<monoPeak;cnt++) {
Serial.print(">");
}
Serial.println();
}
}
}

+ 24
- 14
examples/Analysis/StereoPeakMeter/StereoPeakMeter.ino Zobrazit soubor

@@ -30,25 +30,35 @@ void setup() {
audioShield.inputSelect(myInput);
audioShield.volume(0.75);
audioShield.unmuteLineout();
Serial.begin(Serial.baud());
Serial.begin(9600);
}

// for best effect make your terminal/monitor a minimum of 62 chars wide and as high as you can.

elapsedMillis fps;
uint8_t cnt=0;

void loop() {
if(fps>24) { // for best effect make your terminal/monitor a minimum of 62 chars wide and as high as you can.
Serial.println();
fps=0;
uint8_t leftPeak=peak_L.Dpp()/2184.5321; // 65536 / 2184.5321 ~ 30.
for(cnt=0;cnt<30-leftPeak;cnt++) Serial.print(" ");
while(cnt++<30) Serial.print("<");
Serial.print("||");
uint8_t rightPeak=peak_R.Dpp()/2184.5321;
for(cnt=0;cnt<rightPeak;cnt++) Serial.print(">");
while(cnt++<30) Serial.print(" ");
peak_L.begin(); // no need to call .stop if all you want
peak_R.begin(); // is to zero it.
if(fps > 24) {
if (peak_L.available() && peak_R.available()) {
fps=0;
uint8_t leftPeak=peak_L.read() * 30.0;
uint8_t rightPeak=peak_R.read() * 30.0;

for(cnt=0;cnt<30-leftPeak;cnt++) {
Serial.print(" ");
}
while(cnt++<30) {
Serial.print("<");
}
Serial.print("||");
for(cnt=0;cnt<rightPeak;cnt++) {
Serial.print(">");
}
while(cnt++<30) {
Serial.print(" ");
}
Serial.println();
}
}
}

Načítá se…
Zrušit
Uložit