Core
core
Reusable, pure algorithmic components for inference and training.
Classes:
Name | Description |
---|---|
Audio |
|
NormalizationStats |
Statistics for normalizing |
NormalizedAudio |
Container for normalized audio and its original stats. |
ModelWaveformToWaveform |
|
Functions:
Name | Description |
---|---|
normalize_audio |
Preprocess the raw audio in the time domain to have a mean of 0 and a std of 1 |
denormalize_audio |
Take the model output and restore them to their original loudness. |
generate_chunks |
Generates batches of overlapping chunks from an audio tensor. |
stitch_chunks |
Stitches processed audio chunks back together using the overlap-add method. |
apply_mask |
Applies a complex mask to a spectrogram. |
create_w2w_model |
|
derive_stems |
It is the caller's responsibility to ensure that all tensors are aligned and have the same shape. |
str_to_torch_dtype |
|
Audio
dataclass
Audio(data: _AudioTensorLike, sample_rate: SampleRate)
Bases: Generic[_AudioTensorLike]
Attributes:
Name | Type | Description |
---|---|---|
data |
_AudioTensorLike
|
This should either be an raw or a |
sample_rate |
SampleRate
|
|
data
instance-attribute
data: _AudioTensorLike
This should either be an raw or a normalized audio tensor.
NormalizationStats
dataclass
NormalizedAudio
dataclass
NormalizedAudio(
audio: Audio[NormalizedAudioTensor],
stats: NormalizationStats,
)
Container for normalized audio and its original stats.
Attributes:
Name | Type | Description |
---|---|---|
audio |
Audio[NormalizedAudioTensor]
|
|
stats |
NormalizationStats
|
|
normalize_audio
normalize_audio(
audio: Audio[RawAudioTensor],
) -> NormalizedAudio
Preprocess the raw audio in the time domain to have a mean of 0 and a std of 1 before passing it to the model.
Operates on the mean of the channels.
Source code in src/splifft/core.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
denormalize_audio
denormalize_audio(
audio_data: NormalizedAudioTensor,
stats: NormalizationStats,
) -> RawAudioTensor
Take the model output and restore them to their original loudness.
Source code in src/splifft/core.py
90 91 92 93 94 |
|
generate_chunks
generate_chunks(
audio_data: RawAudioTensor | NormalizedAudioTensor,
chunk_size: ChunkSize,
hop_size: HopSize,
batch_size: BatchSize,
*,
padding_mode: PaddingMode = "reflect",
) -> Iterator[PaddedChunkedAudioTensor]
Generates batches of overlapping chunks from an audio tensor.
Returns:
Type | Description |
---|---|
Iterator[PaddedChunkedAudioTensor]
|
An iterator that yields batches of chunks of shape (B, C, chunk_T). |
Source code in src/splifft/core.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
stitch_chunks
stitch_chunks(
processed_chunks: Sequence[SeparatedChunkedTensor],
num_stems: NumModelStems,
chunk_size: ChunkSize,
hop_size: HopSize,
target_num_samples: Samples,
*,
window: WindowTensor,
) -> RawSeparatedTensor
Stitches processed audio chunks back together using the overlap-add method.
Reconstructs the full audio signal from a sequence of overlapping, processed chunks. Ensures that the sum of all overlapping windows is constant at every time step: \(\sum_{m=-\infty}^{\infty} w[n - mH] = C\) where \(H\) is the hop size.
Source code in src/splifft/core.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
apply_mask
apply_mask(
spec_for_masking: ComplexSpectrogram,
mask_batch: ComplexSpectrogram,
mask_add_sub_dtype: dtype | None,
mask_out_dtype: dtype | None,
) -> SeparatedSpectrogramTensor
Applies a complex mask to a spectrogram.
While this can be simply replaced by a complex multiplication and torch.view_as_complex
,
CoreML does not support it: https://github.com/apple/coremltools/issues/2003 so we handroll our
own.
Source code in src/splifft/core.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
ModelWaveformToWaveform
ModelWaveformToWaveform(
model: Module,
preprocess: PreprocessFn,
postprocess: PostprocessFn,
)
Bases: Module
Methods:
Name | Description |
---|---|
forward |
|
Attributes:
Name | Type | Description |
---|---|---|
model |
|
|
preprocess |
|
|
postprocess |
|
Source code in src/splifft/core.py
228 229 230 231 232 233 234 235 236 237 |
|
model
instance-attribute
model = model
preprocess
instance-attribute
preprocess = preprocess
postprocess
instance-attribute
postprocess = postprocess
forward
forward(
waveform_chunk: RawAudioTensor | NormalizedAudioTensor,
) -> SeparatedChunkedTensor
Source code in src/splifft/core.py
239 240 241 242 243 244 |
|
create_w2w_model
create_w2w_model(
model: Module,
model_input_type: ModelInputType,
model_output_type: ModelOutputType,
stft_cfg: StftConfig | None,
num_channels: Channels,
chunk_size: ChunkSize,
masking_cfg: MaskingConfig,
) -> ModelWaveformToWaveform
Source code in src/splifft/core.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
derive_stems
derive_stems(
separated_stems: Mapping[
ModelOutputStemName, RawAudioTensor
],
mixture_input: RawAudioTensor,
stem_rules: DerivedStemsConfig,
) -> dict[StemName, RawAudioTensor]
It is the caller's responsibility to ensure that all tensors are aligned and have the same shape.
Note
Mixture input and separated stems must first be denormalized.
Source code in src/splifft/core.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
str_to_torch_dtype
Source code in src/splifft/core.py
422 423 424 425 426 427 428 429 430 431 |
|