Fix most of the time
This commit is contained in:
parent
dc9225f74d
commit
1ff7c3b76a
2 changed files with 44 additions and 25 deletions
10
README.md
Normal file
10
README.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
LV2 plugins:
|
||||||
|
- Linux Studio Plugins `lv2-lsp-plugins`
|
||||||
|
|
||||||
|
C requirements (headers):
|
||||||
|
- lilv `liblilv-0-devel`
|
||||||
|
- sndfile `libsndfile-devel`
|
||||||
|
|
||||||
|
Python requirements:
|
||||||
|
- lilv `python3-lilv` (not on pypi)
|
||||||
|
- soundfile `python311-SoundFile`
|
59
main.py
59
main.py
|
@ -1,11 +1,11 @@
|
||||||
import lilv, numpy, wave
|
import lilv, numpy, time
|
||||||
import soundfile
|
import soundfile
|
||||||
from ctypes import c_float, c_int
|
|
||||||
|
CHUNK_SIZE = 128
|
||||||
|
|
||||||
frames, sample_rate = soundfile.read('a.flac')
|
frames, sample_rate = soundfile.read('a.flac')
|
||||||
num_frames = len(frames)
|
num_frames = len(frames)
|
||||||
print(f"{sample_rate}Hz | {int(num_frames/sample_rate/60)}:{int(num_frames/sample_rate%60)}")
|
print(f"{sample_rate}Hz | {int(num_frames/sample_rate/60)}:{int(num_frames/sample_rate%60)}")
|
||||||
print(frames.dtype)
|
|
||||||
frames = frames.astype(numpy.float32)
|
frames = frames.astype(numpy.float32)
|
||||||
|
|
||||||
world = lilv.World()
|
world = lilv.World()
|
||||||
|
@ -14,57 +14,66 @@ world.load_all()
|
||||||
plugins = world.get_all_plugins()
|
plugins = world.get_all_plugins()
|
||||||
|
|
||||||
plugin = plugins.get_by_uri("http://lsp-plug.in/plugins/lv2/comp_delay_x2_stereo")
|
plugin = plugins.get_by_uri("http://lsp-plug.in/plugins/lv2/comp_delay_x2_stereo")
|
||||||
|
if plugin is None:
|
||||||
|
print("No plugin comp_delay_x2_stereo")
|
||||||
|
exit()
|
||||||
|
|
||||||
print(plugin.get_name())
|
print("Using:", plugin.get_name())
|
||||||
|
|
||||||
for i in range(plugin.get_num_ports()):
|
for i in range(plugin.get_num_ports()):
|
||||||
port = plugin.get_port(i)
|
port = plugin.get_port(i)
|
||||||
print(f"Port {i}: {port.get_name()} = {port.get_range()[0]}")
|
#print(f"Port {i}: {port.get_name()} = {port.get_range()[0]}")
|
||||||
|
|
||||||
instance = lilv.Instance(plugin, sample_rate)
|
instance = lilv.Instance(plugin, sample_rate)
|
||||||
|
|
||||||
|
instance.connect_port(4, numpy.array([1], dtype=numpy.int32)) # while 1 is default it needs to be set as int32 for whatever reason
|
||||||
|
|
||||||
|
knob_mode = numpy.array([2], dtype=numpy.float32) # by the way, this can't be put into connect_port, even if just the number is a variable
|
||||||
|
instance.connect_port(16, knob_mode)
|
||||||
|
|
||||||
|
knob_time = numpy.array([10.0], dtype=numpy.float32) # but this can?????? it can be any of the three
|
||||||
|
instance.connect_port(22, knob_time)
|
||||||
|
|
||||||
output_left = numpy.zeros(num_frames, frames.dtype)
|
output_left = numpy.zeros(num_frames, frames.dtype)
|
||||||
output_right = numpy.zeros(num_frames, frames.dtype)
|
output_right = numpy.zeros(num_frames, frames.dtype)
|
||||||
|
|
||||||
input_left_chunk = numpy.zeros(512, frames.dtype)
|
input_left_chunk = numpy.zeros(CHUNK_SIZE, frames.dtype)
|
||||||
input_right_chunk = numpy.zeros(512, frames.dtype)
|
input_right_chunk = numpy.zeros(CHUNK_SIZE, frames.dtype)
|
||||||
output_left_chunk = numpy.zeros(512, frames.dtype)
|
output_left_chunk = numpy.zeros(CHUNK_SIZE, frames.dtype)
|
||||||
output_right_chunk = numpy.zeros(512, frames.dtype)
|
output_right_chunk = numpy.zeros(CHUNK_SIZE, frames.dtype)
|
||||||
|
|
||||||
instance.connect_port(0, input_left_chunk)
|
instance.connect_port(0, input_left_chunk)
|
||||||
instance.connect_port(1, input_right_chunk)
|
instance.connect_port(1, input_right_chunk)
|
||||||
instance.connect_port(2, output_left_chunk)
|
instance.connect_port(2, output_left_chunk)
|
||||||
instance.connect_port(3, output_right_chunk)
|
instance.connect_port(3, output_right_chunk)
|
||||||
|
|
||||||
mode_left = numpy.array([2], dtype=numpy.int32)
|
|
||||||
instance.connect_port(5, mode_left)
|
|
||||||
|
|
||||||
time_left = numpy.array([0.0], dtype=numpy.float32)
|
|
||||||
instance.connect_port(11, time_left)
|
|
||||||
|
|
||||||
mode_right = numpy.array([2], dtype=numpy.int32)
|
|
||||||
instance.connect_port(16, mode_right)
|
|
||||||
|
|
||||||
time_right = numpy.array([500.0], dtype=numpy.float32)
|
|
||||||
instance.connect_port(22, time_right)
|
|
||||||
|
|
||||||
instance.activate()
|
instance.activate()
|
||||||
|
|
||||||
print(f"frames: {num_frames}\n")
|
print(f"\nFrames: {num_frames}")
|
||||||
for start in range(0, num_frames, 512):
|
print(f"Chunk size: {CHUNK_SIZE}")
|
||||||
end = min(start + 512, num_frames)
|
print(f"So {int(numpy.ceil(num_frames/CHUNK_SIZE))} iterations\n")
|
||||||
|
|
||||||
|
for start in range(0, num_frames, CHUNK_SIZE):
|
||||||
|
end = min(start + CHUNK_SIZE, num_frames)
|
||||||
chunk_size = end - start
|
chunk_size = end - start
|
||||||
print("\033[F", start, chunk_size, end)
|
print(start, chunk_size, end, " \033[F")
|
||||||
|
|
||||||
input_left_chunk[:chunk_size] = frames[start:end, 0]
|
input_left_chunk[:chunk_size] = frames[start:end, 0]
|
||||||
input_right_chunk[:chunk_size] = frames[start:end, 1]
|
input_right_chunk[:chunk_size] = frames[start:end, 1]
|
||||||
|
output_left_chunk.fill(0)
|
||||||
|
output_right_chunk.fill(0)
|
||||||
|
|
||||||
instance.run(chunk_size)
|
instance.run(chunk_size)
|
||||||
|
|
||||||
output_left[start:end] = output_left_chunk[:chunk_size]
|
output_left[start:end] = output_left_chunk[:chunk_size]
|
||||||
output_right[start:end] = output_right_chunk[:chunk_size]
|
output_right[start:end] = output_right_chunk[:chunk_size]
|
||||||
|
|
||||||
|
print("done processing ")
|
||||||
instance.deactivate()
|
instance.deactivate()
|
||||||
|
|
||||||
merged = numpy.column_stack((output_left, output_right))
|
merged = numpy.column_stack((output_left, output_right))
|
||||||
|
|
||||||
|
if numpy.allclose(frames, merged, rtol=0.5, atol=0.5):
|
||||||
|
print("Warning: output is identical")
|
||||||
|
|
||||||
soundfile.write('aoutt.flac', merged, sample_rate)
|
soundfile.write('aoutt.flac', merged, sample_rate)
|
Loading…
Reference in a new issue