speaker-calibration 2.1.3 → 2.1.4

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.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "Speaker calibration library for auditory testing",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
@@ -44,7 +44,7 @@ class AudioPeer {
44
44
  this.targetElement = param.targetElementId;
45
45
 
46
46
  this.siteUrl = param.siteUrl;
47
-
47
+ this.debug = false;
48
48
  // Store for all incoming data
49
49
  this.dataStore = [];
50
50
 
@@ -23,10 +23,10 @@ class Speaker extends AudioPeer {
23
23
  */
24
24
  constructor(params, CalibratorInstance) {
25
25
  super(params);
26
-
27
26
  this.siteUrl += '/listener?';
28
27
  this.ac = CalibratorInstance;
29
28
  this.result = null;
29
+ this.debug = params?.debug ?? false;
30
30
 
31
31
  /* Set up callbacks that handle any events related to our peer object. */
32
32
  this.peer.on('open', this.#onPeerOpen);
@@ -71,7 +71,11 @@ class Speaker extends AudioPeer {
71
71
  await sleep(1);
72
72
  }
73
73
  // resolve when we have a result
74
- speaker.result = await speaker.ac.startCalibration(stream, params.gainValues);
74
+ speaker.result = await speaker.ac.startCalibration(
75
+ stream,
76
+ params.gainValues,
77
+ params.ICalib
78
+ );
75
79
  speaker.#removeUIElems();
76
80
  resolve(speaker.result);
77
81
  });
@@ -158,7 +162,7 @@ class Speaker extends AudioPeer {
158
162
  // If specified HTML Id is available, show QR code there
159
163
  if (document.getElementById(this.targetElement)) {
160
164
  if (document.getElementById(this.targetElement)) {
161
- if (process.env.NODE_ENV === 'development') {
165
+ if (this.debug) {
162
166
  const linkTag = document.createElement('a');
163
167
  linkTag.setAttribute('href', uri);
164
168
  linkTag.innerHTML = "Click here to connect to the speaker's microphone";
@@ -82,7 +82,7 @@ class PythonServerAPI {
82
82
  return res.data[task];
83
83
  };
84
84
 
85
- getVolumeCalibration = async ({payload, sampleRate}) => {
85
+ getVolumeCalibration = async ({payload, sampleRate, lCalib}) => {
86
86
  const task = 'volume';
87
87
  let res = null;
88
88
 
@@ -92,6 +92,7 @@ class PythonServerAPI {
92
92
  task,
93
93
  payload,
94
94
  'sample-rate': sampleRate,
95
+ lCalib,
95
96
  });
96
97
 
97
98
  await axios({
@@ -113,7 +114,7 @@ class PythonServerAPI {
113
114
  return res.data[task];
114
115
  };
115
116
 
116
- getVolumeCalibrationParameters = async ({inDBValues, outDBSPLValues}) => {
117
+ getVolumeCalibrationParameters = async ({inDBValues, outDBSPLValues, lCalib}) => {
117
118
  const task = 'volume-parameters';
118
119
  let res = null;
119
120
 
@@ -121,6 +122,7 @@ class PythonServerAPI {
121
122
  task,
122
123
  inDBValues,
123
124
  outDBSPLValues,
125
+ lCalib,
124
126
  });
125
127
 
126
128
  await axios({
@@ -143,6 +145,7 @@ class PythonServerAPI {
143
145
  //below is an example of res.data[task]
144
146
  //{
145
147
  // R: 16.56981076554259,
148
+ // RMSError: 1.9289162528535229
146
149
  // T: -47.79799120884434,
147
150
  // W: 61.0485247483732,
148
151
  // backgroundDBSPL: 43.88233142069752,
@@ -128,7 +128,8 @@ class AudioCalibrator extends AudioRecorder {
128
128
  playCalibrationAudio,
129
129
  beforeRecord = () => {},
130
130
  afterRecord = () => {},
131
- gainValue
131
+ gainValue,
132
+ lCalib = 104.92978421490648
132
133
  ) => {
133
134
  this.numCalibratingRoundsCompleted = 0;
134
135
 
@@ -149,7 +150,7 @@ class AudioCalibrator extends AudioRecorder {
149
150
  await this.stopRecording();
150
151
 
151
152
  // after recording
152
- await afterRecord();
153
+ await afterRecord(lCalib);
153
154
 
154
155
  this.calibrationNodes = [];
155
156
 
@@ -25,14 +25,9 @@ class Volume extends AudioCalibrator {
25
25
  #CALIBRATION_TONE_DURATION = 5; // seconds
26
26
 
27
27
  /** @private */
28
- soundGainDBSPL = null;
29
28
  outDBSPL = null;
30
- power = null;
31
- power1000 = null;
32
- RMS = null;
33
29
  THD = null;
34
30
  outDBSPL1000 = null;
35
- soundGainDBSPL1000 = null;
36
31
 
37
32
  handleIncomingData = data => {
38
33
  console.log('Received data: ', data);
@@ -120,23 +115,19 @@ class Volume extends AudioCalibrator {
120
115
  await sleep(totalDuration);
121
116
  };
122
117
 
123
- #sendToServerForProcessing = () => {
118
+ #sendToServerForProcessing = (lCalib = 104.92978421490648) => {
124
119
  console.log('Sending data to server');
125
120
  this.pyServerAPI
126
121
  .getVolumeCalibration({
127
122
  sampleRate: this.sourceSamplingRate,
128
123
  payload: this.#getTruncatedSignal(),
124
+ lCalib: lCalib,
129
125
  })
130
126
  .then(res => {
131
127
  if (this.outDBSPL === null) {
132
128
  this.outDBSPL = res['outDbSPL'];
133
- this.soundGainDBSPL = res['soundGainDbSPL'];
134
129
  this.outDBSPL1000 = res['outDbSPL1000'];
135
- this.power = res['power']
136
- this.power1000 = res['power1000']
137
- this.THD = res['thd']
138
- this.RMS = res['rms']
139
- this.soundGainDBSPL1000 = res['soundGainDbSPL1000'];
130
+ this.THD = res['thd'];
140
131
  }
141
132
  })
142
133
  .catch(err => {
@@ -144,19 +135,13 @@ class Volume extends AudioCalibrator {
144
135
  });
145
136
  };
146
137
 
147
- startCalibration = async (stream, gainValues) => {
138
+ startCalibration = async (stream, gainValues, lCalib = 104.92978421490648) => {
148
139
  const trialIterations = gainValues.length;
149
- const soundGainDBSPLValues = [];
150
- const soundGainDBSPL1000Values = [];
151
- const power1000Values = [];
152
- const powerValues = [];
153
- const rmsValues = [];
154
140
  const thdValues = [];
155
141
  const inDBValues = [];
156
142
  let inDB = 0;
157
143
  const outDBSPLValues = [];
158
144
  const outDBSPL1000Values = [];
159
-
160
145
  // run the calibration at different gain values provided by the user
161
146
  for (let i = 0; i < trialIterations; i++) {
162
147
  //convert gain to DB and add to inDB
@@ -170,31 +155,26 @@ class Volume extends AudioCalibrator {
170
155
  this.#playCalibrationAudio,
171
156
  this.#createCalibrationToneWithGainValue,
172
157
  this.#sendToServerForProcessing,
173
- gainValues[i]
158
+ gainValues[i],
159
+ lCalib //todo make this a class parameter
174
160
  );
175
161
  } while (this.outDBSPL === null);
176
162
  outDBSPL1000Values.push(this.outDBSPL1000);
177
- power1000Values.push(this.power1000);
178
- powerValues.push(this.power);
179
- rmsValues.push(this.RMS);
180
163
  thdValues.push(this.THD);
181
164
  outDBSPLValues.push(this.outDBSPL);
182
- soundGainDBSPLValues.push(this.soundGainDBSPL);
183
- soundGainDBSPL1000Values.push(this.soundGainDBSPL1000);
184
165
 
185
166
  this.outDBSPL = null;
186
- this.soundGainDBSPL = null;
187
- this.power1000 = null;
188
- this.power = null;
189
167
  this.outDBSPL1000 = null;
190
- this.RMS = null;
191
168
  this.THD = null;
192
- this.soundGainDBSPL1000=null;
193
169
  }
194
170
 
195
171
  // get the volume calibration parameters from the server
196
172
  const parameters = await this.pyServerAPI
197
- .getVolumeCalibrationParameters({inDBValues: inDBValues, outDBSPLValues: outDBSPL1000Values})
173
+ .getVolumeCalibrationParameters({
174
+ inDBValues: inDBValues,
175
+ outDBSPLValues: outDBSPL1000Values,
176
+ lCalib: lCalib,
177
+ })
198
178
  .then(res => {
199
179
  return res;
200
180
  });
@@ -202,13 +182,8 @@ class Volume extends AudioCalibrator {
202
182
  parameters: parameters,
203
183
  inDBValues: inDBValues,
204
184
  outDBSPLValues: outDBSPLValues,
205
- soundGainDBSPLValues: soundGainDBSPLValues,
206
- powerValues: powerValues,
207
- power1000Values: power1000Values,
208
185
  outDBSPL1000Values: outDBSPL1000Values,
209
- rmsValues: rmsValues,
210
186
  thdValues: thdValues,
211
- soundGainDBSPL1000Values: soundGainDBSPL1000Values
212
187
  };
213
188
 
214
189
  return result;