Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview This is the low-level class that generates ChromeVox's | 6 * @fileoverview This is the low-level class that generates ChromeVox's |
| 7 * earcons. It's designed to be self-contained and not depend on the | 7 * earcons. It's designed to be self-contained and not depend on the |
| 8 * rest of the code. | 8 * rest of the code. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 */ | 150 */ |
| 151 EarconEngine.HALF_STEP = Math.pow(2.0, 1.0 / 12.0); | 151 EarconEngine.HALF_STEP = Math.pow(2.0, 1.0 / 12.0); |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * @type {string} The base url for earcon sound resources. | 154 * @type {string} The base url for earcon sound resources. |
| 155 * @const | 155 * @const |
| 156 */ | 156 */ |
| 157 EarconEngine.BASE_URL = chrome.extension.getURL('cvox2/background/earcons/'); | 157 EarconEngine.BASE_URL = chrome.extension.getURL('cvox2/background/earcons/'); |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * The maximum value to pass to PannerNode.setPosition. | |
| 161 */ | |
| 162 EarconEngine.MAX_PAN_X_POSITION = 2; | |
|
dmazzoni
2016/12/05 20:07:45
I'd call it something like ABS_POSITION or MAGNITU
David Tseng
2016/12/08 19:05:37
Sure; done.
| |
| 163 | |
| 164 /** | |
| 160 * Fetches a sound asynchronously and loads its data into an AudioBuffer. | 165 * Fetches a sound asynchronously and loads its data into an AudioBuffer. |
| 161 * | 166 * |
| 162 * @param {string} name The name of the sound to load. | 167 * @param {string} name The name of the sound to load. |
| 163 * @param {string} url The url where the sound should be fetched from. | 168 * @param {string} url The url where the sound should be fetched from. |
| 164 */ | 169 */ |
| 165 EarconEngine.prototype.loadSound = function(name, url) { | 170 EarconEngine.prototype.loadSound = function(name, url) { |
| 166 var request = new XMLHttpRequest(); | 171 var request = new XMLHttpRequest(); |
| 167 request.open('GET', url, true); | 172 request.open('GET', url, true); |
| 168 request.responseType = 'arraybuffer'; | 173 request.responseType = 'arraybuffer'; |
| 169 | 174 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 } | 206 } |
| 202 var gainNode = this.context_.createGain(); | 207 var gainNode = this.context_.createGain(); |
| 203 gainNode.gain.value = gain; | 208 gainNode.gain.value = gain; |
| 204 var first = gainNode; | 209 var first = gainNode; |
| 205 var last = gainNode; | 210 var last = gainNode; |
| 206 | 211 |
| 207 var pan = this.masterPan; | 212 var pan = this.masterPan; |
| 208 if (properties.pan !== undefined) { | 213 if (properties.pan !== undefined) { |
| 209 pan = properties.pan; | 214 pan = properties.pan; |
| 210 } | 215 } |
| 216 | |
| 211 if (pan != 0) { | 217 if (pan != 0) { |
| 212 var panNode = this.context_.createPanner(); | 218 var panNode = this.context_.createPanner(); |
| 213 panNode.setPosition(pan, 0, -1); | 219 panNode.setPosition(pan, 0, 0); |
| 214 panNode.setOrientation(0, 0, 1); | 220 panNode.setOrientation(0, -1, 0); |
|
dmazzoni
2016/12/05 20:07:45
Are you sure this is right? Did the original orien
David Tseng
2016/12/08 19:05:37
I was fiddling with the audio listener earlier. Re
| |
| 215 last.connect(panNode); | 221 last.connect(panNode); |
| 216 last = panNode; | 222 last = panNode; |
| 217 } | 223 } |
| 218 | 224 |
| 219 var reverb = this.masterReverb; | 225 var reverb = this.masterReverb; |
| 220 if (properties.reverb !== undefined) { | 226 if (properties.reverb !== undefined) { |
| 221 reverb = properties.reverb; | 227 reverb = properties.reverb; |
| 222 } | 228 } |
| 223 if (reverb) { | 229 if (reverb) { |
| 224 if (!this.reverbConvolver_) { | 230 if (!this.reverbConvolver_) { |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 706 } | 712 } |
| 707 | 713 |
| 708 for (var i = 0; i < this.progressSources_.length; i++) { | 714 for (var i = 0; i < this.progressSources_.length; i++) { |
| 709 this.progressSources_[i][1].stop(); | 715 this.progressSources_[i][1].stop(); |
| 710 } | 716 } |
| 711 this.progressSources_ = []; | 717 this.progressSources_ = []; |
| 712 | 718 |
| 713 window.clearInterval(this.progressIntervalID_); | 719 window.clearInterval(this.progressIntervalID_); |
| 714 this.progressIntervalID_ = null; | 720 this.progressIntervalID_ = null; |
| 715 }; | 721 }; |
| 722 | |
| 723 /** | |
| 724 * @param {chrome.automation.Rect} rect | |
| 725 * @param {chrome.automation.Rect} container | |
| 726 */ | |
| 727 EarconEngine.prototype.setPositionForRect = function(rect, container) { | |
| 728 // The horizontal position computed as a percentage relative to its container. | |
| 729 var left = (rect.left + rect.width / 2) / container.width; | |
|
dmazzoni
2016/12/05 20:07:45
Maybe just x? It's really the midpoint of the rect
David Tseng
2016/12/08 19:05:37
Done.
| |
| 730 | |
| 731 // Clamp. | |
| 732 left = left > 1.0 ? 1.0 : left; | |
|
dmazzoni
2016/12/05 20:07:45
x = Math.max(Math.min(x, 1.0), 0.0) or something l
David Tseng
2016/12/08 19:05:37
Done.
| |
| 733 left = left < 0 ? 0 : left; | |
| 734 | |
| 735 // Map to between the negative maximum pan x position and the positive max x | |
| 736 // pan position. | |
| 737 left = left * 2 * EarconEngine.MAX_PAN_X_POSITION - | |
|
dmazzoni
2016/12/05 20:07:45
x = (2 * x - 1) * EarconEngine.MAX_PAN_X_POSITION
David Tseng
2016/12/08 19:05:37
Done.
| |
| 738 EarconEngine.MAX_PAN_X_POSITION; | |
| 739 | |
| 740 this.masterPan = left; | |
| 741 }; | |
| OLD | NEW |