speaker-calibration 2.2.225 → 2.2.227

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -383,7 +383,11 @@ class Combination extends AudioCalibrator {
383
383
  return element != undefined;
384
384
  }); //log any errors that are found in this step
385
385
  console.log('filteredComputedIRs', filteredComputedIRs);
386
- const mls = this.#mls[this.icapture];
386
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
387
+ const mls = this.downsampleSignal(
388
+ this.#mls[this.icapture],
389
+ this._calibrateSoundBurstDownsample
390
+ );
387
391
  const lowHz = this.#lowHz; //gain of 1 below cutoff, need gain of 0
388
392
  const highHz = this.#highHz; //check error for anything other than 10 kHz
389
393
  const iirLength = this.iirLength;
@@ -393,17 +397,23 @@ class Combination extends AudioCalibrator {
393
397
  `All Hz Calibration: computing the IIR...`.toString()
394
398
  ).toString();
395
399
  this.emit('update', {message: this.status});
400
+ const filteredComputedIRs_slice = filteredComputedIRs.slice(0, this.numCaptures);
401
+ // for each element in filteredComputedIRs_slice, downsample it
402
+ const payload_downsampled = filteredComputedIRs_slice.map(ir =>
403
+ this.downsampleSignal(ir, this._calibrateSoundBurstDownsample)
404
+ );
396
405
  return await this.pyServerAPI
397
406
  .getSystemInverseImpulseResponseWithRetry({
398
- payload: filteredComputedIRs.slice(0, this.numCaptures),
407
+ payload: payload_downsampled,
399
408
  mls,
400
409
  lowHz,
401
410
  highHz,
402
411
  iirLength,
403
- sampleRate: this.sourceSamplingRate || 96000,
412
+ sampleRate: fMLS,
404
413
  mlsAmplitude: Math.pow(10, this.power_dB / 20),
405
414
  calibrateSoundBurstFilteredExtraDb: this._calibrateSoundBurstFilteredExtraDb,
406
415
  calibrateSoundIIRPhase: this.calibrateSoundIIRPhase,
416
+ downsample: this._calibrateSoundBurstDownsample,
407
417
  })
408
418
  .then(async res => {
409
419
  this.stepNum += 1;
@@ -429,8 +439,14 @@ class Combination extends AudioCalibrator {
429
439
  })
430
440
  .then(result => {
431
441
  console.log(result);
432
- this.systemConvolution = result['convolution'];
433
- this.systemConvolutionNoBandpass = result['convolution_no_bandpass'];
442
+ this.systemConvolution = this.upsampleSignal(
443
+ result['convolution'],
444
+ this._calibrateSoundBurstDownsample
445
+ );
446
+ this.systemConvolutionNoBandpass = this.upsampleSignal(
447
+ result['convolution_no_bandpass'],
448
+ this._calibrateSoundBurstDownsample
449
+ );
434
450
  });
435
451
 
436
452
  // attenuate the system convolution if the amplitude is greater than this.calibrateSoundLimit
@@ -460,6 +476,12 @@ class Combination extends AudioCalibrator {
460
476
  const filteredComputedIRs = computedIRs.filter(element => {
461
477
  return element != undefined;
462
478
  });
479
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
480
+ const filteredComputedIRs_slice = filteredComputedIRs.slice(0, this.numCaptures);
481
+ // for each element in filteredComputedIRs_slice, downsample it
482
+ const payload_downsampled = filteredComputedIRs_slice.map(ir =>
483
+ this.downsampleSignal(ir, this._calibrateSoundBurstDownsample)
484
+ );
463
485
  let componentIRGains = this.componentIR['Gain'];
464
486
  const componentIRFreqs = this.componentIR['Freq'];
465
487
  //normalize the component IR gains
@@ -472,7 +494,10 @@ class Combination extends AudioCalibrator {
472
494
  return value - sineGainAt1000Hz_dB;
473
495
  });
474
496
  }
475
- const mls = this.#mls[this.icapture];
497
+ const mls = this.downsampleSignal(
498
+ this.#mls[this.icapture],
499
+ this._calibrateSoundBurstDownsample
500
+ );
476
501
  const lowHz = this.#lowHz;
477
502
  const iirLength = this.iirLength;
478
503
  const irLength = this.irLength;
@@ -483,23 +508,24 @@ class Combination extends AudioCalibrator {
483
508
  `All Hz Calibration: computing the IIR...`.toString()
484
509
  ).toString();
485
510
  this.emit('update', {message: this.status});
486
- console.log();
511
+
487
512
  return this.pyServerAPI
