hum 0.1.33__tar.gz → 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hum-1.0.2/PKG-INFO +27 -0
- hum-1.0.2/README.md +15 -0
- hum-1.0.2/hum/__init__.py +10 -0
- hum-1.0.2/hum/examples/pyo_util_examples.py +194 -0
- hum-1.0.2/hum/extra_util.py +40 -0
- hum-1.0.2/hum/pyo_util.py +885 -0
- hum-1.0.2/hum/scrap/belangeo_Degradation.py +104 -0
- hum-1.0.2/hum/util.py +131 -0
- {hum-0.1.33 → hum-1.0.2}/hum/utils/__init__.py +1 -2
- {hum-0.1.33 → hum-1.0.2}/hum/utils/plotting.py +28 -2
- hum-1.0.2/hum.egg-info/PKG-INFO +27 -0
- hum-1.0.2/hum.egg-info/SOURCES.txt +21 -0
- hum-1.0.2/hum.egg-info/requires.txt +10 -0
- {hum-0.1.33 → hum-1.0.2}/setup.cfg +13 -12
- hum-0.1.33/PKG-INFO +0 -570
- hum-0.1.33/README.md +0 -559
- hum-0.1.33/hum/__init__.py +0 -18
- hum-0.1.33/hum/examples/annotated_sounds.py +0 -70
- hum-0.1.33/hum/examples/tagged_intervals.py +0 -246
- hum-0.1.33/hum/gen/__init__.py +0 -46
- hum-0.1.33/hum/gen/diagnosis_sounds.py +0 -439
- hum-0.1.33/hum/gen/signal_generators.py +0 -162
- hum-0.1.33/hum/gen/simple.py +0 -72
- hum-0.1.33/hum/gen/sine_mix.py +0 -213
- hum-0.1.33/hum/gen/util.py +0 -5
- hum-0.1.33/hum/gen/voiced_time.py +0 -141
- hum-0.1.33/hum/lite_sample_sounds.py +0 -258
- hum-0.1.33/hum/sound/__init__.py +0 -5
- hum-0.1.33/hum/sound/audio.py +0 -277
- hum-0.1.33/hum/sound/audio_librosa.py +0 -298
- hum-0.1.33/hum/util.py +0 -55
- hum-0.1.33/hum/utils/infinite_waveform.py +0 -52
- hum-0.1.33/hum/utils/librosa_utils.py +0 -1408
- hum-0.1.33/hum.egg-info/PKG-INFO +0 -570
- hum-0.1.33/hum.egg-info/SOURCES.txt +0 -32
- hum-0.1.33/hum.egg-info/requires.txt +0 -12
- {hum-0.1.33 → hum-1.0.2}/LICENSE +0 -0
- {hum-0.1.33 → hum-1.0.2}/hum/examples/__init__.py +0 -0
- {hum-0.1.33 → hum-1.0.2}/hum/scrap/__init__.py +0 -0
- {hum-0.1.33 → hum-1.0.2}/hum/utils/date_ticks.py +0 -0
- {hum-0.1.33 → hum-1.0.2}/hum.egg-info/dependency_links.txt +0 -0
- {hum-0.1.33 → hum-1.0.2}/hum.egg-info/not-zip-safe +0 -0
- {hum-0.1.33 → hum-1.0.2}/hum.egg-info/top_level.txt +0 -0
- {hum-0.1.33 → hum-1.0.2}/setup.py +0 -0
hum-1.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: hum
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: A python synthesizer for creating and manipulating audio signals.
|
|
5
|
+
Home-page: https://github.com/thorwhalen/hum
|
|
6
|
+
License: mit
|
|
7
|
+
Keywords: signal processing,audio generation,data,synthesizer,sonification
|
|
8
|
+
Platform: any
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Provides-Extra: testing
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
|
|
13
|
+
# hum
|
|
14
|
+
|
|
15
|
+
A python synthesizer for creating and manipulating audio signals.
|
|
16
|
+
|
|
17
|
+
To install: ```pip install hum```
|
|
18
|
+
|
|
19
|
+
Note: Some functionalities depend on [pyo](https://belangeo.github.io/pyo/download.html),
|
|
20
|
+
which itself requires some tools (namely, [portaudio](https://www.portaudio.com/)
|
|
21
|
+
and [Portmidi](https://github.com/PortMidi/portmidi)) that _may_ have to be
|
|
22
|
+
installed manually.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
hum-1.0.2/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# hum
|
|
2
|
+
|
|
3
|
+
A python synthesizer for creating and manipulating audio signals.
|
|
4
|
+
|
|
5
|
+
To install: ```pip install hum```
|
|
6
|
+
|
|
7
|
+
Note: Some functionalities depend on [pyo](https://belangeo.github.io/pyo/download.html),
|
|
8
|
+
which itself requires some tools (namely, [portaudio](https://www.portaudio.com/)
|
|
9
|
+
and [Portmidi](https://github.com/PortMidi/portmidi)) that _may_ have to be
|
|
10
|
+
installed manually.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Example functions for testing the Synth class
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def example_01_basic_dual_osc():
|
|
7
|
+
from hum.pyo_util import Synth, DFLT_PYO_SR
|
|
8
|
+
import time
|
|
9
|
+
from pyo import Sine, Mix, ButLP, SigTo
|
|
10
|
+
|
|
11
|
+
# Dual sine oscillator with LFO-controlled lowpass filter
|
|
12
|
+
def dual_osc_graph(freq1=220, freq2=330, amp=0.3, lfo_freq=0.5):
|
|
13
|
+
osc1 = Sine(freq=freq1)
|
|
14
|
+
osc2 = Sine(freq=freq2)
|
|
15
|
+
blend = Mix([osc1, osc2], voices=2) * amp
|
|
16
|
+
lfo = Sine(freq=lfo_freq).range(400, 2000)
|
|
17
|
+
return ButLP(blend, freq=lfo)
|
|
18
|
+
|
|
19
|
+
synth = Synth(dual_osc_graph, nchnls=2)
|
|
20
|
+
# 👂 Frequency shifts with LFO sweeping filter
|
|
21
|
+
with synth:
|
|
22
|
+
time.sleep(0.5)
|
|
23
|
+
synth["freq1"] = 440
|
|
24
|
+
time.sleep(1)
|
|
25
|
+
synth["freq2"] = SigTo(550, time=0.5) # Smooth shift
|
|
26
|
+
time.sleep(0.5)
|
|
27
|
+
synth.knobs.update(dict(freq1={"value": 880, "time": 0.1}, freq2=1100))
|
|
28
|
+
time.sleep(1)
|
|
29
|
+
|
|
30
|
+
# ------------------------- replay the events -------------------------
|
|
31
|
+
time.sleep(0.5)
|
|
32
|
+
|
|
33
|
+
events = synth.get_recording()
|
|
34
|
+
synth.replay_events(events)
|
|
35
|
+
|
|
36
|
+
# ------------------------- get the wav_bytes of this recording --------------------
|
|
37
|
+
wav_bytes = synth.render_events()
|
|
38
|
+
assert isinstance(wav_bytes, bytes)
|
|
39
|
+
assert len(wav_bytes) > 0, "No bytes returned"
|
|
40
|
+
# verify that the bytes are a valid WAV file
|
|
41
|
+
import recode
|
|
42
|
+
|
|
43
|
+
wf, sr = recode.decode_wav_bytes(wav_bytes)
|
|
44
|
+
assert sr == DFLT_PYO_SR, "Sample rate mismatch"
|
|
45
|
+
len(wf) > sr * 3, "Not enough samples in the WAV file"
|
|
46
|
+
|
|
47
|
+
return wf, sr
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def example_02_distortion_and_reverb():
|
|
51
|
+
from hum.pyo_util import Synth
|
|
52
|
+
import time
|
|
53
|
+
from pyo import Sine, Atan2, Biquadx, WGVerb, SigTo
|
|
54
|
+
|
|
55
|
+
# Distorted sine tone through a filter and reverb
|
|
56
|
+
def distorted_reverb_graph(freq=440, amp=0.25, cutoff=1000):
|
|
57
|
+
base = Sine(freq=freq) * amp
|
|
58
|
+
distorted = Atan2(base * 4)
|
|
59
|
+
filtered = Biquadx(distorted, freq=cutoff, q=3, type=0)
|
|
60
|
+
return WGVerb(filtered, feedback=0.8, cutoff=5000, bal=0.3)
|
|
61
|
+
|
|
62
|
+
# 👂 Brightness control of distorted tone
|
|
63
|
+
with Synth(distorted_reverb_graph) as synth:
|
|
64
|
+
time.sleep(1)
|
|
65
|
+
synth["cutoff"] = 500
|
|
66
|
+
time.sleep(1)
|
|
67
|
+
synth["cutoff"] = SigTo(3000, time=2.0)
|
|
68
|
+
time.sleep(2)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def example_03_detuned_polyphonic_feel():
|
|
72
|
+
from hum.pyo_util import Synth
|
|
73
|
+
import time
|
|
74
|
+
from pyo import Sine, Mix, MoogLP, SigTo
|
|
75
|
+
|
|
76
|
+
# Two slightly detuned sine waves with resonant Moog filter
|
|
77
|
+
def poly_synth_graph(freq=330, amp=0.2, cutoff=800, res=0.5):
|
|
78
|
+
osc1 = Sine(freq=freq * 0.995)
|
|
79
|
+
osc2 = Sine(freq=freq * 1.005)
|
|
80
|
+
summed = Mix([osc1, osc2], voices=2) * amp
|
|
81
|
+
return MoogLP(summed, freq=cutoff, res=res)
|
|
82
|
+
|
|
83
|
+
# 👂 Sweeping resonance and cutoff
|
|
84
|
+
with Synth(poly_synth_graph) as synth:
|
|
85
|
+
time.sleep(1)
|
|
86
|
+
synth["cutoff"] = 200
|
|
87
|
+
time.sleep(1)
|
|
88
|
+
synth["cutoff"] = SigTo(4000, time=1.5)
|
|
89
|
+
synth["res"] = 0.9
|
|
90
|
+
time.sleep(2)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def example_04_dynamic_tremolo_and_filter_sweep():
|
|
94
|
+
from hum.pyo_util import Synth
|
|
95
|
+
import time
|
|
96
|
+
from pyo import Sine, ButLP
|
|
97
|
+
|
|
98
|
+
# Tremolo via amplitude modulation with filter
|
|
99
|
+
def tremolo_filter_graph(freq=440, trem_rate=3.0, amp=0.5, cutoff=1200):
|
|
100
|
+
tone = Sine(freq=freq)
|
|
101
|
+
trem = Sine(freq=trem_rate).range(0.2, 1.0)
|
|
102
|
+
modulated = tone * trem * amp
|
|
103
|
+
return ButLP(modulated, freq=cutoff)
|
|
104
|
+
|
|
105
|
+
# 👂 Tremolo rate and filter brightness changes
|
|
106
|
+
with Synth(tremolo_filter_graph) as synth:
|
|
107
|
+
time.sleep(1)
|
|
108
|
+
synth["trem_rate"] = 7.0
|
|
109
|
+
time.sleep(1)
|
|
110
|
+
synth["cutoff"] = 400
|
|
111
|
+
time.sleep(1)
|
|
112
|
+
synth["cutoff"] = 2000
|
|
113
|
+
time.sleep(2)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def example_05_offline_rendering():
|
|
117
|
+
import statistics
|
|
118
|
+
from hum.pyo_util import OfflineSynthRenderer
|
|
119
|
+
from pyo import Sine, ButLP
|
|
120
|
+
|
|
121
|
+
import recode
|
|
122
|
+
|
|
123
|
+
def my_graph(frequency, tempo, amplitude, cutoff):
|
|
124
|
+
osc = Sine(freq=frequency)
|
|
125
|
+
lfo = Sine(freq=tempo / 60.0).range(0.2, 1.0)
|
|
126
|
+
modulated = osc * amplitude * lfo
|
|
127
|
+
return ButLP(modulated, freq=cutoff)
|
|
128
|
+
|
|
129
|
+
frames = [
|
|
130
|
+
{"tempo": 120, "frequency": 440, "amplitude": 0.5, "cutoff": 1000},
|
|
131
|
+
{"tempo": 135, "frequency": 330, "amplitude": 0.7, "cutoff": 500},
|
|
132
|
+
{"tempo": 100, "frequency": 550, "amplitude": 0.3, "cutoff": 2000},
|
|
133
|
+
{"tempo": 150, "frequency": 220, "amplitude": 0.9, "cutoff": 750},
|
|
134
|
+
{"tempo": 110, "frequency": 660, "amplitude": 0.6, "cutoff": 1500},
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
renderer = OfflineSynthRenderer(
|
|
138
|
+
synth_func=my_graph,
|
|
139
|
+
parameter_frames=frames,
|
|
140
|
+
frame_durations=2.0,
|
|
141
|
+
sr=44100,
|
|
142
|
+
egress=recode.decode_wav_bytes,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
wf, sr = renderer.render()
|
|
146
|
+
assert sr == 44100
|
|
147
|
+
assert isinstance(wf, list)
|
|
148
|
+
assert len(wf) == int(len(frames) * 2.0 * 44100)
|
|
149
|
+
assert isinstance(wf[0], int)
|
|
150
|
+
assert statistics.stdev(wf) > 0, "all samples are the same, something is wrong"
|
|
151
|
+
|
|
152
|
+
return wf, sr
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def example_06_knob_recording_playback():
|
|
156
|
+
from hum.pyo_util import Synth
|
|
157
|
+
import time
|
|
158
|
+
import recode
|
|
159
|
+
from pyo import Sine, ButLP, SigTo
|
|
160
|
+
|
|
161
|
+
# Dual sine oscillator with LFO-controlled lowpass filter
|
|
162
|
+
def dual_osc_graph(freq1=220, freq2=330, amp=0.3, lfo_freq=0.5):
|
|
163
|
+
osc1 = Sine(freq=freq1)
|
|
164
|
+
osc2 = Sine(freq=freq2)
|
|
165
|
+
blend = Mix([osc1, osc2], voices=2) * amp
|
|
166
|
+
lfo = Sine(freq=lfo_freq).range(400, 2000)
|
|
167
|
+
return ButLP(blend, freq=lfo)
|
|
168
|
+
|
|
169
|
+
synth = Synth(dual_osc_graph)
|
|
170
|
+
|
|
171
|
+
with synth:
|
|
172
|
+
synth["freq1"] = 440
|
|
173
|
+
time.sleep(1)
|
|
174
|
+
synth["freq2"] = SigTo(550, time=0.5) # Smooth shift
|
|
175
|
+
time.sleep(1)
|
|
176
|
+
synth.knobs.update(dict(freq1={"value": 880, "time": 0.1}, freq2=1100))
|
|
177
|
+
time.sleep(1)
|
|
178
|
+
|
|
179
|
+
control_events = synth.get_recording()
|
|
180
|
+
assert len(control_events) > 0, "No frames recorded"
|
|
181
|
+
|
|
182
|
+
def dual_osc_graph_offline(freq1=220, freq2=330, amp=0.3, lfo_freq=0.5):
|
|
183
|
+
osc1 = Sine(freq=freq1)
|
|
184
|
+
osc2 = Sine(freq=freq2)
|
|
185
|
+
blend = Mix([osc1, osc2], voices=2) * amp
|
|
186
|
+
lfo_freq_sig = (
|
|
187
|
+
lfo_freq if isinstance(lfo_freq, (PyoObject, SigTo)) else Sig(lfo_freq)
|
|
188
|
+
)
|
|
189
|
+
lfo = Sine(freq=lfo_freq_sig).range(400, 2000)
|
|
190
|
+
return ButLP(blend, freq=lfo)
|
|
191
|
+
|
|
192
|
+
synth2 = Synth(dual_osc_graph_offline)
|
|
193
|
+
wf, sr = synth2.render_events(control_events, egress=recode.decode_wav_bytes)
|
|
194
|
+
return wf, sr
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Extra utils that require more dependencies"""
|
|
2
|
+
|
|
3
|
+
from typing import Iterable, Callable
|
|
4
|
+
from functools import partial
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def estimate_chunk_frequency(chk: Iterable, sr: int):
|
|
8
|
+
from scipy.signal import find_peaks
|
|
9
|
+
from scipy.fft import fft, fftfreq
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
# Perform FFT
|
|
13
|
+
N = len(chk)
|
|
14
|
+
yf = fft(chk)
|
|
15
|
+
xf = fftfreq(N, 1 / sr)[: N // 2]
|
|
16
|
+
|
|
17
|
+
# Find peaks in the FFT result
|
|
18
|
+
peaks, _ = find_peaks(np.abs(yf[: N // 2]), height=0)
|
|
19
|
+
|
|
20
|
+
# Get the frequencies of the peaks
|
|
21
|
+
peak_freqs = xf[peaks]
|
|
22
|
+
|
|
23
|
+
# Return the frequency with the highest amplitude
|
|
24
|
+
return peak_freqs[np.argmax(np.abs(yf[peaks]))]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def estimate_frequencies(wf: Iterable, sr: int, chunker: int | Callable):
|
|
28
|
+
if isinstance(chunker, int):
|
|
29
|
+
chk_size = chunker
|
|
30
|
+
from hum.util import simple_chunker
|
|
31
|
+
|
|
32
|
+
chunker = partial(simple_chunker, chk_size=chk_size, include_tail=True)
|
|
33
|
+
elif not callable(chunker):
|
|
34
|
+
raise ValueError("chunker must be an int or callable")
|
|
35
|
+
|
|
36
|
+
for chk in chunker(wf):
|
|
37
|
+
if len(chk) == 0:
|
|
38
|
+
continue
|
|
39
|
+
freq = estimate_chunk_frequency(chk, sr)
|
|
40
|
+
yield freq
|