Elementary synth
MIDI enabled synthesizer built with Elementary audio library

## Modular synth ​

Built with JS, but operated by WASM lib in a separate audio thread. Construction started around June 2023 and is ongoing till then. Supposed to be gradually substituting the sitewide Tone.js synth used by now.

## Snippets ​

### Mic input ​

When you use el.in() you have to be specific about which channel you want to tap, i.e. el.in({channel: 0}), but then you need to make sure that your WebAudioNode running elementary's engine actually has input signals. So you would need to call core.initialize to declare that input channels are expected, and then you would need to actually connect your web audio input nodes to the node returned by core.initialize. Does that make sense?

js
``````let node = await core.initialize(audioContext, {
numberOfInputs: 1,
numberOfOutputs: 1,
inputChannelCount: , // Notice, it's a mono input
outputChannelCount: ,
}, 8);

let micStream = await navigator.mediaDevices.getUserMedia({audio: true});
let streamSource = audioContext.createMediaStreamSource(micStream);
streamSource.connect(node);
}``````
``````let node = await core.initialize(audioContext, {
numberOfInputs: 1,
numberOfOutputs: 1,
inputChannelCount: , // Notice, it's a mono input
outputChannelCount: ,
}, 8);

let micStream = await navigator.mediaDevices.getUserMedia({audio: true});
let streamSource = audioContext.createMediaStreamSource(micStream);
streamSource.connect(node);
}``````

### Skew by upheaver​

Sharing a useful snippet. JUCE's logskew function in Typescript, if anyone wants to scale their parameter values (for example convert 0-1 range to 20-20000 hz in a non linear way) :

js
``````const clamp = ( min: number, max: number, num: number ) => {
return Math.min(Math.max(num, min), max);
}

const skew = ( min: number, max: number, centerPoint: number ) => {
return Math.log(0.5) / Math.log((centerPoint - min) / (max - min));
}

const logskew = ( a: number, b: number, time: number, centerPoint: number) => {
const proportion = clamp(0, 1, time);
const sk = skew(a, b, centerPoint);
const v = Math.exp (Math.log (proportion) / sk);
return a + (b - a) * v;
}

console.log(logskew( 20, 20000, 0.5, 1000)) // will output 1000``````
``````const clamp = ( min: number, max: number, num: number ) => {
return Math.min(Math.max(num, min), max);
}

const skew = ( min: number, max: number, centerPoint: number ) => {
return Math.log(0.5) / Math.log((centerPoint - min) / (max - min));
}

const logskew = ( a: number, b: number, time: number, centerPoint: number) => {
const proportion = clamp(0, 1, time);
const sk = skew(a, b, centerPoint);
const v = Math.exp (Math.log (proportion) / sk);
return a + (b - a) * v;
}

console.log(logskew( 20, 20000, 0.5, 1000)) // will output 1000``````

## Metronome ​

Yea long story short I think metro was maybe not a great idea and it's worth considering to deprecate it. More effective in my opinion is to take el.time() which monotonically increases, counting the number of elapsed samples, and derive a quarter-note phasor from el.time(). (From bpm you calculate seconds per beat, from which you calculate samples per beat, which you can use to convert el.time() into a phasor running at exactly quarter-note rate). Then of course if you want to change bpm you just change the numbers in your calculation but it will all be perfectly time-synced because it's derived from the actual time signal. And then you can turn your quarter-note phasor into a pulse train with el.le(phasor, 0.5)
{"ft_lang_label":"__label__en","ft_lang_prob":0.68611205,"math_prob":0.94965637,"size":4664,"snap":"2023-40-2023-50","text_gpt3_token_len":1263,"char_repetition_ratio":0.12446352,"word_repetition_ratio":0.4347826,"special_character_ratio":0.2707976,"punctuation_ratio":0.24593717,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9921746,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-21T22:58:53Z\",\"WARC-Record-ID\":\"<urn:uuid:154e5fa4-523c-4fd6-85d5-afd3819d5f0b>\",\"Content-Length\":\"146042\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:de39aa1f-b1be-402d-9e38-0cdb51963d97>\",\"WARC-Concurrent-To\":\"<urn:uuid:a8dc71eb-c10d-425c-aa1d-d314f6cb09f9>\",\"WARC-IP-Address\":\"185.199.108.153\",\"WARC-Target-URI\":\"https://chromatone.center/practice/synth/elementary/\",\"WARC-Payload-Digest\":\"sha1:YFPJ2OBBDWMDKR4TYFVP3HWG6HZDAIM6\",\"WARC-Block-Digest\":\"sha1:BFOQNLQZF5U7TEUMFJ6RGMK463QJIZ3Y\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233506045.12_warc_CC-MAIN-20230921210007-20230922000007-00612.warc.gz\"}"}