@@ -37,18 +37,23 @@ struct PWMConfig : public AudioInfo {
3737 bits_per_sample = 16 ;
3838 }
3939
40- // basic pwm information
40+ // / size of an inidividual buffer
4141 uint16_t buffer_size = PWM_BUFFER_SIZE;
42+ // / number of buffers
4243 uint8_t buffers = PWM_BUFFER_COUNT;
4344
44- // additinal info which might not be used by all processors
45- uint32_t pwm_frequency = PWM_AUDIO_FREQUENCY; // audable range is from 20 to
46- // 20,000Hz (not used by ESP32)
47- uint8_t resolution = 8 ; // Only used by ESP32: must be between 8 and 11 ->
48- // drives pwm frequency
49- uint8_t timer_id = 0 ; // Only used by ESP32 must be between 0 and 3
45+ // / additinal info which might not be used by all processors
46+ uint32_t pwm_frequency = 0 ; // audable range is from 20 to
47+ // / Only used by ESP32: must be between 8 and 11 -> drives pwm frequency // 20,000Hz (not used by ESP32)
48+ uint8_t resolution = 8 ;
49+ // / Timer used: Only used by ESP32 must be between 0 and 3
50+ uint8_t timer_id = 0 ;
51+
52+ // / max sample sample rate that still produces good audio
53+ uint32_t max_sample_rate = PWM_MAX_SAMPLE_RATE;
5054
5155#ifndef __AVR__
56+ // / GPIO of starting pin
5257 uint16_t start_pin = PIN_PWM_START;
5358
5459 // / support assignament of int array
@@ -116,7 +121,8 @@ class DriverPWMBase {
116121
117122 // restart with prior definitions
118123 bool begin (PWMConfig cfg) {
119- TRACED ();
124+ TRACEI ();
125+
120126 decimation_factor = 0 ;
121127 audio_config = cfg;
122128 decimate.setChannels (cfg.channels );
@@ -140,9 +146,9 @@ class DriverPWMBase {
140146 // initialize if necessary
141147 if (!isTimerStarted () || !cfg.equals (actual_info)) {
142148 audio_config.logConfig ();
149+ actual_info = cfg;
143150 setupPWM ();
144151 setupTimer ();
145- actual_info = cfg;
146152 }
147153
148154 // reset class variables
@@ -323,19 +329,19 @@ class DriverPWMBase {
323329 }
324330
325331 // / Provides the max working sample rate
326- virtual int maxSampleRate () { return 48000 ; }
332+ virtual int maxSampleRate () { return audio_config. max_sample_rate ; }
327333
328334 // / The requested sampling rate is too hight: we only process half of the
329335 // / samples so we can half the sampling rate
330336 virtual bool isDecimateActive () {
331- return audio_config.sample_rate >= ANALOG_MAX_SAMPLE_RATE ;
337+ return audio_config.sample_rate >= audio_config. max_sample_rate ;
332338 }
333339
334340 // / Decimation factor to reduce the sample rate
335341 virtual int decimation () {
336342 if (decimation_factor == 0 ){
337343 for (int j = 1 ; j < 20 ; j++){
338- if (audio_config.sample_rate / j <= ANALOG_MAX_SAMPLE_RATE ){
344+ if (audio_config.sample_rate / j <= audio_config. max_sample_rate ){
339345 decimation_factor = j;
340346 LOGI (" Decimation factor: %d" ,j);
341347 return j;
0 commit comments