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 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef USBaudio_h_
  2. #define USBaudio_h_
  3. #include "usb_desc.h"
  4. #ifdef AUDIO_INTERFACE
  5. #define FEATURE_MAX_VOLUME 0xFFF // volume accepted from 0 to 0xFFF
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. extern uint16_t usb_audio_receive_buffer[];
  10. extern uint16_t usb_audio_transmit_buffer[];
  11. extern void usb_audio_receive_callback(unsigned int len);
  12. extern unsigned int usb_audio_transmit_callback(void);
  13. int usb_audio_set_feature(void *stp, uint8_t *buf);
  14. int usb_audio_get_feature(void *stp, uint8_t *data, uint32_t *datalen);
  15. extern uint32_t usb_audio_sync_feedback;
  16. extern uint8_t usb_audio_receive_setting;
  17. extern uint8_t usb_audio_transmit_setting;
  18. #ifdef __cplusplus
  19. }
  20. // audio features supported
  21. struct usb_audio_features_struct {
  22. int change; // set to 1 when any value is changed
  23. int mute; // 1=mute, 0=unmute
  24. int volume; // volume from 0 to FEATURE_MAX_VOLUME, maybe should be float from 0.0 to 1.0
  25. };
  26. #include "AudioStream.h"
  27. class AudioInputUSB : public AudioStream
  28. {
  29. public:
  30. AudioInputUSB(void) : AudioStream(0, NULL) { begin(); }
  31. virtual void update(void);
  32. void begin(void);
  33. friend void usb_audio_receive_callback(unsigned int len);
  34. friend int usb_audio_set_feature(void *stp, uint8_t *buf);
  35. friend int usb_audio_get_feature(void *stp, uint8_t *data, uint32_t *datalen);
  36. static struct usb_audio_features_struct features;
  37. float volume(void) {
  38. if (features.mute) return 0.0;
  39. return (float)(features.volume) * (1.0 / (float)FEATURE_MAX_VOLUME);
  40. }
  41. private:
  42. static bool update_responsibility;
  43. static audio_block_t *incoming_left;
  44. static audio_block_t *incoming_right;
  45. static audio_block_t *ready_left;
  46. static audio_block_t *ready_right;
  47. static uint16_t incoming_count;
  48. static uint8_t receive_flag;
  49. };
  50. class AudioOutputUSB : public AudioStream
  51. {
  52. public:
  53. AudioOutputUSB(void) : AudioStream(2, inputQueueArray) { begin(); }
  54. virtual void update(void);
  55. void begin(void);
  56. friend unsigned int usb_audio_transmit_callback(void);
  57. private:
  58. static bool update_responsibility;
  59. static audio_block_t *left_1st;
  60. static audio_block_t *left_2nd;
  61. static audio_block_t *right_1st;
  62. static audio_block_t *right_2nd;
  63. static uint16_t offset_1st;
  64. audio_block_t *inputQueueArray[2];
  65. };
  66. #endif // __cplusplus
  67. #endif // AUDIO_INTERFACE
  68. #endif // USBaudio_h_