made with requirebin
Last active
December 20, 2015 07:29
-
-
Save NHQ/6094074 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the master audio context | |
var context = webkitAudioContext || AudioContext | |
var master = new context() | |
// for intro to this module, see http://requirebin.com/?gist=6093984 | |
var jsynth = require('jsynth'); | |
// for intro to this module, see http://requirebin.com/?gist=6094039 | |
var oscillators = require('oscillators') | |
// for intro to this module, see http://requirebin.com/?gist=6094056 | |
// var amod = require('amod') | |
// requirebin is not updating to the newest version of amod | |
/// but this is all it is: | |
var amod = function(c, r, t, f){ | |
return (c + (r * oscillators.sine(t, f))) | |
} | |
// mix and match and... synthesize | |
// below a modulator is used in place of a static frequency value for both the oscillator and the amplitude modifier... | |
var dsp = function (time){ | |
return + | |
oscillators.sine(time, amod(220, 60, time, 12)) * | |
amod(.5, .25, time, amod(1/4, 1/64, time, 1/12)) | |
} | |
var synth = jsynth(master, dsp); | |
// connect it to the master out | |
synth.connect(master.destination) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require=function e(t,n,r){function o(u,a){if(!n[u]){if(!t[u]){var f="function"==typeof require&&require;if(!a&&f)return f(u,!0);if(i)return i(u,!0);throw Error("Cannot find module '"+u+"'")}var c=n[u]={exports:{}};t[u][0].call(c.exports,function(n){var r=t[u][1][n];return o(r?r:n)},c,c.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;r.length>u;u++)o(r[u]);return o}({mzwRRj:[function(t,n){n.exports=function(t,n,r){"function"==typeof t&&(n=t,t=new webkitAudioContext),r||(r=4096);var e=t.createScriptProcessor(r,1,1);return e.fn=n,e.i=e.t=0,window._SAMPLERATE=e.sampleRate=e.rate=t.sampleRate,e.duration=1/0,e.recording=!1,e.onaudioprocess=function(t){var n=t.outputBuffer.getChannelData(0),r=t.inputBuffer.getChannelData(0);e.tick(n,r)},e._input=[],e.tick=function(t,n){t=t||e._buffer,n=n||e._input;for(var r=0;t.length>r;r+=1)if(e.t=e.i/e.rate,e.i+=1,t[r]=e.fn(e.t,e.i,n),e.i>=e.duration){e.stop();break}return t},e.stop=function(){e.disconnect(),e.playing=!1,e.recording},e.play=function(){e.playing||(e.connect(e.context.destination),e.playing=!0)},e.record=function(){},e.reset=function(){e.i=e.t=0},e.createSample=function(t){e.reset();var n=e.context.createBuffer(1,t,e.context.sampleRate),r=n.getChannelData(0);return e.tick(r),n},e}},{}],jsynth:[function(t,n){n.exports=t("mzwRRj")},{}]},{},[]),require=function e(t,n,r){function o(u,a){if(!n[u]){if(!t[u]){var f="function"==typeof require&&require;if(!a&&f)return f(u,!0);if(i)return i(u,!0);throw Error("Cannot find module '"+u+"'")}var c=n[u]={exports:{}};t[u][0].call(c.exports,function(n){var r=t[u][1][n];return o(r?r:n)},c,c.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;r.length>u;u++)o(r[u]);return o}({O19dfy:[function(t,n){function r(t,n){return Math.sin(t*c*n)}function e(t,n){var r=t%(1/n)*n%1;return-1+2*r}function o(t,n){var r=t%(1/n)*n%1;return 1-2*r}function i(t,n){var r=t%(1/n)*n%1;return.5>r?-1+2*2*r:1-2*2*r}function u(t,n){var r=t%(1/n)*n%1,e=Math.abs(Math.sin(t));return e>r?-1+2*2*(r/e):1-2*2*(r/e)}function a(t,n){return t%(1/n)*n%1>.5?1:-1}var f=n.exports,c=2*Math.PI;f.sine=r,f.saw=e,f.saw_i=o,f.triangle=i,f.triangle_s=u,f.square=a},{}],oscillators:[function(t,n){n.exports=t("O19dfy")},{}]},{},[]);var context=webkitAudioContext||AudioContext,master=new context,jsynth=require("jsynth"),oscillators=require("oscillators"),amod=function(t,n,r,e){return t+n*oscillators.sine(r,e)},dsp=function(t){return+oscillators.sine(t,amod(220,60,t,12))*amod(.5,.25,t,amod(.25,1/64,t,1/12))},synth=jsynth(master,dsp);synth.connect(master.destination); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"jsynth": "2.2.0", | |
"oscillators": "1.0.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; } | |
body, html { height: 100%; width: 100%; }</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment