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_ABS_X_POSITION = 4; |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
211 if (pan != 0) { | 216 if (pan != 0) { |
212 var panNode = this.context_.createPanner(); | 217 var panNode = this.context_.createPanner(); |
213 panNode.setPosition(pan, 0, -1); | 218 panNode.setPosition(pan, 0, 0); |
214 panNode.setOrientation(0, 0, 1); | 219 panNode.setOrientation(0, 0, 1); |
215 last.connect(panNode); | 220 last.connect(panNode); |
216 last = panNode; | 221 last = panNode; |
217 } | 222 } |
218 | 223 |
219 var reverb = this.masterReverb; | 224 var reverb = this.masterReverb; |
220 if (properties.reverb !== undefined) { | 225 if (properties.reverb !== undefined) { |
221 reverb = properties.reverb; | 226 reverb = properties.reverb; |
222 } | 227 } |
223 if (reverb) { | 228 if (reverb) { |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 } | 711 } |
707 | 712 |
708 for (var i = 0; i < this.progressSources_.length; i++) { | 713 for (var i = 0; i < this.progressSources_.length; i++) { |
709 this.progressSources_[i][1].stop(); | 714 this.progressSources_[i][1].stop(); |
710 } | 715 } |
711 this.progressSources_ = []; | 716 this.progressSources_ = []; |
712 | 717 |
713 window.clearInterval(this.progressIntervalID_); | 718 window.clearInterval(this.progressIntervalID_); |
714 this.progressIntervalID_ = null; | 719 this.progressIntervalID_ = null; |
715 }; | 720 }; |
| 721 |
| 722 /** |
| 723 * @param {chrome.automation.Rect} rect |
| 724 * @param {chrome.automation.Rect} container |
| 725 */ |
| 726 EarconEngine.prototype.setPositionForRect = function(rect, container) { |
| 727 // The horizontal position computed as a percentage relative to its container. |
| 728 var x = (rect.left + rect.width / 2) / container.width; |
| 729 |
| 730 // Clamp. |
| 731 x = Math.min(Math.max(x, 0.0), 1.0); |
| 732 |
| 733 // Map to between the negative maximum pan x position and the positive max x |
| 734 // pan position. |
| 735 x = (2 * x - 1) * EarconEngine.MAX_PAN_ABS_X_POSITION; |
| 736 |
| 737 this.masterPan = x; |
| 738 }; |
OLD | NEW |