PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

97 linhas
3.6KB

  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 async_input_spdif3_h_
  30. #define async_input_spdif3_h_
  31. #include "Resampler.h"
  32. #include "Quantizer.h"
  33. #include "Arduino.h"
  34. #include "AudioStream.h"
  35. #include "DMAChannel.h"
  36. #include <arm_math.h>
  37. //#define DEBUG_SPDIF_IN //activates debug output
  38. class AsyncAudioInputSPDIF3 : public AudioStream
  39. {
  40. public:
  41. ///@param attenuation target attenuation [dB] of the anti-aliasing filter. Only used if newFs<fs. The attenuation can't be reached if the needed filter length exceeds 2*MAX_FILTER_SAMPLES+1
  42. ///@param minHalfFilterLength If newFs >= fs, the filter length of the resampling filter is 2*minHalfFilterLength+1. If fs y newFs the filter is maybe longer to reach the desired attenuation
  43. AsyncAudioInputSPDIF3(bool dither=true, bool noiseshaping=true,float attenuation=100, int32_t minHalfFilterLength=20);
  44. ~AsyncAudioInputSPDIF3();
  45. virtual void update(void);
  46. void begin();
  47. void stop();
  48. double getBufferedTime() const;
  49. double getInputFrequency() const;
  50. bool isLocked() const;
  51. double getTargetLantency() const;
  52. protected:
  53. static DMAChannel dma;
  54. static void isr(void);
  55. private:
  56. void resample(int16_t* data_left, int16_t* data_right, int32_t& block_offset);
  57. void monitorResampleBuffer();
  58. void configure();
  59. double getNewValidInputFrequ();
  60. void config_spdifIn();
  61. //accessed in isr ====
  62. static volatile int32_t buffer_offset;
  63. static int32_t resample_offset;
  64. static volatile uint32_t microsLast;
  65. //====================
  66. // spdif lock-changed interrupt
  67. static volatile bool locked;
  68. static volatile bool lockChanged;
  69. static volatile bool resetResampler;
  70. static void spdif_interrupt();
  71. #ifdef MEASURE_FREQ
  72. static FrequencyMeasurement frequMeasure;
  73. #endif
  74. //=============================
  75. float _attenuation;
  76. int32_t _minHalfFilterLength;
  77. Resampler _resampler;
  78. Quantizer* quantizer[2];
  79. arm_biquad_cascade_df2T_instance_f32 _bufferLPFilter;
  80. volatile double _bufferedTime;
  81. volatile double _lastValidInputFrequ;
  82. double _inputFrequency;
  83. double _targetLatencyS; //target latency [seconds]
  84. const double _blockDuration=AUDIO_BLOCK_SAMPLES/AUDIO_SAMPLE_RATE; //[seconds]
  85. const double _maxLatency=2.*_blockDuration;
  86. #ifdef DEBUG_SPDIF_IN
  87. static volatile bool bufferOverflow;
  88. #endif
  89. };
  90. #endif