Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

10 роки тому
10 роки тому
10 роки тому
10 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifndef control_sgtl5000_h_
  27. #define control_sgtl5000_h_
  28. #include "AudioControl.h"
  29. class AudioControlSGTL5000 : public AudioControl
  30. {
  31. public:
  32. bool enable(void);
  33. bool disable(void) { return false; }
  34. bool volume(float n) { return volumeInteger(n * 1.29 + 0.499); }
  35. bool inputLevel(float n) {return false;}
  36. bool muteHeadphone(void) { return write(0x0024, ana_ctrl | (1<<4)); }
  37. bool unmuteHeadphone(void) { return write(0x0024, ana_ctrl & ~(1<<4)); }
  38. bool muteLineout(void) { return write(0x0024, ana_ctrl | (1<<8)); }
  39. bool unmuteLineout(void) { return write(0x0024, ana_ctrl & ~(1<<8)); }
  40. bool inputSelect(int n) {
  41. if (n == AUDIO_INPUT_LINEIN) {
  42. return write(0x0024, ana_ctrl | (1<<2));
  43. } else if (n == AUDIO_INPUT_MIC) {
  44. //return write(0x002A, 0x0172) && write(0x0024, ana_ctrl & ~(1<<2));
  45. return write(0x002A, 0x0173) && write(0x0024, ana_ctrl & ~(1<<2)); // +40dB
  46. } else {
  47. return false;
  48. }
  49. }
  50. //bool inputLinein(void) { return write(0x0024, ana_ctrl | (1<<2)); }
  51. //bool inputMic(void) { return write(0x002A, 0x0172) && write(0x0024, ana_ctrl & ~(1<<2)); }
  52. bool volume(float left, float right);
  53. unsigned short micGain(unsigned int n) { return modify(0x002A, n&3, 3); }
  54. unsigned short lo_lvl(uint8_t n);
  55. unsigned short lo_lvl(uint8_t left, uint8_t right);
  56. unsigned short dac_vol(float n);
  57. unsigned short dac_vol(float left, float right);
  58. unsigned short adc_hpf(uint8_t bypass, uint8_t freeze);
  59. unsigned short adc_hpf(uint8_t bypass);
  60. unsigned short dap_mix_enable(uint8_t n);
  61. unsigned short dap_enable(uint8_t n);
  62. unsigned short dap_enable(void);
  63. unsigned short dap_peqs(uint8_t n);
  64. unsigned short dap_audio_eq(uint8_t n);
  65. unsigned short dap_audio_eq_band(uint8_t bandNum, float n);
  66. void dap_audio_eq_geq(float bass, float mid_bass, float midrange, float mid_treble, float treble);
  67. void dap_audio_eq_tone(float bass, float treble);
  68. void load_peq(uint8_t filterNum, int *filterParameters);
  69. unsigned short dap_avc(uint8_t maxGain, uint8_t lbiResponse, uint8_t hardLimit, float threshold, float attack, float decay);
  70. unsigned short dap_avc_enable(uint8_t n);
  71. unsigned short dap_avc_enable(void);
  72. unsigned short dap_bass_enhance(float lr_lev, float bass_lev);
  73. unsigned short dap_bass_enhance(float lr_lev, float bass_lev, uint8_t hpf_bypass, uint8_t cutoff);
  74. unsigned short dap_bass_enhance_enable(uint8_t n);
  75. unsigned short dap_bass_enhance_enable(void);
  76. unsigned short dap_surround(uint8_t width);
  77. unsigned short dap_surround(uint8_t width, uint8_t select);
  78. unsigned short dap_surround_enable(uint8_t n);
  79. unsigned short dap_surround_enable(void);
  80. protected:
  81. bool muted;
  82. bool volumeInteger(unsigned int n); // range: 0x00 to 0x80
  83. uint16_t ana_ctrl;
  84. unsigned char calcVol(float n, unsigned char range);
  85. unsigned int read(unsigned int reg);
  86. bool write(unsigned int reg, unsigned int val);
  87. unsigned int modify(unsigned int reg, unsigned int val, unsigned int iMask);
  88. };
  89. //For Filter Type: 0 = LPF, 1 = HPF, 2 = BPF, 3 = NOTCH, 4 = PeakingEQ, 5 = LowShelf, 6 = HighShelf
  90. #define FILTER_LOPASS 0
  91. #define FILTER_HIPASS 1
  92. #define FILTER_BANDPASS 2
  93. #define FILTER_NOTCH 3
  94. #define FILTER_PARAEQ 4
  95. #define FILTER_LOSHELF 5
  96. #define FILTER_HISHELF 6
  97. void calcBiquad(uint8_t filtertype, float fC, float dB_Gain, float Q, uint32_t quantization_unit, uint32_t fS, int *coef);
  98. #endif