@@ -388,7 +388,17 @@ class ResampleStreamT : public ReformatBaseStream {
388
388
389
389
bool begin () {
390
390
setupReader ();
391
- setStepSize (cfg.step_size );
391
+ if (cfg.step_size ) {
392
+ setStepSize (cfg.step_size );
393
+ } else if (cfg.to_sample_rate > 0 ) {
394
+ // calculate step size from sample rate
395
+ cfg.step_size = static_cast <float >(cfg.sample_rate ) /
396
+ static_cast <float >(cfg.to_sample_rate );
397
+ setStepSize (cfg.step_size );
398
+ } else {
399
+ cfg.step_size = 1 .0f ;
400
+ setStepSize (1 .0f );
401
+ }
392
402
return true ;
393
403
}
394
404
@@ -415,7 +425,9 @@ class ResampleStreamT : public ReformatBaseStream {
415
425
*/
416
426
AudioInfo audioInfoOut () override {
417
427
AudioInfo out = audioInfo ();
418
- if (cfg.step_size != 1 .0f ) {
428
+ if (cfg.to_sample_rate > 0 ) {
429
+ out.sample_rate = cfg.to_sample_rate ;
430
+ } else if (cfg.step_size != 1 .0f ) {
419
431
out.sample_rate = out.sample_rate / cfg.step_size ;
420
432
}
421
433
return out;
@@ -453,6 +465,13 @@ class ResampleStreamT : public ReformatBaseStream {
453
465
AudioStream::setAudioInfo (newInfo);
454
466
_resampler.setChannels (newInfo.channels );
455
467
cfg.copyFrom (newInfo);
468
+ // if target sample rate is set, calculate step size
469
+ if (cfg.to_sample_rate > 0 ) {
470
+ // calculate step size from sample rate
471
+ cfg.step_size = static_cast <float >(cfg.sample_rate ) /
472
+ static_cast <float >(cfg.to_sample_rate );
473
+ setStepSize (cfg.step_size );
474
+ }
456
475
}
457
476
458
477
float getByteFactor () override { return 1 .0f / cfg.step_size ; }
0 commit comments