Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/resources/whispernet_proxy/js/wrapper.js

Issue 444373004: Add Audible support to the whispernet client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Function to convert an array of bytes to a base64 string 8 * Function to convert an array of bytes to a base64 string
9 * TODO(rkc): Change this to use a Uint8array instead of a string. 9 * TODO(rkc): Change this to use a Uint8array instead of a string.
10 * @param {string} bytes String containing the bytes we want to convert. 10 * @param {string} bytes String containing the bytes we want to convert.
(...skipping 26 matching lines...) Expand all
37 * @param {Object} whisperNacl The NaclBridge object to use to communicate with 37 * @param {Object} whisperNacl The NaclBridge object to use to communicate with
38 * the whispernet wrapper. 38 * the whispernet wrapper.
39 */ 39 */
40 function WhisperEncoder(params, whisperNacl) { 40 function WhisperEncoder(params, whisperNacl) {
41 params = params || {}; 41 params = params || {};
42 this.repetitions_ = params.repetitions || 3; 42 this.repetitions_ = params.repetitions || 3;
43 43
44 this.whisperNacl_ = whisperNacl; 44 this.whisperNacl_ = whisperNacl;
45 this.whisperNacl_.addListener(this.onNaclMessage_.bind(this)); 45 this.whisperNacl_.addListener(this.onNaclMessage_.bind(this));
46 46
47 var symbolCoder = {};
Charlie 2014/08/07 15:46:47 What happened to all of these parameters?
rkc 2014/08/07 16:30:41 The defaults are embedded in the nacl binary. Ther
48 symbolCoder.sample_rate = params.sampleRate || 48000.0;
49 symbolCoder.upsampling_factor = params.bitsPerSample || 16;
50 symbolCoder.desired_carrier_frequency = params.carrierFrequency || 18500.0;
51 symbolCoder.bits_per_symbol = 4;
52 symbolCoder.min_cycles_per_frame = 4;
53 symbolCoder.baseband_decimation_factor = 4;
54
55 var msg = { 47 var msg = {
56 type: 'initialize_encoder', 48 type: 'initialize_encoder',
57 symbol_coder: symbolCoder, 49 sample_rate: params.sampleRate || 48000.0,
58 encoder_params: { 50 upsampling_factor: params.bitsPerSample || 16,
59 bytes_per_token: 6,
60 include_parity_symbol: true,
61 single_sideband: true
62 }
63 }; 51 };
64 this.whisperNacl_.send(JSON.stringify(msg)); 52 this.whisperNacl_.send(JSON.stringify(msg));
65 } 53 }
66 54
67 /** 55 /**
68 * Method to encode a token. 56 * Method to encode a token.
69 * @param {string} token Token to encode. 57 * @param {string} token Token to encode.
70 * @param {boolean} raw Whether we should return the encoded samples in raw 58 * @param {boolean} raw Whether we should return the encoded samples in raw
71 * format or as a Wave file. 59 * format or as a Wave file.
72 */ 60 */
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 * the whispernet wrapper. 103 * the whispernet wrapper.
116 */ 104 */
117 function WhisperDecoder(params, whisperNacl) { 105 function WhisperDecoder(params, whisperNacl) {
118 params = params || {}; 106 params = params || {};
119 107
120 this.whisperNacl_ = whisperNacl; 108 this.whisperNacl_ = whisperNacl;
121 this.whisperNacl_.addListener(this.onNaclMessage_.bind(this)); 109 this.whisperNacl_.addListener(this.onNaclMessage_.bind(this));
122 110
123 var msg = { 111 var msg = {
124 type: 'initialize_decoder', 112 type: 'initialize_decoder',
125 num_channels: params.channels, 113 channels: params.channels || 1,
126 symbol_coder: { 114 sample_rate: params.sampleRate || 48000.0,
127 sample_rate: params.sampleRate || 48000.0, 115 upsampling_factor: params.bitsPerSample || 16,
128 upsampling_factor: params.bitsPerSample || 16, 116 max_candidates: 1,
129 desired_carrier_frequency: params.carrierFrequency || 18500.0, 117 max_buffer_duration_in_seconds: 3
130 bits_per_symbol: 4,
131 min_cycles_per_frame: 4,
132 baseband_decimation_factor: 4
133 },
134 decoder_params: {
135 bytes_per_token: 6,
136 include_parity_symbol: true,
137 max_candidates: 1,
138 broadcaster_stopped_threshold_in_seconds: 10
139 },
140 acquisition_params: {
141 max_buffer_duration_in_seconds: 3
142 }
143 }; 118 };
144 this.whisperNacl_.send(JSON.stringify(msg)); 119 this.whisperNacl_.send(JSON.stringify(msg));
145 } 120 }
146 121
147 /** 122 /**
148 * Method to request the decoder to wipe its internal buffer. 123 * Method to request the decoder to wipe its internal buffer.
149 */ 124 */
150 WhisperDecoder.prototype.wipeDecoder = function() { 125 WhisperDecoder.prototype.wipeDecoder = function() {
151 var msg = { 126 var msg = {
152 type: 'wipe_decode_buffer' 127 type: 'wipe_decode_buffer'
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 */ 190 */
216 WhisperDecoder.prototype.handleCandidates_ = function(candidates) { 191 WhisperDecoder.prototype.handleCandidates_ = function(candidates) {
217 if (!this.tokenCallback_ || !candidates || candidates.length == 0) 192 if (!this.tokenCallback_ || !candidates || candidates.length == 0)
218 return; 193 return;
219 194
220 var returnCandidates = []; 195 var returnCandidates = [];
221 for (var i = 0; i < candidates.length; ++i) 196 for (var i = 0; i < candidates.length; ++i)
222 returnCandidates[i] = bytesToBase64(candidates[i]); 197 returnCandidates[i] = bytesToBase64(candidates[i]);
223 this.tokenCallback_(returnCandidates); 198 this.tokenCallback_(returnCandidates);
224 }; 199 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698