Created
December 4, 2016 20:47
-
-
Save josiah-wolf-oberholtzer/5527f92178604a0e163f5c21c4802663 to your computer and use it in GitHub Desktop.
Supriya Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
import subprocess | |
import time | |
from supriya import Server, SynthDefBuilder, Synth | |
from supriya import patterntools | |
from supriya import synthdefs | |
from supriya import synthdeftools | |
from supriya import ugentools | |
channel_count = 2 | |
with SynthDefBuilder( | |
duration=1.0, | |
level=1.0, | |
out=0, | |
) as builder: | |
window = ugentools.Line.kr( | |
done_action=2, | |
duration=builder['duration'], | |
).hanning_window() | |
source = ugentools.Dust2.ar( | |
density=ugentools.ExpRand.ir(1, 50), | |
) * window | |
ugentools.Out.ar( | |
bus=builder['out'], | |
source=[source, source], | |
) | |
dust_synthdef = builder.build() | |
with SynthDefBuilder( | |
level=synthdeftools.Parameter(value=0.0, lag=15), | |
out=0, | |
) as builder: | |
source = ugentools.In.ar( | |
bus=builder['out'], | |
channel_count=channel_count, | |
) * builder['level'].s_curve() | |
ugentools.ReplaceOut.ar( | |
bus=builder['out'], | |
source=source, | |
) | |
volume_synthdef = builder.build() | |
with SynthDefBuilder( | |
duration=1.0, | |
level=1.0, | |
out=0, | |
) as builder: | |
window = ugentools.Line.kr( | |
done_action=2, | |
duration=builder['duration'], | |
).hanning_window() | |
source = ugentools.In.ar( | |
bus=builder['out'], | |
channel_count=channel_count, | |
) * window | |
source = source[0] + source[1] | |
source += ugentools.LocalIn.ar(channel_count=1) | |
allpasses = [] | |
allpass_count = 16 | |
maximum_delay_time = 0.05 | |
for _ in range(allpass_count): | |
allpass = ugentools.AllpassC.ar( | |
decay_time=ugentools.LFDNoise3.kr( | |
frequency=ugentools.ExpRand.ir(0.1, 5), | |
).scale(-1, 1, 0., 0.1), | |
delay_time=ugentools.LFDNoise3.kr( | |
frequency=ugentools.ExpRand.ir(0.1, 5), | |
).scale(-1, 1, 0., maximum_delay_time), | |
maximum_delay_time=maximum_delay_time, | |
source=source, | |
) | |
allpasses.append(allpass) | |
source = ugentools.Mix.new(allpasses) / allpass_count | |
source = ugentools.LeakDC.ar(source=source) | |
source = ugentools.Limiter.ar(source=source) | |
ugentools.XOut.ar( | |
bus=builder['out'], | |
crossfade=window, | |
source=[source, source], | |
) | |
ugentools.LocalOut.ar( | |
source=source * -0.9 * abs(ugentools.LFDNoise1.kr(frequency=0.1)) | |
) | |
mono_chorus_synthdef = builder.build() | |
with SynthDefBuilder( | |
duration=1.0, | |
level=1.0, | |
out=0, | |
damping=0.5, | |
room_size=0.5, | |
) as builder: | |
window = ugentools.Line.kr( | |
done_action=2, | |
duration=builder['duration'], | |
).hanning_window() | |
source = ugentools.In.ar( | |
bus=builder['out'], | |
channel_count=channel_count, | |
) * window | |
source = ugentools.FreeVerb.ar( | |
source=source, | |
damping=builder['damping'], | |
room_size=builder['room_size'], | |
mix=1.0, | |
) | |
source = (source * 1.5).tanh() | |
source = ugentools.LeakDC.ar( | |
source=source, | |
) | |
source = ugentools.Limiter.ar(source=source) | |
ugentools.XOut.ar( | |
bus=builder['out'], | |
crossfade=window, | |
source=source, | |
) | |
freeverb_synthdef = builder.build() | |
with SynthDefBuilder( | |
duration=1.0, | |
level=1.0, | |
out=0, | |
pitch_shift=0., | |
pitch_dispersion=0, | |
time_dispersion=0, | |
window_size=0.5, | |
) as builder: | |
window = ugentools.Line.kr( | |
done_action=2, | |
duration=builder['duration'], | |
).hanning_window() | |
source = ugentools.In.ar( | |
bus=builder['out'], | |
channel_count=channel_count, | |
) * window | |
source = ugentools.PitchShift.ar( | |
source=source, | |
pitch_dispersion=builder['pitch_dispersion'], | |
pitch_ratio=builder['pitch_shift'].semitones_to_ratio(), | |
time_dispersion=builder['time_dispersion'] * builder['window_size'], | |
window_size=builder['window_size'], | |
) | |
source = ugentools.LeakDC.ar( | |
source=source, | |
) | |
source = ugentools.Limiter.ar(source=source) | |
ugentools.XOut.ar( | |
bus=builder['out'], | |
crossfade=window, | |
source=source, | |
) | |
pitchshift_synthdef = builder.build() | |
with SynthDefBuilder( | |
duration=1.0, | |
level=1.0, | |
out=0, | |
) as builder: | |
window = ugentools.Line.kr( | |
done_action=2, | |
duration=builder['duration'], | |
).hanning_window() | |
source = ugentools.In.ar( | |
bus=builder['out'], | |
channel_count=channel_count, | |
) * window | |
source += ugentools.LocalIn.ar(channel_count=channel_count) | |
allpasses = [] | |
maximum_delay = ugentools.Rand.ir(0.1, 1) | |
for output in source: | |
for _ in range(3): | |
output = ugentools.AllpassC.ar( | |
decay_time=ugentools.LFDNoise3.kr( | |
frequency=ugentools.ExpRand.ir(0.01, 1), | |
).scale(-1, 1, 0.001, 1), | |
delay_time=ugentools.LFDNoise3.kr( | |
frequency=ugentools.ExpRand.ir(0.01, 1), | |
).scale(-1, 1, 0.001, 1) * maximum_delay, | |
maximum_delay_time=maximum_delay, | |
source=output, | |
) | |
allpasses.append(output) | |
source = synthdeftools.UGenArray(allpasses) | |
source = ugentools.LeakDC.ar( | |
source=source, | |
) | |
source = ugentools.Limiter.ar(source=source) | |
ugentools.XOut.ar( | |
bus=builder['out'], | |
crossfade=window, | |
source=source, | |
) | |
ugentools.LocalOut.ar( | |
source=source * -0.9 * ugentools.LFDNoise1.kr(frequency=0.1) | |
) | |
allpass_synthdef = builder.build() | |
source_pattern = patterntools.Pbind( | |
synthdef=patterntools.Prand( | |
[ | |
synthdefs.default, | |
synthdefs.default, | |
synthdefs.default, | |
dust_synthdef, | |
], | |
repetitions=None, | |
), | |
amplitude=patterntools.Pwhite(), | |
delta=patterntools.Pwhite(0.0, 2.5), | |
duration=patterntools.Pwhite(0.05, 5), | |
frequency=patterntools.Pwhite(minimum=55, maximum=1760), | |
pan=patterntools.Pwhite(), | |
) | |
pitchshift_pattern = patterntools.Pbind( | |
synthdef=pitchshift_synthdef, | |
level=patterntools.Pwhite(), | |
delta=patterntools.Pwhite(0, 5), | |
duration=patterntools.Pwhite(0.5, 10), | |
pitch_shift=patterntools.Pwhite(-3.0, 3.0), | |
pitch_dispersion=patterntools.Pwhite(0., 0.1), | |
time_dispersion=patterntools.Pwhite(), | |
window_size=patterntools.Pwhite(0.1, 2.0), | |
) | |
freeverb_pattern = patterntools.Pbind( | |
synthdef=freeverb_synthdef, | |
level=patterntools.Pwhite(), | |
delta=patterntools.Pwhite(0, 5), | |
duration=patterntools.Pwhite(0.5, 20), | |
damping=patterntools.Pwhite(), | |
room_size=patterntools.Pwhite(), | |
) | |
allpass_pattern = patterntools.Pbind( | |
synthdef=allpass_synthdef, | |
level=patterntools.Pwhite(), | |
delta=patterntools.Pwhite(0, 5), | |
duration=patterntools.Pwhite(0.5, 20), | |
) | |
mono_chorus_pattern = patterntools.Pbind( | |
synthdef=mono_chorus_synthdef, | |
level=patterntools.Pwhite(), | |
delta=patterntools.Pwhite(0, 5), | |
duration=patterntools.Pwhite(0.5, 20), | |
) | |
pattern = patterntools.Pbus( | |
patterntools.Ppar([ | |
freeverb_pattern, | |
mono_chorus_pattern, | |
pitchshift_pattern, | |
freeverb_pattern, | |
allpass_pattern, | |
pitchshift_pattern, | |
source_pattern, | |
]), | |
) | |
server = Server().boot(memory_size=8192 * 16) | |
for synthdef in ( | |
allpass_synthdef, | |
freeverb_synthdef, | |
mono_chorus_synthdef, | |
pitchshift_synthdef, | |
synthdefs.default, | |
synthdefs.multiband_compressor, | |
volume_synthdef, | |
dust_synthdef, | |
): | |
synthdef.allocate() | |
multiband_compressor_synth = Synth( | |
synthdefs.multiband_compressor, | |
band_1_threshold=0.85, | |
band_2_threshold=0.85, | |
band_3_threshold=0.85, | |
band_4_threshold=0.85, | |
band_1_pregain=1.25, | |
band_2_pregain=1.25, | |
band_3_pregain=1.25, | |
band_4_pregain=1.25, | |
) | |
volume_synth = Synth(volume_synthdef) | |
server.root_node.extend([multiband_compressor_synth, volume_synth]) | |
server.recorder.start( | |
'~/Desktop/output.aiff', | |
channel_count=channel_count, | |
) | |
volume_synth.controls['level'] = 1.0 | |
for _ in range(4): | |
pattern.play() | |
time.sleep(10) | |
time.sleep(180) | |
volume_synth.controls['level'] = 0.0 | |
time.sleep(5 + server.latency) | |
server.quit() | |
command = 'lame -b 192 ~/Desktop/output.aiff' | |
subprocess.call(command, shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment