MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / repaint_step_injection

Function repaint_step_injection

src/framework/sampling/diffusion_math.cpp:297–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

295}
296
297std::vector<float> repaint_step_injection(
298 const std::vector<float> & generated,
299 const std::vector<float> & clean_source,
300 const std::vector<int32_t> & repaint_mask,
301 float next_timestep,
302 const std::vector<float> & noise,
303 int64_t channels) {
304 require_same_size(generated.size(), clean_source.size(), "repaint injection generated/source size mismatch");
305 require_same_size(generated.size(), noise.size(), "repaint injection generated/noise size mismatch");
306 if (channels <= 0 ||
307 generated.size() % static_cast<size_t>(channels) != 0 ||
308 repaint_mask.size() != generated.size() / static_cast<size_t>(channels)) {
309 throw std::runtime_error("repaint injection shape mismatch");
310 }
311 std::vector<float> out = generated;
312 for (size_t frame = 0; frame < repaint_mask.size(); ++frame) {
313 if (repaint_mask[frame] != 0) {
314 continue;
315 }
316 const size_t offset = frame * static_cast<size_t>(channels);
317 for (int64_t channel = 0; channel < channels; ++channel) {
318 const size_t index = offset + static_cast<size_t>(channel);
319 out[index] = next_timestep * noise[index] + (1.0F - next_timestep) * clean_source[index];
320 }
321 }
322 return out;
323}
324
325} // namespace engine::sampling

Callers 1

test_masksFunction · 0.85

Calls 2

require_same_sizeFunction · 0.85
sizeMethod · 0.45

Tested by 1

test_masksFunction · 0.68