488
513
  .getComponentInverseImpulseResponseWithRetry({
489
- payload: filteredComputedIRs.slice(0, this.numCaptures),
514
+ payload: payload_downsampled,
490
515
  mls,
491
516
  lowHz,
492
517
  highHz,
493
518
  iirLength,
494
519
  componentIRGains,
495
520
  componentIRFreqs,
496
- sampleRate: this.sourceSamplingRate || 96000,
521
+ sampleRate: fMLS,
497
522
  mlsAmplitude: Math.pow(10, this.power_dB / 20),
498
523
  irLength,
499
524
  calibrateSoundSmoothOctaves: this._calibrateSoundSmoothOctaves,
500
525
  calibrateSoundSmoothMinBandwidthHz: this._calibrateSoundSmoothMinBandwidthHz,
501
526
  calibrateSoundBurstFilteredExtraDb: this._calibrateSoundBurstFilteredExtraDb,
502
527
  calibrateSoundIIRPhase: this.calibrateSoundIIRPhase,
528
+ downsample: this._calibrateSoundBurstDownsample,
503
529
  })
504
530
  .then(async res => {
505
531
  this.stepNum += 1;
@@ -530,9 +556,20 @@ class Combination extends AudioCalibrator {
530
556
  mls_amplitude: Math.pow(10, this.power_dB / 20),
531
557
  })
532
558
  .then(result => {
533
- console.log(result);
534
- this.componentConvolution = result['convolution'];
535
- this.componentConvolutionNoBandpass = result['convolution_no_bandpass'];
559
+ console.log('result', result);
560
+ this.componentConvolution = this.upsampleSignal(
561
+ result['convolution'],
562
+ this._calibrateSoundBurstDownsample
563
+ );
564
+ this.componentConvolutionNoBandpass = this.upsampleSignal(
565
+ result['convolution_no_bandpass'],
566
+ this._calibrateSoundBurstDownsample
567
+ );
568
+ console.log('this.componentConvolution...', this.componentConvolution);
569
+ console.log(
570
+ 'this.componentConvolutionNoBandpass...',
571
+ this.componentConvolutionNoBandpass
572
+ );
536
573
  });
537
574
  // attenuate the component convolution if the amplitude is greater than this.calibrateSoundLimit
538
575
  // find max of absolute value of component convolution
@@ -554,6 +591,44 @@ class Combination extends AudioCalibrator {
554
591
  });
555
592
  };
556
593
 
