PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

102 行
2.9KB

  1. /* Audio Library for Teensy 3.X
  2. * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
  3. *
  4. * Development of this audio library was funded by PJRC.COM, LLC by sales of
  5. * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
  6. * open source software by purchasing Teensy or other PJRC products.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice, development funding notice, and this permission
  16. * notice shall be included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include <Arduino.h>
  27. #include "analyze_print.h"
  28. #define STATE_IDLE 0 // doing nothing
  29. #define STATE_WAIT_TRIGGER 1 // looking for trigger condition
  30. #define STATE_DELAY 2 // waiting from trigger to print
  31. #define STATE_PRINTING 3 // printing data
  32. void AudioAnalyzePrint::update(void)
  33. {
  34. audio_block_t *block;
  35. uint32_t offset = 0;
  36. uint32_t remain, n;
  37. block = receiveReadOnly();
  38. if (!block) return;
  39. while (offset < AUDIO_BLOCK_SAMPLES) {
  40. remain = AUDIO_BLOCK_SAMPLES - offset;
  41. switch (state) {
  42. case STATE_WAIT_TRIGGER:
  43. // TODO: implement this....
  44. offset = AUDIO_BLOCK_SAMPLES;
  45. break;
  46. case STATE_DELAY:
  47. //Serial.printf("STATE_DELAY, count = %u\n", count);
  48. if (remain < count) {
  49. count -= remain;
  50. offset = AUDIO_BLOCK_SAMPLES;
  51. } else {
  52. offset += count;
  53. count = print_length;
  54. state = STATE_PRINTING;
  55. }
  56. break;
  57. case STATE_PRINTING:
  58. n = count;
  59. if (n > remain) n = remain;
  60. count -= n;
  61. while (n > 0) {
  62. Serial.println(block->data[offset++]);
  63. n--;
  64. }
  65. if (count == 0) state = STATE_IDLE;
  66. break;
  67. default: // STATE_IDLE
  68. offset = AUDIO_BLOCK_SAMPLES;
  69. break;
  70. }
  71. }
  72. release(block);
  73. }
  74. void AudioAnalyzePrint::trigger(void)
  75. {
  76. uint32_t n = delay_length;
  77. if (n > 0) {
  78. Serial.print("trigger ");
  79. if (myname) Serial.print(myname);
  80. Serial.print(", delay=");
  81. Serial.println(n);
  82. count = n;
  83. state = 2;
  84. } else {
  85. Serial.print("trigger ");
  86. if (myname) Serial.println(myname);
  87. count = print_length;
  88. state = 3;
  89. }
  90. }