@libraz/libsonare 1.7.2 → 1.8.0

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.
Files changed (303) hide show
  1. package/NOTICE +178 -0
  2. package/README.md +26 -203
  3. package/dist/_chain_config.d.ts +14 -0
  4. package/dist/_chain_config.d.ts.map +1 -0
  5. package/dist/_effects_common.d.ts +6 -0
  6. package/dist/_effects_common.d.ts.map +1 -0
  7. package/dist/_feature_validation.d.ts +8 -0
  8. package/dist/_feature_validation.d.ts.map +1 -0
  9. package/dist/_fft_options.d.ts +24 -0
  10. package/dist/_fft_options.d.ts.map +1 -0
  11. package/dist/align_take.d.ts +50 -0
  12. package/dist/align_take.d.ts.map +1 -0
  13. package/dist/analysis.d.ts +29 -5840
  14. package/dist/analysis.d.ts.map +1 -0
  15. package/dist/analysis.js +873 -722
  16. package/dist/analysis.js.map +1 -1
  17. package/dist/analysis_helpers.d.ts +9 -0
  18. package/dist/analysis_helpers.d.ts.map +1 -0
  19. package/dist/audio.d.ts +163 -0
  20. package/dist/audio.d.ts.map +1 -0
  21. package/dist/clip_page_streamer.d.ts +133 -0
  22. package/dist/clip_page_streamer.d.ts.map +1 -0
  23. package/dist/codes.d.ts +44 -0
  24. package/dist/codes.d.ts.map +1 -0
  25. package/dist/effects_mastering.d.ts +23 -0
  26. package/dist/effects_mastering.d.ts.map +1 -0
  27. package/dist/effects_note_ops.d.ts +477 -0
  28. package/dist/effects_note_ops.d.ts.map +1 -0
  29. package/dist/effects_percussive.d.ts +185 -0
  30. package/dist/effects_percussive.d.ts.map +1 -0
  31. package/dist/effects_separation.d.ts +65 -0
  32. package/dist/effects_separation.d.ts.map +1 -0
  33. package/dist/effects_spectral.d.ts +28 -0
  34. package/dist/effects_spectral.d.ts.map +1 -0
  35. package/dist/effects_timepitch.d.ts +129 -0
  36. package/dist/effects_timepitch.d.ts.map +1 -0
  37. package/dist/effects_voice_change.d.ts +53 -0
  38. package/dist/effects_voice_change.d.ts.map +1 -0
  39. package/dist/errors.d.ts +51 -0
  40. package/dist/errors.d.ts.map +1 -0
  41. package/dist/feature_core.d.ts +341 -0
  42. package/dist/feature_core.d.ts.map +1 -0
  43. package/dist/feature_decompose.d.ts +278 -0
  44. package/dist/feature_decompose.d.ts.map +1 -0
  45. package/dist/feature_inverse.d.ts +128 -0
  46. package/dist/feature_inverse.d.ts.map +1 -0
  47. package/dist/feature_loudness.d.ts +66 -0
  48. package/dist/feature_loudness.d.ts.map +1 -0
  49. package/dist/feature_music.d.ts +307 -0
  50. package/dist/feature_music.d.ts.map +1 -0
  51. package/dist/feature_pitch.d.ts +108 -0
  52. package/dist/feature_pitch.d.ts.map +1 -0
  53. package/dist/feature_resample.d.ts +16 -0
  54. package/dist/feature_resample.d.ts.map +1 -0
  55. package/dist/feature_spectral.d.ts +137 -0
  56. package/dist/feature_spectral.d.ts.map +1 -0
  57. package/dist/feature_spectrogram.d.ts +198 -0
  58. package/dist/feature_spectrogram.d.ts.map +1 -0
  59. package/dist/features.d.ts +10 -0
  60. package/dist/features.d.ts.map +1 -0
  61. package/dist/hrtf/default.shrf +0 -0
  62. package/dist/index.d.ts +74 -7431
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +3758 -1362
  65. package/dist/index.js.map +1 -1
  66. package/dist/instrument_types.d.ts +517 -0
  67. package/dist/instrument_types.d.ts.map +1 -0
  68. package/dist/live_audio.d.ts +35 -0
  69. package/dist/live_audio.d.ts.map +1 -0
  70. package/dist/mastering_chain.d.ts +213 -0
  71. package/dist/mastering_chain.d.ts.map +1 -0
  72. package/dist/mastering_core.d.ts +457 -0
  73. package/dist/mastering_core.d.ts.map +1 -0
  74. package/dist/mastering_dynamics.d.ts +80 -0
  75. package/dist/mastering_dynamics.d.ts.map +1 -0
  76. package/dist/metering.d.ts +287 -0
  77. package/dist/metering.d.ts.map +1 -0
  78. package/dist/mixer.d.ts +464 -0
  79. package/dist/mixer.d.ts.map +1 -0
  80. package/dist/mixing_assistant.d.ts +62 -0
  81. package/dist/mixing_assistant.d.ts.map +1 -0
  82. package/dist/mixing_oneshot.d.ts +40 -0
  83. package/dist/mixing_oneshot.d.ts.map +1 -0
  84. package/dist/module_state.d.ts +15 -0
  85. package/dist/module_state.d.ts.map +1 -0
  86. package/dist/opfs_clip_pages.d.ts +28 -0
  87. package/dist/opfs_clip_pages.d.ts.map +1 -0
  88. package/dist/playback_renderer.d.ts +128 -0
  89. package/dist/playback_renderer.d.ts.map +1 -0
  90. package/dist/polyphony.d.ts +202 -0
  91. package/dist/polyphony.d.ts.map +1 -0
  92. package/dist/project.d.ts +8 -0
  93. package/dist/project.d.ts.map +1 -0
  94. package/dist/project_class.d.ts +562 -0
  95. package/dist/project_class.d.ts.map +1 -0
  96. package/dist/project_internal.d.ts +194 -0
  97. package/dist/project_internal.d.ts.map +1 -0
  98. package/dist/project_synth.d.ts +74 -0
  99. package/dist/project_synth.d.ts.map +1 -0
  100. package/dist/project_types.d.ts +652 -0
  101. package/dist/project_types.d.ts.map +1 -0
  102. package/dist/public_types.d.ts +185 -0
  103. package/dist/public_types.d.ts.map +1 -0
  104. package/dist/public_types_acoustic.d.ts +215 -0
  105. package/dist/public_types_acoustic.d.ts.map +1 -0
  106. package/dist/public_types_mastering.d.ts +510 -0
  107. package/dist/public_types_mastering.d.ts.map +1 -0
  108. package/dist/public_types_mixing.d.ts +436 -0
  109. package/dist/public_types_mixing.d.ts.map +1 -0
  110. package/dist/public_types_music.d.ts +619 -0
  111. package/dist/public_types_music.d.ts.map +1 -0
  112. package/dist/public_types_playback.d.ts +164 -0
  113. package/dist/public_types_playback.d.ts.map +1 -0
  114. package/dist/public_types_realtime.d.ts +174 -0
  115. package/dist/public_types_realtime.d.ts.map +1 -0
  116. package/dist/public_types_repair.d.ts +424 -0
  117. package/dist/public_types_repair.d.ts.map +1 -0
  118. package/dist/public_types_spectral.d.ts +697 -0
  119. package/dist/public_types_spectral.d.ts.map +1 -0
  120. package/dist/quick_analysis.d.ts +445 -0
  121. package/dist/quick_analysis.d.ts.map +1 -0
  122. package/dist/realtime_engine.d.ts +850 -0
  123. package/dist/realtime_engine.d.ts.map +1 -0
  124. package/dist/realtime_voice_changer.d.ts +158 -0
  125. package/dist/realtime_voice_changer.d.ts.map +1 -0
  126. package/dist/repair_dereverb.d.ts +187 -0
  127. package/dist/repair_dereverb.d.ts.map +1 -0
  128. package/dist/repair_impulsive.d.ts +186 -0
  129. package/dist/repair_impulsive.d.ts.map +1 -0
  130. package/dist/repair_noise.d.ts +239 -0
  131. package/dist/repair_noise.d.ts.map +1 -0
  132. package/dist/repair_trim.d.ts +123 -0
  133. package/dist/repair_trim.d.ts.map +1 -0
  134. package/dist/sample_bank.d.ts +84 -0
  135. package/dist/sample_bank.d.ts.map +1 -0
  136. package/dist/scale.d.ts +10 -0
  137. package/dist/scale.d.ts.map +1 -0
  138. package/dist/schemas/mixer-scene.schema.json +393 -0
  139. package/dist/schemas/playback-renderer-config.schema.json +392 -0
  140. package/dist/sonare-analysis.d.ts +8 -0
  141. package/dist/sonare-analysis.js +2 -2
  142. package/dist/sonare-analysis.wasm +0 -0
  143. package/dist/sonare.d.ts +3909 -0
  144. package/dist/sonare.js +2 -2
  145. package/dist/sonare.wasm +0 -0
  146. package/dist/stream_analyzer.d.ts +163 -0
  147. package/dist/stream_analyzer.d.ts.map +1 -0
  148. package/dist/stream_types.d.ts +214 -0
  149. package/dist/stream_types.d.ts.map +1 -0
  150. package/dist/streaming_mixing.d.ts +6 -0
  151. package/dist/streaming_mixing.d.ts.map +1 -0
  152. package/dist/streaming_processors.d.ts +335 -0
  153. package/dist/streaming_processors.d.ts.map +1 -0
  154. package/dist/transcribe.d.ts +77 -0
  155. package/dist/transcribe.d.ts.map +1 -0
  156. package/dist/validation.d.ts +140 -0
  157. package/dist/validation.d.ts.map +1 -0
  158. package/dist/web_midi.d.ts +77 -0
  159. package/dist/web_midi.d.ts.map +1 -0
  160. package/dist/worker.d.ts +5 -48
  161. package/dist/worker.d.ts.map +1 -0
  162. package/dist/worker.js +94 -41
  163. package/dist/worker.js.map +1 -1
  164. package/dist/worker_client.d.ts +96 -0
  165. package/dist/worker_client.d.ts.map +1 -0
  166. package/dist/worker_protocol.d.ts +43 -0
  167. package/dist/worker_protocol.d.ts.map +1 -0
  168. package/dist/worklet/audio_types.d.ts +21 -0
  169. package/dist/worklet/audio_types.d.ts.map +1 -0
  170. package/dist/worklet/engine-automation.d.ts +29 -0
  171. package/dist/worklet/engine-automation.d.ts.map +1 -0
  172. package/dist/worklet/engine-capture-facade.d.ts +35 -0
  173. package/dist/worklet/engine-capture-facade.d.ts.map +1 -0
  174. package/dist/worklet/engine-clips.d.ts +23 -0
  175. package/dist/worklet/engine-clips.d.ts.map +1 -0
  176. package/dist/worklet/engine-markers.d.ts +40 -0
  177. package/dist/worklet/engine-markers.d.ts.map +1 -0
  178. package/dist/worklet/engine-mixer-facade.d.ts +128 -0
  179. package/dist/worklet/engine-mixer-facade.d.ts.map +1 -0
  180. package/dist/worklet/engine-node.d.ts +81 -0
  181. package/dist/worklet/engine-node.d.ts.map +1 -0
  182. package/dist/worklet/engine-offline.d.ts +81 -0
  183. package/dist/worklet/engine-offline.d.ts.map +1 -0
  184. package/dist/worklet/engine-options.d.ts +12 -0
  185. package/dist/worklet/engine-options.d.ts.map +1 -0
  186. package/dist/worklet/engine-parameter-facade.d.ts +106 -0
  187. package/dist/worklet/engine-parameter-facade.d.ts.map +1 -0
  188. package/dist/worklet/engine-processor.d.ts +68 -0
  189. package/dist/worklet/engine-processor.d.ts.map +1 -0
  190. package/dist/worklet/engine-register.d.ts +2 -0
  191. package/dist/worklet/engine-register.d.ts.map +1 -0
  192. package/dist/worklet/engine-strips.d.ts +73 -0
  193. package/dist/worklet/engine-strips.d.ts.map +1 -0
  194. package/dist/worklet/engine-sync.d.ts +37 -0
  195. package/dist/worklet/engine-sync.d.ts.map +1 -0
  196. package/dist/worklet/engine-tempo-facade.d.ts +48 -0
  197. package/dist/worklet/engine-tempo-facade.d.ts.map +1 -0
  198. package/dist/worklet/engine.d.ts +397 -0
  199. package/dist/worklet/engine.d.ts.map +1 -0
  200. package/dist/worklet/guards.d.ts +47 -0
  201. package/dist/worklet/guards.d.ts.map +1 -0
  202. package/dist/worklet/messages.d.ts +710 -0
  203. package/dist/worklet/messages.d.ts.map +1 -0
  204. package/dist/worklet/mixer-processor.d.ts +46 -0
  205. package/dist/worklet/mixer-processor.d.ts.map +1 -0
  206. package/dist/worklet/playback-processor.d.ts +62 -0
  207. package/dist/worklet/playback-processor.d.ts.map +1 -0
  208. package/dist/worklet/protocol.d.ts +323 -0
  209. package/dist/worklet/protocol.d.ts.map +1 -0
  210. package/dist/worklet/voice-changer-processor.d.ts +41 -0
  211. package/dist/worklet/voice-changer-processor.d.ts.map +1 -0
  212. package/dist/worklet.d.ts +16 -2515
  213. package/dist/worklet.d.ts.map +1 -0
  214. package/dist/worklet.js +2763 -501
  215. package/dist/worklet.js.map +1 -1
  216. package/package.json +23 -12
  217. package/src/_effects_common.ts +17 -0
  218. package/src/_feature_validation.ts +34 -0
  219. package/src/_fft_options.ts +39 -0
  220. package/src/align_take.ts +64 -0
  221. package/src/analysis.ts +56 -3
  222. package/src/analysis_helpers.ts +7 -0
  223. package/src/audio.ts +106 -3
  224. package/src/codes.ts +39 -2
  225. package/src/effects_mastering.ts +97 -22
  226. package/src/effects_note_ops.ts +635 -0
  227. package/src/effects_percussive.ts +217 -0
  228. package/src/effects_separation.ts +150 -0
  229. package/src/effects_spectral.ts +60 -0
  230. package/src/effects_timepitch.ts +377 -0
  231. package/src/errors.ts +23 -1
  232. package/src/feature_core.ts +127 -2
  233. package/src/feature_decompose.ts +633 -0
  234. package/src/feature_inverse.ts +454 -0
  235. package/src/feature_loudness.ts +125 -0
  236. package/src/feature_music.ts +107 -14
  237. package/src/feature_pitch.ts +96 -1
  238. package/src/feature_spectral.ts +16 -611
  239. package/src/feature_spectrogram.ts +63 -450
  240. package/src/features.ts +36 -22
  241. package/src/index.ts +282 -30
  242. package/src/instrument_types.ts +645 -0
  243. package/src/live_audio.ts +27 -1
  244. package/src/mastering_chain.ts +184 -0
  245. package/src/mastering_core.ts +346 -32
  246. package/src/mastering_dynamics.ts +22 -11
  247. package/src/metering.ts +67 -24
  248. package/src/mixer.ts +212 -3
  249. package/src/mixing_assistant.ts +138 -0
  250. package/src/mixing_oneshot.ts +10 -5
  251. package/src/module_state.ts +24 -2
  252. package/src/playback_renderer.ts +252 -0
  253. package/src/polyphony.ts +279 -0
  254. package/src/project.ts +61 -24
  255. package/src/project_class.ts +450 -27
  256. package/src/project_internal.ts +149 -42
  257. package/src/project_synth.ts +67 -1
  258. package/src/project_types.ts +268 -270
  259. package/src/public_types.ts +122 -3
  260. package/src/public_types_acoustic.ts +112 -3
  261. package/src/public_types_mastering.ts +254 -73
  262. package/src/public_types_mixing.ts +363 -1
  263. package/src/public_types_music.ts +312 -2
  264. package/src/public_types_playback.ts +195 -0
  265. package/src/public_types_realtime.ts +39 -7
  266. package/src/public_types_repair.ts +446 -0
  267. package/src/public_types_spectral.ts +487 -1
  268. package/src/quick_analysis.ts +203 -26
  269. package/src/realtime_engine.ts +711 -28
  270. package/src/realtime_voice_changer.ts +55 -1
  271. package/src/repair_dereverb.ts +299 -0
  272. package/src/repair_impulsive.ts +395 -0
  273. package/src/repair_noise.ts +425 -0
  274. package/src/repair_trim.ts +226 -0
  275. package/src/sample_bank.ts +113 -0
  276. package/src/sonare.js.d.ts +1122 -30
  277. package/src/stream_analyzer.ts +36 -4
  278. package/src/stream_types.ts +37 -0
  279. package/src/streaming_mixing.ts +1 -1
  280. package/src/streaming_processors.ts +194 -10
  281. package/src/transcribe.ts +89 -0
  282. package/src/validation.ts +285 -11
  283. package/src/web_midi.ts +1 -6
  284. package/src/worker.ts +18 -2
  285. package/src/worklet/audio_types.ts +37 -0
  286. package/src/worklet/engine-mixer-facade.ts +444 -10
  287. package/src/worklet/engine-node.ts +78 -26
  288. package/src/worklet/engine-offline.ts +14 -8
  289. package/src/worklet/engine-parameter-facade.ts +21 -0
  290. package/src/worklet/engine-processor.ts +272 -83
  291. package/src/worklet/engine-register.ts +32 -18
  292. package/src/worklet/engine-strips.ts +280 -9
  293. package/src/worklet/engine-sync.ts +14 -6
  294. package/src/worklet/engine.ts +365 -31
  295. package/src/worklet/guards.ts +140 -44
  296. package/src/worklet/messages.ts +227 -2
  297. package/src/worklet/mixer-processor.ts +109 -47
  298. package/src/worklet/playback-processor.ts +300 -0
  299. package/src/worklet/protocol.ts +53 -3
  300. package/src/worklet/voice-changer-processor.ts +17 -11
  301. package/src/worklet.ts +17 -0
  302. package/src/effects_transform.ts +0 -718
  303. package/src/mastering_repair.ts +0 -273
