PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Audio Library for Teensy 3.X
  2. * Copyright (c) 2019, 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. /*
  27. by Alexander Walch
  28. */
  29. #ifndef quantizer_h_
  30. #define quantizer_h_
  31. #include "Arduino.h"
  32. //#define DEBUG_QUANTIZER
  33. #define NOISE_SHAPE_F_LENGTH 9 //order of filter is 10, but the first coefficient equals 1 and doesn't need to be stored
  34. class Quantizer {
  35. public:
  36. ///@param audio_sample_rate currently only 44.1kHz and 48kHz are supported
  37. Quantizer(float audio_sample_rate);
  38. void configure(bool noiseShaping, bool dither, float factor);
  39. void quantize(float* input, int16_t* output, uint16_t length);
  40. //attention outputInterleaved must have length 2*length
  41. void quantize(float* input0, float* input1, int32_t* outputInterleaved, uint16_t length);
  42. void reset();
  43. private:
  44. bool _noiseShaping=true;
  45. bool _dither=true;
  46. float _fOutputLastIt0=0.f;
  47. float _fOutputLastIt1=0.f;
  48. float _buffer0[NOISE_SHAPE_F_LENGTH];
  49. float _buffer1[NOISE_SHAPE_F_LENGTH];
  50. float* _bPtr0=_buffer0;
  51. float* _bufferEnd0;
  52. float* _bPtr1=_buffer1;
  53. float _noiseSFilter[NOISE_SHAPE_F_LENGTH ];
  54. float _factor;
  55. };
  56. #endif