Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

analyze_print.cpp 2.9KB

10 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "analyze_print.h"
  27. #define STATE_IDLE 0 // doing nothing
  28. #define STATE_WAIT_TRIGGER 1 // looking for trigger condition
  29. #define STATE_DELAY 2 // waiting from trigger to print
  30. #define STATE_PRINTING 3 // printing data
  31. void AudioAnalyzePrint::update(void)
  32. {
  33. audio_block_t *block;
  34. uint32_t offset = 0;
  35. uint32_t remain, n;
  36. block = receiveReadOnly();
  37. if (!block) return;
  38. while (offset < AUDIO_BLOCK_SAMPLES) {
  39. remain = AUDIO_BLOCK_SAMPLES - offset;
  40. switch (state) {
  41. case STATE_WAIT_TRIGGER:
  42. // TODO: implement this....
  43. offset = AUDIO_BLOCK_SAMPLES;
  44. break;
  45. case STATE_DELAY:
  46. //Serial.printf("STATE_DELAY, count = %u\n", count);
  47. if (remain < count) {
  48. count -= remain;
  49. offset = AUDIO_BLOCK_SAMPLES;
  50. } else {
  51. offset += count;
  52. count = print_length;
  53. state = STATE_PRINTING;
  54. }
  55. break;
  56. case STATE_PRINTING:
  57. n = count;
  58. if (n > remain) n = remain;
  59. count -= n;
  60. while (n > 0) {
  61. Serial.println(block->data[offset++]);
  62. n--;
  63. }
  64. if (count == 0) state = STATE_IDLE;
  65. break;
  66. default: // STATE_IDLE
  67. offset = AUDIO_BLOCK_SAMPLES;
  68. break;
  69. }
  70. }
  71. release(block);
  72. }
  73. void AudioAnalyzePrint::trigger(void)
  74. {
  75. uint32_t n = delay_length;
  76. if (n > 0) {
  77. Serial.print("trigger ");
  78. if (myname) Serial.print(myname);
  79. Serial.print(", delay=");
  80. Serial.println(n);
  81. count = n;
  82. state = 2;
  83. } else {
  84. Serial.print("trigger ");
  85. if (myname) Serial.println(myname);
  86. count = print_length;
  87. state = 3;
  88. }
  89. }