PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

record_queue.cpp 2.4KB

il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "record_queue.h"
  28. #include "utility/dspinst.h"
  29. int AudioRecordQueue::available(void)
  30. {
  31. uint32_t h, t;
  32. h = head;
  33. t = tail;
  34. if (h >= t) return h - t;
  35. return max_buffers + h - t;
  36. }
  37. void AudioRecordQueue::clear(void)
  38. {
  39. uint32_t t;
  40. if (userblock) {
  41. release(userblock);
  42. userblock = NULL;
  43. }
  44. t = tail;
  45. while (t != head) {
  46. if (++t >= max_buffers) t = 0;
  47. release(queue[t]);
  48. }
  49. tail = t;
  50. }
  51. int16_t * AudioRecordQueue::readBuffer(void)
  52. {
  53. uint32_t t;
  54. if (userblock) return NULL;
  55. t = tail;
  56. if (t == head) return NULL;
  57. if (++t >= max_buffers) t = 0;
  58. userblock = queue[t];
  59. tail = t;
  60. return userblock->data;
  61. }
  62. void AudioRecordQueue::freeBuffer(void)
  63. {
  64. if (userblock == NULL) return;
  65. release(userblock);
  66. userblock = NULL;
  67. }
  68. void AudioRecordQueue::update(void)
  69. {
  70. audio_block_t *block;
  71. uint32_t h;
  72. block = receiveReadOnly();
  73. if (!block) return;
  74. if (!enabled) {
  75. release(block);
  76. return;
  77. }
  78. h = head + 1;
  79. if (h >= max_buffers) h = 0;
  80. if (h == tail) {
  81. release(block);
  82. } else {
  83. queue[h] = block;
  84. head = h;
  85. }
  86. }