Skip to content

Commit

Permalink
Envelope test
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Oct 22, 2018
1 parent ac35d9b commit 14ae8de
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 126 deletions.
13 changes: 5 additions & 8 deletions index.html
Expand Up @@ -76,9 +76,6 @@ <h3 class="text-5 {[prefix|is:'.'|yesno:'dot-indent','']}">
</section>
</section>




<!--div class="grid-block block">
<select class="grid-1/6 block" id="meter-select">
<option value="2/4">2/4</option>
Expand Down Expand Up @@ -404,13 +401,13 @@ <h3 class="text-5 {[prefix|is:'.'|yesno:'dot-indent','']}">

<!-- Tests -->
<script type="module">
//import './test/node-envelope.test.js';
//import './test/audio-param.test.js';
import './test/audio-param.test.js';
//import './test/controls.test.js';
//import './test/location.test.js';
import './test/soundstage.test.js';
//import './modules/nodes/node-graph.test.js';
import './modules/nodes/node-graph.test.js';
import './modules/nodes/envelope.test.js';
//import './modules/nodes/tone.test.js';
//import './modules/nodes/tone-synth.test.js';
import './modules/nodes/tone-synth.test.js';
import './test/soundstage.test.js';
</script>
</body>
59 changes: 0 additions & 59 deletions modules/audio-objects/output.js

This file was deleted.

3 changes: 2 additions & 1 deletion modules/nodes/envelope.js
Expand Up @@ -22,7 +22,8 @@ function cueAutomation(param, events, time, gain, rate) {
param.cancelAndHoldAtTime(time);

for (let event of events) {
automate(param, time + event[0] / rate, event[1], event[2] * gain, event[3], arguments[5]);
// param, time, curve, value, decay
automate(param, time + event[0] / rate, event[1], event[2] * gain, event[3]);
}
}

Expand Down
64 changes: 31 additions & 33 deletions test/node-envelope.test.js → modules/nodes/envelope.test.js
@@ -1,11 +1,11 @@
import { test } from '../../fn/fn.js';
import { create, append, find } from '../../dom/dom.js';
import { getValueAtTime, getAutomationEvents, requestAutomationData } from '../modules/audio-param.js';
import EnvelopeNode from '../modules/nodes/envelope.js';
import { drawYAxisAmplitude, drawCurve, drawPoint } from '../modules/canvas.js';
import audio from '../modules/audio-context.js';
import { test } from '../../../fn/fn.js';
import { create, append, find } from '../../../dom/dom.js';
import { getValueAtTime, getAutomationEvents, requestAutomationData } from '../audio-param.js';
import Envelope from './envelope.js';
import { drawYAxisAmplitude, drawCurve, drawPoint } from '../canvas.js';
import audio from '../audio-context.js';

