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.

usb_audio.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2017 PJRC.COM, LLC.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * 1. The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * 2. If the Software is incorporated into a build system that allows
  17. * selection among a list of target devices, then similar target
  18. * devices manufactured by PJRC.COM must be included in the list of
  19. * target devices and selectable in the same manner.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  25. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  26. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  27. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28. * SOFTWARE.
  29. */
  30. #pragma once
  31. #include "usb_desc.h"
  32. #ifdef AUDIO_INTERFACE
  33. #define FEATURE_MAX_VOLUME 0xFFF // volume accepted from 0 to 0xFFF
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. extern void usb_audio_configure();
  38. extern uint16_t usb_audio_receive_buffer[];
  39. extern uint16_t usb_audio_transmit_buffer[];
  40. extern uint32_t usb_audio_sync_feedback;
  41. extern uint8_t usb_audio_receive_setting;
  42. extern uint8_t usb_audio_transmit_setting;
  43. extern void usb_audio_receive_callback(unsigned int len);
  44. extern unsigned int usb_audio_transmit_callback(void);
  45. extern int usb_audio_set_feature(void *stp, uint8_t *buf);
  46. extern int usb_audio_get_feature(void *stp, uint8_t *data, uint32_t *datalen);
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. // audio features supported
  51. struct usb_audio_features_struct {
  52. int change; // set to 1 when any value is changed
  53. int mute; // 1=mute, 0=unmute
  54. int volume; // volume from 0 to FEATURE_MAX_VOLUME, maybe should be float from 0.0 to 1.0
  55. };
  56. #ifdef __cplusplus
  57. #include "AudioStream.h"
  58. class AudioInputUSB : public AudioStream
  59. {
  60. public:
  61. AudioInputUSB(void) : AudioStream(0, NULL) { begin(); }
  62. virtual void update(void);
  63. void begin(void);
  64. friend void usb_audio_receive_callback(unsigned int len);
  65. friend int usb_audio_set_feature(void *stp, uint8_t *buf);
  66. friend int usb_audio_get_feature(void *stp, uint8_t *data, uint32_t *datalen);
  67. static struct usb_audio_features_struct features;
  68. float volume(void) {
  69. if (features.mute) return 0.0;
  70. return (float)(features.volume) * (1.0 / (float)FEATURE_MAX_VOLUME);
  71. }
  72. private:
  73. static bool update_responsibility;
  74. static audio_block_t *incoming_left;
  75. static audio_block_t *incoming_right;
  76. static audio_block_t *ready_left;
  77. static audio_block_t *ready_right;
  78. static uint16_t incoming_count;
  79. static uint8_t receive_flag;
  80. };
  81. class AudioOutputUSB : public AudioStream
  82. {
  83. public:
  84. AudioOutputUSB(void) : AudioStream(2, inputQueueArray) { begin(); }
  85. virtual void update(void);
  86. void begin(void);
  87. friend unsigned int usb_audio_transmit_callback(void);
  88. private:
  89. static bool update_responsibility;
  90. static audio_block_t *left_1st;
  91. static audio_block_t *left_2nd;
  92. static audio_block_t *right_1st;
  93. static audio_block_t *right_2nd;
  94. static uint16_t offset_1st;
  95. audio_block_t *inputQueueArray[2];
  96. };
  97. #endif // __cplusplus
  98. #endif // AUDIO_INTERFACE