Skip to content

Commit

Permalink
Adds Steinway piano test
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Sep 22, 2023
1 parent 4383db4 commit 36dfa39
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 88 deletions.
10 changes: 5 additions & 5 deletions nodes/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ const properties = {
// Import JSON
// Todo: Expose a better way than this.promise
this.promise = requestData(src)
.then((data) => {
.then((sampleMap) => {
this.promise = undefined;
privates.src = src;
privates.map = data;
privates.src = src;
privates.regions = sampleMap.data;

// Populate buffer cache with buffer data
return Promise.all(data.map((region) =>
return Promise.all(privates.regions.map((region) =>
requestBuffer(context, region.src)
.then((buffer) => cache[region.src] = buffer)
));
Expand Down Expand Up @@ -309,7 +309,7 @@ assign(Sample.prototype, Playable.prototype, NodeGraph.prototype, {
this.frequency = frequency;

gainNode.gain.setValueAtTime(this.gain, this.startTime);
startSources(privates.sources, gainNode, detuneNode, privates.map, this.startTime, this.frequency, note, this.gain) ;
startSources(privates.sources, gainNode, detuneNode, privates.regions, this.startTime, this.frequency, note, this.gain) ;

return this;
},
Expand Down
68 changes: 68 additions & 0 deletions nodes/test/instrument-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ assign(constructors, {
tone: Tone
});

run('Start context', [], function(test, done) {
context.resume().then(done);
});

/*
run('Instrument() sample', [false], function(test, done) {
const duration = 0.1;
const instrument = new Instrument(context, {
Expand Down Expand Up @@ -261,3 +266,66 @@ run('Instrument() sample and tone', [false], function(test, done) {
}, 2000);
}, 1000);
});
*/

//const path = 'http://sound.stephen.band/';
const path = 'http://localhost/sound.stephen.band/';

run('Instrument() Chromatic and dynamic test', [false], function(test, done) {
const duration = 0.1;
const instrument = new Instrument(context, {
voice: {
nodes: [{
id: 'sample',
type: 'sample',
data: {
src: path + 'samples/steinway-piano/sample-map-local.json',
nominalFrequency: 440,
// TODO: gain is working? Do we need gain?
gain: 1
}
}, {
id: 'mix',
type: 'mix',
data: { gain: 1, pan: 0 }
}, {
id: 'output',
type: 'gain',
data: { gain: 1 }
}],

connections: [
{ source: 'sample', target: 'mix' },
{ source: 'mix', target: 'output' }
],

commands: [
{ target: 'sample' }
],

output: 'output'
},

output: 1
});

instrument.connect(context.destination);

function playChromatic(min, max, gain) {
const t = context.currentTime;
let n = min - 1;
while (++n < max) {
instrument
.start(t + 0.12 * (n - min), n, gain)
.stop( t + 0.12 * (n - min) + 0.3) ;
}
}

setTimeout(() => playChromatic(25, 108, 0.03125), 0);
setTimeout(() => playChromatic(25, 108, 0.0625), 10000);
setTimeout(() => playChromatic(25, 108, 0.125), 20000);
setTimeout(() => playChromatic(25, 108, 0.25), 30000);
setTimeout(() => playChromatic(25, 108, 0.5), 40000);
setTimeout(() => playChromatic(25, 108, 1), 50000);
setTimeout(() => done, 60000);
});
80 changes: 0 additions & 80 deletions sample-maps/mis-piano.js

This file was deleted.

4 changes: 2 additions & 2 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
//import './nodes/test/tick-test.js';
//import './nodes/test/tone-test.js';
//import './nodes/test/voice-test.js';
//import './nodes/test/instrument-test.js';
import './nodes/test/instrument-test.js';

// Soundstage
//import './test/soundstage-test.js';

import SoundstagePlayer from './player/module.js';
//import SoundstagePlayer from './player/module.js';

// Report results
done((totals) => (totals.fail > 0 ? fail() : pass()));
Expand Down
5 changes: 4 additions & 1 deletion test/soundstage-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
}],

"events": [
[0, "sequence", "test", "tone", 4]
[0, "sequence", "test", "tone", 4],
[4, "sequence", "test", "tone", 4],
[8, "sequence", "test", "tone", 4],
[12, "sequence", "test", "tone", 4]
]
}

0 comments on commit 36dfa39

Please sign in to comment.