mixi-cut 0.3.3__py3-none-any.whl
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.
- mixi_cut/__init__.py +4 -0
- mixi_cut/carrier.py +162 -0
- mixi_cut/cli.py +203 -0
- mixi_cut/decoder.py +419 -0
- mixi_cut/encoder.py +271 -0
- mixi_cut/generator.py +176 -0
- mixi_cut/gf256.py +196 -0
- mixi_cut/protocol.py +124 -0
- mixi_cut/verifier.py +163 -0
- mixi_cut-0.3.3.dist-info/METADATA +321 -0
- mixi_cut-0.3.3.dist-info/RECORD +14 -0
- mixi_cut-0.3.3.dist-info/WHEEL +4 -0
- mixi_cut-0.3.3.dist-info/entry_points.txt +2 -0
- mixi_cut-0.3.3.dist-info/licenses/LICENSE +21 -0
mixi_cut/__init__.py
ADDED
mixi_cut/carrier.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""Carrier signal generation and RIAA pre-emphasis.
|
|
2
|
+
|
|
3
|
+
Generates stereo quadrature signals (L=sin, R=cos) and applies
|
|
4
|
+
RIAA recording curve via cascaded IIR filters.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
from mixi_cut.protocol import (
|
|
10
|
+
AMPLITUDE,
|
|
11
|
+
CARRIER_FREQ,
|
|
12
|
+
FADE_SAMPLES,
|
|
13
|
+
SAMPLE_RATE,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def generate_quadrature(
|
|
18
|
+
duration: float,
|
|
19
|
+
freq: float = CARRIER_FREQ,
|
|
20
|
+
sr: int = SAMPLE_RATE,
|
|
21
|
+
amplitude: float = AMPLITUDE,
|
|
22
|
+
speed: float = 1.0,
|
|
23
|
+
) -> tuple[np.ndarray, np.ndarray]:
|
|
24
|
+
"""Generate stereo quadrature carrier signals.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
duration: Signal duration in seconds
|
|
28
|
+
freq: Carrier frequency in Hz
|
|
29
|
+
sr: Sample rate in Hz
|
|
30
|
+
amplitude: Peak amplitude (linear)
|
|
31
|
+
speed: Playback speed multiplier
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
(left, right) arrays — L=sin, R=cos
|
|
35
|
+
"""
|
|
36
|
+
n = int(duration * sr)
|
|
37
|
+
t = np.arange(n, dtype=np.float64) / sr
|
|
38
|
+
phase = 2 * np.pi * freq * speed * t
|
|
39
|
+
return np.sin(phase) * amplitude, np.cos(phase) * amplitude
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def make_riaa_iir_coeffs(sr: int) -> tuple:
|
|
43
|
+
"""Design cascaded IIR sections for RIAA recording pre-emphasis.
|
|
44
|
+
|
|
45
|
+
Uses bilinear transform of the analog RIAA transfer function.
|
|
46
|
+
Two first-order sections: high-shelf (t1/t2) + high-boost (t3).
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
sr: Sample rate in Hz
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
(section1, section2) — each is (a_num, b_num, a_den, b_den)
|
|
53
|
+
"""
|
|
54
|
+
t1, t2, t3 = 3180e-6, 318e-6, 75e-6
|
|
55
|
+
|
|
56
|
+
def prewarp(tau):
|
|
57
|
+
return 2.0 * sr * np.tan(1.0 / (2.0 * sr * tau))
|
|
58
|
+
|
|
59
|
+
w1 = prewarp(t1)
|
|
60
|
+
w2 = prewarp(t2)
|
|
61
|
+
w3 = prewarp(t3)
|
|
62
|
+
|
|
63
|
+
# Section 1: (s + w2) / (s + w1)
|
|
64
|
+
a1_num = 2 * sr + w2
|
|
65
|
+
b1_num = -2 * sr + w2
|
|
66
|
+
a1_den = 2 * sr + w1
|
|
67
|
+
b1_den = -2 * sr + w1
|
|
68
|
+
|
|
69
|
+
# Section 2: (s + w3) / s
|
|
70
|
+
a2_num = 2 * sr + w3
|
|
71
|
+
b2_num = -2 * sr + w3
|
|
72
|
+
a2_den = 2 * sr
|
|
73
|
+
b2_den = -2 * sr
|
|
74
|
+
|
|
75
|
+
return (a1_num, b1_num, a1_den, b1_den), (a2_num, b2_num, a2_den, b2_den)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _apply_iir_section(signal: np.ndarray, section: tuple) -> np.ndarray:
|
|
79
|
+
"""Apply a single first-order IIR section to a signal.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
signal: Input signal array
|
|
83
|
+
section: (a_num, b_num, a_den, b_den) coefficients
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
Filtered signal
|
|
87
|
+
"""
|
|
88
|
+
result = signal.copy()
|
|
89
|
+
b0 = section[0] / section[2]
|
|
90
|
+
b1 = section[1] / section[2]
|
|
91
|
+
a1 = section[3] / section[2]
|
|
92
|
+
z1 = 0.0
|
|
93
|
+
for i in range(len(result)):
|
|
94
|
+
x = result[i]
|
|
95
|
+
y = b0 * x + z1
|
|
96
|
+
z1 = b1 * x - a1 * y
|
|
97
|
+
result[i] = y
|
|
98
|
+
return result
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def apply_riaa_iir(signal: np.ndarray, sr: int = SAMPLE_RATE) -> np.ndarray:
|
|
102
|
+
"""Apply RIAA pre-emphasis using cascaded IIR filters.
|
|
103
|
+
|
|
104
|
+
O(1) memory — processes sample-by-sample.
|
|
105
|
+
Normalizes to unity gain at 1 kHz.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
signal: Input signal array
|
|
109
|
+
sr: Sample rate in Hz
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
Pre-emphasized signal
|
|
113
|
+
"""
|
|
114
|
+
sec1, sec2 = make_riaa_iir_coeffs(sr)
|
|
115
|
+
|
|
116
|
+
result = _apply_iir_section(signal, sec1)
|
|
117
|
+
result = _apply_iir_section(result, sec2)
|
|
118
|
+
|
|
119
|
+
# Normalize: unity gain at 1 kHz
|
|
120
|
+
test_len = sr
|
|
121
|
+
t_test = np.arange(test_len) / sr
|
|
122
|
+
test_in = np.sin(2 * np.pi * 1000 * t_test)
|
|
123
|
+
test_out = _apply_iir_section(test_in, sec1)
|
|
124
|
+
test_out = _apply_iir_section(test_out, sec2)
|
|
125
|
+
|
|
126
|
+
rms_in = np.sqrt(np.mean(test_in[sr // 2:] ** 2))
|
|
127
|
+
rms_out = np.sqrt(np.mean(test_out[sr // 2:] ** 2))
|
|
128
|
+
gain_1k = rms_out / rms_in if rms_in > 0 else 1.0
|
|
129
|
+
|
|
130
|
+
result /= gain_1k
|
|
131
|
+
return result
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def apply_fades(
|
|
135
|
+
left: np.ndarray,
|
|
136
|
+
right: np.ndarray,
|
|
137
|
+
lead_in_samples: int,
|
|
138
|
+
signal_samples: int,
|
|
139
|
+
fade_samples: int = FADE_SAMPLES,
|
|
140
|
+
) -> None:
|
|
141
|
+
"""Apply quadratic fade-in and fade-out to avoid clicks.
|
|
142
|
+
|
|
143
|
+
Modifies arrays in-place.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
left: Left channel array (full length with lead-in/out)
|
|
147
|
+
right: Right channel array
|
|
148
|
+
lead_in_samples: Number of lead-in silence samples
|
|
149
|
+
signal_samples: Number of signal samples
|
|
150
|
+
fade_samples: Number of fade transition samples
|
|
151
|
+
"""
|
|
152
|
+
fade = np.linspace(0, 1, fade_samples) ** 2
|
|
153
|
+
|
|
154
|
+
# Fade in
|
|
155
|
+
s = lead_in_samples
|
|
156
|
+
left[s:s + fade_samples] *= fade
|
|
157
|
+
right[s:s + fade_samples] *= fade
|
|
158
|
+
|
|
159
|
+
# Fade out
|
|
160
|
+
e = lead_in_samples + signal_samples
|
|
161
|
+
left[e - fade_samples:e] *= fade[::-1]
|
|
162
|
+
right[e - fade_samples:e] *= fade[::-1]
|
mixi_cut/cli.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"""MIXI-CUT CLI — Unified command-line interface.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
mixi-cut generate [--duration N] [--preset NAME] [--riaa] [--loop] [--output FILE]
|
|
5
|
+
mixi-cut verify FILE [--strict]
|
|
6
|
+
mixi-cut bench [--test CATEGORY] [--pdf] [--compare] [--history] [--ci]
|
|
7
|
+
mixi-cut decode FILE
|
|
8
|
+
mixi-cut info
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import sys
|
|
13
|
+
|
|
14
|
+
from mixi_cut import __protocol_version__, __version__
|
|
15
|
+
from mixi_cut.protocol import CARRIER_FREQ, PRESETS, SAMPLE_RATE
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def cmd_generate(args):
|
|
19
|
+
"""Generate a timecode WAV file."""
|
|
20
|
+
from mixi_cut.generator import generate_timecode, write_wav
|
|
21
|
+
|
|
22
|
+
duration = args.duration
|
|
23
|
+
riaa = args.riaa
|
|
24
|
+
loop = args.loop
|
|
25
|
+
output = args.output
|
|
26
|
+
|
|
27
|
+
# Apply preset if specified
|
|
28
|
+
if args.preset:
|
|
29
|
+
if args.preset not in PRESETS:
|
|
30
|
+
print(f"Unknown preset: {args.preset}")
|
|
31
|
+
print(f"Available: {', '.join(PRESETS.keys())}")
|
|
32
|
+
sys.exit(1)
|
|
33
|
+
preset = PRESETS[args.preset]
|
|
34
|
+
duration = duration or preset["duration"]
|
|
35
|
+
riaa = riaa or preset["riaa"]
|
|
36
|
+
loop = loop or preset["loop"]
|
|
37
|
+
print(f"Preset: {args.preset} — {preset['description']}")
|
|
38
|
+
|
|
39
|
+
if duration is None:
|
|
40
|
+
duration = 900 # 15 min default
|
|
41
|
+
|
|
42
|
+
if output is None:
|
|
43
|
+
suffix = f"_{duration}s" if duration != 900 else ""
|
|
44
|
+
riaa_suffix = "_riaa" if riaa else ""
|
|
45
|
+
output = f"mixi_timecode_v2{suffix}{riaa_suffix}.wav"
|
|
46
|
+
|
|
47
|
+
left, right, meta = generate_timecode(
|
|
48
|
+
duration=duration,
|
|
49
|
+
freq=args.freq or CARRIER_FREQ,
|
|
50
|
+
sr=SAMPLE_RATE,
|
|
51
|
+
amplitude=0.85,
|
|
52
|
+
apply_riaa=riaa,
|
|
53
|
+
loop=loop,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
write_wav(left, right, output)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def cmd_verify(args):
|
|
60
|
+
"""Verify a timecode WAV file."""
|
|
61
|
+
from mixi_cut.verifier import verify_timecode
|
|
62
|
+
|
|
63
|
+
passed, results = verify_timecode(args.file, strict=args.strict)
|
|
64
|
+
sys.exit(0 if passed else 1)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def cmd_bench(args):
|
|
68
|
+
"""Run benchmark suite."""
|
|
69
|
+
# Import the benchmark module from the project root
|
|
70
|
+
import importlib.util
|
|
71
|
+
import os
|
|
72
|
+
|
|
73
|
+
# Try to find benchmark.py in common locations
|
|
74
|
+
for path in ["benchmark.py", "benchmarks/suite.py"]:
|
|
75
|
+
full_path = os.path.join(os.getcwd(), path)
|
|
76
|
+
if os.path.exists(full_path):
|
|
77
|
+
spec = importlib.util.spec_from_file_location("benchmark", full_path)
|
|
78
|
+
mod = importlib.util.module_from_spec(spec)
|
|
79
|
+
spec.loader.exec_module(mod)
|
|
80
|
+
|
|
81
|
+
# Build argv for the benchmark
|
|
82
|
+
bench_args = []
|
|
83
|
+
if args.test:
|
|
84
|
+
bench_args.extend(["--test", args.test])
|
|
85
|
+
if args.pdf:
|
|
86
|
+
bench_args.append("--pdf")
|
|
87
|
+
if args.compare:
|
|
88
|
+
bench_args.append("--compare")
|
|
89
|
+
if args.history:
|
|
90
|
+
bench_args.append("--history")
|
|
91
|
+
if args.ci:
|
|
92
|
+
bench_args.append("--no-color")
|
|
93
|
+
|
|
94
|
+
sys.argv = ["benchmark"] + bench_args
|
|
95
|
+
mod.main()
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
print("benchmark.py not found. Run from the project root directory.")
|
|
99
|
+
sys.exit(1)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def cmd_decode(args):
|
|
103
|
+
"""Decode a timecode WAV file (reference decoder)."""
|
|
104
|
+
import soundfile as sf
|
|
105
|
+
|
|
106
|
+
from mixi_cut.decoder import Decoder
|
|
107
|
+
|
|
108
|
+
data, sr = sf.read(args.file)
|
|
109
|
+
if data.ndim != 2:
|
|
110
|
+
print("Error: expected stereo WAV")
|
|
111
|
+
sys.exit(1)
|
|
112
|
+
|
|
113
|
+
left = data[:, 0]
|
|
114
|
+
right = data[:, 1]
|
|
115
|
+
block = 128
|
|
116
|
+
dec = Decoder(sr=sr)
|
|
117
|
+
|
|
118
|
+
print(f"Decoding: {args.file}")
|
|
119
|
+
print(f" Duration: {len(left)/sr:.1f}s")
|
|
120
|
+
print(f" Sample rate: {sr} Hz")
|
|
121
|
+
print()
|
|
122
|
+
|
|
123
|
+
positions = []
|
|
124
|
+
for i in range(0, len(left), block):
|
|
125
|
+
j = min(i + block, len(left))
|
|
126
|
+
speed, lock, pos = dec.process(left[i:j], right[i:j])
|
|
127
|
+
t = (i + block // 2) / sr
|
|
128
|
+
if i % (sr * 1) < block: # print every ~1 second
|
|
129
|
+
lock_bar = "█" * int(lock * 20) + "░" * (20 - int(lock * 20))
|
|
130
|
+
print(f" t={t:6.1f}s speed={speed:+.3f}x lock=[{lock_bar}] {lock:.3f} pos={pos:.2f}s")
|
|
131
|
+
positions.append((t, speed, lock, pos))
|
|
132
|
+
|
|
133
|
+
print(f"\n Decoded {len(positions)} blocks.")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def cmd_info(args):
|
|
137
|
+
"""Show version and protocol information."""
|
|
138
|
+
print(f"MIXI-CUT v{__version__}")
|
|
139
|
+
print(f"Protocol: v{__protocol_version__}")
|
|
140
|
+
print(f"Carrier: {CARRIER_FREQ} Hz stereo quadrature")
|
|
141
|
+
print(f"Sample rate: {SAMPLE_RATE} Hz")
|
|
142
|
+
print("\nPresets:")
|
|
143
|
+
for name, p in PRESETS.items():
|
|
144
|
+
print(f" {name:20s} {p['description']}")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def main():
|
|
148
|
+
parser = argparse.ArgumentParser(
|
|
149
|
+
prog="mixi-cut",
|
|
150
|
+
description="MIXI-CUT — Open-source DVS timecode generator for vinyl lathe cutting",
|
|
151
|
+
)
|
|
152
|
+
parser.add_argument("--version", action="version", version=f"mixi-cut {__version__}")
|
|
153
|
+
subparsers = parser.add_subparsers(dest="command", help="Available commands")
|
|
154
|
+
|
|
155
|
+
# generate
|
|
156
|
+
gen = subparsers.add_parser("generate", help="Generate timecode WAV file",
|
|
157
|
+
aliases=["gen", "g"])
|
|
158
|
+
gen.add_argument("--duration", type=int, help="Signal duration in seconds")
|
|
159
|
+
gen.add_argument("--preset", choices=list(PRESETS.keys()), help="Use a preset configuration")
|
|
160
|
+
gen.add_argument("--freq", type=int, help=f"Carrier frequency (default: {CARRIER_FREQ})")
|
|
161
|
+
gen.add_argument("--output", "-o", type=str, help="Output WAV filename")
|
|
162
|
+
gen.add_argument("--riaa", action="store_true", help="RIAA pre-emphasis (PHONO input)")
|
|
163
|
+
gen.add_argument("--loop", action="store_true", help="Phase-continuous locked groove")
|
|
164
|
+
gen.set_defaults(func=cmd_generate)
|
|
165
|
+
|
|
166
|
+
# verify
|
|
167
|
+
ver = subparsers.add_parser("verify", help="Verify timecode WAV file",
|
|
168
|
+
aliases=["v"])
|
|
169
|
+
ver.add_argument("file", help="WAV file to verify")
|
|
170
|
+
ver.add_argument("--strict", action="store_true", help="Fail on any warning")
|
|
171
|
+
ver.set_defaults(func=cmd_verify)
|
|
172
|
+
|
|
173
|
+
# bench
|
|
174
|
+
bench = subparsers.add_parser("bench", help="Run benchmark suite",
|
|
175
|
+
aliases=["b"])
|
|
176
|
+
bench.add_argument("--test", "--category", dest="test", help="Run specific category")
|
|
177
|
+
bench.add_argument("--pdf", action="store_true", help="Generate PDF report")
|
|
178
|
+
bench.add_argument("--compare", action="store_true", help="Compare with last run")
|
|
179
|
+
bench.add_argument("--history", action="store_true", help="Show history")
|
|
180
|
+
bench.add_argument("--ci", action="store_true", help="CI mode (no color, JSON output)")
|
|
181
|
+
bench.set_defaults(func=cmd_bench)
|
|
182
|
+
|
|
183
|
+
# decode
|
|
184
|
+
dec = subparsers.add_parser("decode", help="Decode timecode WAV (reference decoder)",
|
|
185
|
+
aliases=["d"])
|
|
186
|
+
dec.add_argument("file", help="WAV file to decode")
|
|
187
|
+
dec.set_defaults(func=cmd_decode)
|
|
188
|
+
|
|
189
|
+
# info
|
|
190
|
+
info = subparsers.add_parser("info", help="Show version and protocol info",
|
|
191
|
+
aliases=["i"])
|
|
192
|
+
info.set_defaults(func=cmd_info)
|
|
193
|
+
|
|
194
|
+
args = parser.parse_args()
|
|
195
|
+
if not args.command:
|
|
196
|
+
parser.print_help()
|
|
197
|
+
sys.exit(1)
|
|
198
|
+
|
|
199
|
+
args.func(args)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
if __name__ == "__main__":
|
|
203
|
+
main()
|