浏览代码

Improve AudioAnalyzePrint

dds
PaulStoffregen 10 年前
父节点
当前提交
ec3c9074ff
共有 2 个文件被更改,包括 75 次插入14 次删除
  1. +63
    -13
      analyze_print.cpp
  2. +12
    -1
      analyze_print.h

+ 63
- 13
analyze_print.cpp 查看文件

@@ -26,26 +26,76 @@

#include "analyze_print.h"

// TODO: this needs some sort of trigger or delay or other options to make
// actually useful for watching interesting parts of data, without spewing
// tremendous and endless data to the Arduino Serial Monitor
#define STATE_IDLE 0 // doing nothing
#define STATE_WAIT_TRIGGER 1 // looking for trigger condition
#define STATE_DELAY 2 // waiting from trigger to print
#define STATE_PRINTING 3 // printing data

void AudioAnalyzePrint::update(void)
{
audio_block_t *block;
uint32_t i;
uint32_t offset = 0;
uint32_t remain, n;

Serial.println("AudioAnalyzePrint::update");
Serial.println(name);
//Serial.println(name);
block = receiveReadOnly();
if (block) {
for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
Serial.print(block->data[i]);
Serial.print(", ");
if ((i % 12) == 11) Serial.println();
if (!block) return;

while (offset < AUDIO_BLOCK_SAMPLES) {
remain = AUDIO_BLOCK_SAMPLES - offset;
switch (state) {
case STATE_WAIT_TRIGGER:
// TODO: implement this....
offset = AUDIO_BLOCK_SAMPLES;
break;

case STATE_DELAY:
//Serial.printf("STATE_DELAY, count = %u\n", count);
if (remain < count) {
count -= remain;
offset = AUDIO_BLOCK_SAMPLES;
} else {
offset += count;
count = print_length;
state = STATE_PRINTING;
}
break;

case STATE_PRINTING:
n = count;
if (n > remain) n = remain;
count -= n;
while (n > 0) {
Serial.println(block->data[offset++]);
n--;
}
if (count == 0) state = STATE_IDLE;
break;

default: // STATE_IDLE
offset = AUDIO_BLOCK_SAMPLES;
break;
}
Serial.println();
release(block);
}
release(block);
}

void AudioAnalyzePrint::trigger(void)
{
uint32_t n = delay_length;

if (n > 0) {
Serial.print("trigger ");
Serial.print(name);
Serial.print(", delay=");
Serial.println(n);
count = n;
state = 2;
} else {
Serial.print("trigger ");
Serial.println(name);
count = print_length;
state = 3;
}
}


+ 12
- 1
analyze_print.h 查看文件

@@ -32,10 +32,21 @@
class AudioAnalyzePrint : public AudioStream
{
public:
AudioAnalyzePrint(const char *str) : AudioStream(1, inputQueueArray), name(str) {}
AudioAnalyzePrint(const char *str) : AudioStream(1, inputQueueArray),
name(str), state(0), trigger_edge(0), delay_length(0), print_length(500) {}
virtual void update(void);
void trigger(void);
void trigger(float level, int edge);
void delay(uint32_t num) { delay_length = num; }
void length(uint32_t num) { print_length = num; }
private:
const char *name;
uint8_t state;
uint8_t trigger_edge; // trigger type, 0=none, 2=RISING, 3=FALLING
int16_t trigger_level;
uint32_t delay_length; // number of samples between trigger and printing
uint32_t print_length; // number of samples to print
uint32_t count;
audio_block_t *inputQueueArray[1];
};


正在加载...
取消
保存