594
+ /**
595
+ * Upsamples a signal by repeating each sample N times
596
+ * @param {Array<number>} signal - The input signal to upsample
597
+ * @param {number} N - The upsampling factor
598
+ * @returns {Array<number>} - The upsampled signal
599
+ */
600
+ upsampleSignal = (signal, N) => {
601
+ if (N <= 1) return signal;
602
+
603
+ const result = [];
604
+ for (let sample of signal) {
605
+ // Repeat each sample N times
606
+ for (let i = 0; i < N; i++) {
607
+ result.push(sample);
608
+ }
609
+ }
610
+ return result;
611
+ };
612
+
613
+ /**
614
+ * Downsamples a signal by averaging groups of N samples
615
+ * @param {Array<number>} signal - The input signal to downsample
616
+ * @param {number} N - The downsampling factor
617
+ * @returns {Array<number>} - The downsampled signal
618
+ */
619
+ downsampleSignal = (signal, N) => {
620
+ if (N <= 1) return signal;
621
+
622
+ const result = [];
623
+ for (let i = 0; i < signal.length; i += N) {
624
+ const chunk = signal.slice(i, Math.min(i + N, signal.length));
625
+ // Calculate average of the chunk
626
+ const avg = chunk.reduce((sum, val) => sum + val, 0) / chunk.length;
627
+ result.push(avg);
628
+ }
629
+ return result;
630
+ };
631
+
557
632
  sendBackgroundRecording = () => {
558
633
  const allSignals = this.getAllBackgroundRecordings();
559
634
  const numSignals = allSignals.length;
@@ -565,10 +640,16 @@ class Combination extends AudioCalibrator {
565
640
  const background_rec = background_rec_whole.slice(startIndex);
566
641
  console.log('Sending background recording to server for processing');
567
642
  this.addTimeStamp('Compute PSD of background');
643
+ const fBackground = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
644
+ const background_rec_downsampled = this.downsampleSignal(
645
+ background_rec,
646
+ this._calibrateSoundBurstDownsample
647
+ );
648
+
568
649
  this.pyServerAPI
569
650
  .getBackgroundNoisePSDWithRetry({
570
- background_rec,
571
- sampleRate: this.sourceSamplingRate || 96000,
651
+ background_rec: background_rec_downsampled,
652
+ sampleRate: fBackground,
572
653
  })
573
654
  .then(res => {
574
655
  if (this.numSuccessfulBackgroundCaptured < 1) {
@@ -609,14 +690,16 @@ class Combination extends AudioCalibrator {
609
690
  ).toString();
610
691
  this.emit('update', {message: this.status});
611
692
  if (this.isCalibrating) return null;
693
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
612
694
  await this.pyServerAPI
613
695
  .allHzPowerCheck({
614
696
  payload,
615
- sampleRate: this.sourceSamplingRate || 96000,
697
+ sampleRate: fMLS,
616
698
  binDesiredSec: this._calibrateSoundPowerBinDesiredSec,
617
699
  burstSec: this.desired_time_per_mls,
618
700
  repeats: this.numMLSPerCapture - this.num_mls_to_skip,
619
701
  warmUp: this.num_mls_to_skip,
702
+ downsample: this._calibrateSoundBurstDownsample,
620
703
  })
621
704
  .then(async result => {
622
705
  if (result) {
@@ -675,12 +758,17 @@ class Combination extends AudioCalibrator {
675
758
  console.log('start calculate impulse response');
676
759
  const usedPeriodStart = this.num_mls_to_skip * this.sourceSamplingRate;
677
760
  const payload_skipped_warmUp = payload.slice(usedPeriodStart);
761
+ const payload_skipped_warmUp_downsampled = this.downsampleSignal(
762
+ payload_skipped_warmUp,
763
+ this._calibrateSoundBurstDownsample
764
+ );
678
765
  await this.pyServerAPI
679
766
  .getAutocorrelation({
680
767
  mls: mls,
681
- payload: payload_skipped_warmUp,
682
- sampleRate: this.sourceSamplingRate || 96000,
768
+ payload: payload_skipped_warmUp_downsampled,
769
+ sampleRate: fMLS,
683
770
  numPeriods: this.numMLSPerCapture - this.num_mls_to_skip,
771
+ downsample: this._calibrateSoundBurstDownsample,
684
772
  })
685
773
  .then(async res => {
686
774
  this.autocorrelations.push(res['autocorrelation']);
@@ -691,12 +779,13 @@ class Combination extends AudioCalibrator {
691
779
  await this.pyServerAPI
692
780
  .getImpulseResponse({
693
781
  mls,
694
- sampleRate: this.sourceSamplingRate || 96000,
782
+ sampleRate: fMLS,
695
783
  numPeriods: this.numMLSPerCapture - this.num_mls_to_skip,
696
- sig: payload_skipped_warmUp,
784
+ sig: payload_skipped_warmUp_downsampled,
697
785
  fs2: this.fs2,
698
786
  L_new_n: this.L_new_n,
699
787
  dL_n: this.dL_n,
788
+ downsample: this._calibrateSoundBurstDownsample,
700
789
  })
701
790
  .then(res => {
702
791
  this.numSuccessfulCaptured += 2;
@@ -746,17 +835,17 @@ class Combination extends AudioCalibrator {
746
835
  message: this.status,
747
836
  });
748
837
  let time_to_wait = 0;
838
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
749
839
  if (this.mode === 'unfiltered') {
750
840
  //unfiltered
751
- time_to_wait = (this.#mls[0].length / this.sourceSamplingRate) * this.numMLSPerCapture;
841
+ time_to_wait = (this.#mls[0].length / fMLS) * this.numMLSPerCapture;
752
842
  time_to_wait = time_to_wait + this._calibrateSoundBurstPostSec;
753
843
  } else if (this.mode === 'filtered') {
754
844
  //filtered
755
845
  // time_to_wait =
756
846
  // (this.#currentConvolution.length / this.sourceSamplingRate) *
757
847
  // (this.numMLSPerCapture / (this.num_mls_to_skip + this.numMLSPerCapture));
758
- time_to_wait =
759
- (this.#currentConvolution.length / this.sourceSamplingRate) * this.numMLSPerCapture;
848
+ time_to_wait = (this.#currentConvolution.length / fMLS) * this.numMLSPerCapture;
760
849
  time_to_wait = time_to_wait + this._calibrateSoundBurstPostSec;
761
850
  } else {
762
851
  throw new Error('Mode broke in awaitDesiredMLSLength');
@@ -798,15 +887,15 @@ class Combination extends AudioCalibrator {
798
887
  });
799
888
  let number_of_bursts_to_skip = 0;
800
889
  let time_to_sleep = 0;
890
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
801
891
  if (this.mode === 'unfiltered') {
802
- time_to_sleep = (this.#mls[0].length / this.sourceSamplingRate) * number_of_bursts_to_skip;
892
+ time_to_sleep = (this.#mls[0].length / fMLS) * number_of_bursts_to_skip;
803
893
  } else if (this.mode === 'filtered') {
804
894
  console.log(this.#currentConvolution.length);
805
895
  // time_to_sleep =
806
896
  // (this.#currentConvolution.length / this.sourceSamplingRate) *
807
897
  // (number_of_bursts_to_skip / (number_of_bursts_to_skip + this.numMLSPerCapture));
808
- time_to_sleep =
809
- (this.#currentConvolution.length / this.sourceSamplingRate) * number_of_bursts_to_skip;
898
+ time_to_sleep = (this.#currentConvolution.length / fMLS) * number_of_bursts_to_skip;
810
899
  } else {
811
900
  throw new Error('Mode broke in awaitSignalOnset');
812
901
  }
@@ -1077,7 +1166,7 @@ class Combination extends AudioCalibrator {
1077
1166
  let unconv_rec = recs[0];
1078
1167
  let return_unconv_rec = unconv_rec;
1079
1168
  let conv_rec = component_conv_recs[component_conv_recs.length - 1];
1080
-
1169
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
1081
1170
  //psd of component
1082
1171
  let knownGain = this.oldComponentIR.Gain;
1083
1172
  let knownFreq = this.oldComponentIR.Freq;
@@ -1085,7 +1174,13 @@ class Combination extends AudioCalibrator {
1085
1174
  this.addTimeStamp('Compute PSD of MLS recording');
1086
1175
  if (this.isCalibrating) return null;
1087
1176
  let component_unconv_rec_psd = await this.pyServerAPI
1088
- .getSubtractedPSDWithRetry(unconv_rec, knownGain, knownFreq, sampleRate)
1177
+ .getSubtractedPSDWithRetry(
1178
+ this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
1179
+ knownGain,
1180
+ knownFreq,
1181
+ fMLS,
1182
+ this._calibrateSoundBurstDownsample
1183
+ )
1089
1184
  .then(res => {
1090
1185
  this.incrementStatusBar();
1091
1186
  this.status = this.generateTemplate(
@@ -1101,7 +1196,13 @@ class Combination extends AudioCalibrator {
1101
1196
  this.addTimeStamp('Compute PSD of filtered recording (component)');
1102
1197
  if (this.isCalibrating) return null;
1103
1198
  let component_conv_rec_psd = await this.pyServerAPI
1104
- .getSubtractedPSDWithRetry(conv_rec, knownGain, knownFreq, sampleRate)
1199
+ .getSubtractedPSDWithRetry(
1200
+ this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
1201
+ knownGain,
1202
+ knownFreq,
1203
+ fMLS,
1204
+ this._calibrateSoundBurstDownsample
1205
+ )
1105
1206
  .then(res => {
1106
1207
  let interpolatedGain = res.x.map((freq, index) => {
1107
1208
  let i = 0;
@@ -1140,9 +1241,10 @@ class Combination extends AudioCalibrator {
1140
1241
  if (this.isCalibrating) return null;
1141
1242
  let system_recs_psd = await this.pyServerAPI
1142
1243
  .getPSDWithRetry({
1143
- unconv_rec,
1144
- conv_rec,
1145
- sampleRate: this.sourceSamplingRate || 96000,
1244
+ unconv_rec: this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
1245
+ conv_rec: this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
1246
+ sampleRate: fMLS,
1247
+ downsample: this._calibrateSoundBurstDownsample,
1146
1248
  })
1147
1249
  .then(res => {
1148
1250
  let filtered_psd = res.y_conv
@@ -1179,9 +1281,10 @@ class Combination extends AudioCalibrator {
1179
1281
  if (this.isCalibrating) return null;
1180
1282
  let component_iir_psd = await this.pyServerAPI
1181
1283
  .getPSDWithRetry({
1182
- unconv_rec,
1183
- conv_rec,
1184
- sampleRate: this.sourceSamplingRate || 96000,
1284
+ unconv_rec: this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
1285
+ conv_rec: this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
1286
+ sampleRate: fMLS,
1287
+ downsample: this._calibrateSoundBurstDownsample,
1185
1288
  })
1186
1289
  .then(res => {
1187
1290
  this.incrementStatusBar();
@@ -1200,9 +1303,10 @@ class Combination extends AudioCalibrator {
1200
1303
  if (this.isCalibrating) return null;
1201
1304
  let system_iir_psd = await this.pyServerAPI
1202
1305
  .getPSDWithRetry({
1203
- unconv_rec,
1204
- conv_rec,
1205
- sampleRate: this.sourceSamplingRate || 96000,
1306
+ unconv_rec: this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
1307
+ conv_rec: this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
1308
+ sampleRate: fMLS,
1309
+ downsample: this._calibrateSoundBurstDownsample,
1206
1310
  })
1207
1311
  .then(res => {
1208
1312
  this.incrementStatusBar();
@@ -1220,8 +1324,9 @@ class Combination extends AudioCalibrator {
1220
1324
  if (this.isCalibrating) return null;
1221
1325
  let mls_psd = await this.pyServerAPI
1222
1326
  .getMLSPSDWithRetry({
1223
- mls: this.#mlsBufferView[0],
1224
- sampleRate: this.sourceSamplingRate || 96000,
1327
+ mls: this.downsampleSignal(this.#mlsBufferView[0], this._calibrateSoundBurstDownsample),
1328
+ sampleRate: fMLS,
1329
+ downsample: this._calibrateSoundBurstDownsample,
1225
1330
  })
1226
1331
  .then(res => {
1227
1332
  this.incrementStatusBar();
@@ -1239,8 +1344,9 @@ class Combination extends AudioCalibrator {
1239
1344
  if (this.isCalibrating) return null;
1240
1345
  let system_filtered_mls_psd = await this.pyServerAPI
1241
1346
  .getMLSPSDWithRetry({
1242
- mls: this.systemConvolution,
1243
- sampleRate: this.sourceSamplingRate || 96000,
1347
+ mls: this.downsampleSignal(this.systemConvolution, this._calibrateSoundBurstDownsample),
1348
+ sampleRate: fMLS,
1349
+ downsample: this._calibrateSoundBurstDownsample,
1244
1350
  })
1245
1351
  .then(res => {
1246
1352
  this.incrementStatusBar();
@@ -1256,8 +1362,12 @@ class Combination extends AudioCalibrator {
1256
1362
 
1257
1363
  let system_no_bandpass_filtered_mls_psd = await this.pyServerAPI
1258
1364
  .getMLSPSDWithRetry({
1259
- mls: this.systemConvolution,
1260
- sampleRate: this.sourceSamplingRate || 96000,
1365
+ mls: this.downsampleSignal(
1366
+ this.systemConvolutionNoBandpass,
1367
+ this._calibrateSoundBurstDownsample
1368
+ ),
1369
+ sampleRate: fMLS,
1370
+ downsample: this._calibrateSoundBurstDownsample,
1261
1371
  })
1262
1372
  .then(res => {
1263
1373
  this.incrementStatusBar();
@@ -1275,8 +1385,9 @@ class Combination extends AudioCalibrator {
1275
1385
  if (this.isCalibrating) return null;
1276
1386
  let component_filtered_mls_psd = await this.pyServerAPI
1277
1387
  .getMLSPSDWithRetry({
1278
- mls: this.componentConvolution,
1279
- sampleRate: this.sourceSamplingRate || 96000,
1388
+ mls: this.downsampleSignal(this.componentConvolution, this._calibrateSoundBurstDownsample),
1389
+ sampleRate: fMLS,
1390
+ downsample: this._calibrateSoundBurstDownsample,
1280
1391
  })
1281
1392
  .then(res => {
1282
1393
  this.incrementStatusBar();
@@ -1292,8 +1403,12 @@ class Combination extends AudioCalibrator {
1292
1403
 
1293
1404
  let component_no_bandpass_filtered_mls_psd = await this.pyServerAPI
1294
1405
  .getMLSPSDWithRetry({
1295
- mls: this.componentConvolutionNoBandpass,
1296
- sampleRate: this.sourceSamplingRate || 96000,
1406
+ mls: this.downsampleSignal(
1407
+ this.componentConvolutionNoBandpass,
1408
+ this._calibrateSoundBurstDownsample
1409
+ ),
1410
+ sampleRate: fMLS,
1411
+ downsample: this._calibrateSoundBurstDownsample,
1297
1412
  })
1298
1413
  .then(res => {
1299
1414
  this.incrementStatusBar();
@@ -1475,8 +1590,16 @@ class Combination extends AudioCalibrator {
1475
1590
  let sampleRate = this.sourceSamplingRate || 96000;
1476
1591
  this.addTimeStamp('Compute PSD of MLS recording');
1477
1592
  if (this.isCalibrating) return null;
1593
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
1594
+
1478
1595
  let unconv_results = await this.pyServerAPI
1479
- .getSubtractedPSDWithRetry(unconv_rec, knownGain, knownFreq, sampleRate)
1596
+ .getSubtractedPSDWithRetry(
1597
+ this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
1598
+ knownGain,
1599
+ knownFreq,
1600
+ fMLS,
1601
+ this._calibrateSoundBurstDownsample
1602
+ )
1480
1603
  .then(res => {
1481
1604
  console.log(res);
1482
1605
  let mls_psd = res.y
@@ -1499,8 +1622,15 @@ class Combination extends AudioCalibrator {
1499
1622
 
1500
1623
  this.addTimeStamp('Compute PSD recording of speaker+ mic IIR-filtered MLS recording');
1501
1624
  if (this.isCalibrating) return null;
1625
+
1502
1626
  let conv_results = await this.pyServerAPI
1503
- .getSubtractedPSDWithRetry(conv_rec, knownGain, knownFreq, sampleRate)
1627
+ .getSubtractedPSDWithRetry(
1628
+ this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
1629
+ knownGain,
1630
+ knownFreq,
1631
+ fMLS,
1632
+ this._calibrateSoundBurstDownsample
1633
+ )
1504
1634
  .then(res => {
1505
1635
  let interpolatedGain = res.x.map((freq, index) => {
1506
1636
  let i = 0;
@@ -1542,11 +1672,13 @@ class Combination extends AudioCalibrator {
1542
1672
  conv_rec = this.componentInvertedImpulseResponse;
1543
1673
  this.addTimeStamp('Compute PSD of speaker or mic IIR, with and without bandpass');
1544
1674
  if (this.isCalibrating) return null;
1675
+
1545
1676
  let component_iir_psd = await this.pyServerAPI
1546
1677
  .getPSDWithRetry({
1547
- unconv_rec,
1548
- conv_rec,
1549
- sampleRate: this.sourceSamplingRate || 96000,
1678
+ unconv_rec: this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
1679
+ conv_rec: this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
1680
+ sampleRate: fMLS,
1681
+ downsample: this._calibrateSoundBurstDownsample,
1550
1682
  })
1551
1683
  .then(res => {
1552
1684
  this.incrementStatusBar();
@@ -1565,9 +1697,10 @@ class Combination extends AudioCalibrator {
1565
1697
  if (this.isCalibrating) return null;
1566
1698
  let system_iir_psd = await this.pyServerAPI
1567
1699
  .getPSDWithRetry({
1568
- unconv_rec,
1569
- conv_rec,
1570
- sampleRate: this.sourceSamplingRate || 96000,
1700
+ unconv_rec: this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
1701
+ conv_rec: this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
1702
+ sampleRate: fMLS,
1703
+ downsample: this._calibrateSoundBurstDownsample,
1571
1704
  })
1572
1705
  .then(res => {
1573
1706
  this.incrementStatusBar();
@@ -1585,8 +1718,12 @@ class Combination extends AudioCalibrator {
1585
1718
  if (this.isCalibrating) return null;
1586
1719
  let mls_psd = await this.pyServerAPI
1587
1720
  .getMLSPSDWithRetry({
1588
- mls: this.#mlsBufferView[this.icapture],
1589
- sampleRate: this.sourceSamplingRate || 96000,
1721
+ mls: this.downsampleSignal(
1722
+ this.#mlsBufferView[this.icapture],
1723
+ this._calibrateSoundBurstDownsample
1724
+ ),
1725
+ sampleRate: fMLS,
1726
+ downsample: this._calibrateSoundBurstDownsample,
1590
1727
  })
1591
1728
  .then(res => {
1592
1729
  this.incrementStatusBar();
@@ -1604,8 +1741,12 @@ class Combination extends AudioCalibrator {
1604
1741
  if (this.isCalibrating) return null;
1605
1742
  let filtered_mls_psd = await this.pyServerAPI
1606
1743
  .getMLSPSDWithRetry({
1607
- mls: this.componentConvolution,
1608
- sampleRate: this.sourceSamplingRate || 96000,
1744
+ mls: this.downsampleSignal(
1745
+ this.componentConvolution,
1746
+ this._calibrateSoundBurstDownsample
1747
+ ),
1748
+ sampleRate: fMLS,
1749
+ downsample: this._calibrateSoundBurstDownsample,
1609
1750
  })
1610
1751
  .then(res => {
1611
1752
  this.incrementStatusBar();
@@ -1621,8 +1762,12 @@ class Combination extends AudioCalibrator {
1621
1762
 
1622
1763
  let filtered_no_bandpass_mls_psd = await this.pyServerAPI
1623
1764
  .getMLSPSDWithRetry({
1624
- mls: this.componentConvolutionNoBandpass,
1625
- sampleRate: this.sourceSamplingRate || 96000,
1765
+ mls: this.downsampleSignal(
1766
+ this.componentConvolutionNoBandpass,
1767
+ this._calibrateSoundBurstDownsample
1768
+ ),
1769
+ sampleRate: fMLS,
1770
+ downsample: this._calibrateSoundBurstDownsample,
1626
1771
  })
1627
1772
  .then(res => {
1628
1773
  this.incrementStatusBar();
@@ -1711,11 +1856,13 @@ class Combination extends AudioCalibrator {
1711
1856
  } else {
1712
1857
  this.addTimeStamp('Compute PSD of filtered recording (system) and unfiltered recording');
1713
1858
  if (this.isCalibrating) return null;
1859
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
1714
1860
  let results = await this.pyServerAPI
1715
1861
  .getPSDWithRetry({
1716
- unconv_rec,
1717
- conv_rec,
1718
- sampleRate: this.sourceSamplingRate || 96000,
1862
+ unconv_rec: this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
1863
+ conv_rec: this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
1864
+ sampleRate: fMLS,
1865
+ downsample: this._calibrateSoundBurstDownsample,
1719
1866
  })
1720
1867
  .then(res => {
1721
1868
  let filtered_psd = res.y_conv
@@ -1751,9 +1898,10 @@ class Combination extends AudioCalibrator {
1751
1898
  if (this.isCalibrating) return null;
1752
1899
  let component_iir_psd = await this.pyServerAPI
1753
1900
  .getPSDWithRetry({
1754
- unconv_rec,
1755
- conv_rec,
1756
- sampleRate: this.sourceSamplingRate || 96000,
1901
+ unconv_rec: this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
1902
+ conv_rec: this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
1903
+ sampleRate: fMLS,
1904
+ downsample: this._calibrateSoundBurstDownsample,
1757
1905
  })
1758
1906
  .then(res => {
1759
1907
  this.incrementStatusBar();
@@ -1772,9 +1920,10 @@ class Combination extends AudioCalibrator {
1772
1920
  if (this.isCalibrating) return null;
1773
1921
  let system_iir_psd = await this.pyServerAPI
1774
1922
  .getPSDWithRetry({
1775
- unconv_rec,
1776
- conv_rec,
1777
- sampleRate: this.sourceSamplingRate || 96000,
1923
+ unconv_rec: this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
1924
+ conv_rec: this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
1925
+ sampleRate: fMLS,
1926
+ downsample: this._calibrateSoundBurstDownsample,
1778
1927
  })
1779
1928
  .then(res => {
1780
1929
  this.incrementStatusBar();
@@ -1792,8 +1941,12 @@ class Combination extends AudioCalibrator {
1792
1941
  if (this.isCalibrating) return null;
1793
1942
  let mls_psd = await this.pyServerAPI
1794
1943
  .getMLSPSDWithRetry({
1795
- mls: this.#mlsBufferView[this.icapture],
1796
- sampleRate: this.sourceSamplingRate || 96000,
1944
+ mls: this.downsampleSignal(
1945
+ this.#mlsBufferView[this.icapture],
1946
+ this._calibrateSoundBurstDownsample
1947
+ ),
1948
+ sampleRate: fMLS,
1949
+ downsample: this._calibrateSoundBurstDownsample,
1797
1950
  })
1798
1951
  .then(res => {
1799
1952
  this.incrementStatusBar();
@@ -1811,8 +1964,9 @@ class Combination extends AudioCalibrator {
1811
1964
  if (this.isCalibrating) return null;
1812
1965
  let filtered_mls_psd = await this.pyServerAPI
1813
1966
  .getMLSPSDWithRetry({
1814
- mls: this.systemConvolution,
1815
- sampleRate: this.sourceSamplingRate || 96000,
1967
+ mls: this.downsampleSignal(this.systemConvolution, this._calibrateSoundBurstDownsample),
1968
+ sampleRate: fMLS,
1969
+ downsample: this._calibrateSoundBurstDownsample,
1816
1970
  })
1817
1971
  .then(res => {
1818
1972
  this.incrementStatusBar();
@@ -1828,8 +1982,12 @@ class Combination extends AudioCalibrator {
1828
1982
 
1829
1983
  let filtered_no_bandpass_mls_psd = await this.pyServerAPI
1830
1984
  .getMLSPSDWithRetry({
1831
- mls: this.systemConvolutionNoBandpass,
1832
- sampleRate: this.sourceSamplingRate || 96000,
1985
+ mls: this.downsampleSignal(
1986
+ this.systemConvolutionNoBandpass,
1987
+ this._calibrateSoundBurstDownsample
1988
+ ),
1989
+ sampleRate: fMLS,
1990
+ downsample: this._calibrateSoundBurstDownsample,
1833
1991
  })
1834
1992
  .then(res => {
1835
1993
  this.incrementStatusBar();
@@ -1961,9 +2119,11 @@ class Combination extends AudioCalibrator {
1961
2119
  let desired_time = this.desired_time_per_mls;
1962
2120
  let checkRec = 'allhz';
1963
2121
 
1964
- console.log('MLS sequence should be of length: ' + this.sourceSamplingRate * desired_time);
2122
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
2123
+
2124
+ console.log('MLS sequence should be of length: ' + fMLS * desired_time);
1965
2125
 
1966
- length = this.sourceSamplingRate * desired_time;
2126
+ length = fMLS * desired_time;
1967
2127
  //get mls here
1968
2128
  // const calibrateSoundBurstDb = Math.pow(10, this._calibrateSoundBurstDb / 20);
1969
2129
 
@@ -1984,11 +2144,12 @@ class Combination extends AudioCalibrator {
1984
2144
  length,
1985
2145
  amplitude,
1986
2146
  calibrateSoundBurstMLSVersions: this.numCaptures,
2147
+ calibrateSoundBurstDownsample: this._calibrateSoundBurstDownsample,
1987
2148
  })
1988
2149
  .then(res => {
1989
2150
  console.log(res);
1990
- this.#mlsBufferView = res['mls'];
1991
- this.#mls = res['unscaledMLS'];
2151
+ this.#mlsBufferView = this.upsampleSignal(res['mls'], this._calibrateSoundBurstDownsample);
2152
+ this.#mls = this.upsampleSignal(res['unscaledMLS'], this._calibrateSoundBurstDownsample);
1992
2153
  })
1993
2154
  .catch(err => {
1994
2155
  // this.emit('InvertedImpulseResponse', {res: false});
@@ -2063,9 +2224,10 @@ class Combination extends AudioCalibrator {
2063
2224
  if (this.isCalibrating) return null;
2064
2225
  let component_iir_psd = await this.pyServerAPI
2065
2226
  .getPSDWithRetry({
2066
- unconv_rec,
2067
- conv_rec,
2068
- sampleRate: this.sourceSamplingRate || 96000,
2227
+ unconv_rec: this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
2228
+ conv_rec: this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
2229
+ sampleRate: fMLS,
2230
+ downsample: this._calibrateSoundBurstDownsample,
2069
2231
  })
2070
2232
  .then(res => {
2071
2233
  this.incrementStatusBar();
@@ -2083,9 +2245,10 @@ class Combination extends AudioCalibrator {
2083
2245
  if (this.isCalibrating) return null;
2084
2246
  let system_iir_psd = await this.pyServerAPI
2085
2247
  .getPSDWithRetry({
2086
- unconv_rec,
2087
- conv_rec,
2088
- sampleRate: this.sourceSamplingRate || 96000,
2248
+ unconv_rec: this.downsampleSignal(unconv_rec, this._calibrateSoundBurstDownsample),
2249
+ conv_rec: this.downsampleSignal(conv_rec, this._calibrateSoundBurstDownsample),
2250
+ sampleRate: fMLS,
2251
+ downsample: this._calibrateSoundBurstDownsample,
2089
2252
  })
2090
2253
  .then(res => {
2091
2254
  this.incrementStatusBar();
@@ -2337,7 +2500,7 @@ class Combination extends AudioCalibrator {
2337
2500
  });
2338
2501
  }
2339
2502
  const totalDuration = this.CALIBRATION_TONE_DURATION * 1.2;
2340
-
2503
+ console.log('this.calibrationNodes', this.calibrationNodes);
2341
2504
  this.calibrationNodes[0].start(0);
2342
2505
  this.calibrationNodes[0].stop(totalDuration);
2343
2506
  console.log(`Playing a buffer of ${this.CALIBRATION_TONE_DURATION} seconds of audio`);
@@ -2349,6 +2512,7 @@ class Combination extends AudioCalibrator {
2349
2512
  if (this.calibrationNodes.length > 0) {
2350
2513
  this.calibrationNodes[0].stop();
2351
2514
  }
2515
+ this.calibrationNodes = [];
2352
2516
  };
2353
2517
 
2354
2518
  #sendToServerForProcessing = async lCalib => {
@@ -2455,6 +2619,7 @@ class Combination extends AudioCalibrator {
2455
2619
  //this.emit('update', {message: `1000 Hz Calibration: Sound Level ${soundLevelToDiscard} dB`});
2456
2620
  this.emit('update', {message: this.status});
2457
2621
  this.startTime = new Date().getTime();
2622
+ this.calibrationNodes = [];
2458
2623
 
2459
2624
  do {
2460
2625
  console.log('while loop');
@@ -2779,15 +2944,18 @@ class Combination extends AudioCalibrator {
2779
2944
  // });
2780
2945
 
2781
2946
  const rec = recordings[recordings.length - 1];
2947
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
2948
+ const payload_downsampled = this.downsampleSignal(rec, this._calibrateSoundBurstDownsample);
2782
2949
 
2783
2950
  await this.pyServerAPI
2784
2951
  .allHzPowerCheck({
2785
- payload: rec,
2786
- sampleRate: this.sourceSamplingRate || 96000,
2952
+ payload: payload_downsampled,
2953
+ sampleRate: fMLS,
2787
2954
  binDesiredSec: this._calibrateSoundPowerBinDesiredSec,
2788
2955
  burstSec: this.desired_time_per_mls,
2789
2956
  repeats: this.numMLSPerCapture - this.num_mls_to_skip,
2790
2957
  warmUp: this.num_mls_to_skip,
2958
+ downsample: this._calibrateSoundBurstDownsample,
2791
2959
  })
2792
2960
  .then(result => {
2793
2961
  if (result) {
@@ -2901,8 +3069,10 @@ class Combination extends AudioCalibrator {
2901
3069
  language,
2902
3070
  loudspeakerModelName = '',
2903
3071
  phrases,
2904
- soundSubtitleId
3072
+ soundSubtitleId,
3073
+ calibrateSoundBurstDownsample = 1
2905
3074
  ) => {
3075
+ this._calibrateSoundBurstDownsample = calibrateSoundBurstDownsample;
2906
3076
  this._calibrateSoundBurstPreSec = _calibrateSoundBurstPreSec;
2907
3077
  this._calibrateSoundBurstRepeats = _calibrateSoundBurstRepeats;
2908
3078
  this._calibrateSoundBurstSec = _calibrateSoundBurstSec;
@@ -2919,8 +3089,9 @@ class Combination extends AudioCalibrator {
2919
3089
  this.calibrateSound1000HzPreSec = calibrateSound1000HzPreSec;
2920
3090
  this.calibrateSound1000HzSec = calibrateSound1000HzSec;
2921
3091
  this.calibrateSound1000HzPostSec = calibrateSound1000HzPostSec;
2922
- this.iirLength = Math.floor(_calibrateSoundIIRSec * this.sourceSamplingRate);
2923
- this.irLength = Math.floor(_calibrateSoundIRSec * this.sourceSamplingRate);
3092
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
3093
+ this.iirLength = Math.floor(_calibrateSoundIIRSec * fMLS);
3094
+ this.irLength = Math.floor(_calibrateSoundIRSec * fMLS);
2924
3095
  this.calibrateSoundIIRPhase = _calibrateSoundIIRPhase;
2925
3096
  this.num_mls_to_skip = Math.ceil(_calibrateSoundBurstPreSec / _calibrateSoundBurstSec);
2926
3097
  this._calibrateSoundBurstPostSec = _calibrateSoundBurstPostSec;
@@ -3171,6 +3342,8 @@ class Combination extends AudioCalibrator {
3171
3342
  console.log('Time Stamps');
3172
3343
  console.log(timeStampresult);
3173
3344
 
3345
+ this.stopCalibrationAudio();
3346
+
3174
3347
  resolve(total_results);
3175
3348
  });
3176
3349
  };