@@ -37,18 +37,23 @@ struct PWMConfig : public AudioInfo {
37
37
bits_per_sample = 16 ;
38
38
}
39
39
40
- // basic pwm information
40
+ // / size of an inidividual buffer
41
41
uint16_t buffer_size = PWM_BUFFER_SIZE;
42
+ // / number of buffers
42
43
uint8_t buffers = PWM_BUFFER_COUNT;
43
44
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;
50
54
51
55
#ifndef __AVR__
56
+ // / GPIO of starting pin
52
57
uint16_t start_pin = PIN_PWM_START;
53
58
54
59
// / support assignament of int array
@@ -116,7 +121,8 @@ class DriverPWMBase {
116
121
117
122
// restart with prior definitions
118
123
bool begin (PWMConfig cfg) {
119
- TRACED ();
124
+ TRACEI ();
125
+
120
126
decimation_factor = 0 ;
121
127
audio_config = cfg;
122
128
decimate.setChannels (cfg.channels );
@@ -140,9 +146,9 @@ class DriverPWMBase {
140
146
// initialize if necessary
141
147
if (!isTimerStarted () || !cfg.equals (actual_info)) {
142
148
audio_config.logConfig ();
149
+ actual_info = cfg;
143
150
setupPWM ();
144
151
setupTimer ();
145
- actual_info = cfg;
146
152
}
147
153
148
154
// reset class variables
@@ -323,19 +329,19 @@ class DriverPWMBase {
323
329
}
324
330
325
331
// / Provides the max working sample rate
326
- virtual int maxSampleRate () { return 48000 ; }
332
+ virtual int maxSampleRate () { return audio_config. max_sample_rate ; }
327
333
328
334
// / The requested sampling rate is too hight: we only process half of the
329
335
// / samples so we can half the sampling rate
330
336
virtual bool isDecimateActive () {
331
- return audio_config.sample_rate >= ANALOG_MAX_SAMPLE_RATE ;
337
+ return audio_config.sample_rate >= audio_config. max_sample_rate ;
332
338
}
333
339
334
340
// / Decimation factor to reduce the sample rate
335
341
virtual int decimation () {
336
342
if (decimation_factor == 0 ){
337
343
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 ){
339
345
decimation_factor = j;
340
346
LOGI (" Decimation factor: %d" ,j);
341
347
return j;
0 commit comments