|
1 | 1 | import {ElementaryWebAudioRenderer as core, el} from '@elemaudio/core'; |
2 | 2 | import srvb from '@elemaudio/srvb'; |
3 | | -import teoria from 'teoria'; |
4 | 3 |
|
5 | | -import Synth from './Synth'; |
| 4 | +import genSynth from './genSynth'; |
6 | 5 | import {clear, draw} from './drawing'; |
7 | 6 |
|
8 | 7 |
|
@@ -31,65 +30,13 @@ const state = { |
31 | 30 | ], |
32 | 31 | }; |
33 | 32 |
|
34 | | -// Random seed stuff |
35 | | -let baseNote = teoria.note.fromKey(25 + Math.round(Math.random() * 24)); |
36 | | -let accentNote = teoria.note.fromKey(baseNote.key() + 12); |
37 | | -let scaleType = ['major', 'minor', 'lydian', 'mixolydian'][Math.round(Math.random() * 3)]; |
38 | | -let scale = accentNote.scale(scaleType).notes().concat(baseNote.scale(scaleType).notes()); |
39 | | -let density = 0.02 + Math.random() * 0.2; |
40 | | -let similarity = Math.random(); |
41 | | - |
42 | | -console.log(`${baseNote.toString()} ${scaleType} ${density.toFixed(3)}/${similarity.toFixed(3)} alpha:${globalAlpha.toFixed(3)}`); |
43 | | - |
44 | | -// Record a bunch of operations against our synth |
45 | | -let syn1 = new Synth('ll', 4); |
46 | | -let syn2 = new Synth('rr', 4); |
47 | | -let adsrDecay = 3.5; |
48 | | -let nextNote1 = 0; |
49 | | -let nextNote2 = 0; |
50 | | -let bpm = 76; |
51 | | -let n64Rate = 1 / ((60 / bpm) / 8); |
52 | | - |
53 | | -// Eight bars of 16th notes |
54 | | -let atLeastOneNote = false; |
55 | | - |
56 | | -while (!atLeastOneNote) { |
57 | | - syn1.reset(); |
58 | | - syn2.reset(); |
59 | | - |
60 | | - for (let i = 0; i < 128; ++i) { |
61 | | - let playLeft = Math.random() < density; |
62 | | - let playSimilar = Math.random() < similarity; |
63 | | - |
64 | | - if (playLeft) { |
65 | | - syn1.noteOff(nextNote1); |
66 | | - nextNote1 = scale[Math.floor(Math.random() * (scale.length - 1))].fq(); |
67 | | - syn1.noteOn(nextNote1, 0.125 + Math.random()); |
68 | | - atLeastOneNote = true; |
69 | | - } |
70 | | - |
71 | | - // If we have high similarity, we duplicate the note event into the right |
72 | | - // channel synth. If we fail our similarity check, we optionally play whatever |
73 | | - // note we want in the right channel synth |
74 | | - if (playLeft && playSimilar) { |
75 | | - syn2.noteOff(nextNote2); |
76 | | - nextNote2 = nextNote1; |
77 | | - syn2.noteOn(nextNote2, Math.random()); |
78 | | - } else { |
79 | | - if (Math.random() < density) { |
80 | | - syn2.noteOff(nextNote2); |
81 | | - nextNote2 = scale[Math.floor(Math.random() * (scale.length - 1))].fq(); |
82 | | - syn2.noteOn(nextNote2, 0.125 + Math.random() * 0.5); |
83 | | - atLeastOneNote = true; |
84 | | - } |
85 | | - } |
86 | | - |
87 | | - syn1.step(); |
88 | | - syn2.step(); |
89 | | - } |
90 | | -} |
91 | | - |
| 33 | +// Our main audio rendering step |
92 | 34 | core.on('load', function(e) { |
| 35 | + const bpm = 76; |
| 36 | + const n64Rate = 1 / ((60 / bpm) / 8); |
| 37 | + const adsrDecay = 3.5; |
| 38 | + const [syn1, syn2] = genSynth(); |
| 39 | + |
93 | 40 | let ll = el.add(...syn1.render(function(key, gs, fs, vs, i) { |
94 | 41 | let t = el.train(n64Rate); |
95 | 42 | let env = el.adsr(0.01, adsrDecay, 0, adsrDecay, el.seq({key: `${key}:gs`, seq: gs, hold: true}, t)); |
|
0 commit comments