How to use osc method in wpt

Best JavaScript code snippet using wpt

Oscillator.test.ts

Source:Oscillator.test.ts Github

copy

Full Screen

1import { expect } from "chai";2import { BasicTests } from "test/helper/Basic";3import { CompareToFile } from "test/helper/CompareToFile";4import { Offline } from "test/helper/Offline";5import { OscillatorTests } from "test/helper/OscillatorTests";6import { OutputAudio } from "test/helper/OutputAudio";7import { SourceTests } from "test/helper/SourceTests";8import { Oscillator } from "./Oscillator";9import { ToneOscillatorType } from "./OscillatorInterface";10describe("Oscillator", () => {11 // run the common tests12 BasicTests(Oscillator);13 SourceTests(Oscillator);14 OscillatorTests(Oscillator);15 it("matches a file", () => {16 return CompareToFile(() => {17 const osc = new Oscillator().toDestination();18 osc.type = "square";19 osc.start(0).stop(0.2);20 }, "oscillator.wav", 0.1);21 });22 context("Get/Set", () => {23 it("can be set with an options object", () => {24 const osc = new Oscillator();25 osc.set({26 detune: -21,27 frequency: 231,28 type: "square",29 });30 expect(osc.frequency.value).to.equal(231);31 expect(osc.detune.value).to.equal(-21);32 expect(osc.type).to.equal("square");33 osc.dispose();34 });35 it("can be get the values as an object", () => {36 const osc = new Oscillator(450, "square");37 expect(osc.get().frequency).to.equal(450);38 expect(osc.get().type).to.equal("square");39 osc.dispose();40 });41 });42 context("Phase Rotation", () => {43 it("can change the phase to 90", () => {44 return Offline(() => {45 const instance = new Oscillator({46 frequency: 1,47 phase: 90,48 });49 instance.toDestination();50 instance.start(0);51 }, 1).then((buffer) => {52 buffer.forEach((sample, time) => {53 if (time < 0.25) {54 expect(sample).to.be.within(-1, 0);55 } else if (time > 0.25 && time < 0.5) {56 expect(sample).to.be.within(0, 1);57 }58 });59 });60 });61 it("can change the phase to -90", () => {62 return Offline(() => {63 const instance = new Oscillator({64 frequency: 1,65 phase: 270,66 });67 instance.toDestination();68 instance.start(0);69 }, 1).then((buffer) => {70 buffer.forEach((sample, time) => {71 if (time < 0.25) {72 expect(sample).to.be.within(0, 1);73 } else if (time > 0.25 && time < 0.5) {74 expect(sample).to.be.within(-1, 0);75 }76 });77 });78 });79 it("can go past the cache max size of 100", () => {80 const osc = new Oscillator();81 for (let i = 0; i < 110; i++) {82 osc.phase = i;83 }84 osc.dispose();85 });86 });87 context("Type", () => {88 it("can get and set the type", () => {89 const osc = new Oscillator({90 type: "sawtooth",91 });92 expect(osc.type).to.equal("sawtooth");93 osc.dispose();94 });95 it("can set the type after starting", () => {96 const osc = new Oscillator(110, "sawtooth10").start();97 expect(osc.type).to.equal("sawtooth10");98 osc.type = "sawtooth20";99 expect(osc.type).to.equal("sawtooth20");100 osc.dispose();101 });102 it("handles 4 basic types", () => {103 const osc = new Oscillator();104 const types: ToneOscillatorType[] = ["triangle", "sawtooth", "sine", "square"];105 for (const type of types) {106 osc.type = type;107 expect(osc.type).to.equal(type);108 }109 osc.dispose();110 });111 it("throws an error if invalid type is set", () => {112 const osc = new Oscillator();113 expect(() => {114 // @ts-ignore115 osc.type = "invalid";116 }).to.throw(Error);117 osc.dispose();118 });119 it("can set extended types", () => {120 const osc = new Oscillator();121 osc.type = "sine5";122 expect(osc.type).to.equal("sine5");123 osc.type = "triangle2";124 expect(osc.type).to.equal("triangle2");125 osc.dispose();126 });127 it("can get/set the baseType", () => {128 const osc = new Oscillator();129 osc.type = "sine5";130 expect(osc.baseType).to.equal("sine");131 osc.baseType = "triangle";132 expect(osc.type).to.equal("triangle5");133 expect(osc.partialCount).to.equal(5);134 osc.partialCount = 2;135 expect(osc.type).to.equal("triangle2");136 osc.baseType = "custom";137 expect(osc.type).to.equal("custom");138 osc.partials = [1, 2, 3];139 expect(osc.baseType).to.equal("custom");140 osc.baseType = "square";141 expect(osc.type).to.equal("square");142 osc.dispose();143 });144 });145 context("Partials", () => {146 it("can pass partials in the constructor", () => {147 const osc = new Oscillator({148 partials: [1, 0.3, 0.3],149 type: "custom",150 });151 expect(osc.type).to.equal("custom");152 expect(osc.partials[1]).to.equal(0.3);153 osc.dispose();154 });155 it("can set partials", () => {156 const osc = new Oscillator();157 osc.partials = [1, 0.2, 0.2, 0.2];158 expect(osc.type).to.equal("custom");159 expect(osc.partials[1]).to.equal(0.2);160 osc.dispose();161 });162 it("makes a sound with custom partials", () => {163 return OutputAudio(() => {164 const osc = new Oscillator().toDestination().start();165 osc.partials = [1, 0.2, 0.2, 0.2];166 });167 });168 it("outputs the partials of the given waveform", () => {169 const osc = new Oscillator();170 osc.type = "sine2";171 expect(osc.type).to.equal("sine2");172 expect(osc.partials.length).to.equal(2);173 expect(osc.partials).to.deep.equal([1, 1]);174 osc.dispose();175 });176 it("partialCount is 0 when set to max", () => {177 const osc = new Oscillator();178 expect(osc.partialCount).to.equal(0);179 osc.type = "square32";180 expect(osc.partialCount).to.equal(32);181 osc.type = "square";182 expect(osc.partialCount).to.equal(0);183 osc.dispose();184 });185 it("can pass in number of partials into constructor", () => {186 const osc = new Oscillator({187 partialCount: 3,188 type: "sine",189 });190 expect(osc.type).to.equal("sine3");191 expect(osc.partialCount).to.equal(3);192 osc.partialCount = 4;193 expect(osc.partialCount).to.equal(4);194 expect(osc.type).to.equal("sine4");195 osc.dispose();196 });197 });198 context("Synchronization", () => {199 it("can sync the frequency to the Transport", () => {200 return Offline(({ transport }) => {201 transport.bpm.value = 120;202 const osc = new Oscillator(2);203 osc.frequency.toDestination();204 osc.syncFrequency();205 transport.bpm.value = 240;206 }).then((buffer) => {207 expect(buffer.value()).to.be.closeTo(4, 0.001);208 });209 });210 it("can unsync the frequency from the Transport", () => {211 return Offline(({ transport }) => {212 transport.bpm.value = 120;213 const osc = new Oscillator(2);214 osc.frequency.toDestination();215 osc.syncFrequency();216 transport.bpm.value = 240;217 osc.unsyncFrequency();218 }).then((buffer) => {219 expect(buffer.value()).to.be.closeTo(2, 0.001);220 });221 });222 });223 context("initialValue", () => {224 it("can get the initial value of a basic oscillator type", () => {225 const osc = new Oscillator(10, "sine");226 expect(osc.getInitialValue()).to.be.closeTo(0, 0.01);227 osc.dispose();228 });229 it("can get the initial value when the phase is rotated", () => {230 const osc = new Oscillator({231 phase: 90,232 type: "sine",233 });234 expect(osc.getInitialValue()).to.be.closeTo(-1, 0.01);235 osc.dispose();236 });237 it("can get the initial value of more complex types", () => {238 const osc = new Oscillator({239 partials: [0, 2, 4, 1, 3],240 phase: 145,241 type: "custom",242 });243 expect(osc.getInitialValue()).to.be.closeTo(-0.2, 0.05);244 osc.dispose();245 });246 });...

Full Screen

Full Screen

synth.js

Source:synth.js Github

copy

Full Screen

1// web synth author: Greg M2var audio = new window.AudioContext();3var SITE_VOLUME = .5;4var TET = 12; //tone equal temperament5class OscModel {6 constructor(type, dest, frequency, attack, decay) {7 this.type = type;8 this.dest = dest;9 this.freq = frequency; //null if tied to input10 this.attack = attack;11 this.decay = decay;12 this.destprop = null; //null if tied to output13 }14}15var oscillators = []; //each osc: [model, view]16function createOscillator(model, userfreq) {17 var attack = model.attack,18 decay = model.decay,19 gain = audio.createGain(),20 osc = audio.createOscillator();21 if (model.dest == "out") {22 gain.gain.setValueAtTime(0, audio.currentTime);23 gain.gain.linearRampToValueAtTime(.15 * SITE_VOLUME, audio.currentTime + attack / 1000);24 gain.gain.linearRampToValueAtTime(0, audio.currentTime + decay / 1000);25 gain.connect(audio.destination);26 if(model.freq == null) {27 osc.frequency.value = userfreq;28 } else {29 osc.frequency.value = model.freq;30 }31 }32 33 osc.type = model.type;34 osc.connect(gain);35 osc.start(0);36 setTimeout(function() {37 osc.stop(0);38 try {39 osc.disconnect(gain);40 gain.disconnect(audio.destination);41 } catch(err) {}42 }, decay)43 return [osc, gain, model.dest, model.destprop];44}45function createOscs(oscillators, userfreq) {46 oscs = [] //list of lists [osc, gain, destination, destproperty]47 //create list of oscillators48 for (const osc of oscillators) {49 oscs.push(createOscillator(osc[0], userfreq));50 }51 //assign their gains to given output52 for (const osc of oscs) {53 if (osc[3] == "f") {54 osc[1].gain.value = 100;55 osc[0].frequency.value = 1;56 osc[1].connect(oscs[osc[2]][0].frequency);57 } else if (osc[3] == "a") {58 osc[1].gain.value = .1;59 osc[0].frequency.value = 1;60 osc[1].connect(oscs[osc[2]][1].gain);61 }62 }63}64function createOscTemplate() {65 const idx = oscillators.length;66 //create osc model67 var model = new OscModel("sine", "out", null, "0.001", "999");68 //create menu69 var oscDiv = document.getElementById('oscs');70 var view = oscDiv.appendChild(document.createElement('div'));71 view.id = "osc"+idx;72 //write html73 s = `<h2>Oscillator ${idx+1}</h2><br>`;74 s +=75 `<p>Oscillator Type:</p>76 <input type="radio" id="square${idx}" name="osc${idx}" value="square">77 <label for="square">Square</label><br>78 <input type="radio" id="sine${idx}" name="osc${idx}" value="sine" checked>79 <label for="sine">Sine</label><br>80 <input type="radio" id="triangle${idx}" name="osc${idx}" value="triangle">81 <label for="triangle">Triangle</label><br>82 <input type="radio" id="sawtooth${idx}" name="osc${idx}" value="sawtooth">83 <label for="sawtooth">Sawtooth</label><br><br>`;84 s += 85 `<div class="dropdown">86 <p>Oscillator Output:</p>87 <button class="dropbtn" id="dropbtn${idx}">Output</button>88 <div id="dc${idx}" class="dropdown-content">89 <button class="dropdown-button" id=${idx}outputout>Output</button>`90 for (i=0;i<oscillators.length+1;i++) {91 if (i != idx) {92 s += `<button class="dropdown-button" id=${idx}output${i}>Osc ${i+1} Frequency</button>` 93 //name format: {this}output{type}{dest}94 s += `<button class="dropdown-button" id=${idx}outputa${i}>Osc ${i+1} Amplitude</button>`95 }96 }97 s += 98 `</div>99 </div>`100 view.innerHTML = s;101 //create button event handlers102 document.getElementById(`square${idx}`).onclick = function() {model.type = "square"};103 document.getElementById(`sine${idx}`).onclick = function() {model.type = "sine"};104 document.getElementById(`triangle${idx}`).onclick = function() {model.type = "triangle"};105 document.getElementById(`sawtooth${idx}`).onclick = function() {model.type = "sawtooth"};106 document.getElementById(`${idx}outputout`).onclick = function() {107 model.dest = "out";108 model.destprop = null;109 document.getElementById(`dropbtn${idx}`).innerHTML = "Output";110 };111 for (i=0;i<oscillators.length+1;i++) {112 if (i != idx) {113 const num = i;114 document.getElementById(idx + `output${i}`).onclick = function() {115 model.dest = num;116 model.destprop = "f"; 117 document.getElementById("dropbtn" + idx).innerHTML = `Osc ${num+1} Frequency`;118 };119 document.getElementById(idx + `outputa${i}`).onclick = function() {120 model.dest = num;121 model.destprop = "a"; 122 document.getElementById("dropbtn" + idx).innerHTML = `Osc ${num+1} Amplitude`;123 }; 124 }125 }126 oscillators[idx] = [model, view]127}128document.getElementById("makeosc").onclick = function() {129 createOscTemplate();130}131function deleteOsc() {132 var div = document.getElementById("osc"+(oscillators.length-1));133 div.parentNode.removeChild(div); //remove html134 oscillators.pop(); //remove object135}136document.getElementById("remosc").onclick = function() {137 deleteOsc();138}139var keys = ["q", "2", "w", "3", "e", "r", "5", "t", "6", "y", "7", "u", "i", "9", "o", "0", "p"];140var keyValues = {};141function setKeys() {142 var i = 0;143 for(const key of keys) {144 keyValues[key] = 262.0 * Math.pow(2, (i/TET));145 i++;146 }147}148setKeys();149window.addEventListener('keydown', function(event) {150 if (event.key in keyValues) {151 createOscs(oscillators, keyValues[event.key]);152 };153});154document.getElementById("volume").oninput = function() {155 SITE_VOLUME = this.value * .01;156}157document.getElementById("tetplus").onclick = function() {158 TET++;159 document.getElementById("tet").innerHTML = "TET: " + String(TET);160 setKeys();161}162document.getElementById("tetminus").onclick = function() {163 TET--;164 document.getElementById("tet").innerHTML = "TET: " + String(TET);165 setKeys();166}167document.getElementById("tetreset").onclick = function() {168 TET = 12;169 document.getElementById("tet").innerHTML = "TET: " + String(TET);170 setKeys();...

Full Screen

Full Screen

osc.js

Source:osc.js Github

copy

Full Screen

1import _ from 'lodash';2import OSC from "osc-js";3import React, {useEffect} from 'react';4import useOsc from './useOsc';5import PC from "./pc";6const Osc = () => {7 const [state, actions] = useOsc(8 ({beat, midi, oscHost, seq}) => ({beat, midi, oscHost, seq}), // https://github.com/andregardi/use-global-hook#avoid-unnecessary-renders9 actions => actions,10 );11 useEffect(() => {12 const oscHost = {13 host: window.location.hostname,14 port: '8080',15 };16 const osc = new OSC({17 plugin: new OSC.WebsocketClientPlugin(oscHost),18 });19 osc.open();20 // window.sendOsc = (address, ...args) => osc.send(new OSC.Message(address, ...args));21 const {22 clearSeq,23 setBeat,24 setInSeq,25 setMidiEvent,26 setOscHost,27 } = actions;28 setOscHost(oscHost);29 osc.on('/midiSeq/clear', () => clearSeq());30 osc.on('/midiSeq/beat', ({args: [beat]}) => setBeat(beat));31 osc.on('/midi/*', ({address, args: [note, vel]}) => {32 const instrument = _.last(address.split('/'));33 setMidiEvent(instrument, {[note]: vel});34 });35 osc.on('/midiSeq/note/*', ({address, args}) => {36 const beat = parseInt(_.takeRight(address.split('/'), 2)[0], 10);37 setInSeq(beat, _(args).chunk(2).map(([note, vel]) => ({note, vel})).value()); // args is array of interleaved note, vel...38 });39 }, []);40 const pcs = (state.seq[state.beat] || []).map(({note}) => note % 12);41 const [ewiNote, ewiVel] = state.midi.ewi;42 return <div>43 <h1>{state.beat}</h1>44 {/*<pre>{JSON.stringify((state.seq[state.beat] || []).map(({note}) => note), null, 2)}</pre>*/}45 {/*<pre>{JSON.stringify(state.midi.ewi, null, 2)}</pre>*/}46 <div style={{47 backgroundColor: 'deeppink',48 color: 'black',49 height: '30vh',50 position: 'relative',51 width: '30vh',52 }}>53 {(state.seq[state.beat] || []).map(({note, vel}, idx) => {54 return <PC key={idx} n={note}/>55 })}56 {(_.range(12)).map((pc, idx) => {57 const theta = (pc / 12) * Math.PI * 2;58 return (59 <PC60 key={idx}61 n={pc}62 style={{63 color: _.includes(pcs, pc) ? 'cyan' : 'black',64 background: `rgba(255, 255, 255, ${pc === ewiNote % 12 ? ewiVel / 127 : 0})`,65 borderRadius: '50%',66 // borderStyle: pc === ewiNote % 12 ? 'solid' : 'none',67 fontSize: '1.5em',68 position: 'absolute',69 left: `${(0.25 * Math.sin(theta) + 0.5) * 100}%`,70 top: `${(-0.25 * Math.cos(theta) + 0.5) * 100}%`,71 }}/>)72 })}73 </div>74 </div>;75};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var osc = require('osc-min');2var dgram = require('dgram');3var client = dgram.createSocket('udp4');4var message = {5 {6 },7 {8 }9};10var buffer = osc.toBuffer(message);11client.send(buffer, 0, buffer.length, 3333, '

Full Screen

Using AI Code Generation

copy

Full Screen

1var osc = require('node-osc');2var oscServer, oscClient;3var wptk = require('wptoolkit');4var wp = new wptk();5var wpClient;6var wpServer;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', 'A.4d4e4ec4a9c9c8f8fa3f3c3d3e3f3f3e');5wpt.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 console.log('Test submitted to WebPagetest for %s', url);8 console.log('View your test at: %s', data.data.userUrl);9});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful