Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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