{
"cells": [
{
"cell_type": "markdown",
"id": "459265e4-faaa-471e-aa06-cd120a390f3b",
"metadata": {},
"source": [
"# Dynamic stochastic synthesis\n",
"\n",
"Xenakis mentions the idea of generating stochastic sound material by directly generating amplitude waves that are calculated stochastically.\n",
"\n",
"We can use an [EnvGen](https://doc.sccode.org/Classes/EnvGen.html) at audiorate to set levels and the time positions of these levels dynamically by other UGens, therefore allowing us to generate waves that obey the ideas of dynamic stochastic synthesis.\n",
"\n",
"![ADSR](https://upload.wikimedia.org/wikipedia/commons/e/ea/ADSR_parameter.svg)\n",
"\n",
"Source: [https://commons.wikimedia.org/wiki/File:ADSR_parameter.svg](https://commons.wikimedia.org/wiki/File:ADSR_parameter.svg)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "45352e9a-7dac-44da-b5d0-82c34e74a90d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-> localhost"
]
}
],
"source": [
"s.boot;"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eac13ce8-7283-4811-937a-69adabd9b992",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Env([ [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new, BinaryOpUGen.new ], [ BinaryOpUGen.new-> Ndef('dynamicStochasticSynthesis')"
]
}
],
"source": [
"Ndef(\\dynamicStochasticSynthesis, {\n",
"\tvar freq = \\freq.kr(150.0);\n",
"\n",
"\t// maybe this is just a too complicated way to\n",
"\t// create a lo-res wavetable synth?\n",
"\t// but at least it can do this w/ n channels\n",
"\n",
"\t// by increasing the steps of the env we can enrich overtones\n",
"\t// how could one modulate this b/c this plays with\n",
"\t// the number of channels in the ugen graph :?\n",
"\t// can go up to 5000\n",
"\tvar steps = 100;\n",
"\tvar levels = steps.collect({\n",
"\t\t// provide a function for each step of our env\n",
"\t\t// !2 makes it stereo but could be increased beyond\n",
"\t\tLFDNoise3.kr(1!2);\n",
"\t});\n",
"\tvar times = steps.collect({\n",
"\t\t// provide a function for each step of our env\n",
"\t\t// !2 makes it stereo but could be increased beyond\n",
"\t\tLFDNoise3.kr(1!2);\n",
"\t})/steps;\n",
"\n",
"\tvar env = EnvGen.ar(\n",
"\t\tenvelope: Env(\n",
"\t\t\tlevels: levels+1, // we need to offset as env seems to perform .min(0.0) on the levels\n",
"\t\t\ttimes: times[1..],\n",
"\t\t\t//times: 1/(freq*(levels.size-1)),\n",
"\t\t\t// another parameter is to fluctuate the envelope times at each section\n",
"\t\t\t// best is to distribute from something which sums up to 1 so its pitch is stable\n",
"\t\t\t// times: (levels.size-1).collect({1/(freq*(levels.size-1))*LFDNoise1.kr(mul: 0.21)}),\n",
"\n",
"\t\t\t// another parameter is the steepness of each segment\n",
"\t\t\t// this could be set globally for the env or for each step independently\n",
"\t\t\tcurve: 0.5,\n",
"\t\t\t// curve: LFDNoise0.ar(1.0)*0.2, // bigger values lead to more metallic sound\n",
"\t\t).postcs,\n",
"\t\tgate: Impulse.ar(freq),\n",
"\t)-1; // remove the offset\n",
"\t0.2*SplayAz.ar(2, env);\n",
"}).play(numChannels: 2);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "25843d1a-011d-4c91-b110-6a40576e4e2e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-> localhost"
]
}
],
"source": [
"%% record \"dynamic_syntha.flac\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "146cdeb2-f01c-43db-b89e-c74ed813a8d6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Recording Stopped: (dynamic_syntha.flac)\n",
"-> Ndef('dynamicStochasticSynthesis')"
]
}
],
"source": [
"s.stopRecording;\n",
"Ndef(\\dynamicStochasticSynthesis).stop(fadeTime: 2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "30201444-6ee0-4c9a-a0ea-fabafbadf077",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-> Ndef('dynamicStochasticSynthesis')"
]
}
],
"source": [
"Ndef(\\dynamicStochasticSynthesis, {\n",
"\tvar sig;\n",
"\t\n",
"\tsig = {\n",
"\t\tvar env;\n",
"\t\tvar levels, time;\n",
"\t\tlevels = { LFDNoise1.kr(MouseX.kr(0.01, 100, 1)) } ! 20;\n",
"\t\ttime = { LFDNoise1.kr(MouseY.kr(0.05, 100, 1)).range(1/200, 1/20000) } ! 19;\n",
"\t\tenv = Env(levels, time[1..]).circle(time[0]);\n",
"\t\tEnvGen.ar(env, timeScale:1/10) * 0.1\n",
"\t\t\n",
"\t} ! 2;\n",
"\t\n",
"\tsig;\n",
"}).play(numChannels: 2);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6dfedfb0-48bc-4146-abb1-bb86db83fa46",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-> localhost"
]
}
],
"source": [
"%% record \"dynamic_synthb.flac\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83108b9e-deeb-4a55-a3b0-2743a70b0ac1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Recording Stopped: (dynamic_synthb.flac)\n",
"-> Ndef('dynamicStochasticSynthesis')"
]
}
],
"source": [
"s.stopRecording;\n",
"Ndef(\\dynamicStochasticSynthesis).stop(fadeTime: 2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d83a60a4-9d33-49f8-b02b-0e73f359b872",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-> Ndef('dynamicStochasticSynthesis')"
]
}
],
"source": [
"Ndef(\\dynamicStochasticSynthesis, {\n",
"\tvar sig, mx, my;\n",
"\tvar nLevels;\n",
"\tmx = MouseX.kr(0, 1);\n",
"\tmy = MouseX.kr(0, 1);\n",
"\t\n",
"\tnLevels = 20;\n",
"\tsig = {\n",
"\t\tvar env;\n",
"\t\tvar levels, time;\n",
"\t\tlevels = { LFDNoise1.kr(mx.linexp(0, 1, 0.01, 100, 1)) } ! nLevels;\n",
"\t\ttime = { LFDNoise1.kr(my.linexp(0, 1, 0.05, 100, 1)).exprange(1/100, 1/2000) } ! (nLevels - 1);\n",
"\t\tenv = Env(levels, time[1..]).circle(time[0]);\n",
"\t\tEnvGen.ar(env, timeScale:1/10) * 0.1\n",
"\t\t\n",
"\t} ! 16;\n",
"\t\n",
"\tSplay.ar(sig)\n",
"\t\n",
"}).play(numChannels: 2);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "37a960cb-ee13-4130-be3c-f169d73bf6ab",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-> localhost"
]
}
],
"source": [
"%% record \"dynamic_synthc.flac\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "00fd779f-f87a-4cea-b6e6-1731e7b9cba4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"