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.

101 lines
2.4KB

  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. audio_block_t *block;
  39. uint32_t t;
  40. if (userblock) {
  41. release(userblock);
  42. userblock = NULL;
  43. }
  44. t = tail;
  45. while (t != head) {
  46. if (++t >= 53) t = 0;
  47. release(queue[t]);
  48. }
  49. tail = t;
  50. }
  51. int16_t * AudioRecordQueue::readBuffer(void)
  52. {
  53. audio_block_t *block;
  54. uint32_t t;
  55. if (userblock) return NULL;
  56. t = tail;
  57. if (t == head) return NULL;
  58. if (++t >= 53) t = 0;
  59. userblock = queue[t];
  60. tail = t;
  61. return userblock->data;
  62. }
  63. void AudioRecordQueue::freeBuffer(void)
  64. {
  65. if (userblock == NULL) return;
  66. release(userblock);
  67. userblock = NULL;
  68. }
  69. void AudioRecordQueue::update(void)
  70. {
  71. audio_block_t *block;
  72. uint32_t h;
  73. block = receiveReadOnly();
  74. if (!block) return;
  75. if (!enabled) {
  76. release(block);
  77. return;
  78. }
  79. h = head + 1;
  80. if (h >= 53) h = 0;
  81. if (h == tail) {
  82. release(block);
  83. } else {
  84. queue[h] = block;
  85. head = h;
  86. }
  87. }