speaker-calibration 2.2.165 → 2.2.167

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.165",
3
+ "version": "2.2.167",
4
4
  "description": "Speaker calibration library for auditory testing",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
@@ -117,6 +117,7 @@ class Speaker extends AudioPeer {
117
117
  params.calibrateSoundSmoothOctaves,
118
118
  params.calibrateSoundPowerBinDesiredSec,
119
119
  params.calibrateSoundPowerDbSDToleratedDb,
120
+ params.calibrateSoundTaperSec,
120
121
  params.micManufacturer,
121
122
  params.micSerialNumber,
122
123
  params.micModelNumber,
@@ -545,6 +546,7 @@ class Speaker extends AudioPeer {
545
546
  params.calibrateSoundSmoothOctaves,
546
547
  params.calibrateSoundPowerBinDesiredSec,
547
548
  params.calibrateSoundPowerDbSDToleratedDb,
549
+ params.calibrateSoundTaperSec,
548
550
  params.micManufacturer,
549
551
  params.micSerialNumber,
550
552
  params.micModelNumber,
@@ -102,8 +102,6 @@ class Combination extends AudioCalibrator {
102
102
  /** @private */
103
103
  #audioContext;
104
104
 
105
- /** @private */
106
- TAPER_SECS = 5;
107
105
 
108
106
  /** @private */
109
107
  offsetGainNode;
@@ -233,6 +231,10 @@ class Combination extends AudioCalibrator {
233
231
 
234
232
  webAudioDeviceNames = {loudspeaker: '', microphone: '', loudspeakerText: '', microphoneText: ''};
235
233
 
234
+ waveforms = {
235
+ volume: {}
236
+ };
237
+
236
238
  recordingChecks = {
237
239
  volume: {},
238
240
  unfiltered: [],
@@ -2145,6 +2147,7 @@ class Combination extends AudioCalibrator {
2145
2147
  const audioContext = this.makeNewSourceAudioContext();
2146
2148
  const oscilator = audioContext.createOscillator();
2147
2149
  const gainNode = audioContext.createGain();
2150
+ console.log(gainValue);
2148
2151
  const taperGainNode = audioContext.createGain();
2149
2152
  const offsetGainNode = audioContext.createGain();
2150
2153
  const totalDuration = this.CALIBRATION_TONE_DURATION * 1.2;
@@ -2166,6 +2169,32 @@ class Combination extends AudioCalibrator {
2166
2169
  );
2167
2170
  offsetGainNode.connect(audioContext.destination);
2168
2171
 
2172
+ const gainValuesOverTime = [];
2173
+ const sampleRate = this.#CALIBRATION_TONE_FREQUENCY; // Number of samples per second
2174
+ const interval = 1 / sampleRate; // Time between samples
2175
+
2176
+ for (let t = 0; t <= totalDuration; t += interval) {
2177
+
2178
+ let gainValueAtTime = gainValue;
2179
+
2180
+ // Apply the onset curve
2181
+ if (t < this.TAPER_SECS) {
2182
+ const onsetIndex = Math.floor((t / this.TAPER_SECS) * onsetCurve.length);
2183
+ gainValueAtTime *= onsetCurve[onsetIndex];
2184
+ }
2185
+
2186
+ // Apply the offset curve
2187
+ if (t > totalDuration - this.TAPER_SECS) {
2188
+ const offsetTime = t - (totalDuration - this.TAPER_SECS);
2189
+ const offsetIndex = Math.floor((offsetTime / this.TAPER_SECS) * offsetCurve.length);
2190
+ gainValueAtTime *= offsetCurve[offsetIndex];
2191
+ }
2192
+
2193
+ gainValuesOverTime.push(gainValueAtTime);
2194
+ }
2195
+
2196
+ this.waveforms['volume'][this.inDB] = gainValuesOverTime;
2197
+
2169
2198
  this.addCalibrationNode(oscilator);
2170
2199
  };
2171
2200
 
@@ -2246,7 +2275,7 @@ class Combination extends AudioCalibrator {
2246
2275
  };
2247
2276
 
2248
2277
  startCalibrationVolume = async (stream, gainValues, lCalib, componentGainDBSPL) => {
2249
- console.log("JS used memory:", performance.memory.usedJSHeapSize/1024/1024, "mb");
2278
+
2250
2279
  if (this.isCalibrating) return null;
2251
2280
  const trialIterations = gainValues.length;
2252
2281
  this.status_denominator += trialIterations;
@@ -2649,6 +2678,7 @@ class Combination extends AudioCalibrator {
2649
2678
  _calibrateSoundSmoothOctaves = 0.33,
2650
2679
  _calibrateSoundPowerBinDesiredSec = 0.2,
2651
2680
  _calibrateSoundPowerDbSDToleratedDb = 1,
2681
+ _calibrateSoundTaperSec = 0.01,
2652
2682
  micManufacturer = '',
2653
2683
  micSerialNumber = '',
2654
2684
  micModelNumber = '',
@@ -2665,6 +2695,7 @@ class Combination extends AudioCalibrator {
2665
2695
  reminder,
2666
2696
  calibrateSoundLimit,
2667
2697
  ) => {
2698
+ this.TAPER_SECS = _calibrateSoundTaperSec;
2668
2699
  this.calibrateSoundLimit = calibrateSoundLimit;
2669
2700
  this._calibrateSoundBurstDb = _calibrateSoundBurstDb;
2670
2701
  this._calibrateSoundBurstFilteredExtraDb = _calibrateSoundBurstFilteredExtraDb;
@@ -2876,6 +2907,7 @@ class Combination extends AudioCalibrator {
2876
2907
  const timeStampresult = [...this.timeStamp].join('\n');
2877
2908
  total_results['timeStamps'] = timeStampresult;
2878
2909
  total_results['recordingChecks'] = this.recordingChecks;
2910
+ total_results['waveforms'] = this.waveforms;
2879
2911
  total_results['component']['phase'] = this.componentIRPhase;
2880
2912
  total_results['system']['phase'] = this.systemIRPhase;
2881
2913
  total_results['qualityMetrics'] = this.SDofFilteredRange;