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

Method prepare_chunk

src/models/demucs/frontend.cpp:244–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242}
243
244void HTDemucsFrontend::prepare_chunk(std::vector<float> & chunk_planar) {
245 if (chunk_planar.empty() || static_cast<int64_t>(chunk_planar.size()) % config_.audio_channels != 0) {
246 throw std::runtime_error("HTDemucs chunk size mismatch");
247 }
248 input_samples_ = static_cast<int64_t>(chunk_planar.size()) / config_.audio_channels;
249 if (input_samples_ > config_.segment_samples) {
250 throw std::runtime_error("HTDemucs chunk length exceeds training segment length");
251 }
252 if (input_samples_ != config_.segment_samples) {
253 throw std::runtime_error("HTDemucs frontend expects session chunks padded to segment length");
254 }
255 time_input_ = &chunk_planar;
256
257 pad1d_reflect_fast(
258 padded_,
259 *time_input_,
260 config_.audio_channels,
261 config_.segment_samples,
262 pad_indices_);
263 compute_stft_complex_normalized(
264 stft_framed_,
265 stft_spectrum_,
266 padded_,
267 stft_window_,
268 config_.audio_channels,
269 padded_samples_,
270 stft_full_frames_,
271 config_.n_fft,
272 stft_frame_indices_,
273 fft_threads_);
274 const auto [freq_sum, freq_sumsq] = build_demucs_complex_input(
275 freq_input_,
276 stft_spectrum_,
277 config_.audio_channels,
278 config_.stft_freq_bins,
279 config_.stft_frames,
280 stft_full_frames_);
281 std::tie(freq_mean_, freq_std_) = normalize_in_place_with_stats(freq_input_, freq_sum, freq_sumsq);
282 std::tie(time_mean_, time_std_) = normalize_in_place(*time_input_);
283}
284
285const std::vector<float> & HTDemucsFrontend::freq_input() const noexcept { return freq_input_; }
286const std::vector<float> & HTDemucsFrontend::time_input() const noexcept { return *time_input_; }

Callers 1

pipeline.cppFile · 0.80

Calls 7

pad1d_reflect_fastFunction · 0.85
normalize_in_placeFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected