PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

128 lines
5.3KB

  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. AudioControlSGTL5000(void) : i2c_addr(0x0A) { }
  33. void setAddress(uint8_t level);
  34. bool enable(void);
  35. bool disable(void) { return false; }
  36. bool volume(float n) { return volumeInteger(n * 129 + 0.499); }
  37. bool inputLevel(float n) {return false;}
  38. bool muteHeadphone(void) { return write(0x0024, ana_ctrl | (1<<4)); }
  39. bool unmuteHeadphone(void) { return write(0x0024, ana_ctrl & ~(1<<4)); }
  40. bool muteLineout(void) { return write(0x0024, ana_ctrl | (1<<8)); }
  41. bool unmuteLineout(void) { return write(0x0024, ana_ctrl & ~(1<<8)); }
  42. bool inputSelect(int n) {
  43. if (n == AUDIO_INPUT_LINEIN) {
  44. return write(0x0020, 0x055) // +7.5dB gain (1.3Vp-p full scale)
  45. && write(0x0024, ana_ctrl | (1<<2)); // enable linein
  46. } else if (n == AUDIO_INPUT_MIC) {
  47. return write(0x002A, 0x0173) // mic preamp gain = +40dB
  48. && write(0x0020, 0x088) // input gain +12dB (is this enough?)
  49. && write(0x0024, ana_ctrl & ~(1<<2)); // enable mic
  50. } else {
  51. return false;
  52. }
  53. }
  54. bool volume(float left, float right);
  55. bool micGain(unsigned int dB);
  56. bool lineInLevel(uint8_t n) { return lineInLevel(n, n); }
  57. bool lineInLevel(uint8_t left, uint8_t right);
  58. unsigned short lineOutLevel(uint8_t n);
  59. unsigned short lineOutLevel(uint8_t left, uint8_t right);
  60. unsigned short dacVolume(float n);
  61. unsigned short dacVolume(float left, float right);
  62. bool dacVolumeRamp();
  63. bool dacVolumeRampLinear();
  64. bool dacVolumeRampDisable();
  65. unsigned short adcHighPassFilterEnable(void);
  66. unsigned short adcHighPassFilterFreeze(void);
  67. unsigned short adcHighPassFilterDisable(void);
  68. unsigned short audioPreProcessorEnable(void);
  69. unsigned short audioPostProcessorEnable(void);
  70. unsigned short audioProcessorDisable(void);
  71. unsigned short eqFilterCount(uint8_t n);
  72. unsigned short eqSelect(uint8_t n);
  73. unsigned short eqBand(uint8_t bandNum, float n);
  74. void eqBands(float bass, float mid_bass, float midrange, float mid_treble, float treble);
  75. void eqBands(float bass, float treble);
  76. void eqFilter(uint8_t filterNum, int *filterParameters);
  77. unsigned short autoVolumeControl(uint8_t maxGain, uint8_t lbiResponse, uint8_t hardLimit, float threshold, float attack, float decay);
  78. unsigned short autoVolumeEnable(void);
  79. unsigned short autoVolumeDisable(void);
  80. unsigned short enhanceBass(float lr_lev, float bass_lev);
  81. unsigned short enhanceBass(float lr_lev, float bass_lev, uint8_t hpf_bypass, uint8_t cutoff);
  82. unsigned short enhanceBassEnable(void);
  83. unsigned short enhanceBassDisable(void);
  84. unsigned short surroundSound(uint8_t width);
  85. unsigned short surroundSound(uint8_t width, uint8_t select);
  86. unsigned short surroundSoundEnable(void);
  87. unsigned short surroundSoundDisable(void);
  88. void killAutomation(void) { semi_automated=false; }
  89. protected:
  90. bool muted;
  91. bool volumeInteger(unsigned int n); // range: 0x00 to 0x80
  92. uint16_t ana_ctrl;
  93. uint8_t i2c_addr;
  94. unsigned char calcVol(float n, unsigned char range);
  95. unsigned int read(unsigned int reg);
  96. bool write(unsigned int reg, unsigned int val);
  97. unsigned int modify(unsigned int reg, unsigned int val, unsigned int iMask);
  98. unsigned short dap_audio_eq_band(uint8_t bandNum, float n);
  99. private:
  100. bool semi_automated;
  101. void automate(uint8_t dap, uint8_t eq);
  102. void automate(uint8_t dap, uint8_t eq, uint8_t filterCount);
  103. };
  104. //For Filter Type: 0 = LPF, 1 = HPF, 2 = BPF, 3 = NOTCH, 4 = PeakingEQ, 5 = LowShelf, 6 = HighShelf
  105. #define FILTER_LOPASS 0
  106. #define FILTER_HIPASS 1
  107. #define FILTER_BANDPASS 2
  108. #define FILTER_NOTCH 3
  109. #define FILTER_PARAEQ 4
  110. #define FILTER_LOSHELF 5
  111. #define FILTER_HISHELF 6
  112. //For frequency adjustment
  113. #define FLAT_FREQUENCY 0
  114. #define PARAMETRIC_EQUALIZER 1
  115. #define TONE_CONTROLS 2
  116. #define GRAPHIC_EQUALIZER 3
  117. void calcBiquad(uint8_t filtertype, float fC, float dB_Gain, float Q, uint32_t quantization_unit, uint32_t fS, int *coef);
  118. #endif