speaker-calibration 2.2.255 → 2.2.257

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.
@@ -10,6 +10,7 @@ import {
10
10
  getCurrentTimeString,
11
11
  standardDeviation,
12
12
  interpolate,
13
+ reorderMLS
13
14
  } from '../../utils';
14
15
 
15
16
  import {volumePowerCheck, getPower} from '../../powerCheck';
@@ -363,12 +364,21 @@ class Combination extends AudioCalibrator {
363
364
  const reportWebAudioNames = `${this.webAudioDeviceNames.loudspeakerText}<br/> ${this.webAudioDeviceNames.microphoneText}`;
364
365
  soundSubtitle.innerHTML = reportWebAudioNames;
365
366
  }
367
+ const simulationEnabled =
368
+ this.calibrateSoundSimulateMicrophone !== null &&
369
+ this.calibrateSoundSimulateLoudspeaker !== null;
370
+
371
+ const simulateText = simulationEnabled
372
+ ? `
373
+ Simulating Loudspeaker: ${this.calibrateSoundSimulateLoudspeakerFileName}, Microphone: ${this.calibrateSoundSimulateMicrophoneFileName}
374
+ <br>`
375
+ : '';
366
376
 
367
377
  const samplingParamText = this.phrases.RC_SamplingHzBits[this.language]
368
378
  .replace('111', this.sourceSamplingRate)
369
379
  .replace('222', this.sinkSamplingRate)
370
380
  .replace('333', this.calibrateSoundSamplingDesiredBits);
371
- const reportParameters = `${samplingParamText} ↓${this._calibrateSoundBurstDownsample}:1`;
381
+ const reportParameters = `${simulateText}${samplingParamText} ↓${this._calibrateSoundBurstDownsample}:1`;
372
382
  if (this.flags) {
373
383
  flags = `<br> autoGainControl: ${this.flags.autoGainControl}, echoCancellation: ${this.flags.echoCancellation}, noiseSuppression: ${this.flags.noiseSuppression}`;
374
384
  }
@@ -760,7 +770,7 @@ class Combination extends AudioCalibrator {
760
770
  sampleRate: fMLS,
761
771
  binDesiredSec: this._calibrateSoundPowerBinDesiredSec,
762
772
  burstSec: this.desired_time_per_mls,
763
- repeats: this.numMLSPerCapture - this.num_mls_to_skip,
773
+ repeats: this._calibrateSoundBurstRepeats,
764
774
  warmUp: this._calibrateSoundBurstPreSec,
765
775
  downsample: this._calibrateSoundBurstDownsample,
766
776
  })
@@ -833,8 +843,9 @@ class Combination extends AudioCalibrator {
833
843
  }
834
844
  this.recordingChecks['unfiltered'].push(result);
835
845
  console.log('start calculate impulse response');
836
- const usedPeriodStart = this.num_mls_to_skip * this.sourceSamplingRate;
837
- const payload_skipped_warmUp = payload.slice(usedPeriodStart);
846
+ const usedPeriodStart = this.calibrateSoundBurstPreSec * this.sourceSamplingRate;
847
+ const usedPeriodEnd = (this.calibrateSoundBurstPreSec + this._calibrateSoundBurstRepeats * this.calibrateSoundBurstBurstSec) * this.sourceSamplingRate;
848
+ const payload_skipped_warmUp = payload.slice(usedPeriodStart, usedPeriodEnd);
838
849
  const payload_skipped_warmUp_downsampled = this.downsampleSignal(
839
850
  payload_skipped_warmUp,
840
851
  this._calibrateSoundBurstDownsample
@@ -850,7 +861,7 @@ class Combination extends AudioCalibrator {
850
861
  mls: mls,
851
862
  payload: payload_skipped_warmUp_downsampled,
852
863
  sampleRate: fMLS,
853
- numPeriods: (this.numMLSPerCapture - this.num_mls_to_skip) / factor,
864
+ numPeriods: (this._calibrateSoundBurstRepeats) / factor,
854
865
  downsample: this._calibrateSoundBurstDownsample,
855
866
  })
