Best JavaScript code snippet using wpt
mixing-rules.js
Source:mixing-rules.js
...91 * In-place summing to |output| based on 'discrete' channel interpretation.92 * @param {AudioBuffer} input Input audio buffer.93 * @param {AudioBuffer} output Output audio buffer.94 */95function discreteSum(input, output) {96 if (input.length != output.length) {97 throw '[mixing-rules.js] speakerSum(): buffer lengths mismatch (input: '98 + input.length + ', output: ' + output.length + ')';99 }100 var numberOfChannels = Math.min(input.numberOfChannels, output.numberOfChannels)101 for (var channel = 0; channel < numberOfChannels; ++channel) {102 var inputChannel = input.getChannelData(channel);103 var outputChannel = output.getChannelData(channel);104 for (var i = 0; i < outputChannel.length; i++)105 outputChannel[i] += inputChannel[i];106 }107}108/**109 * Perform up-mix by in-place summing to |output| buffer.110 * @param {AudioBuffer} input Input audio buffer.111 * @param {AudioBuffer} output Output audio buffer.112 */113function processUpMix(input, output) {114 var numberOfInputChannels = input.numberOfChannels;115 var numberOfOutputChannels = output.numberOfChannels;116 var i, length = output.length;117 // Up-mixing: 1 -> 2, 1 -> 4118 // output.L += input119 // output.R += input120 // output.SL += 0 (in the case of 1 -> 4)121 // output.SR += 0 (in the case of 1 -> 4)122 if ((numberOfInputChannels === 1 && numberOfOutputChannels === 2) ||123 (numberOfInputChannels === 1 && numberOfOutputChannels === 4)) {124 var inputChannel = input.getChannelData(0);125 var outputChannel0 = output.getChannelData(0);126 var outputChannel1 = output.getChannelData(1);127 for (i = 0; i < length; i++) {128 outputChannel0[i] += inputChannel[i];129 outputChannel1[i] += inputChannel[i];130 }131 return;132 }133 // Up-mixing: 1 -> 5.1134 // output.L += 0135 // output.R += 0136 // output.C += input137 // output.LFE += 0138 // output.SL += 0139 // output.SR += 0140 if (numberOfInputChannels == 1 && numberOfOutputChannels == 6) {141 var inputChannel = input.getChannelData(0);142 var outputChannel2 = output.getChannelData(2);143 for (i = 0; i < length; i++)144 outputChannel2[i] += inputChannel[i];145 return;146 }147 // Up-mixing: 2 -> 4, 2 -> 5.1148 // output.L += input.L149 // output.R += input.R150 // output.C += 0 (in the case of 2 -> 5.1)151 // output.LFE += 0 (in the case of 2 -> 5.1)152 // output.SL += 0153 // output.SR += 0154 if ((numberOfInputChannels === 2 && numberOfOutputChannels === 4) ||155 (numberOfInputChannels === 2 && numberOfOutputChannels === 6)) {156 var inputChannel0 = input.getChannelData(0);157 var inputChannel1 = input.getChannelData(1);158 var outputChannel0 = output.getChannelData(0);159 var outputChannel1 = output.getChannelData(1);160 for (i = 0; i < length; i++) {161 outputChannel0[i] += inputChannel0[i];162 outputChannel1[i] += inputChannel1[i];163 }164 return;165 }166 // Up-mixing: 4 -> 5.1167 // output.L += input.L168 // output.R += input.R169 // output.C += 0170 // output.LFE += 0171 // output.SL += input.SL172 // output.SR += input.SR173 if (numberOfInputChannels === 4 && numberOfOutputChannels === 6) {174 var inputChannel0 = input.getChannelData(0); // input.L175 var inputChannel1 = input.getChannelData(1); // input.R176 var inputChannel2 = input.getChannelData(2); // input.SL177 var inputChannel3 = input.getChannelData(3); // input.SR178 var outputChannel0 = output.getChannelData(0); // output.L179 var outputChannel1 = output.getChannelData(1); // output.R180 var outputChannel4 = output.getChannelData(4); // output.SL181 var outputChannel5 = output.getChannelData(5); // output.SR182 for (i = 0; i < length; i++) {183 outputChannel0[i] += inputChannel0[i];184 outputChannel1[i] += inputChannel1[i];185 outputChannel4[i] += inputChannel2[i];186 outputChannel5[i] += inputChannel3[i];187 }188 return;189 }190 // All other cases, fall back to the discrete sum.191 discreteSum(input, output);192}193/**194 * Perform down-mix by in-place summing to |output| buffer.195 * @param {AudioBuffer} input Input audio buffer.196 * @param {AudioBuffer} output Output audio buffer.197 */198function processDownMix(input, output) {199 var numberOfInputChannels = input.numberOfChannels;200 var numberOfOutputChannels = output.numberOfChannels;201 var i, length = output.length;202 // Down-mixing: 2 -> 1203 // output += 0.5 * (input.L + input.R)204 if (numberOfInputChannels === 2 && numberOfOutputChannels === 1) {205 var inputChannel0 = input.getChannelData(0); // input.L206 var inputChannel1 = input.getChannelData(1); // input.R207 var outputChannel0 = output.getChannelData(0);208 for (i = 0; i < length; i++)209 outputChannel0[i] += 0.5 * (inputChannel0[i] + inputChannel1[i]);210 return;211 }212 // Down-mixing: 4 -> 1213 // output += 0.25 * (input.L + input.R + input.SL + input.SR)214 if (numberOfInputChannels === 4 && numberOfOutputChannels === 1) {215 var inputChannel0 = input.getChannelData(0); // input.L216 var inputChannel1 = input.getChannelData(1); // input.R217 var inputChannel2 = input.getChannelData(2); // input.SL218 var inputChannel3 = input.getChannelData(3); // input.SR219 var outputChannel0 = output.getChannelData(0);220 for (i = 0; i < length; i++) {221 outputChannel0[i] += 0.25 * (inputChannel0[i] + inputChannel1[i]222 + inputChannel2[i] + inputChannel3[i]);223 }224 return;225 }226 // Down-mixing: 5.1 -> 1227 // output += sqrt(1/2) * (input.L + input.R) + input.C228 // + 0.5 * (input.SL + input.SR)229 if (numberOfInputChannels === 6 && numberOfOutputChannels === 1) {230 var inputChannel0 = input.getChannelData(0); // input.L231 var inputChannel1 = input.getChannelData(1); // input.R232 var inputChannel2 = input.getChannelData(2); // input.C233 var inputChannel4 = input.getChannelData(4); // input.SL234 var inputChannel5 = input.getChannelData(5); // input.SR235 var outputChannel0 = output.getChannelData(0);236 var scaleSqrtHalf = Math.sqrt(0.5);237 for (i = 0; i < length; i++) {238 outputChannel0[i] +=239 scaleSqrtHalf * (inputChannel0[i] + inputChannel1[i])240 + inputChannel2[i] + 0.5 * (inputChannel4[i] + inputChannel5[i]);241 }242 return;243 }244 // Down-mixing: 4 -> 2245 // output.L += 0.5 * (input.L + input.SL)246 // output.R += 0.5 * (input.R + input.SR)247 if (numberOfInputChannels == 4 && numberOfOutputChannels == 2) {248 var inputChannel0 = input.getChannelData(0); // input.L249 var inputChannel1 = input.getChannelData(1); // input.R250 var inputChannel2 = input.getChannelData(2); // input.SL251 var inputChannel3 = input.getChannelData(3); // input.SR252 var outputChannel0 = output.getChannelData(0); // output.L253 var outputChannel1 = output.getChannelData(1); // output.R254 for (i = 0; i < length; i++) {255 outputChannel0[i] += 0.5 * (inputChannel0[i] + inputChannel2[i]);256 outputChannel1[i] += 0.5 * (inputChannel1[i] + inputChannel3[i]);257 }258 return;259 }260 // Down-mixing: 5.1 -> 2261 // output.L += input.L + sqrt(1/2) * (input.C + input.SL)262 // output.R += input.R + sqrt(1/2) * (input.C + input.SR)263 if (numberOfInputChannels == 6 && numberOfOutputChannels == 2) {264 var inputChannel0 = input.getChannelData(0); // input.L265 var inputChannel1 = input.getChannelData(1); // input.R266 var inputChannel2 = input.getChannelData(2); // input.C267 var inputChannel4 = input.getChannelData(4); // input.SL268 var inputChannel5 = input.getChannelData(5); // input.SR269 var outputChannel0 = output.getChannelData(0); // output.L270 var outputChannel1 = output.getChannelData(1); // output.R271 var scaleSqrtHalf = Math.sqrt(0.5);272 for (i = 0; i < length; i++) {273 outputChannel0[i] += inputChannel0[i]274 + scaleSqrtHalf * (inputChannel2[i] + inputChannel4[i]);275 outputChannel1[i] += inputChannel1[i]276 + scaleSqrtHalf * (inputChannel2[i] + inputChannel5[i]);277 }278 return;279 }280 // Down-mixing: 5.1 -> 4281 // output.L += input.L + sqrt(1/2) * input.C282 // output.R += input.R + sqrt(1/2) * input.C283 // output.SL += input.SL284 // output.SR += input.SR285 if (numberOfInputChannels === 6 && numberOfOutputChannels === 4) {286 var inputChannel0 = input.getChannelData(0); // input.L287 var inputChannel1 = input.getChannelData(1); // input.R288 var inputChannel2 = input.getChannelData(2); // input.C289 var inputChannel4 = input.getChannelData(4); // input.SL290 var inputChannel5 = input.getChannelData(5); // input.SR291 var outputChannel0 = output.getChannelData(0); // output.L292 var outputChannel1 = output.getChannelData(1); // output.R293 var outputChannel2 = output.getChannelData(2); // output.SL294 var outputChannel3 = output.getChannelData(3); // output.SR295 var scaleSqrtHalf = Math.sqrt(0.5);296 for (i = 0; i < length; i++) {297 outputChannel0[i] += inputChannel0[i] + scaleSqrtHalf * inputChannel2[i];298 outputChannel1[i] += inputChannel1[i] + scaleSqrtHalf * inputChannel2[i];299 outputChannel2[i] += inputChannel4[i];300 outputChannel3[i] += inputChannel5[i];301 }302 return;303 }304 // All other cases, fall back to the discrete sum.305 discreteSum(input, output);...
preisach_utils.js
Source:preisach_utils.js
...72 /**73 * get sum of combo74 * @return {number}, the sum75 */76 function discreteSum(arr, weights) {77 let sum = 0;78 let k = 0;79 // console.log('arr = ', arr);80 // console.log('weights = ', weights);81 // BOGUS82 // SUMMING ENTIRE MATRIX WHEN THERE IS ONLY EVER GOING TO BE vals ON 1 SIDE 83 // 84 for(let i = 0; i < arr.length; i++) {85 for (let j = 0; j < arr.length; j++) {86 // console.log('arr[i][j] = ', arr[i][j]);87 // console.log('weights[arr.length] = ', weights[arr.length]);88 // BOGUS89 // uniform weights here !!!90 sum += arr[i][j]*weights[0]; 91 }92 }93 // console.log('sum = ', sum);94 return sum;95 }96 /**97 *98 */99 function getAllIOPairs(arr, arrt, thresholds, weights) {100 let pairs = [];101 let input = [];102 let output = [];103 for ( let i = 0; i < arr.length; i++ ) {104 input = [];105 output = [];106 input[0] = arrt[i][0];107 input[1] = arrt[i][1];108 // weights is 1-D...combos are 2-D109 // console.log("weights = ", weights);110 // console.log("arr = ", arr);111 // console.log("arr shape = ", arr[i].length, "x", arr[i][0].length);112 output[0] = output[1] = discreteSum(arr[i], weights);113 pairs[i] = [input, output];114 }115 return pairs;116 }117 /**118 *119 */120 function createAllCombos (d) {121 // console.log("d = ", d);122 let l = d.thresholds.length - 3;123 // console.log("l = ", l);124 let n = Math.pow(2, l);125 // count is a global...cause the recurser nightmare126 count = 0;...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data.data.median.firstView.SpeedIndex);7 });8});
Using AI Code Generation
1var wptoolbox = require('wptoolbox');2var a = 0.0;3var b = 1.0;4var n = 100;5var f = function(x) {6 return x*x;7}8var result = wptoolbox.discreteSum(f, a, b, n);9console.log(result);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!