|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
-
-
- #include <Arduino.h>
- #include "analyze_print.h"
-
- #define STATE_IDLE 0
- #define STATE_WAIT_TRIGGER 1
- #define STATE_DELAY 2
- #define STATE_PRINTING 3
-
- void AudioAnalyzePrint::update(void)
- {
- audio_block_t *block;
- uint32_t offset = 0;
- uint32_t remain, n;
-
- block = receiveReadOnly();
- if (!block) return;
-
- while (offset < AUDIO_BLOCK_SAMPLES) {
- remain = AUDIO_BLOCK_SAMPLES - offset;
- switch (state) {
- case STATE_WAIT_TRIGGER:
-
- offset = AUDIO_BLOCK_SAMPLES;
- break;
-
- case STATE_DELAY:
-
- 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:
- offset = AUDIO_BLOCK_SAMPLES;
- break;
- }
- }
- release(block);
- }
-
- void AudioAnalyzePrint::trigger(void)
- {
- uint32_t n = delay_length;
-
- if (n > 0) {
- Serial.print("trigger ");
- if (myname) Serial.print(myname);
- Serial.print(", delay=");
- Serial.println(n);
- count = n;
- state = 2;
- } else {
- Serial.print("trigger ");
- if (myname) Serial.println(myname);
- count = print_length;
- state = 3;
- }
- }
-
|