@@ -26,9 +26,15 @@ bool Resampler::initialize(ResamplerConfiguration &config) {
2626
2727 this ->float_input_buffer_ =
2828 (float *) heap_caps_malloc (this ->input_buffer_samples_ * sizeof (float ), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
29+ if (this ->float_input_buffer_ == nullptr ) {
30+ this ->float_input_buffer_ = (float *) malloc (this ->input_buffer_samples_ * sizeof (float ));
31+ }
2932
3033 this ->float_output_buffer_ =
3134 (float *) heap_caps_malloc (this ->output_buffer_samples_ * sizeof (float ), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
35+ if (this ->float_output_buffer_ == nullptr ) {
36+ this ->float_output_buffer_ = (float *) malloc (this ->output_buffer_samples_ * sizeof (float ));
37+ }
3238
3339 if ((this ->float_input_buffer_ == nullptr ) || (this ->float_output_buffer_ == nullptr )) {
3440 return false ;
@@ -76,15 +82,20 @@ bool Resampler::initialize(ResamplerConfiguration &config) {
7682 }
7783
7884 if (this ->sample_ratio_ < 1 .0f ) {
79- this ->resampler_ = art_resampler::resampleInit (this ->channels_ , this ->number_of_taps_ , this ->number_of_filters_ ,
85+ this ->resampler_ =
86+ art_resampler::resampleInit (this ->channels_ , this ->number_of_taps_ , this ->number_of_filters_ ,
8087 this ->sample_ratio_ * this ->lowpass_ratio_ , flags | INCLUDE_LOWPASS);
8188 } else if (this ->lowpass_ratio_ < 1 .0f ) {
8289 this ->resampler_ = art_resampler::resampleInit (this ->channels_ , this ->number_of_taps_ , this ->number_of_filters_ ,
83- this ->lowpass_ratio_ , flags | INCLUDE_LOWPASS);
90+ this ->lowpass_ratio_ , flags | INCLUDE_LOWPASS);
8491 } else {
85- this ->resampler_ = art_resampler::resampleInit (this ->channels_ , this ->number_of_taps_ , this ->number_of_filters_ , 1 .0f , flags);
92+ this ->resampler_ =
93+ art_resampler::resampleInit (this ->channels_ , this ->number_of_taps_ , this ->number_of_filters_ , 1 .0f , flags);
8694 }
8795
96+ if (this ->resampler_ == nullptr ) {
97+ return false ;
98+ }
8899 art_resampler::resampleAdvancePosition (this ->resampler_ , this ->number_of_taps_ / 2 .0f );
89100 }
90101
@@ -104,12 +115,12 @@ ResamplerResults Resampler::resample(const uint8_t *input_buffer, uint8_t *outpu
104115 }
105116 uint32_t conversion_time = 0 ;
106117 if (this ->requires_resampling_ ) {
107- quantization_utils::quantized_to_float (input_buffer, this ->float_input_buffer_ , frames_to_process * this ->channels_ , this -> input_bits_ ,
108- gain_db);
118+ quantization_utils::quantized_to_float (input_buffer, this ->float_input_buffer_ , frames_to_process * this ->channels_ ,
119+ this -> input_bits_ , gain_db);
109120 } else {
110121 // Just converting the bits per sample
111- quantization_utils::quantized_to_float (input_buffer, this ->float_output_buffer_ , frames_to_process * this -> channels_ , this -> input_bits_ ,
112- gain_db);
122+ quantization_utils::quantized_to_float (input_buffer, this ->float_output_buffer_ ,
123+ frames_to_process * this -> channels_ , this -> input_bits_ , gain_db);
113124 }
114125
115126 size_t frames_used = frames_to_process;
@@ -119,28 +130,32 @@ ResamplerResults Resampler::resample(const uint8_t *input_buffer, uint8_t *outpu
119130 if (this ->requires_resampling_ ) {
120131 if (this ->pre_filter_ ) {
121132 for (int i = 0 ; i < this ->channels_ ; ++i) {
122- art_resampler::biquad_apply_buffer (&this ->lowpass_ [i][0 ], this ->float_input_buffer_ + i, frames_to_process, this ->channels_ );
123- art_resampler::biquad_apply_buffer (&this ->lowpass_ [i][1 ], this ->float_input_buffer_ + i, frames_to_process, this ->channels_ );
133+ art_resampler::biquad_apply_buffer (&this ->lowpass_ [i][0 ], this ->float_input_buffer_ + i, frames_to_process,
134+ this ->channels_ );
135+ art_resampler::biquad_apply_buffer (&this ->lowpass_ [i][1 ], this ->float_input_buffer_ + i, frames_to_process,
136+ this ->channels_ );
124137 }
125138 }
126139
127140 art_resampler::ResampleResult res =
128141 art_resampler::resampleProcessInterleaved (this ->resampler_ , this ->float_input_buffer_ , frames_to_process,
129- this ->float_output_buffer_ , output_frames_free, this ->sample_ratio_ );
142+ this ->float_output_buffer_ , output_frames_free, this ->sample_ratio_ );
130143
131144 frames_used = res.input_used ;
132145 frames_generated = res.output_generated ;
133146
134147 if (this ->post_filter_ ) {
135148 for (int i = 0 ; i < this ->channels_ ; ++i) {
136- art_resampler::biquad_apply_buffer (&this ->lowpass_ [i][0 ], this ->float_output_buffer_ + i, frames_generated, this ->channels_ );
137- art_resampler::biquad_apply_buffer (&this ->lowpass_ [i][1 ], this ->float_output_buffer_ + i, frames_generated, this ->channels_ );
149+ art_resampler::biquad_apply_buffer (&this ->lowpass_ [i][0 ], this ->float_output_buffer_ + i, frames_generated,
150+ this ->channels_ );
151+ art_resampler::biquad_apply_buffer (&this ->lowpass_ [i][1 ], this ->float_output_buffer_ + i, frames_generated,
152+ this ->channels_ );
138153 }
139154 }
140155 }
141156
142- uint32_t clipped_samples = quantization_utils::float_to_quantized (this -> float_output_buffer_ , output_buffer,
143- frames_generated * this ->channels_ , this ->output_bits_ );
157+ uint32_t clipped_samples = quantization_utils::float_to_quantized (
158+ this -> float_output_buffer_ , output_buffer, frames_generated * this ->channels_ , this ->output_bits_ );
144159
145160 ResamplerResults results = {.frames_used = frames_used,
146161 .frames_generated = frames_generated,
0 commit comments