speaker-calibration 2.2.254 → 2.2.256

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speaker-calibration",
3
- "version": "2.2.254",
3
+ "version": "2.2.256",
4
4
  "description": "Speaker calibration library for auditory testing",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
@@ -154,6 +154,8 @@ class Speaker extends AudioPeer {
154
154
  //set sampling rates
155
155
  speaker.ac.setSamplingRates(speaker.calibrateSoundHz);
156
156
  speaker.ac.setSampleSize(speaker.calibrateSoundSamplingDesiredBits);
157
+ speaker.#removeUIElems();
158
+ speaker.#showSpinner();
157
159
  speaker.result = await speaker.ac.startCalibration(
158
160
  null,
159
161
  params.gainValues,
@@ -213,6 +215,8 @@ class Speaker extends AudioPeer {
213
215
  params.calibrateSoundSimulateLoudspeakerFrequencies,
214
216
  params.calibrateSoundSimulateMicrophoneType,
215
217
  params.calibrateSoundSimulateLoudspeakerType,
218
+ params.calibrateSoundSimulateLoudspeakerFileName,
219
+ params.calibrateSoundSimulateMicrophoneFileName,
216
220
  params.isLoudspeakerCalibration
217
221
  );
218
222
  speaker.#removeUIElems();
@@ -355,6 +359,8 @@ class Speaker extends AudioPeer {
355
359
  params.calibrateSoundSimulateLoudspeakerFrequencies,
356
360
  params.calibrateSoundSimulateMicrophoneType,
357
361
  params.calibrateSoundSimulateLoudspeakerType,
362
+ params.calibrateSoundSimulateLoudspeakerFileName,
363
+ params.calibrateSoundSimulateMicrophoneFileName,
358
364
  params.isLoudspeakerCalibration
359
365
  );
360
366
  speaker.#removeUIElems();
@@ -951,6 +957,8 @@ class Speaker extends AudioPeer {
951
957
  params.calibrateSoundSimulateLoudspeakerFrequencies,
952
958
  params.calibrateSoundSimulateMicrophoneType,
953
959
  params.calibrateSoundSimulateLoudspeakerType,
960
+ params.calibrateSoundSimulateLoudspeakerFileName,
961
+ params.calibrateSoundSimulateMicrophoneFileName,
954
962
  params.isLoudspeakerCalibration
955
963
  );
956
964
  clearInterval(permissionCheckInterval);
@@ -363,12 +363,21 @@ class Combination extends AudioCalibrator {
363
363
  const reportWebAudioNames = `${this.webAudioDeviceNames.loudspeakerText}<br/> ${this.webAudioDeviceNames.microphoneText}`;
364
364
  soundSubtitle.innerHTML = reportWebAudioNames;
365
365
  }
366
+ const simulationEnabled =
367
+ this.calibrateSoundSimulateMicrophone !== null &&
368
+ this.calibrateSoundSimulateLoudspeaker !== null;
369
+
370
+ const simulateText = simulationEnabled
371
+ ? `
372
+ Simulating Loudspeaker: ${this.calibrateSoundSimulateLoudspeakerFileName}, Microphone: ${this.calibrateSoundSimulateMicrophoneFileName}
373
+ <br>`
374
+ : '';
366
375
 
367
376
  const samplingParamText = this.phrases.RC_SamplingHzBits[this.language]
368
377
  .replace('111', this.sourceSamplingRate)
369
378
  .replace('222', this.sinkSamplingRate)
370
379
  .replace('333', this.calibrateSoundSamplingDesiredBits);
371
- const reportParameters = `${samplingParamText} ↓${this._calibrateSoundBurstDownsample}:1`;
380
+ const reportParameters = `${simulateText}${samplingParamText} ↓${this._calibrateSoundBurstDownsample}:1`;
372
381
  if (this.flags) {
373
382
  flags = `<br> autoGainControl: ${this.flags.autoGainControl}, echoCancellation: ${this.flags.echoCancellation}, noiseSuppression: ${this.flags.noiseSuppression}`;
374
383
  }
@@ -423,7 +432,7 @@ class Combination extends AudioCalibrator {
423
432
  * @example
424
433
  */
425
434
  sendSystemImpulseResponsesToServerForProcessing = async () => {
426
- this.addTimeStamp('Compute system IIR');
435
+ this.addTimeStamp('Compute speaker+mic IIR');
427
436
  const computedIRs = await Promise.all(this.impulseResponses);
428
437
  const filteredComputedIRs = computedIRs.filter(element => {
429
438
  return element != undefined;
@@ -689,7 +698,7 @@ class Combination extends AudioCalibrator {
689
698
  const background_rec = background_rec_whole.slice(startIndex);
690
699
  console.log('Sending background recording to server for processing');
691
700
  let backgroundSec = this._calibrateSoundBackgroundSecs + 0.5;
692
- this.addTimeStamp(`Record ${backgroundSec.toFixed(1)} s of background.`);
701
+ this.addTimeStamp(`Recorded ${backgroundSec.toFixed(1)} s of background.`);
693
702
  const fBackground = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
694
703
  const background_rec_downsampled = this.downsampleSignal(
695
704
  background_rec,
@@ -1451,7 +1460,7 @@ class Combination extends AudioCalibrator {
1451
1460
  });
1452
1461
  unconv_rec = this.systemInvertedImpulseResponseNoBandpass;
1453
1462
  conv_rec = this.systemInvertedImpulseResponse;
1454
- this.addTimeStamp('Compute spectrum of system IIR and system IIR no band pass');
1463
+ this.addTimeStamp('Compute spectrum of speaker+mic IIR and speaker+mic IIR no band pass');
1455
1464
  if (this.isCalibrating) return null;
1456
1465
  let system_iir_psd = await this.pyServerAPI
1457
1466
  .getPSDWithRetry({
@@ -2086,7 +2095,7 @@ class Combination extends AudioCalibrator {
2086
2095
  });
2087
2096
  unconv_rec = this.systemInvertedImpulseResponseNoBandpass;
2088
2097
  conv_rec = this.systemInvertedImpulseResponse;
2089
- this.addTimeStamp('Compute spectrum of system IIR and system IIR no band pass');
2098
+ this.addTimeStamp('Compute spectrum of speaker+mic IIR and speaker+mic no band pass');
2090
2099
  if (this.isCalibrating) return null;
2091
2100
  let system_iir_psd = await this.pyServerAPI
2092
2101
  .getPSDWithRetry({
@@ -2130,7 +2139,7 @@ class Combination extends AudioCalibrator {
2130
2139
  console.error(err);
2131
2140
  });
2132
2141
 
2133
- this.addTimeStamp('Compute spectrum of filtered MLS (system)');
2142
+ this.addTimeStamp('Compute spectrum of filtered MLS (speaker+mic)');
2134
2143
  if (this.isCalibrating) return null;
2135
2144
  let filtered_mls_psd = await this.pyServerAPI
2136
2145
  .getMLSPSDWithRetry({
@@ -2419,9 +2428,147 @@ class Combination extends AudioCalibrator {
2419
2428
  iir_ir_and_plots = await this.bothSoundCheck(stream);
2420
2429
  if (this.isCalibrating) return null;
2421
2430
  }
2431
+
2432
+ // } else {
2433
+ // let unconv_rec = this.componentInvertedImpulseResponseNoBandpass;
2434
+ // let conv_rec = this.componentInvertedImpulseResponse;
2435
+ // if (this.isCalibrating) return null;
2436
+ // let component_iir_psd = await this.pyServerAPI
2437
+ // .getPSDWithRetry({
2438
+ // unconv_rec: this.componentInvertedImpulseResponseNoBandpass,
2439
+ // conv_rec: this.componentInvertedImpulseResponse,
2440
+ // sampleRate: fMLS,
2441
+ // downsample: this._calibrateSoundBurstDownsample,
2442
+ // })
2443
+ // .then(res => {
2444
+ // this.incrementStatusBar();
2445
+ // this.status = this.generateTemplate(
2446
+ // `All Hz Calibration: done computing the PSD graphs...`.toString()
2447
+ // ).toString();
2448
+ // this.emit('update', {message: this.status});
2449
+ // return res;
2450
+ // })
2451
+ // .catch(err => {
2452
+ // console.error(err);
2453
+ // });
2454
+ // unconv_rec = this.systemInvertedImpulseResponseNoBandpass;
2455
+ // conv_rec = this.systemInvertedImpulseResponse;
2456
+ // if (this.isCalibrating) return null;
2457
+ // let system_iir_psd = await this.pyServerAPI
2458
+ // .getPSDWithRetry({
2459
+ // unconv_rec: this.systemInvertedImpulseResponseNoBandpass,
2460
+ // conv_rec: this.systemInvertedImpulseResponse,
2461
+ // sampleRate: fMLS,
2462
+ // downsample: this._calibrateSoundBurstDownsample,
2463
+ // })
2464
+ // .then(res => {
2465
+ // this.incrementStatusBar();
2466
+ // this.status = this.generateTemplate(
2467
+ // `All Hz Calibration: done computing the PSD graphs...`.toString()
2468
+ // ).toString();
2469
+ // this.emit('update', {message: this.status});
2470
+ // return res;
2471
+ // })
2472
+ // .catch(err => {
2473
+ // console.error(err);
2474
+ // });
2475
+
2476
+ // let gainValue = this.getGainDBSPL();
2477
+ // let return_unconv_rec = unconv_rec;
2478
+ // let return_conv_rec = conv_rec;
2479
+ // iir_ir_and_plots = {
2480
+ // unfiltered_recording: return_unconv_rec,
2481
+ // filtered_recording: return_conv_rec,
2482
+ // system: {
2483
+ // iir: this.systemInvertedImpulseResponse,
2484
+ // iir_no_bandpass: this.systemInvertedImpulseResponseNoBandpass,
2485
+ // ir: this.systemIR,
2486
+ // iir_psd: {
2487
+ // y: system_iir_psd['y_conv'],
2488
+ // x: system_iir_psd['y_conv'],
2489
+ // y_no_bandpass: system_iir_psd['y_unconv'],
2490
+ // x_no_bandpass: system_iir_psd['x_unconv'],
2491
+ // },
2492
+ // filtered_recording: [],
2493
+ // convolution: this.systemConvolution,
2494
+ // convolutionNoBandpass: this.systemConvolutionNoBandpass,
2495
+ // psd: {
2496
+ // unconv: {
2497
+ // x: [],
2498
+ // y: [],
2499
+ // },
2500
+ // conv: {
2501
+ // x: [],
2502
+ // y: [],
2503
+ // },
2504
+ // },
2505
+ // },
2506
+ // component: {
2507
+ // iir: this.componentInvertedImpulseResponse,
2508
+ // iir_no_bandpass: this.componentInvertedImpulseResponseNoBandpass,
2509
+ // ir: this.componentIR,
2510
+ // ir_in_time_domain: this.componentIRInTimeDomain,
2511
+ // iir_psd: {
2512
+ // y: component_iir_psd['y_conv'],
2513
+ // x: component_iir_psd['x_conv'],
2514
+ // y_no_bandpass: component_iir_psd['y_unconv'],
2515
+ // x_no_bandpass: component_iir_psd['x_unconv'],
2516
+ // },
2517
+ // convolution: this.componentConvolution,
2518
+ // convolutionNoBandpass: this.componentConvolutionNoBandpass,
2519
+ // psd: {
2520
+ // unconv: {
2521
+ // x: [],
2522
+ // y: [],
2523
+ // },
2524
+ // conv: {
2525
+ // x: [],
2526
+ // y: [],
2527
+ // },
2528
+ // },
2529
+ // gainDBSPL: gainValue,
2530
+ // },
2531
+ // mls: this.#mlsBufferView,
2532
+ // autocorrelations: this.autocorrelations,
2533
+ // impulseResponses: [],
2534
+ // };
2535
+ // if (this.isCalibrating) return null;
2536
+ // await Promise.all(this.impulseResponses).then(res => {
2537
+ // for (let i = 0; i < res.length; i++) {
2538
+ // if (res[i] != undefined) {
2539
+ // iir_ir_and_plots['impulseResponses'].push(res[i]);
2540
+ // }
2541
+ // }
2542
+ // });
2543
+
2544
+ // if (this.#download) {
2545
+ // saveToCSV(this.#mls, 'MLS.csv');
2546
+ // saveToCSV(this.componentConvolution, 'python_component_convolution_mls_iir.csv');
2547
+ // saveToCSV(this.systemConvolution, 'python_system_convolution_mls_iir.csv');
2548
+ // saveToCSV(this.componentInvertedImpulseResponse, 'componentIIR.csv');
2549
+ // saveToCSV(this.systemInvertedImpulseResponse, 'systemIIR.csv');
2550
+ // for (let i = 0; i < this.autocorrelations.length; i++) {
2551
+ // saveToCSV(this.autocorrelations[i], `autocorrelation_${i}`);
2552
+ // }
2553
+ // const computedIRagain = await Promise.all(this.impulseResponses).then(res => {
2554
+ // for (let i = 0; i < res.length; i++) {
2555
+ // if (res[i] != undefined) {
2556
+ // saveToCSV(res[i], `IR_${i}`);
2557
+ // }
2558
+ // }
2559
+ // });
2560
+ // }
2561
+ // }
2422
2562
  } else {
2423
2563
  let unconv_rec = this.componentInvertedImpulseResponseNoBandpass;
2424
2564
  let conv_rec = this.componentInvertedImpulseResponse;
2565
+
2566
+ let return_unconv_rec = unconv_rec;
2567
+ let return_conv_rec = conv_rec;
2568
+
2569
+ const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
2570
+
2571
+ this.addTimeStamp('Compute spectrum of component IIR and component IIR no band pass');
2425
2572
  if (this.isCalibrating) return null;
2426
2573
  let component_iir_psd = await this.pyServerAPI
2427
2574
  .getPSDWithRetry({
@@ -2433,7 +2580,7 @@ class Combination extends AudioCalibrator {
2433
2580
  .then(res => {
2434
2581
  this.incrementStatusBar();
2435
2582
  this.status = this.generateTemplate(
2436
- `All Hz Calibration: done computing the PSD graphs...`.toString()
2583
+ `All Hz Calibration: done computing the PSD graphs...`
2437
2584
  ).toString();
2438
2585
  this.emit('update', {message: this.status});
2439
2586
  return res;
@@ -2441,8 +2588,8 @@ class Combination extends AudioCalibrator {
2441
2588
  .catch(err => {
2442
2589
  console.error(err);
2443
2590
  });
2444
- unconv_rec = this.systemInvertedImpulseResponseNoBandpass;
2445
- conv_rec = this.systemInvertedImpulseResponse;
2591
+
2592
+ this.addTimeStamp('Compute spectrum of speaker+mic IIR and speaker+mic IIR no band pass');
2446
2593
  if (this.isCalibrating) return null;
2447
2594
  let system_iir_psd = await this.pyServerAPI
2448
2595
  .getPSDWithRetry({
@@ -2454,7 +2601,7 @@ class Combination extends AudioCalibrator {
2454
2601
  .then(res => {
2455
2602
  this.incrementStatusBar();
2456
2603
  this.status = this.generateTemplate(
2457
- `All Hz Calibration: done computing the PSD graphs...`.toString()
2604
+ `All Hz Calibration: done computing the PSD graphs...`
2458
2605
  ).toString();
2459
2606
  this.emit('update', {message: this.status});
2460
2607
  return res;
@@ -2464,37 +2611,37 @@ class Combination extends AudioCalibrator {
2464
2611
  });
2465
2612
 
2466
2613
  let gainValue = this.getGainDBSPL();
2614
+
2467
2615
  iir_ir_and_plots = {
2468
2616
  unfiltered_recording: return_unconv_rec,
2469
2617
  filtered_recording: return_conv_rec,
2618
+
2470
2619
  system: {
2471
2620
  iir: this.systemInvertedImpulseResponse,
2472
2621
  iir_no_bandpass: this.systemInvertedImpulseResponseNoBandpass,
2473
2622
  ir: this.systemIR,
2474
2623
  iir_psd: {
2475
2624
  y: system_iir_psd['y_conv'],
2476
- x: system_iir_psd['y_conv'],
2625
+ x: system_iir_psd['x_conv'],
2477
2626
  y_no_bandpass: system_iir_psd['y_unconv'],
2478
2627
  x_no_bandpass: system_iir_psd['x_unconv'],
2479
2628
  },
2480
- filtered_recording: [],
2629
+
2630
+ filtered_mls_psd: {},
2631
+ filtered_no_bandpass_mls_psd: {},
2481
2632
  convolution: this.systemConvolution,
2482
2633
  convolutionNoBandpass: this.systemConvolutionNoBandpass,
2483
2634
  psd: {
2484
- unconv: {
2485
- x: [],
2486
- y: [],
2487
- },
2488
- conv: {
2489
- x: [],
2490
- y: [],
2491
- },
2635
+ unconv: {x: [], y: []},
2636
+ conv: {x: [], y: []},
2492
2637
  },
2493
2638
  },
2639
+
2494
2640
  component: {
2495
2641
  iir: this.componentInvertedImpulseResponse,
2496
2642
  iir_no_bandpass: this.componentInvertedImpulseResponseNoBandpass,
2497
2643
  ir: this.componentIR,
2644
+ ir_origin: this.componentIROrigin,
2498
2645
  ir_in_time_domain: this.componentIRInTimeDomain,
2499
2646
  iir_psd: {
2500
2647
  y: component_iir_psd['y_conv'],
@@ -2502,29 +2649,28 @@ class Combination extends AudioCalibrator {
2502
2649
  y_no_bandpass: component_iir_psd['y_unconv'],
2503
2650
  x_no_bandpass: component_iir_psd['x_unconv'],
2504
2651
  },
2652
+
2653
+ filtered_mls_psd: {},
2654
+ filtered_no_bandpass_mls_psd: {},
2505
2655
  convolution: this.componentConvolution,
2506
2656
  convolutionNoBandpass: this.componentConvolutionNoBandpass,
2507
2657
  psd: {
2508
- unconv: {
2509
- x: [],
2510
- y: [],
2511
- },
2512
- conv: {
2513
- x: [],
2514
- y: [],
2515
- },
2658
+ unconv: {x: [], y: []},
2659
+ conv: {x: [], y: []},
2516
2660
  },
2517
2661
  gainDBSPL: gainValue,
2518
2662
  },
2663
+
2519
2664
  mls: this.#mlsBufferView,
2520
2665
  autocorrelations: this.autocorrelations,
2521
- impulseResponses: [],
2666
+ impulseResponses: [], // filled below
2522
2667
  };
2668
+
2523
2669
  if (this.isCalibrating) return null;
2524
- await Promise.all(this.impulseResponses).then(res => {
2525
- for (let i = 0; i < res.length; i++) {
2526
- if (res[i] != undefined) {
2527
- iir_ir_and_plots['impulseResponses'].push(res[i]);
2670
+ await Promise.all(this.impulseResponses).then(resArray => {
2671
+ for (let i = 0; i < resArray.length; i++) {
2672
+ if (resArray[i] != undefined) {
2673
+ iir_ir_and_plots.impulseResponses.push(resArray[i]);
2528
2674
  }
2529
2675
  }
2530
2676
  });
@@ -2538,10 +2684,10 @@ class Combination extends AudioCalibrator {
2538
2684
  for (let i = 0; i < this.autocorrelations.length; i++) {
2539
2685
  saveToCSV(this.autocorrelations[i], `autocorrelation_${i}`);
2540
2686
  }
2541
- const computedIRagain = await Promise.all(this.impulseResponses).then(res => {
2542
- for (let i = 0; i < res.length; i++) {
2543
- if (res[i] != undefined) {
2544
- saveToCSV(res[i], `IR_${i}`);
2687
+ await Promise.all(this.impulseResponses).then(resArray => {
2688
+ for (let i = 0; i < resArray.length; i++) {
2689
+ if (resArray[i] != undefined) {
2690
+ saveToCSV(resArray[i], `IR_${i}`);
2545
2691
  }
2546
2692
  }
2547
2693
  });
@@ -2553,9 +2699,7 @@ class Combination extends AudioCalibrator {
2553
2699
  this.addTimeStamp('Done');
2554
2700
  this.emit('update', {message: this.status});
2555
2701
 
2556
- //here after calibration we have the component calibration (either loudspeaker or microphone) in the same form as the componentIR
2557
- //that was used to calibrate
2558
- // saveToJSON(iir_ir_and_plots);
2702
+ console.log('irr_ir_and_plots for none: ', iir_ir_and_plots);
2559
2703
  return iir_ir_and_plots;
2560
2704
  };
2561
2705
 
@@ -2940,7 +3084,7 @@ class Combination extends AudioCalibrator {
2940
3084
 
2941
3085
  if (this.isCalibrating) return null;
2942
3086
  // get the volume calibration parameters from the server
2943
- this.addTimeStamp('Compute sound calibration parameters');
3087
+ this.addTimeStamp('Compute 1000 Hz calibration parameters');
2944
3088
 
2945
3089
  console.log('inDBValues', inDBValues);
2946
3090
  console.log('outDBSPL1000Values', outDBSPL1000Values);
@@ -3337,6 +3481,8 @@ class Combination extends AudioCalibrator {
3337
3481
  calibrateSoundSimulateLoudspeakerFrequencies = null,
3338
3482
  calibrateSoundSimulateMicrophoneType = 'impulseResponse',
3339
3483
  calibrateSoundSimulateLoudspeakerType = 'impulseResponse',
3484
+ calibrateSoundSimulateMicrophoneFileName = null,
3485
+ calibrateSoundSimulateLoudspeakerFileName = null,
3340
3486
  isLoudspeakerCalibration = true
3341
3487
  ) => {
3342
3488
  this._calibrateSoundBurstDownsample = calibrateSoundBurstDownsample;
@@ -3360,6 +3506,8 @@ class Combination extends AudioCalibrator {
3360
3506
  // Set simulation impulse responses
3361
3507
  this.calibrateSoundSimulateMicrophone = calibrateSoundSimulateMicrophone;
3362
3508
  this.calibrateSoundSimulateLoudspeaker = calibrateSoundSimulateLoudspeaker;
3509
+ this.calibrateSoundSimulateMicrophoneFileName = calibrateSoundSimulateMicrophoneFileName;
3510
+ this.calibrateSoundSimulateLoudspeakerFileName = calibrateSoundSimulateLoudspeakerFileName;
3363
3511
 
3364
3512
  const fMLS = this.sourceSamplingRate / this._calibrateSoundBurstDownsample;
3365
3513
  this.iirLength = Math.floor(_calibrateSoundIIRSec * fMLS);
@@ -3512,6 +3660,7 @@ class Combination extends AudioCalibrator {
3512
3660
  };
3513
3661
  this.componentGainDBSPL = frequencyResponse.gain_at_1000hz;
3514
3662
  lCalib = this.componentGainDBSPL;
3663
+ micInfo['gainDBSPL'] = lCalib;
3515
3664
  }
3516
3665
  } else {
3517
3666
  const impulseResponse = await this.pyServerAPI.getImpulseResponseFromFrequencyResponse({
@@ -3530,6 +3679,7 @@ class Combination extends AudioCalibrator {
3530
3679
  };
3531
3680
  this.componentGainDBSPL = impulseResponse.gain_at_1000hz;
3532
3681
  lCalib = this.componentGainDBSPL;
3682
+ micInfo['gainDBSPL'] = lCalib;
3533
3683
  }
3534
3684
  this.simulatedMicrophoneIR = {
3535
3685
  Freq: impulseResponse.frequencies,