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.

121 lines
5.2KB

  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. #define SGTL_ADC 0
  30. #define SGTL_I2S_TEENSY 1
  31. #define SGTL_AUDIO_PROCESSOR 3
  32. class AudioControlSGTL5000 : public AudioControl
  33. {
  34. public:
  35. bool enable(void);
  36. bool disable(void) { return false; }
  37. bool volume(float n) { return volumeInteger(n * 129 + 0.499); }
  38. bool inputLevel(float n) {return false;}
  39. bool muteHeadphone(void) { return write(0x0024, ana_ctrl | (1<<4)); }
  40. bool unmuteHeadphone(void) { return write(0x0024, ana_ctrl & ~(1<<4)); }
  41. bool muteLineout(void) { return write(0x0024, ana_ctrl | (1<<8)); }
  42. bool unmuteLineout(void) { return write(0x0024, ana_ctrl & ~(1<<8)); }
  43. bool inputSelect(int n) {
  44. if (n == AUDIO_INPUT_LINEIN) {
  45. return write(0x0024, ana_ctrl | (1<<2));
  46. } else if (n == AUDIO_INPUT_MIC) {
  47. //return write(0x002A, 0x0172) && write(0x0024, ana_ctrl & ~(1<<2));
  48. return write(0x002A, 0x0173) && write(0x0024, ana_ctrl & ~(1<<2)); // +40dB
  49. } else {
  50. return false;
  51. }
  52. }
  53. //bool inputLinein(void) { return write(0x0024, ana_ctrl | (1<<2)); }
  54. //bool inputMic(void) { return write(0x002A, 0x0172) && write(0x0024, ana_ctrl & ~(1<<2)); }
  55. unsigned short route(uint8_t i2s_out, uint8_t dac, uint8_t dap, uint8_t dap_mix);
  56. unsigned short route(uint8_t i2s_out, uint8_t dac, uint8_t dap) { return route(i2s_out,dac,dap,0); }
  57. bool volume(float left, float right);
  58. unsigned short micGain(unsigned int n) { return modify(0x002A, n&3, 3); }
  59. unsigned short lineOutLevel(uint8_t n);
  60. unsigned short lineOutLevel(uint8_t left, uint8_t right);
  61. unsigned short dacVolume(float n);
  62. unsigned short dacVolume(float left, float right);
  63. unsigned short adcHighPassFilterControl(uint8_t bypass, uint8_t freeze);
  64. unsigned short adcHighPassFilterControl(uint8_t bypass);
  65. unsigned short audioMixerEnable(uint8_t n);
  66. unsigned short audioProcessorEnable(uint8_t n);
  67. unsigned short audioProcessorEnable(void);
  68. unsigned short eqFilterCount(uint8_t n);
  69. unsigned short eqSelect(uint8_t n);
  70. unsigned short eqBand(uint8_t bandNum, float n);
  71. void eqBands(float bass, float mid_bass, float midrange, float mid_treble, float treble);
  72. void eqBands(float bass, float treble);
  73. void eqFilter(uint8_t filterNum, int *filterParameters);
  74. unsigned short autoVolumeControl(uint8_t maxGain, uint8_t lbiResponse, uint8_t hardLimit, float threshold, float attack, float decay);
  75. unsigned short autoVolumeEnable(uint8_t n);
  76. unsigned short autoVolumeEnable(void);
  77. unsigned short enhanceBass(float lr_lev, float bass_lev);
  78. unsigned short enhanceBass(float lr_lev, float bass_lev, uint8_t hpf_bypass, uint8_t cutoff);
  79. unsigned short enhanceBassEnable(uint8_t n);
  80. unsigned short enhanceBassEnable(void);
  81. unsigned short surroundSound(uint8_t width);
  82. unsigned short surroundSound(uint8_t width, uint8_t select);
  83. unsigned short surroundSoundEnable(uint8_t n);
  84. unsigned short surroundSoundEnable(void);
  85. void killAutomation(void) { semi_automated=false; }
  86. protected:
  87. bool muted;
  88. bool volumeInteger(unsigned int n); // range: 0x00 to 0x80
  89. uint16_t ana_ctrl;
  90. unsigned char calcVol(float n, unsigned char range);
  91. unsigned int read(unsigned int reg);
  92. bool write(unsigned int reg, unsigned int val);
  93. unsigned int modify(unsigned int reg, unsigned int val, unsigned int iMask);
  94. unsigned short dap_audio_eq_band(uint8_t bandNum, float n);
  95. private:
  96. bool semi_automated;
  97. void automate(uint8_t dap, uint8_t eq);
  98. void automate(uint8_t dap, uint8_t eq, uint8_t filterCount);
  99. };
  100. //For Filter Type: 0 = LPF, 1 = HPF, 2 = BPF, 3 = NOTCH, 4 = PeakingEQ, 5 = LowShelf, 6 = HighShelf
  101. #define FILTER_LOPASS 0
  102. #define FILTER_HIPASS 1
  103. #define FILTER_BANDPASS 2
  104. #define FILTER_NOTCH 3
  105. #define FILTER_PARAEQ 4
  106. #define FILTER_LOSHELF 5
  107. #define FILTER_HISHELF 6
  108. void calcBiquad(uint8_t filtertype, float fC, float dB_Gain, float Q, uint32_t quantization_unit, uint32_t fS, int *coef);
  109. #endif