speaker-calibration 2.2.10 → 2.2.11
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
|
@@ -21,6 +21,10 @@ class Listener extends AudioPeer {
|
|
|
21
21
|
this.receiverPeerId = null;
|
|
22
22
|
|
|
23
23
|
const urlParameters = this.parseURLSearchParams();
|
|
24
|
+
this.calibrateSoundHz =
|
|
25
|
+
urlParameters.calibrateSoundHz !== null && urlParameters.calibrateSoundHz !== undefined
|
|
26
|
+
? urlParameters.calibrateSoundHz
|
|
27
|
+
: 48000;
|
|
24
28
|
this.speakerPeerId = urlParameters.speakerPeerId;
|
|
25
29
|
|
|
26
30
|
this.peer.on('open', this.onPeerOpen);
|
|
@@ -99,7 +103,7 @@ class Listener extends AudioPeer {
|
|
|
99
103
|
this.displayUpdate('Created connection');
|
|
100
104
|
this.conn.on('open', async () => {
|
|
101
105
|
this.displayUpdate('Listener - conn open');
|
|
102
|
-
|
|
106
|
+
await this.getDeviceInfo();
|
|
103
107
|
// this.sendSamplingRate();
|
|
104
108
|
await this.openAudioStream();
|
|
105
109
|
});
|
|
@@ -134,27 +138,35 @@ class Listener extends AudioPeer {
|
|
|
134
138
|
});
|
|
135
139
|
};
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
getDeviceInfo = async () => {
|
|
142
|
+
try {
|
|
143
|
+
const deviceInfo = {};
|
|
144
|
+
fod.complete(function (data) {
|
|
145
|
+
deviceInfo['IsMobile'] = data.device['ismobile'];
|
|
146
|
+
deviceInfo['HardwareName'] = data.device['hardwarename'];
|
|
147
|
+
deviceInfo['HardwareFamily'] = data.device['hardwarefamily'];
|
|
148
|
+
deviceInfo['HardwareModel'] = data.device['hardwaremodel'];
|
|
149
|
+
deviceInfo['OEM'] = data.device['oem'];
|
|
150
|
+
deviceInfo['HardwareModelVariants'] = data.device['hardwaremodelvariants'];
|
|
151
|
+
deviceInfo['DeviceId'] = data.device['deviceid'];
|
|
152
|
+
deviceInfo['PlatformName'] = data.device['platformname'];
|
|
153
|
+
deviceInfo['PlatformVersion'] = data.device['platformversion'];
|
|
154
|
+
deviceInfo['DeviceType'] = data.device['devicetype'];
|
|
155
|
+
});
|
|
156
|
+
this.conn.send({
|
|
157
|
+
name: 'deviceInfo',
|
|
158
|
+
payload: deviceInfo,
|
|
159
|
+
});
|
|
160
|
+
return deviceInfo;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error('Error fetching or executing script:', error.message);
|
|
163
|
+
return null;
|
|
144
164
|
}
|
|
145
|
-
|
|
146
|
-
this.conn.send({
|
|
147
|
-
name: 'deviceType',
|
|
148
|
-
payload: deviceType,
|
|
149
|
-
});
|
|
150
|
-
this.conn.send({
|
|
151
|
-
name: 'deviceName',
|
|
152
|
-
payload: deviceName,
|
|
153
|
-
});
|
|
154
165
|
};
|
|
155
166
|
|
|
156
167
|
applyHQTrackConstraints = async stream => {
|
|
157
168
|
// Contraint the incoming audio to the sampling rate we want
|
|
169
|
+
|
|
158
170
|
const track = stream.getAudioTracks()[0];
|
|
159
171
|
const capabilities = track.getCapabilities();
|
|
160
172
|
|
|
@@ -169,7 +181,7 @@ class Listener extends AudioPeer {
|
|
|
169
181
|
}
|
|
170
182
|
|
|
171
183
|
if (capabilities.sampleRate) {
|
|
172
|
-
constraints.sampleRate =
|
|
184
|
+
constraints.sampleRate = this.calibrateSoundHz;
|
|
173
185
|
}
|
|
174
186
|
|
|
175
187
|
if (capabilities.sampleSize) {
|
|
@@ -211,7 +223,7 @@ class Listener extends AudioPeer {
|
|
|
211
223
|
// ? {echoCancellation: {exact: false}}
|
|
212
224
|
// : {}),
|
|
213
225
|
...(availableConstraints.sampleRate && availableConstraints.sampleRate == true
|
|
214
|
-
? {sampleRate: {ideal:
|
|
226
|
+
? {sampleRate: {ideal: this.calibrateSoundHz}}
|
|
215
227
|
: {}),
|
|
216
228
|
...(availableConstraints.sampleSize && availableConstraints.sampleSize == true
|
|
217
229
|
? {sampleSize: {ideal: 24}}
|
|
@@ -219,9 +231,9 @@ class Listener extends AudioPeer {
|
|
|
219
231
|
...(availableConstraints.channelCount && availableConstraints.channelCount == true
|
|
220
232
|
? {channelCount: {exact: 1}}
|
|
221
233
|
: {}),
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
234
|
+
echoCancellation: false,
|
|
235
|
+
noiseSuppression: false,
|
|
236
|
+
autoGainControl: false,
|
|
225
237
|
};
|
|
226
238
|
|
|
227
239
|
console.log(contraints);
|
|
@@ -32,6 +32,7 @@ class Speaker extends AudioPeer {
|
|
|
32
32
|
this.result = null;
|
|
33
33
|
this.debug = params?.debug ?? false;
|
|
34
34
|
this.isSmartPhone = params?.isSmartPhone ?? false;
|
|
35
|
+
this.calibrateSoundHz = params?.calibrateSoundHz ?? 48000;
|
|
35
36
|
this.instructionDisplayId = params?.instructionDisplayId ?? '';
|
|
36
37
|
this.titleDisplayId = params?.titleDisplayId ?? '';
|
|
37
38
|
this.timeToCalibrate = params?.timeToCalibrate ?? 10;
|
|
@@ -99,7 +100,11 @@ class Speaker extends AudioPeer {
|
|
|
99
100
|
params.calibrateSoundBurstRepeats,
|
|
100
101
|
params.calibrateSoundBurstSec,
|
|
101
102
|
params.calibrateSoundBurstsWarmup,
|
|
102
|
-
params.calibrateSoundHz
|
|
103
|
+
params.calibrateSoundHz,
|
|
104
|
+
params.micManufacturer,
|
|
105
|
+
params.micSerialNumber,
|
|
106
|
+
params.micModelNumber,
|
|
107
|
+
params.micModelName
|
|
103
108
|
);
|
|
104
109
|
speaker.#removeUIElems();
|
|
105
110
|
resolve(speaker.result);
|
|
@@ -173,6 +178,7 @@ class Speaker extends AudioPeer {
|
|
|
173
178
|
const queryStringParameters = {
|
|
174
179
|
speakerPeerId: this.peer.id,
|
|
175
180
|
isSmartPhone: this.isSmartPhone,
|
|
181
|
+
calibrateSoundHz: this.calibrateSoundHz,
|
|
176
182
|
};
|
|
177
183
|
const queryString = this.queryStringFromObject(queryStringParameters);
|
|
178
184
|
const uri = this.siteUrl + queryString;
|
|
@@ -379,6 +385,8 @@ class Speaker extends AudioPeer {
|
|
|
379
385
|
case 'deviceName':
|
|
380
386
|
this.ac.setDeviceName(data.payload);
|
|
381
387
|
break;
|
|
388
|
+
case 'deviceInfo':
|
|
389
|
+
this.ac.setDeviceInfo(data.payload);
|
|
382
390
|
case UnsupportedDeviceError.name:
|
|
383
391
|
case MissingSpeakerIdError.name:
|
|
384
392
|
throw data.payload;
|
|
@@ -141,6 +141,8 @@ class Combination extends AudioCalibrator {
|
|
|
141
141
|
|
|
142
142
|
deviceName = null;
|
|
143
143
|
|
|
144
|
+
deviceInfo = null;
|
|
145
|
+
|
|
144
146
|
desired_time_per_mls = 0;
|
|
145
147
|
|
|
146
148
|
num_mls_to_skip = 0;
|
|
@@ -176,6 +178,10 @@ class Combination extends AudioCalibrator {
|
|
|
176
178
|
this.deviceName = deviceName;
|
|
177
179
|
};
|
|
178
180
|
|
|
181
|
+
setDeviceInfo = deviceInfo => {
|
|
182
|
+
this.deviceInfo = deviceInfo;
|
|
183
|
+
};
|
|
184
|
+
|
|
179
185
|
/** .
|
|
180
186
|
* .
|
|
181
187
|
* .
|
|
@@ -347,16 +353,16 @@ class Combination extends AudioCalibrator {
|
|
|
347
353
|
message: this.status,
|
|
348
354
|
});
|
|
349
355
|
let time_to_wait = 0;
|
|
350
|
-
if (this.mode === 'unfiltered'){
|
|
356
|
+
if (this.mode === 'unfiltered') {
|
|
351
357
|
time_to_wait = (this.#mls.length / this.sourceSamplingRate) * this.numMLSPerCapture;
|
|
352
|
-
}else if (this.mode === 'filtered'){
|
|
358
|
+
} else if (this.mode === 'filtered') {
|
|
353
359
|
time_to_wait =
|
|
354
|
-
|
|
355
|
-
}else{
|
|
356
|
-
throw new Error(
|
|
360
|
+
(this.#currentConvolution.length / this.sourceSamplingRate) * this.numMLSPerCapture;
|
|
361
|
+
} else {
|
|
362
|
+
throw new Error('Mode broke in awaitDesiredMLSLength');
|
|
357
363
|
}
|
|
358
|
-
|
|
359
|
-
await sleep(time_to_wait*1.1);
|
|
364
|
+
|
|
365
|
+
await sleep(time_to_wait * 1.1);
|
|
360
366
|
};
|
|
361
367
|
|
|
362
368
|
/** .
|
|
@@ -377,12 +383,12 @@ class Combination extends AudioCalibrator {
|
|
|
377
383
|
});
|
|
378
384
|
let number_of_bursts_to_skip = this.num_mls_to_skip;
|
|
379
385
|
let time_to_sleep = 0;
|
|
380
|
-
if (this.mode === 'unfiltered'){
|
|
386
|
+
if (this.mode === 'unfiltered') {
|
|
381
387
|
time_to_sleep = this.#mls.length / this.sourceSamplingRate;
|
|
382
|
-
}else if (this.mode === 'filtered'){
|
|
388
|
+
} else if (this.mode === 'filtered') {
|
|
383
389
|
time_to_sleep = this.#currentConvolution.length / this.sourceSamplingRate;
|
|
384
|
-
}else{
|
|
385
|
-
throw new Error(
|
|
390
|
+
} else {
|
|
391
|
+
throw new Error('Mode broke in awaitSignalOnset');
|
|
386
392
|
}
|
|
387
393
|
await sleep(time_to_sleep);
|
|
388
394
|
};
|
|
@@ -455,10 +461,10 @@ class Combination extends AudioCalibrator {
|
|
|
455
461
|
#createCalibrationNodeFromBuffer = dataBuffer => {
|
|
456
462
|
console.log('databuffer');
|
|
457
463
|
console.log(dataBuffer);
|
|
458
|
-
if (!this.sourceAudioContext){
|
|
464
|
+
if (!this.sourceAudioContext) {
|
|
459
465
|
this.makeNewSourceAudioContext();
|
|
460
466
|
}
|
|
461
|
-
|
|
467
|
+
|
|
462
468
|
const buffer = this.sourceAudioContext.createBuffer(
|
|
463
469
|
1, // number of channels
|
|
464
470
|
dataBuffer.length,
|
|
@@ -474,10 +480,8 @@ class Combination extends AudioCalibrator {
|
|
|
474
480
|
} catch (error) {
|
|
475
481
|
console.error(error);
|
|
476
482
|
}
|
|
477
|
-
|
|
483
|
+
|
|
478
484
|
this.sourceNode = this.sourceAudioContext.createBufferSource();
|
|
479
|
-
|
|
480
|
-
|
|
481
485
|
|
|
482
486
|
this.sourceNode.buffer = buffer;
|
|
483
487
|
this.sourceNode.loop = true;
|
|
@@ -568,23 +572,23 @@ class Combination extends AudioCalibrator {
|
|
|
568
572
|
* @example
|
|
569
573
|
*/
|
|
570
574
|
#playCalibrationAudio = () => {
|
|
571
|
-
if (this.mode === 'unfiltered'){
|
|
575
|
+
if (this.mode === 'unfiltered') {
|
|
572
576
|
this.calibrationNodes[0].start(0);
|
|
573
577
|
this.#mls = this.calibrationNodes[0].buffer.getChannelData(0);
|
|
574
578
|
console.log('play calibration audio ' + this.stepNum);
|
|
575
579
|
this.status =
|
|
576
|
-
|
|
577
|
-
|
|
580
|
+
`All Hz Calibration: playing the calibration tone...`.toString() +
|
|
581
|
+
this.generateTemplate().toString();
|
|
578
582
|
this.emit('update', {message: this.status});
|
|
579
|
-
} else if (this.mode === 'filtered'){
|
|
583
|
+
} else if (this.mode === 'filtered') {
|
|
580
584
|
this.calibrationNodes[0].start(0);
|
|
581
585
|
console.log('play convolved audio ' + this.stepNum);
|
|
582
586
|
this.status =
|
|
583
587
|
`All Hz Calibration: playing the convolved calibration tone...`.toString() +
|
|
584
|
-
|
|
588
|
+
this.generateTemplate().toString();
|
|
585
589
|
this.emit('update', {message: this.status});
|
|
586
|
-
} else{
|
|
587
|
-
throw new Error(
|
|
590
|
+
} else {
|
|
591
|
+
throw new Error('Mode is incorrect');
|
|
588
592
|
}
|
|
589
593
|
this.stepNum += 1;
|
|
590
594
|
console.log('sink sampling rate');
|
|
@@ -593,7 +597,6 @@ class Combination extends AudioCalibrator {
|
|
|
593
597
|
console.log(this.sourceSamplingRate);
|
|
594
598
|
};
|
|
595
599
|
|
|
596
|
-
|
|
597
600
|
/** .
|
|
598
601
|
* .
|
|
599
602
|
* .
|
|
@@ -602,7 +605,6 @@ class Combination extends AudioCalibrator {
|
|
|
602
605
|
* @example
|
|
603
606
|
*/
|
|
604
607
|
#stopCalibrationAudio = () => {
|
|
605
|
-
|
|
606
608
|
this.calibrationNodes[0].stop(0);
|
|
607
609
|
this.calibrationNodes = [];
|
|
608
610
|
this.sourceNode.disconnect();
|
|
@@ -628,7 +630,7 @@ class Combination extends AudioCalibrator {
|
|
|
628
630
|
this.#awaitDesiredMLSLength, // during record
|
|
629
631
|
this.#afterMLSwIIRRecord, // after record
|
|
630
632
|
this.mode
|
|
631
|
-
)
|
|
633
|
+
);
|
|
632
634
|
};
|
|
633
635
|
|
|
634
636
|
/**
|
|
@@ -641,11 +643,9 @@ class Combination extends AudioCalibrator {
|
|
|
641
643
|
* @example
|
|
642
644
|
*/
|
|
643
645
|
startCalibrationImpulseResponse = async stream => {
|
|
644
|
-
|
|
645
646
|
let desired_time = this.desired_time_per_mls;
|
|
646
647
|
|
|
647
|
-
console.log(
|
|
648
|
-
|
|
648
|
+
console.log('MLS sequence should be of length: ' + this.sourceSamplingRate * desired_time);
|
|
649
649
|
|
|
650
650
|
length = this.sourceSamplingRate * desired_time;
|
|
651
651
|
//get mls here
|
|
@@ -669,8 +669,7 @@ class Combination extends AudioCalibrator {
|
|
|
669
669
|
this.#afterMLSRecord, // after record
|
|
670
670
|
this.mode
|
|
671
671
|
),
|
|
672
|
-
|
|
673
|
-
this.#stopCalibrationAudio();
|
|
672
|
+
this.#stopCalibrationAudio();
|
|
674
673
|
|
|
675
674
|
// at this stage we've captured all the required signals,
|
|
676
675
|
// and have received IRs for each one
|
|
@@ -684,7 +683,7 @@ class Combination extends AudioCalibrator {
|
|
|
684
683
|
if (this._calibrateSoundCheck != 'none') {
|
|
685
684
|
if (this._calibrateSoundCheck != 'system') {
|
|
686
685
|
this.#currentConvolution = this.componentConvolution;
|
|
687
|
-
}else{
|
|
686
|
+
} else {
|
|
688
687
|
this.#currentConvolution = this.systemConvolution;
|
|
689
688
|
}
|
|
690
689
|
await this.playMLSwithIIR(stream, this.invertedImpulseResponse);
|
|
@@ -841,8 +840,8 @@ class Combination extends AudioCalibrator {
|
|
|
841
840
|
j += 1 / this.sourceSamplingRate;
|
|
842
841
|
}
|
|
843
842
|
return curve;
|
|
844
|
-
|
|
845
|
-
|
|
843
|
+
};
|
|
844
|
+
|
|
846
845
|
#getTruncatedSignal = (left = 3.5, right = 4.5) => {
|
|
847
846
|
const start = Math.floor(left * this.sourceSamplingRate);
|
|
848
847
|
const end = Math.floor(right * this.sourceSamplingRate);
|
|
@@ -1141,7 +1140,11 @@ class Combination extends AudioCalibrator {
|
|
|
1141
1140
|
_calibrateSoundBurstRepeats = 4,
|
|
1142
1141
|
_calibrateSoundBurstSec = 1,
|
|
1143
1142
|
_calibrateSoundBurstsWarmup = 1,
|
|
1144
|
-
_calibrateSoundHz = 48000
|
|
1143
|
+
_calibrateSoundHz = 48000,
|
|
1144
|
+
micManufacturer = '',
|
|
1145
|
+
micSerialNumber = '',
|
|
1146
|
+
micModelNumber = '',
|
|
1147
|
+
micModelName = ''
|
|
1145
1148
|
) => {
|
|
1146
1149
|
this.numMLSPerCapture = _calibrateSoundBurstRepeats;
|
|
1147
1150
|
this.desired_time_per_mls = _calibrateSoundBurstSec;
|