選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

108 行
3.6KB

  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. #ifndef USBaudio_h_
  31. #define USBaudio_h_
  32. #include "usb_desc.h"
  33. #ifdef AUDIO_INTERFACE
  34. #define FEATURE_MAX_VOLUME 0xFFF // volume accepted from 0 to 0xFFF
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. extern uint16_t usb_audio_receive_buffer[];
  39. extern uint16_t usb_audio_transmit_buffer[];
  40. extern void usb_audio_receive_callback(unsigned int len);
  41. extern unsigned int usb_audio_transmit_callback(void);
  42. int usb_audio_set_feature(void *stp, uint8_t *buf);
  43. int usb_audio_get_feature(void *stp, uint8_t *data, uint32_t *datalen);
  44. extern uint32_t usb_audio_sync_feedback;
  45. extern uint8_t usb_audio_receive_setting;
  46. extern uint8_t usb_audio_transmit_setting;
  47. #ifdef __cplusplus
  48. }
  49. // audio features supported
  50. struct usb_audio_features_struct {
  51. int change; // set to 1 when any value is changed
  52. int mute; // 1=mute, 0=unmute
  53. int volume; // volume from 0 to FEATURE_MAX_VOLUME, maybe should be float from 0.0 to 1.0
  54. };
  55. #include "AudioStream.h"
  56. class AudioInputUSB : public AudioStream
  57. {
  58. public:
  59. AudioInputUSB(void) : AudioStream(0, NULL) { begin(); }
  60. virtual void update(void);
  61. void begin(void);
  62. friend void usb_audio_receive_callback(unsigned int len);
  63. friend int usb_audio_set_feature(void *stp, uint8_t *buf);
  64. friend int usb_audio_get_feature(void *stp, uint8_t *data, uint32_t *datalen);
  65. static struct usb_audio_features_struct features;
  66. float volume(void) {
  67. if (features.mute) return 0.0;
  68. return (float)(features.volume) * (1.0 / (float)FEATURE_MAX_VOLUME);
  69. }
  70. private:
  71. static bool update_responsibility;
  72. static audio_block_t *incoming_left;
  73. static audio_block_t *incoming_right;
  74. static audio_block_t *ready_left;
  75. static audio_block_t *ready_right;
  76. static uint16_t incoming_count;
  77. static uint8_t receive_flag;
  78. };
  79. class AudioOutputUSB : public AudioStream
  80. {
  81. public:
  82. AudioOutputUSB(void) : AudioStream(2, inputQueueArray) { begin(); }
  83. virtual void update(void);
  84. void begin(void);
  85. friend unsigned int usb_audio_transmit_callback(void);
  86. private:
  87. static bool update_responsibility;
  88. static audio_block_t *left_1st;
  89. static audio_block_t *left_2nd;
  90. static audio_block_t *right_1st;
  91. static audio_block_t *right_2nd;
  92. static uint16_t offset_1st;
  93. audio_block_t *inputQueueArray[2];
  94. };
  95. #endif // __cplusplus
  96. #endif // AUDIO_INTERFACE
  97. #endif // USBaudio_h_