Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Minimal Elementary Starting Template</h1>
<p>To get started, edit the code in the JavaScript pane. To hear the default output of
  the starting template, hit start</p>
<button id="clickMe">Start</button>
              
            
!

CSS

              
                
              
            
!

JS

              
                // Welcome to the starting template! Follow along with the comments below
// to get a brief sense of working with Elementary. Documentation is available
// here: https://docs.elementary.audio/
import {ElementaryWebAudioRenderer as core, el} from 'https://cdn.skypack.dev/@nick-thompson/[email protected]';

const ctx = new (window.AudioContext || window.webkitAudioContext)();

// After we've imported and set up our context, we install a load event listener
// so that once the audio backend is ready we can kick off our render
core.on('load', function() {
  // Before actually rendering anything we put a click handler on the button so that
  // this example doesn't start making noise automatically
  document.getElementById('clickMe').addEventListener('click', async function(e) {
    if (ctx.state === 'suspended') {
      await ctx.resume();
    }
    
    let synthVoice = (hz) => el.mul(
      0.25,
      el.add(
        el.blepsaw(el.mul(hz, 1.001)),
        el.blepsquare(el.mul(hz, 0.994)),
        el.blepsquare(el.mul(hz, 0.501)),
        el.blepsaw(el.mul(hz, 0.496)),
      ),
    );

    // Finally we render a tiny arpeggio example with sine tones. Start here
    // to remix and explore Elementary!
    let train = el.train(4.8);
    let arp = [0, 4, 7, 11, 12, 11, 7, 4].map(x => 261.63 * 0.5 * Math.pow(2, x / 12));

    let modulate = (x, rate, amt) => el.add(x, el.mul(amt, el.cycle(rate)));
    let env = el.adsr(0.01, 0.5, 0, 0.4, train);
    let filt = (x) => el.lowpass(
      el.add(40, el.mul(modulate(1840, 0.05, 1800), env)),
      1,
      x
    );
    
    let dry = el.mul(0.25, filt(synthVoice(el.seq({seq: arp, hold: true}, train))));
    let wet = el.mul(0.25, el.freeverb({name: 'fv'}, 0.94, 0.14, dry));

    core.render(
      el.add(el.mul(0.4, wet), dry),
      el.add(el.mul(0.4, wet), dry),
    );
  });
});

// After installing our load event handler, we initialize the core renderer
// which will spin up the audio backend with the web audio context and fire
// our load event above when ready.
(async function main() {
  let node = await core.initialize(ctx, {
    numberOfInputs: 0,
    numberOfOutputs: 1,
    outputChannelCount: [2],
  });

  node.connect(ctx.destination);
})();

              
            
!
999px

Console