856
867
  .then(async res => {
@@ -863,7 +874,7 @@ class Combination extends AudioCalibrator {
863
874
  .getImpulseResponse({
864
875
  mls,
865
876
  sampleRate: fMLS,
866
- numPeriods: (this.numMLSPerCapture - this.num_mls_to_skip) / factor,
877
+ numPeriods: (this._calibrateSoundBurstRepeats) / factor,
867
878
  sig: payload_skipped_warmUp_downsampled,
868
879
  fs2: this.fs2,
869
880
  L_new_n: this.L_new_n,
@@ -978,7 +989,7 @@ class Combination extends AudioCalibrator {
978
989
  let number_of_bursts_to_skip = 0;
979
990
  let time_to_sleep = 0;
980
991
  if (this.mode === 'unfiltered') {
981
- time_to_sleep = (this.#mls[0].length / this.sourceSamplingRate) * number_of_bursts_to_skip;
992
+ time_to_sleep = this._calibrateSoundBurstPreSec;
982
993
  } else if (this.mode === 'filtered') {
983
994
  console.log(this.#currentConvolution.length);
984
995
  // time_to_sleep =
@@ -1050,15 +1061,16 @@ class Combination extends AudioCalibrator {
1050
1061
  * @example
1051
1062
  */
1052
1063
  #createCalibrationNodeFromBuffer = dataBuffer => {
1064
+ const mlsSignal = reorderMLS(dataBuffer, this.calibrateSound1000HzPreSec, this.sourceSamplingRate);
1053
1065
  console.log('length databuffer');
1054
- console.log(dataBuffer.length);
1066
+ console.log(mlsSignal.length);
1055
1067
  if (!this.sourceAudioContext) {
1056
1068
  this.makeNewSourceAudioContext();
1057
1069
  }
1058
1070
 
1059
1071
  const buffer = this.sourceAudioContext.createBuffer(
1060
1072
  1, // number of channels
1061
- dataBuffer.length,
1073
+ mlsSignal.length,
1062
1074
  this.sourceAudioContext.sampleRate // sample rate
1063
1075
  );
1064
1076
 
@@ -1066,8 +1078,8 @@ class Combination extends AudioCalibrator {
1066
1078
 
1067
1079
  // fill the buffer with our data
1068
1080
  try {
1069
- for (let i = 0; i < dataBuffer.length; i += 1) {
1070
- data[i] = dataBuffer[i];
1081
+ for (let i = 0; i < mlsSignal.length; i += 1) {
1082
+ data[i] = mlsSignal[i];
1071
1083
  }
1072
1084
  } catch (error) {
1073
1085
  console.error(error);
@@ -2354,9 +2366,13 @@ class Combination extends AudioCalibrator {
2354
2366
  for (var i = 0; i < this.numCaptures; i++) {
2355
2367
  this.icapture = i;
2356
2368
  if (this.isCalibrating) return null;
2357
-
2369
+ // From Denis July 20th, 2025:
2370
+ // Imagine playing the 10 s MLS, repeatedly, forever, and we record part of it. That piece should be
2371
+ // 2.5+10+10+1 second long. To synthesize this, the pre-interval should be the final 2.5 sec of MLS.
2372
+ // Followed by two whole MLS. Followed by the initial 1 sec of MLS. Again, all the pieces together
2373
+ // should be one contiguous piece cut out from an infinitely repeating MLS.
2358
2374
  // Get the MLS signal for this capture
2359
- const mlsSignal = this.#mlsBufferView[this.icapture];
2375
+ const mlsSignal = reorderMLS(this.#mlsBufferView[this.icapture], this.calibrateSound1000HzPreSec, this.sourceSamplingRate);
2360
2376
 
2361
2377
  // Run the simulation
2362
2378
  await this.simulatedMLSCalibration(
@@ -2376,6 +2392,8 @@ class Combination extends AudioCalibrator {
2376
2392
  }
2377
2393
  } else {
2378
2394
  // Use actual recording mode
2395
+
2396
+
2379
2397
  for (var i = 0; i < this.numCaptures; i++) {
2380
2398
  this.icapture = i;
2381
2399
  await this.calibrationSteps(
@@ -2419,281 +2437,278 @@ class Combination extends AudioCalibrator {
2419
2437
  iir_ir_and_plots = await this.bothSoundCheck(stream);
2420
2438
  if (this.isCalibrating) return null;
2421
2439
  }
2422
-
2423
- // } else {
2424
- // let unconv_rec = this.componentInvertedImpulseResponseNoBandpass;
2425
- // let conv_rec = this.componentInvertedImpulseResponse;
2426
- // if (this.isCalibrating) return null;
2427
- // let component_iir_psd = await this.pyServerAPI
2428
- // .getPSDWithRetry({
2429
- // unconv_rec: this.componentInvertedImpulseResponseNoBandpass,
2430
- // conv_rec: this.componentInvertedImpulseResponse,
2431
- // sampleRate: fMLS,
2432
- // downsample: this._calibrateSoundBurstDownsample,
2433
- // })
2434
- // .then(res => {
2435
- // this.incrementStatusBar();
2436
- // this.status = this.generateTemplate(
2437
- // `All Hz Calibration: done computing the PSD graphs...`.toString()
2438
- // ).toString();
2439
- // this.emit('update', {message: this.status});
2440
- // return res;
2441
- // })
2442
- // .catch(err => {
2443
- // console.error(err);
2444
- // });
2445
- // unconv_rec = this.systemInvertedImpulseResponseNoBandpass;
2446
- // conv_rec = this.systemInvertedImpulseResponse;
2447
- // if (this.isCalibrating) return null;
2448
- // let system_iir_psd = await this.pyServerAPI
2449
- // .getPSDWithRetry({
2450
- // unconv_rec: this.systemInvertedImpulseResponseNoBandpass,
2451
- // conv_rec: this.systemInvertedImpulseResponse,
2452
- // sampleRate: fMLS,
2453
- // downsample: this._calibrateSoundBurstDownsample,
2454
- // })
2455
- // .then(res => {
2456
- // this.incrementStatusBar();
2457
- // this.status = this.generateTemplate(
2458
- // `All Hz Calibration: done computing the PSD graphs...`.toString()
2459
- // ).toString();
2460
- // this.emit('update', {message: this.status});
2461
- // return res;
2462
- // })
2463
- // .catch(err => {
2464
- // console.error(err);
2465
- // });
2466
-
2467
- // let gainValue = this.getGainDBSPL();
2468
- // let return_unconv_rec = unconv_rec;
2469
- // let return_conv_rec = conv_rec;
2470
- // iir_ir_and_plots = {
2471
- // unfiltered_recording: return_unconv_rec,
2472
- // filtered_recording: return_conv_rec,
2473
- // system: {
2474
- // iir: this.systemInvertedImpulseResponse,
2475
- // iir_no_bandpass: this.systemInvertedImpulseResponseNoBandpass,
2476
- // ir: this.systemIR,
2477
- // iir_psd: {
2478
- // y: system_iir_psd['y_conv'],
2479
- // x: system_iir_psd['y_conv'],
2480
- // y_no_bandpass: system_iir_psd['y_unconv'],
2481
- // x_no_bandpass: system_iir_psd['x_unconv'],
2482
- // },
2483
- // filtered_recording: [],
2484
- // convolution: this.systemConvolution,
2485
- // convolutionNoBandpass: this.systemConvolutionNoBandpass,
2486
- // psd: {
2487
- // unconv: {
2488
- // x: [],
2489
- // y: [],
2490
- // },
2491
- // conv: {
2492
- // x: [],
2493
- // y: [],
2494
- // },
2495
- // },
2496
- // },
2497
- // component: {
2498
- // iir: this.componentInvertedImpulseResponse,
2499
- // iir_no_bandpass: this.componentInvertedImpulseResponseNoBandpass,
2500
- // ir: this.componentIR,
2501
- // ir_in_time_domain: this.componentIRInTimeDomain,
2502
- // iir_psd: {
2503
- // y: component_iir_psd['y_conv'],
2504
- // x: component_iir_psd['x_conv'],
2505
- // y_no_bandpass: component_iir_psd['y_unconv'],
2506
- // x_no_bandpass: component_iir_psd['x_unconv'],
2507
- // },
2508
- // convolution: this.componentConvolution,
2509
- // convolutionNoBandpass: this.componentConvolutionNoBandpass,
2510
- // psd: {
2511
- // unconv: {
2512
- // x: [],
2513
- // y: [],
2514
- // },
2515
- // conv: {
2516
- // x: [],
2517
- // y: [],
2518
- // },
2519
- // },
2520
- // gainDBSPL: gainValue,
2521
- // },
2522
- // mls: this.#mlsBufferView,
2523
- // autocorrelations: this.autocorrelations,
2524
- // impulseResponses: [],
2525
- // };
2526
- // if (this.isCalibrating) return null;
2527
- // await Promise.all(this.impulseResponses).then(res => {
2528
- // for (let i = 0; i < res.length; i++) {
2529
- // if (res[i] != undefined) {
2530
- // iir_ir_and_plots['impulseResponses'].push(res[i]);
2531
- // }
2532
- // }
2533
- // });
2534
2440
 
2535
- // if (this.#download) {
2536
- // saveToCSV(this.#mls, 'MLS.csv');
2537
- // saveToCSV(this.componentConvolution, 'python_component_convolution_mls_iir.csv');
2538
- // saveToCSV(this.systemConvolution, 'python_system_convolution_mls_iir.csv');
2539
- // saveToCSV(this.componentInvertedImpulseResponse, 'componentIIR.csv');
2540
- // saveToCSV(this.systemInvertedImpulseResponse, 'systemIIR.csv');
2541
- // for (let i = 0; i < this.autocorrelations.length; i++) {
2542
- // saveToCSV(this.autocorrelations[i], `autocorrelation_${i}`);
2543
- // }
2544
- // const computedIRagain = await Promise.all(this.impulseResponses).then(res => {
2545
- // for (let i = 0; i < res.length; i++) {
2546
- // if (res[i] != undefined) {
2547
- // saveToCSV(res[i], `IR_${i}`);
2548
- // }
2549
- // }
2550
- // });
2551
- // }
2552
- // }
2553
- } else {
2554
-
2555
- let unconv_rec = this.componentInvertedImpulseResponseNoBandpass;
2556
- let conv_rec = this.componentInvertedImpulseResponse;
2557
-
2558
-
2559
- let return_unconv_rec = unconv_rec;
2560
- let return_conv_rec = conv_rec;
2561
-
2562
- const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
2563
-
2564
-
2565
- this.addTimeStamp('Compute spectrum of component IIR and component IIR no band pass');
2566
- if (this.isCalibrating) return null;
2567
- let component_iir_psd = await this.pyServerAPI.getPSDWithRetry({
2568
- unconv_rec: this.componentInvertedImpulseResponseNoBandpass,
2569
- conv_rec: this.componentInvertedImpulseResponse,
2570
- sampleRate: fMLS,
2571
- downsample: this._calibrateSoundBurstDownsample,
2572
- })
2573
- .then(res => {
2574
- this.incrementStatusBar();
2575
- this.status = this.generateTemplate(`All Hz Calibration: done computing the PSD graphs...`).toString();
2576
- this.emit('update', { message: this.status });
2577
- return res;
2578
- })
2579
- .catch(err => {
2580
- console.error(err);
2581
- });
2582
-
2583
-
2584
- this.addTimeStamp('Compute spectrum of speaker+mic IIR and speaker+mic IIR no band pass');
2585
- if (this.isCalibrating) return null;
2586
- let system_iir_psd = await this.pyServerAPI.getPSDWithRetry({
2587
- unconv_rec: this.systemInvertedImpulseResponseNoBandpass,
2588
- conv_rec: this.systemInvertedImpulseResponse,
2589
- sampleRate: fMLS,
2590
- downsample: this._calibrateSoundBurstDownsample,
2591
- })
2592
- .then(res => {
2593
- this.incrementStatusBar();
2594
- this.status = this.generateTemplate(`All Hz Calibration: done computing the PSD graphs...`).toString();
2595
- this.emit('update', { message: this.status });
2596
- return res;
2597
- })
2598
- .catch(err => {
2599
- console.error(err);
2600
- });
2601
-
2602
-
2603
- let gainValue = this.getGainDBSPL();
2604
-
2605
-
2606
- iir_ir_and_plots = {
2607
- unfiltered_recording: return_unconv_rec,
2608
- filtered_recording: return_conv_rec,
2609
-
2610
- system: {
2611
- iir: this.systemInvertedImpulseResponse,
2612
- iir_no_bandpass: this.systemInvertedImpulseResponseNoBandpass,
2613
- ir: this.systemIR,
2614
- iir_psd: {
2615
- y: system_iir_psd['y_conv'],
2616
- x: system_iir_psd['x_conv'],
2617
- y_no_bandpass: system_iir_psd['y_unconv'],
2618
- x_no_bandpass: system_iir_psd['x_unconv'],
2619
- },
2620
-
2621
- filtered_mls_psd: {},
2622
- filtered_no_bandpass_mls_psd: {},
2623
- convolution: this.systemConvolution,
2624
- convolutionNoBandpass: this.systemConvolutionNoBandpass,
2625
- psd: {
2626
- unconv: { x: [], y: [] },
2627
- conv: { x: [], y: [] },
2628
- },
2629
- },
2630
-
2631
- component: {
2632
- iir: this.componentInvertedImpulseResponse,
2633
- iir_no_bandpass: this.componentInvertedImpulseResponseNoBandpass,
2634
- ir: this.componentIR,
2635
- ir_origin: this.componentIROrigin,
2636
- ir_in_time_domain: this.componentIRInTimeDomain,
2637
- iir_psd: {
2638
- y: component_iir_psd['y_conv'],
2639
- x: component_iir_psd['x_conv'],
2640
- y_no_bandpass: component_iir_psd['y_unconv'],
2641
- x_no_bandpass: component_iir_psd['x_unconv'],
2441
+ // } else {
2442
+ // let unconv_rec = this.componentInvertedImpulseResponseNoBandpass;
2443
+ // let conv_rec = this.componentInvertedImpulseResponse;
2444
+ // if (this.isCalibrating) return null;
2445
+ // let component_iir_psd = await this.pyServerAPI
2446
+ // .getPSDWithRetry({
2447
+ // unconv_rec: this.componentInvertedImpulseResponseNoBandpass,
2448
+ // conv_rec: this.componentInvertedImpulseResponse,
2449
+ // sampleRate: fMLS,
2450
+ // downsample: this._calibrateSoundBurstDownsample,
2451
+ // })
2452
+ // .then(res => {
2453
+ // this.incrementStatusBar();
2454
+ // this.status = this.generateTemplate(
2455
+ // `All Hz Calibration: done computing the PSD graphs...`.toString()
2456
+ // ).toString();
2457
+ // this.emit('update', {message: this.status});
2458
+ // return res;
2459
+ // })
2460
+ // .catch(err => {
2461
+ // console.error(err);
2462
+ // });
2463
+ // unconv_rec = this.systemInvertedImpulseResponseNoBandpass;
2464
+ // conv_rec = this.systemInvertedImpulseResponse;
2465
+ // if (this.isCalibrating) return null;
2466
+ // let system_iir_psd = await this.pyServerAPI
2467
+ // .getPSDWithRetry({
2468
+ // unconv_rec: this.systemInvertedImpulseResponseNoBandpass,
2469
+ // conv_rec: this.systemInvertedImpulseResponse,
2470
+ // sampleRate: fMLS,
2471
+ // downsample: this._calibrateSoundBurstDownsample,
2472
+ // })
2473
+ // .then(res => {
2474
+ // this.incrementStatusBar();
2475
+ // this.status = this.generateTemplate(
2476
+ // `All Hz Calibration: done computing the PSD graphs...`.toString()
2477
+ // ).toString();
2478
+ // this.emit('update', {message: this.status});
2479
+ // return res;
2480
+ // })
2481
+ // .catch(err => {
2482
+ // console.error(err);
2483
+ // });
2484
+
2485
+ // let gainValue = this.getGainDBSPL();
2486
+ // let return_unconv_rec = unconv_rec;
2487
+ // let return_conv_rec = conv_rec;
2488
+ // iir_ir_and_plots = {
2489
+ // unfiltered_recording: return_unconv_rec,
2490
+ // filtered_recording: return_conv_rec,
2491
+ // system: {
2492
+ // iir: this.systemInvertedImpulseResponse,
2493
+ // iir_no_bandpass: this.systemInvertedImpulseResponseNoBandpass,
2494
+ // ir: this.systemIR,
2495
+ // iir_psd: {
2496
+ // y: system_iir_psd['y_conv'],
2497
+ // x: system_iir_psd['y_conv'],
2498
+ // y_no_bandpass: system_iir_psd['y_unconv'],
2499
+ // x_no_bandpass: system_iir_psd['x_unconv'],
2500
+ // },
2501
+ // filtered_recording: [],
2502
+ // convolution: this.systemConvolution,
2503
+ // convolutionNoBandpass: this.systemConvolutionNoBandpass,
2504
+ // psd: {
2505
+ // unconv: {
2506
+ // x: [],
2507
+ // y: [],
2508
+ // },
2509
+ // conv: {
2510
+ // x: [],
2511
+ // y: [],
2512
+ // },
2513
+ // },
2514
+ // },
2515
+ // component: {
2516
+ // iir: this.componentInvertedImpulseResponse,
2517
+ // iir_no_bandpass: this.componentInvertedImpulseResponseNoBandpass,
2518
+ // ir: this.componentIR,
2519
+ // ir_in_time_domain: this.componentIRInTimeDomain,
2520
+ // iir_psd: {
2521
+ // y: component_iir_psd['y_conv'],
2522
+ // x: component_iir_psd['x_conv'],
2523
+ // y_no_bandpass: component_iir_psd['y_unconv'],
2524
+ // x_no_bandpass: component_iir_psd['x_unconv'],
2525
+ // },
2526
+ // convolution: this.componentConvolution,
2527
+ // convolutionNoBandpass: this.componentConvolutionNoBandpass,
2528
+ // psd: {
2529
+ // unconv: {
2530
+ // x: [],
2531
+ // y: [],
2532
+ // },
2533
+ // conv: {
2534
+ // x: [],
2535
+ // y: [],
2536
+ // },
2537
+ // },
2538
+ // gainDBSPL: gainValue,
2539
+ // },
2540
+ // mls: this.#mlsBufferView,
2541
+ // autocorrelations: this.autocorrelations,
2542
+ // impulseResponses: [],
2543
+ // };
2544
+ // if (this.isCalibrating) return null;
2545
+ // await Promise.all(this.impulseResponses).then(res => {
2546
+ // for (let i = 0; i < res.length; i++) {
2547
+ // if (res[i] != undefined) {
2548
+ // iir_ir_and_plots['impulseResponses'].push(res[i]);
2549
+ // }
2550
+ // }
2551
+ // });
2552
+
2553
+ // if (this.#download) {
2554
+ // saveToCSV(this.#mls, 'MLS.csv');
2555
+ // saveToCSV(this.componentConvolution, 'python_component_convolution_mls_iir.csv');
2556
+ // saveToCSV(this.systemConvolution, 'python_system_convolution_mls_iir.csv');
2557
+ // saveToCSV(this.componentInvertedImpulseResponse, 'componentIIR.csv');
2558
+ // saveToCSV(this.systemInvertedImpulseResponse, 'systemIIR.csv');
2559
+ // for (let i = 0; i < this.autocorrelations.length; i++) {
2560
+ // saveToCSV(this.autocorrelations[i], `autocorrelation_${i}`);
2561
+ // }
2562
+ // const computedIRagain = await Promise.all(this.impulseResponses).then(res => {
2563
+ // for (let i = 0; i < res.length; i++) {
2564
+ // if (res[i] != undefined) {
2565
+ // saveToCSV(res[i], `IR_${i}`);
2566
+ // }
2567
+ // }
2568
+ // });
2569
+ // }
2570
+ // }
2571
+ } else {
2572
+ let unconv_rec = this.componentInvertedImpulseResponseNoBandpass;
2573
+ let conv_rec = this.componentInvertedImpulseResponse;
2574
+
2575
+ let return_unconv_rec = unconv_rec;
2576
+ let return_conv_rec = conv_rec;
2577
+
2578
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
2579
+
2580
+ this.addTimeStamp('Compute spectrum of component IIR and component IIR no band pass');
2581
+ if (this.isCalibrating) return null;
2582
+ let component_iir_psd = await this.pyServerAPI
2583
+ .getPSDWithRetry({
2584
+ unconv_rec: this.componentInvertedImpulseResponseNoBandpass,
2585
+ conv_rec: this.componentInvertedImpulseResponse,
2586
+ sampleRate: fMLS,
2587
+ downsample: this._calibrateSoundBurstDownsample,
2588
+ })
2589
+ .then(res => {
2590
+ this.incrementStatusBar();
2591
+ this.status = this.generateTemplate(
2592
+ `All Hz Calibration: done computing the PSD graphs...`
2593
+ ).toString();
2594
+ this.emit('update', {message: this.status});
2595
+ return res;
2596
+ })
2597
+ .catch(err => {
2598
+ console.error(err);
2599
+ });
2600
+
2601
+ this.addTimeStamp('Compute spectrum of speaker+mic IIR and speaker+mic IIR no band pass');
2602
+ if (this.isCalibrating) return null;
2603
+ let system_iir_psd = await this.pyServerAPI
2604
+ .getPSDWithRetry({
2605
+ unconv_rec: this.systemInvertedImpulseResponseNoBandpass,
2606
+ conv_rec: this.systemInvertedImpulseResponse,
2607
+ sampleRate: fMLS,
2608
+ downsample: this._calibrateSoundBurstDownsample,
2609
+ })
2610
+ .then(res => {
2611
+ this.incrementStatusBar();
2612
+ this.status = this.generateTemplate(
2613
+ `All Hz Calibration: done computing the PSD graphs...`
2614
+ ).toString();
2615
+ this.emit('update', {message: this.status});
2616
+ return res;
2617
+ })
2618
+ .catch(err => {
2619
+ console.error(err);
2620
+ });
2621
+
2622
+ let gainValue = this.getGainDBSPL();
2623
+
2624
+ iir_ir_and_plots = {
2625
+ unfiltered_recording: return_unconv_rec,
2626
+ filtered_recording: return_conv_rec,
2627
+
2628
+ system: {
2629
+ iir: this.systemInvertedImpulseResponse,
2630
+ iir_no_bandpass: this.systemInvertedImpulseResponseNoBandpass,
2631
+ ir: this.systemIR,
2632
+ iir_psd: {
2633
+ y: system_iir_psd['y_conv'],
2634
+ x: system_iir_psd['x_conv'],
2635
+ y_no_bandpass: system_iir_psd['y_unconv'],
2636
+ x_no_bandpass: system_iir_psd['x_unconv'],
2637
+ },
2638
+
2639
+ filtered_mls_psd: {},
2640
+ filtered_no_bandpass_mls_psd: {},
2641
+ convolution: this.systemConvolution,
2642
+ convolutionNoBandpass: this.systemConvolutionNoBandpass,
2643
+ psd: {
2644
+ unconv: {x: [], y: []},
2645
+ conv: {x: [], y: []},
2646
+ },
2642
2647
  },
2643
-
2644
- filtered_mls_psd: {},
2645
- filtered_no_bandpass_mls_psd: {},
2646
- convolution: this.componentConvolution,
2647
- convolutionNoBandpass: this.componentConvolutionNoBandpass,
2648
- psd: {
2649
- unconv: { x: [], y: [] },
2650
- conv: { x: [], y: [] },
2648
+
2649
+ component: {
2650
+ iir: this.componentInvertedImpulseResponse,
2651
+ iir_no_bandpass: this.componentInvertedImpulseResponseNoBandpass,
2652
+ ir: this.componentIR,
2653
+ ir_origin: this.componentIROrigin,
2654
+ ir_in_time_domain: this.componentIRInTimeDomain,
2655
+ iir_psd: {
2656
+ y: component_iir_psd['y_conv'],
2657
+ x: component_iir_psd['x_conv'],
2658
+ y_no_bandpass: component_iir_psd['y_unconv'],
2659
+ x_no_bandpass: component_iir_psd['x_unconv'],
2660
+ },
2661
+
2662
+ filtered_mls_psd: {},
2663
+ filtered_no_bandpass_mls_psd: {},
2664
+ convolution: this.componentConvolution,
2665
+ convolutionNoBandpass: this.componentConvolutionNoBandpass,
2666
+ psd: {
2667
+ unconv: {x: [], y: []},
2668
+ conv: {x: [], y: []},
2669
+ },
2670
+ gainDBSPL: gainValue,
2651
2671
  },
2652
- gainDBSPL: gainValue,
2653
- },
2654
-
2655
- mls: this.#mlsBufferView,
2656
- autocorrelations: this.autocorrelations,
2657
- impulseResponses: [], // filled below
2658
- };
2659
-
2660
-
2661
- if (this.isCalibrating) return null;
2662
- await Promise.all(this.impulseResponses).then(resArray => {
2663
- for (let i = 0; i < resArray.length; i++) {
2664
- if (resArray[i] != undefined) {
2665
- iir_ir_and_plots.impulseResponses.push(resArray[i]);
2666
- }
2667
- }
2668
- });
2669
-
2670
-
2671
- if (this.#download) {
2672
- saveToCSV(this.#mls, 'MLS.csv');
2673
- saveToCSV(this.componentConvolution, 'python_component_convolution_mls_iir.csv');
2674
- saveToCSV(this.systemConvolution, 'python_system_convolution_mls_iir.csv');
2675
- saveToCSV(this.componentInvertedImpulseResponse, 'componentIIR.csv');
2676
- saveToCSV(this.systemInvertedImpulseResponse, 'systemIIR.csv');
2677
- for (let i = 0; i < this.autocorrelations.length; i++) {
2678
- saveToCSV(this.autocorrelations[i], `autocorrelation_${i}`);
2679
- }
2672
+
2673
+ mls: this.#mlsBufferView,
2674
+ autocorrelations: this.autocorrelations,
2675
+ impulseResponses: [], // filled below
2676
+ };
2677
+
2678
+ if (this.isCalibrating) return null;
2680
2679
  await Promise.all(this.impulseResponses).then(resArray => {
2681
2680
  for (let i = 0; i < resArray.length; i++) {
2682
2681
  if (resArray[i] != undefined) {
2683
- saveToCSV(resArray[i], `IR_${i}`);
2682
+ iir_ir_and_plots.impulseResponses.push(resArray[i]);
2684
2683
  }
2685
2684
  }
2686
2685
  });
2686
+
2687
+ if (this.#download) {
2688
+ saveToCSV(this.#mls, 'MLS.csv');
2689
+ saveToCSV(this.componentConvolution, 'python_component_convolution_mls_iir.csv');
2690
+ saveToCSV(this.systemConvolution, 'python_system_convolution_mls_iir.csv');
2691
+ saveToCSV(this.componentInvertedImpulseResponse, 'componentIIR.csv');
2692
+ saveToCSV(this.systemInvertedImpulseResponse, 'systemIIR.csv');
2693
+ for (let i = 0; i < this.autocorrelations.length; i++) {
2694
+ saveToCSV(this.autocorrelations[i], `autocorrelation_${i}`);
2695
+ }
2696
+ await Promise.all(this.impulseResponses).then(resArray => {
2697
+ for (let i = 0; i < resArray.length; i++) {
2698
+ if (resArray[i] != undefined) {
2699
+ saveToCSV(resArray[i], `IR_${i}`);
2700
+ }
2701
+ }
2702
+ });
2703
+ }
2687
2704
  }
2688
- }
2689
2705
  if (this.isCalibrating) return null;
2690
2706
  this.percent_complete = 100;
2691
2707
  this.status = this.generateTemplate(`All Hz Calibration: Finished`.toString()).toString();
2692
2708
  this.addTimeStamp('Done');
2693
2709
  this.emit('update', {message: this.status});
2694
2710
 
2695
-
2696
- console.log("irr_ir_and_plots for none: ", iir_ir_and_plots);
2711
+ console.log('irr_ir_and_plots for none: ', iir_ir_and_plots);
2697
2712
  return iir_ir_and_plots;
2698
2713
  };
2699
2714
 
@@ -3338,7 +3353,7 @@ class Combination extends AudioCalibrator {
3338
3353
  sampleRate: fMLS,
3339
3354
  binDesiredSec: this._calibrateSoundPowerBinDesiredSec,
3340
3355
  burstSec: this.desired_time_per_mls,
3341
- repeats: this.numMLSPerCapture - this.num_mls_to_skip,
3356
+ repeats: this._calibrateSoundBurstRepeats,
3342
3357
  warmUp: this._calibrateSoundBurstPreSec,
3343
3358
  downsample: this._calibrateSoundBurstDownsample,
3344
3359
  })
@@ -3475,6 +3490,8 @@ class Combination extends AudioCalibrator {
3475
3490
  calibrateSoundSimulateLoudspeakerFrequencies = null,
3476
3491
  calibrateSoundSimulateMicrophoneType = 'impulseResponse',
3477
3492
  calibrateSoundSimulateLoudspeakerType = 'impulseResponse',
3493
+ calibrateSoundSimulateMicrophoneFileName = null,
3494
+ calibrateSoundSimulateLoudspeakerFileName = null,
3478
3495
  isLoudspeakerCalibration = true
3479
3496
  ) => {
3480
3497
  this._calibrateSoundBurstDownsample = calibrateSoundBurstDownsample;
@@ -3498,6 +3515,8 @@ class Combination extends AudioCalibrator {
3498
3515
  // Set simulation impulse responses
3499
3516
  this.calibrateSoundSimulateMicrophone = calibrateSoundSimulateMicrophone;
3500
3517
  this.calibrateSoundSimulateLoudspeaker = calibrateSoundSimulateLoudspeaker;
3518
+ this.calibrateSoundSimulateMicrophoneFileName = calibrateSoundSimulateMicrophoneFileName;
3519
+ this.calibrateSoundSimulateLoudspeakerFileName = calibrateSoundSimulateLoudspeakerFileName;
3501
3520
 
3502
3521
  const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
3503
3522
  this.iirLength = Math.floor(_calibrateSoundIIRSec * fMLS);
@@ -3650,6 +3669,7 @@ class Combination extends AudioCalibrator {
3650
3669
  };
3651
3670
  this.componentGainDBSPL = frequencyResponse.gain_at_1000hz;
3652
3671
  lCalib = this.componentGainDBSPL;
3672
+ micInfo['gainDBSPL'] = lCalib;
3653
3673
  }
3654
3674
  } else {
3655
3675
  const impulseResponse = await this.pyServerAPI.getImpulseResponseFromFrequencyResponse({
@@ -3668,6 +3688,7 @@ class Combination extends AudioCalibrator {
3668
3688
  };
3669
3689
  this.componentGainDBSPL = impulseResponse.gain_at_1000hz;
3670
3690
  lCalib = this.componentGainDBSPL;
3691
+ micInfo['gainDBSPL'] = lCalib;
3671
3692
  }
3672
3693
  this.simulatedMicrophoneIR = {
3673
3694
  Freq: impulseResponse.frequencies,