From 1ff7c3b76a34a0bccd71602f3f6255d354c9827f Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sat, 9 Nov 2024 16:30:08 +0100 Subject: [PATCH] Fix most of the time --- README.md | 10 ++++++++++ main.py | 59 ++++++++++++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..636bc5d --- /dev/null +++ b/README.md @@ -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` \ No newline at end of file diff --git a/main.py b/main.py index a7a1ed5..eb30a2e 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,11 @@ -import lilv, numpy, wave +import lilv, numpy, time import soundfile -from ctypes import c_float, c_int + +CHUNK_SIZE = 128 frames, sample_rate = soundfile.read('a.flac') num_frames = len(frames) 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) world = lilv.World() @@ -14,57 +14,66 @@ world.load_all() plugins = world.get_all_plugins() 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()): 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.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_right = numpy.zeros(num_frames, frames.dtype) -input_left_chunk = numpy.zeros(512, frames.dtype) -input_right_chunk = numpy.zeros(512, frames.dtype) -output_left_chunk = numpy.zeros(512, frames.dtype) -output_right_chunk = numpy.zeros(512, frames.dtype) +input_left_chunk = numpy.zeros(CHUNK_SIZE, frames.dtype) +input_right_chunk = numpy.zeros(CHUNK_SIZE, frames.dtype) +output_left_chunk = numpy.zeros(CHUNK_SIZE, frames.dtype) +output_right_chunk = numpy.zeros(CHUNK_SIZE, frames.dtype) instance.connect_port(0, input_left_chunk) instance.connect_port(1, input_right_chunk) instance.connect_port(2, output_left_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() -print(f"frames: {num_frames}\n") -for start in range(0, num_frames, 512): - end = min(start + 512, num_frames) +print(f"\nFrames: {num_frames}") +print(f"Chunk size: {CHUNK_SIZE}") +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 - print("\033[F", start, chunk_size, end) + print(start, chunk_size, end, " \033[F") input_left_chunk[:chunk_size] = frames[start:end, 0] input_right_chunk[:chunk_size] = frames[start:end, 1] + output_left_chunk.fill(0) + output_right_chunk.fill(0) instance.run(chunk_size) output_left[start:end] = output_left_chunk[:chunk_size] output_right[start:end] = output_right_chunk[:chunk_size] +print("done processing ") instance.deactivate() 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) \ No newline at end of file