You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.5KB

  1. #ifndef control_sgtl5000_h_
  2. #define control_sgtl5000_h_
  3. #include "AudioControl.h"
  4. class AudioControlSGTL5000 : public AudioControl
  5. {
  6. public:
  7. bool enable(void);
  8. bool disable(void) { return false; }
  9. bool volume(float n) { return volumeInteger(n * 1.29 + 0.499); }
  10. bool inputLevel(float n) {return false;}
  11. bool muteHeadphone(void) { return write(0x0024, ana_ctrl | (1<<4)); }
  12. bool unmuteHeadphone(void) { return write(0x0024, ana_ctrl & ~(1<<4)); }
  13. bool muteLineout(void) { return write(0x0024, ana_ctrl | (1<<8)); }
  14. bool unmuteLineout(void) { return write(0x0024, ana_ctrl & ~(1<<8)); }
  15. bool inputSelect(int n) {
  16. if (n == AUDIO_INPUT_LINEIN) {
  17. return write(0x0024, ana_ctrl | (1<<2));
  18. } else if (n == AUDIO_INPUT_MIC) {
  19. //return write(0x002A, 0x0172) && write(0x0024, ana_ctrl & ~(1<<2));
  20. return write(0x002A, 0x0173) && write(0x0024, ana_ctrl & ~(1<<2)); // +40dB
  21. } else {
  22. return false;
  23. }
  24. }
  25. //bool inputLinein(void) { return write(0x0024, ana_ctrl | (1<<2)); }
  26. //bool inputMic(void) { return write(0x002A, 0x0172) && write(0x0024, ana_ctrl & ~(1<<2)); }
  27. bool volume(float left, float right);
  28. unsigned short micGain(unsigned int n) { return modify(0x002A, n&3, 3); }
  29. unsigned short lo_lvl(uint8_t n);
  30. unsigned short lo_lvl(uint8_t left, uint8_t right);
  31. unsigned short dac_vol(float n);
  32. unsigned short dac_vol(float left, float right);
  33. unsigned short dap_mix_enable(uint8_t n);
  34. unsigned short dap_enable(uint8_t n);
  35. unsigned short dap_enable(void);
  36. unsigned short dap_peqs(uint8_t n);
  37. unsigned short dap_audio_eq(uint8_t n);
  38. unsigned short dap_audio_eq_band(uint8_t bandNum, float n);
  39. void dap_audio_eq_geq(float bass, float mid_bass, float midrange, float mid_treble, float treble);
  40. void dap_audio_eq_tone(float bass, float treble);
  41. void load_peq(uint8_t filterNum, int *filterParameters);
  42. protected:
  43. bool muted;
  44. bool volumeInteger(unsigned int n); // range: 0x00 to 0x80
  45. uint16_t ana_ctrl;
  46. unsigned char calcVol(float n, unsigned char range);
  47. unsigned int read(unsigned int reg);
  48. bool write(unsigned int reg, unsigned int val);
  49. unsigned int modify(unsigned int reg, unsigned int val, unsigned int iMask);
  50. };
  51. //For Filter Type: 0 = LPF, 1 = HPF, 2 = BPF, 3 = NOTCH, 4 = PeakingEQ, 5 = LowShelf, 6 = HighShelf
  52. #define FILTER_LOPASS 0
  53. #define FILTER_HIPASS 1
  54. #define FILTER_BANDPASS 2
  55. #define FILTER_NOTCH 3
  56. #define FILTER_PARAEQ 4
  57. #define FILTER_LOSHELF 5
  58. #define FILTER_HISHELF 6
  59. void calcBiquad(uint8_t filtertype, float fC, float dB_Gain, float Q, uint32_t quantization_unit, uint32_t fS, int *coef);
  60. #endif