speaker-calibration 2.1.0 → 2.1.1

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.0",
3
+ "version": "2.1.1",
4
4
  "description": "Speaker calibration library for auditory testing",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
@@ -112,6 +112,44 @@ class PythonServerAPI {
112
112
 
113
113
  return res.data[task];
114
114
  };
115
+
116
+ getVolumeCalibrationParameters = async ({inDBValues, outDBSPLValues}) => {
117
+ const task = 'volume-parameters';
118
+ let res = null;
119
+
120
+ const data = JSON.stringify({
121
+ task,
122
+ inDBValues,
123
+ outDBSPLValues,
124
+ });
125
+
126
+ await axios({
127
+ method: 'post',
128
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
129
+ url: `/task/${task}`,
130
+ headers: {
131
+ 'Content-Type': 'application/json',
132
+ },
133
+ data,
134
+ })
135
+ .then(response => {
136
+ res = response;
137
+ })
138
+ .catch(error => {
139
+ throw error;
140
+ });
141
+
142
+ // console.log(res.data[task]);
143
+ //below is an example of res.data[task]
144
+ //{
145
+ // R: 16.56981076554259,
146
+ // T: -47.79799120884434,
147
+ // W: 61.0485247483732,
148
+ // backgroundDBSPL: 43.88233142069752,
149
+ // gainDBSPL: -128.24742161208985
150
+ //}
151
+ return res.data[task];
152
+ };
115
153
  }
116
154
 
117
155
  export default PythonServerAPI;
@@ -1,5 +1,5 @@
1
1
  import AudioCalibrator from '../audioCalibrator';
2
-
2
+ import axios from 'axios';
3
3
  import {sleep} from '../../utils';
4
4
 
5
5
  /**
@@ -26,6 +26,7 @@ class Volume extends AudioCalibrator {
26
26
 
27
27
  /** @private */
28
28
  soundGainDBSPL = null;
29
+ outDBSPL = null;
29
30
 
30
31
  handleIncomingData = data => {
31
32
  console.log('Received data: ', data);
@@ -121,8 +122,8 @@ class Volume extends AudioCalibrator {
121
122
  payload: this.#getTruncatedSignal(),
122
123
  })
123
124
  .then(res => {
124
- if (this.soundGainDBSPL === null) {
125
- this.soundGainDBSPL = res;
125
+ if (this.outDBSPL === null) {
126
+ this.outDBSPL = res;
126
127
  }
127
128
  })
128
129
  .catch(err => {
@@ -133,10 +134,17 @@ class Volume extends AudioCalibrator {
133
134
  startCalibration = async (stream, gainValues) => {
134
135
  const trialIterations = gainValues.length;
135
136
  const soundGainDBSPLValues = [];
137
+ const inDBValues = [];
138
+ let inDB = 0;
139
+ const outDBSPLValues = [];
140
+
136
141
  // run the calibration at different gain values provided by the user
137
142
  for (let i = 0; i < trialIterations; i++) {
143
+ //convert gain to DB and add to inDB
144
+ inDB = Math.log10(gainValues[i]) * 20;
145
+ inDBValues.push(inDB);
146
+
138
147
  do {
139
- // console.log('Processing gain value: ', gainValues[i]);
140
148
  // eslint-disable-next-line no-await-in-loop
141
149
  await this.volumeCalibrationSteps(
142
150
  stream,
@@ -145,12 +153,21 @@ class Volume extends AudioCalibrator {
145
153
  this.#sendToServerForProcessing,
146
154
  gainValues[i]
147
155
  );
148
- } while (this.soundGainDBSPL === null);
149
- soundGainDBSPLValues.push(this.soundGainDBSPL);
150
- this.soundGainDBSPL = null;
156
+ } while (this.outDBSPL === null);
157
+ outDBSPLValues.push(this.outDBSPL);
158
+ this.outDBSPL = null;
151
159
  }
152
- // return this.soundGainDBSPL;
153
- return soundGainDBSPLValues;
160
+
161
+ // get the volume calibration parameters from the server
162
+ const parameters = await this.pyServerAPI
163
+ .getVolumeCalibrationParameters({inDBValues: inDBValues, outDBSPLValues: outDBSPLValues})
164
+ .then(res => {
165
+ // console.log(res);
166
+ return res;
167
+ });
168
+ // console.log('Parameters: ', parameters);
169
+ // return soundGainDBSPLValues;
170
+ return parameters;
154
171
  };
155
172
  }
156
173