From 36dfa395b3f739b659659a558e0ff12f0a9884fa Mon Sep 17 00:00:00 2001 From: Stephen Date: Fri, 22 Sep 2023 02:42:00 +0200 Subject: [PATCH] Adds Steinway piano test --- nodes/sample.js | 10 ++--- nodes/test/instrument-test.js | 68 +++++++++++++++++++++++++++++ sample-maps/mis-piano.js | 80 ----------------------------------- test.html | 4 +- test/soundstage-test.json | 5 ++- 5 files changed, 79 insertions(+), 88 deletions(-) delete mode 100755 sample-maps/mis-piano.js diff --git a/nodes/sample.js b/nodes/sample.js index 3e7057f..a6219dd 100755 --- a/nodes/sample.js +++ b/nodes/sample.js @@ -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) )); @@ -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; }, diff --git a/nodes/test/instrument-test.js b/nodes/test/instrument-test.js index d3cafa1..4d1d0f6 100755 --- a/nodes/test/instrument-test.js +++ b/nodes/test/instrument-test.js @@ -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, { @@ -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); +}); diff --git a/sample-maps/mis-piano.js b/sample-maps/mis-piano.js deleted file mode 100755 index 315d671..0000000 --- a/sample-maps/mis-piano.js +++ /dev/null @@ -1,80 +0,0 @@ - -// MIS Piano -// Sample map for ao-sampler - -// University of Iowa piano samples: -// http://theremin.music.uiowa.edu/MISpiano.html - -// A region looks like this: -// -// { -// url: 'audio.wav', -// frequency: 440 // number -// noteRange: [minLimit, minFade, maxFade, maxLimit], // All numbers as MIDI note numbers -// velocityRange: [minLimit, minFade, maxFade, maxLimit], // All numbers in the range 0-1 -// velocitySensitivity: // 0-1 -// gain: // 0-1 -// muteDecay: // seconds -// phaseAlign: 100 // Aligns the first 100ms of this sample with others with which it is cross-faded -// } - -import { toNoteNumber, floatToFrequency } from '../../../../midi/module.js'; - - -// Note: URLs are temporary! They will change. -var base = 'http://localhost/soundio/soundio/static/audio/mis-piano/samples/Piano.'; -var extension = '.wav'; - -var ppVelocity = [0, 0, 0.0625, 0.125]; -var mfVelocity = [0.0625, 0.125, 0.25, 0.5]; -var ffVelocity = [0.25, 0.5, 1, 1]; - -var ppGain = 6; -var mfGain = 12/7; -var ffGain = 1; - -function createSample(name, dynamic) { - var number = toNoteNumber(name); - var frequency = floatToFrequency(number); - - return { - src: base + dynamic + '.' + name + extension, - frequency: floatToFrequency(440, number), - noteRange: [ - number - (name === 'C2' ? 6 : (name[name.length - 1] === '2' || name[name.length - 1] === '3' || name[name.length - 1] === '4' || name[name.length - 1] === '5' || name[name.length - 1] === '6') ? 2 : 6), - number, - number + ((name[name.length - 1] === '2' || name[name.length - 1] === '3' || name[name.length - 1] === '4' || name[name.length - 1] === '5') ? 2 : 6) - ], - - gainRange: dynamic === 'pp' ? ppVelocity : - dynamic === 'mf' ? mfVelocity : - ffVelocity , - - gain: dynamic === 'pp' ? ppGain : - dynamic === 'mf' ? mfGain : - ffGain , - - attack: 0.002, - release: 0.072, - mute: 0.2, - - // Allow 6 full wavelengths or 12ms, whichever is greater - phaseAlign: Math.max(6 / frequency, 0.012) - }; -} - -var notes = ['C1', 'C2', 'E2', 'Ab2', 'C3', 'E3', 'Ab3', 'C4', 'E4', 'Ab4', 'C5', 'E5', 'Ab5', 'C6', 'C7', 'C8']; -var dynamics = ['pp', 'mf', 'ff']; - -export default { - label: 'MIS Piano', - data: notes - .map(function(name) { - return dynamics.map(function(dynamic) { - return createSample(name, dynamic); - }); - }) - .reduce(function(out, samples) { - return out.concat(samples); - }, []) -}; diff --git a/test.html b/test.html index a747eac..1a0fd7d 100755 --- a/test.html +++ b/test.html @@ -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())); diff --git a/test/soundstage-test.json b/test/soundstage-test.json index de2395e..06f9b24 100644 --- a/test/soundstage-test.json +++ b/test/soundstage-test.json @@ -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] ] }