@@ -0,0 +1,395 @@
1
+ /**
2
+ * Impulsive-defect repair: declick, declip and decrackle, with their detectors.
3
+ */
4
+
5
+ import { getSonareModule } from './module_state';
6
+ import type {
7
+ ClickDetection,
8
+ ClipDetection,
9
+ CrackleDetection,
10
+ MasteringRepairDeclickStereoResult,
11
+ MasteringRepairDeclipStereoResult,
12
+ MasteringRepairDecrackleStereoResult,
13
+ } from './public_types_repair';
14
+
15
+ function requireModule() {
16
+ return getSonareModule();
17
+ }
18
+
19
+ /** Options for `masteringRepairDeclick`. */
20
+ export interface DeclickOptions {
21
+ threshold?: number;
22
+ neighborRatio?: number;
23
+ maxClickSamples?: number;
24
+ lpcOrder?: number;
25
+ residualRatio?: number;
26
+ }
27
+
28
+ export interface MasteringRepairDeclickRequest extends DeclickOptions {
29
+ samples: Float32Array;
30
+ sampleRate: number;
31
+ }
32
+
33
+ /** Request form of `masteringRepairDeclickStereo`. */
34
+ export interface MasteringRepairDeclickStereoRequest extends DeclickOptions {
35
+ left: Float32Array;
36
+ right: Float32Array;
37
+ sampleRate?: number;
38
+ }
39
+
40
+ /**
41
+ * Offline LPC-based declicker for a stereo pair.
42
+ *
43
+ * A run either channel's own detection selects is repaired in BOTH channels —
44
+ * a common-mode click repaired on one side only would move the stereo image.
45
+ * Only the selection is shared: each channel's fill is computed from its own
46
+ * samples and its own AR model, which is why `leftReport` and `rightReport`
47
+ * genuinely differ. Prefer this over calling `masteringRepairDeclick` on each
48
+ * channel separately whenever a click may land in only one channel — a
49
+ * per-channel pass never repairs the other side's image-shifting click.
50
+ */
51
+ export function masteringRepairDeclickStereo(
52
+ request: MasteringRepairDeclickStereoRequest,
53
+ ): MasteringRepairDeclickStereoResult;
54
+ export function masteringRepairDeclickStereo(
55
+ left: Float32Array,
56
+ right: Float32Array,
57
+ sampleRate: number,
58
+ config?: DeclickOptions,
59
+ ): MasteringRepairDeclickStereoResult;
60
+ export function masteringRepairDeclickStereo(
61
+ left: Float32Array | MasteringRepairDeclickStereoRequest,
62
+ right?: Float32Array,
63
+ sampleRate?: number,
64
+ config: DeclickOptions = {},
65
+ ): MasteringRepairDeclickStereoResult {
66
+ const request: MasteringRepairDeclickStereoRequest =
67
+ left instanceof Float32Array
68
+ ? { left, right: right as Float32Array, sampleRate, ...config }
69
+ : left;
70
+ const { left: leftSamples, right: rightSamples, sampleRate: rate, ...options } = request;
71
+ return requireModule().masteringRepairDeclickStereo(
72
+ leftSamples,
73
+ rightSamples,
74
+ rate ?? 22050,
75
+ options,
76
+ );
77
+ }
78
+
79
+ /** Offline LPC-based declicker. */
80
+ export function masteringRepairDeclick(request: MasteringRepairDeclickRequest): Float32Array;
81
+ export function masteringRepairDeclick(
82
+ samples: Float32Array,
83
+ sampleRate: number,
84
+ options?: DeclickOptions,
85
+ ): Float32Array;
86
+ export function masteringRepairDeclick(
87
+ samples: Float32Array | MasteringRepairDeclickRequest,
88
+ sampleRate?: number,
89
+ options: DeclickOptions = {},
90
+ ): Float32Array {
91
+ const request =
92
+ samples instanceof Float32Array
93
+ ? { samples, sampleRate: sampleRate as number, ...options }
94
+ : samples;
95
+ return requireModule().masteringRepairDeclick(request.samples, request.sampleRate, request);
96
+ }
97
+
98
+ /** Options for `masteringRepairDeclip`. */
99
+ export interface DeclipOptions {
100
+ clipThreshold?: number;
101
+ lpcOrder?: number;
102
+ iterations?: number;
103
+ lpcBlend?: number;
104
+ }
105
+
106
+ export interface MasteringRepairDeclipRequest extends DeclipOptions {
107
+ samples: Float32Array;
108
+ sampleRate: number;
109
+ }
110
+
111
+ /** Request form of `masteringRepairDeclipStereo`. */
112
+ export interface MasteringRepairDeclipStereoRequest extends DeclipOptions {
113
+ left: Float32Array;
114
+ right: Float32Array;
115
+ sampleRate?: number;
116
+ }
117
+
118
+ /** Algorithms accepted by `masteringRepairDecrackle`. */
119
+ export type DecrackleMode = 'median' | 'waveletShrinkage';
120
+
121
+ /** Options for `masteringRepairDecrackle`. */
122
+ export interface DecrackleOptions {
123
+ threshold?: number;
124
+ mode?: DecrackleMode;
125
+ levels?: number;
126
+ }
127
+
128
+ export interface MasteringRepairDecrackleRequest extends DecrackleOptions {
129
+ samples: Float32Array;
130
+ sampleRate: number;
131
+ }
132
+
133
+ /** Request form of `masteringRepairDecrackleStereo`. */
134
+ export interface MasteringRepairDecrackleStereoRequest extends DecrackleOptions {
135
+ left: Float32Array;
136
+ right: Float32Array;
137
+ sampleRate?: number;
138
+ }
139
+
140
+ /**
141
+ * Offline LPC-based declipper.
142
+ *
143
+ * Only clipped runs of at most 512 consecutive samples are reconstructed with the LPC solver.
144
+ * The cap is a fixed sample count: it is not derived from `lpcOrder`, from `sampleRate`, or from
145
+ * any other option, so its duration depends on the rate (~10.7 ms at 48 kHz). A longer run is
146
+ * filled with cubic / linear interpolation instead, which keeps the solver's dense matrices
147
+ * bounded by the cap rather than by the input. Exceeding the cap silently changes the
148
+ * reconstruction method rather than throwing: `lpcOrder`, `iterations` and `lpcBlend` have no
149
+ * effect on the interpolated run.
150
+ */
151
+ export function masteringRepairDeclip(request: MasteringRepairDeclipRequest): Float32Array;
152
+ export function masteringRepairDeclip(
153
+ samples: Float32Array,
154
+ sampleRate: number,
155
+ options?: DeclipOptions,
156
+ ): Float32Array;
157
+ export function masteringRepairDeclip(
158
+ samples: Float32Array | MasteringRepairDeclipRequest,
159
+ sampleRate?: number,
160
+ options: DeclipOptions = {},
161
+ ): Float32Array {
162
+ const request =
163
+ samples instanceof Float32Array
164
+ ? { samples, sampleRate: sampleRate as number, ...options }
165
+ : samples;
166
+ return requireModule().masteringRepairDeclip(request.samples, request.sampleRate, request);
167
+ }
168
+
169
+ /**
170
+ * Offline LPC-based declipper for a stereo pair.
171
+ *
172
+ * Takes the union of both channels' clipped runs. Each channel reconstructs
173
+ * the whole of every union run it has at least one clipped sample in; a
174
+ * channel with none is left untouched there — reconstructing unclipped audio
175
+ * to match the other side would replace real samples with an estimate. A
176
+ * plateau clipped in only one channel therefore produces no linking:
177
+ * `linkedRuns` is non-zero only where both channels are clipped in the same
178
+ * region with different extents.
179
+ */
180
+ export function masteringRepairDeclipStereo(
181
+ request: MasteringRepairDeclipStereoRequest,
182
+ ): MasteringRepairDeclipStereoResult;
183
+ export function masteringRepairDeclipStereo(
184
+ left: Float32Array,
185
+ right: Float32Array,
186
+ sampleRate: number,
187
+ config?: DeclipOptions,
188
+ ): MasteringRepairDeclipStereoResult;
189
+ export function masteringRepairDeclipStereo(
190
+ left: Float32Array | MasteringRepairDeclipStereoRequest,
191
+ right?: Float32Array,
192
+ sampleRate?: number,
193
+ config: DeclipOptions = {},
194
+ ): MasteringRepairDeclipStereoResult {
195
+ const request: MasteringRepairDeclipStereoRequest =
196
+ left instanceof Float32Array
197
+ ? { left, right: right as Float32Array, sampleRate, ...config }
198
+ : left;
199
+ const { left: leftSamples, right: rightSamples, sampleRate: rate, ...options } = request;
200
+ return requireModule().masteringRepairDeclipStereo(
201
+ leftSamples,
202
+ rightSamples,
203
+ rate ?? 22050,
204
+ options,
205
+ );
206
+ }
207
+
208
+ /** Offline crackle suppressor (median or wavelet-shrinkage). */
209
+ export function masteringRepairDecrackle(request: MasteringRepairDecrackleRequest): Float32Array;
210
+ export function masteringRepairDecrackle(
211
+ samples: Float32Array,
212
+ sampleRate: number,
213
+ options?: DecrackleOptions,
214
+ ): Float32Array;
215
+ export function masteringRepairDecrackle(
216
+ samples: Float32Array | MasteringRepairDecrackleRequest,
217
+ sampleRate?: number,
218
+ options: DecrackleOptions = {},
219
+ ): Float32Array {
220
+ const request =
221
+ samples instanceof Float32Array
222
+ ? { samples, sampleRate: sampleRate as number, ...options }
223
+ : samples;
224
+ return requireModule().masteringRepairDecrackle(request.samples, request.sampleRate, request);
225
+ }
226
+
227
+ /**
228
+ * Offline crackle suppressor (median or wavelet-shrinkage) for a stereo pair.
229
+ *
230
+ * Crackle is surface damage: the two channels carry different scratches at different instants,
231
+ * so there is no common event for a shared decision to agree about. Each channel is decrackled
232
+ * on its own -- there is no linking, unlike {@link masteringRepairDeclickStereo} and
233
+ * {@link masteringRepairDeclipStereo} -- and this entry point exists to keep the reports and
234
+ * the channel-length contract in one place.
235
+ */
236
+ export function masteringRepairDecrackleStereo(
237
+ request: MasteringRepairDecrackleStereoRequest,
238
+ ): MasteringRepairDecrackleStereoResult;
239
+ export function masteringRepairDecrackleStereo(
240
+ left: Float32Array,
241
+ right: Float32Array,
242
+ sampleRate: number,
243
+ config?: DecrackleOptions,
244
+ ): MasteringRepairDecrackleStereoResult;
245
+ export function masteringRepairDecrackleStereo(
246
+ left: Float32Array | MasteringRepairDecrackleStereoRequest,
247
+ right?: Float32Array,
248
+ sampleRate?: number,
249
+ config: DecrackleOptions = {},
250
+ ): MasteringRepairDecrackleStereoResult {
251
+ const request: MasteringRepairDecrackleStereoRequest =
252
+ left instanceof Float32Array
253
+ ? { left, right: right as Float32Array, sampleRate, ...config }
254
+ : left;
255
+ const { left: leftSamples, right: rightSamples, sampleRate: rate, ...options } = request;
256
+ return requireModule().masteringRepairDecrackleStereo(
257
+ leftSamples,
258
+ rightSamples,
259
+ rate ?? 22050,
260
+ options,
261
+ );
262
+ }
263
+
264
+ /** Request form of `masteringRepairDetectClicks`. */
265
+ export interface MasteringRepairDetectClicksRequest extends DeclickOptions {
266
+ samples: Float32Array;
267
+ sampleRate: number;
268
+ }
269
+
270
+ /** Request form of `masteringRepairDetectClipping`. */
271
+ export interface MasteringRepairDetectClippingRequest extends DeclipOptions {
272
+ samples: Float32Array;
273
+ sampleRate: number;
274
+ }
275
+
276
+ /** Request form of `masteringRepairDetectCrackle`. */
277
+ export interface MasteringRepairDetectCrackleRequest extends DecrackleOptions {
278
+ samples: Float32Array;
279
+ sampleRate: number;
280
+ }
281
+
282
+ /**
283
+ * Measures clicks without repairing.
284
+ *
285
+ * Runs the same LPC analysis {@link masteringRepairDeclick} runs, so a run counted here is one
286
+ * the repair would act on — a cheaper threshold-only scan would report runs it leaves alone.
287
+ * That also means the options that shape the repair shape the count: a large `rejected` says
288
+ * `maxClickSamples` or `neighborRatio` is too tight for this material, not that the material is
289
+ * clean.
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * const detected = masteringRepairDetectClicks({ samples, sampleRate: 48000 });
294
+ * if (detected.perSecond > 1) samples = masteringRepairDeclick({ samples, sampleRate: 48000 });
295
+ * ```
296
+ */
297
+ export function masteringRepairDetectClicks(
298
+ request: MasteringRepairDetectClicksRequest,
299
+ ): ClickDetection;
300
+ export function masteringRepairDetectClicks(
301
+ samples: Float32Array,
302
+ sampleRate: number,
303
+ options?: DeclickOptions,
304
+ ): ClickDetection;
305
+ export function masteringRepairDetectClicks(
306
+ samples: Float32Array | MasteringRepairDetectClicksRequest,
307
+ sampleRate?: number,
308
+ options: DeclickOptions = {},
309
+ ): ClickDetection {
310
+ const request =
311
+ samples instanceof Float32Array
312
+ ? { samples, sampleRate: sampleRate as number, ...options }
313
+ : samples;
314
+ return requireModule().masteringRepairDetectClicks(request.samples, request.sampleRate, request);
315
+ }
316
+
317
+ /**
318
+ * Measures clipping without repairing.
319
+ *
320
+ * Counts samples at or past `clipThreshold`. No other option reaches the result — `lpcOrder`,
321
+ * `iterations` and `lpcBlend` are validated and then unread, since nothing here is
322
+ * reconstructed. `sampleRate` is validated without being read for the same reason: no field of
323
+ * the result is a rate.
324
+ *
325
+ * Compare `longestRunSamples` against the 512-sample LPC cap to tell in advance which runs
326
+ * {@link masteringRepairDeclip} would fill by interpolation rather than with the solver.
327
+ *
328
+ * `flatRunCount`, `longestFlatRunSamples`, `flatSampleCount` and `flatLevel` answer a different
329
+ * question from the four fields above: those are read against `clipThreshold`, so they count the
330
+ * apex of any waveform that reaches it — a full-scale sine reports thousands of "clipped" samples
331
+ * having never been clipped — and they miss material clipped in one tool and attenuated in the
332
+ * next, which leaves nothing at the threshold. The flat-top fields instead count runs of at least
333
+ * 3 consecutive bit-identical samples whose level sits within 1 dB of the signal's peak, so they
334
+ * catch a clipped-then-attenuated waveform that `sampleCount` reports as clean.
335
+ *
336
+ * Two opposite errors follow from what a flat top actually is. A genuinely flat-topped waveform —
337
+ * a square or pulse train, a fully limited master — counts as clipped here too and cannot be told
338
+ * apart from clipping in the time domain: a false positive. In the other direction, anything that
339
+ * moves the two channels' samples independently before this runs erases a real flat top, so a
340
+ * zero reading is not proof the material was never clipped — a stereo downmix does this, and so
341
+ * do resampling and lossy coding, because the plateau stops being exactly level once each sample
342
+ * is nudged on its own. **Detect each channel of a stereo signal separately, before any downmix,
343
+ * never on the mixed-down result.**
344
+ */
345
+ export function masteringRepairDetectClipping(
346
+ request: MasteringRepairDetectClippingRequest,
347
+ ): ClipDetection;
348
+ export function masteringRepairDetectClipping(
349
+ samples: Float32Array,
350
+ sampleRate: number,
351
+ options?: DeclipOptions,
352
+ ): ClipDetection;
353
+ export function masteringRepairDetectClipping(
354
+ samples: Float32Array | MasteringRepairDetectClippingRequest,
355
+ sampleRate?: number,
356
+ options: DeclipOptions = {},
357
+ ): ClipDetection {
358
+ const request =
359
+ samples instanceof Float32Array
360
+ ? { samples, sampleRate: sampleRate as number, ...options }
361
+ : samples;
362
+ return requireModule().masteringRepairDetectClipping(
363
+ request.samples,
364
+ request.sampleRate,
365
+ request,
366
+ );
367
+ }
368
+
369
+ /**
370
+ * Measures crackle without repairing.
371
+ *
372
+ * Measured by the median criterion whatever `mode` is set to: wavelet shrinkage removes crackle
373
+ * without ever deciding that a sample is crackle, so these counts do not describe what a
374
+ * wavelet-mode repair would remove. A caller therefore gets the same answer before choosing a
375
+ * mode.
376
+ */
377
+ export function masteringRepairDetectCrackle(
378
+ request: MasteringRepairDetectCrackleRequest,
379
+ ): CrackleDetection;
380
+ export function masteringRepairDetectCrackle(
381
+ samples: Float32Array,
382
+ sampleRate: number,
383
+ options?: DecrackleOptions,
384
+ ): CrackleDetection;
385
+ export function masteringRepairDetectCrackle(
386
+ samples: Float32Array | MasteringRepairDetectCrackleRequest,
387
+ sampleRate?: number,
388
+ options: DecrackleOptions = {},
389
+ ): CrackleDetection {
390
+ const request =
391
+ samples instanceof Float32Array
392
+ ? { samples, sampleRate: sampleRate as number, ...options }
393
+ : samples;
394
+ return requireModule().masteringRepairDetectCrackle(request.samples, request.sampleRate, request);
395
+ }