test('EnvelopeNode', function(run, print, fixture) {
test('Envelope', function(run, print, fixture) {
const canvas = find('canvas', fixture);
const ctx = canvas.getContext('2d');
const box = [2, 2, 636, 355];
Expand All @@ -14,23 +14,22 @@ test('EnvelopeNode', function(run, print, fixture) {

run('getValueAtTime(param, time)', function(equals, done) {
const offline = new OfflineAudioContext(1, 22050, 22050);
const envelope = new EnvelopeNode(offline, {
sequences: {
attack: [
[0, 0, 'step'],
[0.05, 1, 'linear'],
[0.05, 0.8, 'target', 0.1]
],
const envelope = new Envelope(offline, {
attack: [
[0, 'step', 0],
[0.05, 'linear', 1],
[0.05, 'target', 0.8, 0.1]
],

release: [
[0, 0, 'target', 0.1]
]
}
release: [
[0, 'target', 0, 0.1]
]
});

envelope.connect(offline.destination);
envelope.start(0.1);
envelope.stop(0.2);
envelope.start(0.1, 'attack');
envelope.start(0.2, 'release');
envelope.stop(1);

offline.startRendering().then(function(buffer) {
console.log(buffer);
Expand All @@ -43,23 +42,22 @@ test('EnvelopeNode', function(run, print, fixture) {

run('getValueAtTime(param, time)', function(equals, done) {
const offline = new OfflineAudioContext(1, 22050, 22050);
const envelope = new EnvelopeNode(offline, {
sequences: {
attack: [
[0, 0, 'step'],
[0.4, 1, 'linear'],
[0.4, 0.8, 'target', 0.1]
],
const envelope = new Envelope(offline, {
attack: [
[0, 'step', 0],
[0.4, 'linear', 1],
[0.4, 'target', 0.8, 0.1]
],

release: [
[0, 0, 'target', 0.1]
]
}
release: [
[0, 'target', 0, 0.1]
]
});

envelope.connect(offline.destination);
envelope.start(0.1);
envelope.stop(0.2);
envelope.start(0.1, 'attack');
envelope.start(0.2, 'release');
envelope.stop(1);

offline.startRendering().then(function(buffer) {
console.log(buffer);
Expand Down
51 changes: 51 additions & 0 deletions modules/nodes/output.js
@@ -0,0 +1,51 @@

const assign = Object.assign;
const define = Object.defineProperties;
const rautoname = /Out\s\d+\/\d+/;
const defaults = {
channels: [0, 1]
};

function increment(n) { return n + 1; }

export default class Output extends ChannelSplitterNode {
constructor(context, settings, output) {
var options = assign({}, defaults, settings);
options.numberOfOutputs = options.channels.length || 2;
super(context, options);

var channels = [];

define(this, {
channels: {
get: function() { return channels; },
set: function(array) {
// Where there is no change do nothing
if (array + '' === channels + '') { return; }

//this.disconnect(output);
var count = array.length > output.numberOfInputs ?
output.numberOfInputs :
array.length ;

while (count--) {
// output.channelCount may not be as high as the index
// of channel in array. Ignore routings to channels the
// output does not have.
if (array[count] > output.channelCount) { continue; }
this.connect(output, count, array[count]);
channels[count] = array[count];
}

if (!this.name || rautoname.test(this.name)) {
this.name = 'Out ' + channels.map(increment).join('-');
}
},
enumerable: true,
configurable: true
}
});

this.channels = options.channels;
}
}
14 changes: 7 additions & 7 deletions modules/nodes/tick.js
Expand Up @@ -113,13 +113,13 @@ export default function Tick(audio, options) {
return this;
};

this.stop = function(time) {
// Don't. It's causing problems. I think we'll simply live with the
// fact that the metronome doesn't stop immediately when you stop
// the sequencer.
//unschedule(time, this.decay);
return this;
};
//this.stop = function(time) {
// // Don't. It's causing problems. I think we'll simply live with the
// // fact that the metronome doesn't stop immediately when you stop
// // the sequencer.
// //unschedule(time, this.decay);
// return this;
//};

this.stop = function(time) {
stop(time || audio.currentTime, this.decay);
Expand Down
20 changes: 2 additions & 18 deletions modules/soundstage.js
Expand Up @@ -7,7 +7,7 @@ import { print } from './print.js';
import { distributeEvent } from './distribute.js';
import audio from './audio-context.js';
import Input from './audio-objects/input.js';
import Output from './audio-objects/output.js';
import Output from './nodes/output.js';
import Graph from './graph.js';
import requestPlugin from './request-plugin.js';
import Controls from './controls.js';
Expand Down Expand Up @@ -79,18 +79,14 @@ export default function Soundstage(data, settings) {
//
// audio: audio context

/*
.context()
The audio context.
*/

const context = settings.context || audio;
const destination = settings.output || context.destination;
const output = createOutputMerger(context, destination);

AudioObject.call(this, context, undefined, output);
Soundstage.inspector && Soundstage.inspector.drawAudioFromNode(output);


// Initialise soundstage as a plugin graph. Assigns:
//
// plugins: array
Expand Down Expand Up @@ -129,12 +125,6 @@ The audio context.
//
// controls: array-like

/*
.controls()
An array-like list of controls.
*/

this.ready(function graphReady(stage) {
define(stage, {
controls: {
Expand All @@ -160,12 +150,6 @@ An array-like list of controls.
//
// regions: array

/*
.regions()
An array of audio regions.
*/

const regions
= this.regions
= (settings.regions || []).map(function(data) {
Expand Down

0 comments on commit 14ae8de

Please sign in to comment.