-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.py
141 lines (103 loc) · 3.97 KB
/
new.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from pyo import *
def main():
s = server_start()
###################
# a = Sine(220, 0, 0.1).out()
# a = hello_audio(s)
# a = hello_audio_plus(s)
###################
s.start()
time.sleep(60)
s.stop()
def config_info():
print("Default input device: %i" % pa_get_default_input())
print("Default output device: %i" % pa_get_default_output())
print pa_list_host_apis()
print pa_list_devices()
print pa_get_default_devices_from_host('wasapi')
# s = Server(sr=48000, nchnls=1, buffersize=512, duplex=0, winhost="asio").boot()
# s = Server(sr=48000, buffersize=512, duplex=0, winhost="WASAPI").boot()
# s = Server(sr=48000, buffersize=512, duplex=0, winhost="MME").boot()
# s = Server(sr=48000, buffersize=512, duplex=0, winhost="Windows DirectSound").boot()
# s = Server(sr=48000, buffersize=512, duplex=0, audio='pa', winhost="Windows WDM-KS").boot()
#default
#(self, sr=44100, nchnls=2, buffersize=256, duplex=1, audio='portaudio',
#jackname='pyo', ichnls=None, winhost="wasapi", midi="portmidi"):
def server_start():
host_apis = ["mme", "directsound", "asio", "wasapi", "wdm-ks"]
s = Server(sr=48000, buffersize=512, duplex=0, winhost=host_apis[3])
s.verbosity = 8
# - 1 = error
# - 2 = message
# - 4 = warning
# - 8 = debug
# s.deactivateMidi()
#- setMidiOutputDevice(x): Set the MIDI output device number. See `pm_list_devices()
s.setOutputDevice(8)
s.setInputDevice(9)
s.boot()
return s
def hello_audio_plus(s):
# Drops the gain by 20 dB.
s.amp = 0.1
# Creates a sine wave as the source to process.
a = Sine()
# Passes the sine wave through an harmonizer.
hr = Harmonizer(a).out()
# Also through a chorus.
ch = Chorus(a).out()
# And through a frequency shifter.
sh = FreqShift(a).out()
return [hr, ch, sh]
# return sh
# s.gui(locals())
def hello_audio(s):
# Drops the gain by 20 dB.
s.amp = 0.1
# Creates a sine wave player.
# The out() method starts the processing
# and sends the signal to the output.
return Sine().out()
def gen1(s):
# Sets fundamental frequency.
freq = 187.5
# Impulse train generator.
lfo1 = Sine(.1).range(1, 50)
osc1 = Blit(freq=freq, harms=lfo1, mul=0.3)
# RC circuit.
lfo2 = Sine(.1, mul=0.5, add=0.5)
osc2 = RCOsc(freq=freq, sharp=lfo2, mul=0.3)
# Sine wave oscillator with feedback.
lfo3 = Sine(.1).range(0, .18)
osc3 = SineLoop(freq=freq, feedback=lfo3, mul=0.3)
# Roland JP-8000 Supersaw emulator.
lfo4 = Sine(.1).range(0.1, 0.75)
osc4 = SuperSaw(freq=freq, detune=lfo4, mul=0.3)
# Interpolates between input objects to produce a single output
sel = Selector([osc1, osc2, osc3, osc4]).out()
# sel.ctrl(title="Input interpolator (0=Blit, 1=RCOsc, 2=SineLoop, 3=SuperSaw)")
# Displays the waveform of the chosen source
# sc = Scope(sel)
# Displays the spectrum contents of the chosen source
# sp = Spectrum(sel)
# s.gui(locals())
def gen2():
wav = SquareTable()
env = CosTable([(0,0), (100,1), (500,.3), (8191,0)])
met = Metro(.125, 12).play()
amp = TrigEnv(met, table=env, mul=.1)
pit = TrigXnoiseMidi(met, dist='loopseg', x1=20, scale=1, mrange=(48,84))
out = Osc(table=wav, freq=pit, mul=amp).out()
if __name__ == "__main__":
main()
#N O T E S
#oscillator: generates a repeating sound waveform
# has a controllable parameter for frequency it repeats
#envelope generator: generates an audio signal in the range of 0 to 1,
# volume control
#amplifiercode: simply multiplies, oscillator output with envelope generator output
# sample by sample
#filter: shape the frequency content of the oscillator before it gets to the amplifier.
#Many synthesis algorithms depend on more than one oscillator,
# either in parallel (e.g., additive synthesis, rich sound by adding many simple waveforms)
# or through modulation (e.g., frequency modulation, one oscillator modulates the pitch of another).