MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / S3GenSessionCache::State

Class S3GenSessionCache::State

src/models/chatterbox/s3gen_inference.cpp:344–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

342 }
343 const int64_t keep = std::min<int64_t>(static_cast<int64_t>(waveform.size()), fade_size);
344 for (int64_t i = 0; i < std::min<int64_t>(keep, n_trim); ++i) {
345 waveform[static_cast<size_t>(i)] = 0.0f;
346 }
347 constexpr double kPi = 3.141592653589793238462643383279502884;
348 for (int64_t i = n_trim; i < keep; ++i) {
349 const double alpha = static_cast<double>(i - n_trim) / static_cast<double>(std::max<int64_t>(n_trim - 1, 1));
350 const float fade = static_cast<float>((std::cos(kPi * (1.0 - alpha)) + 1.0) / 2.0);
351 waveform[static_cast<size_t>(i)] *= fade;
352 }
353}
354
355} // namespace
356
357struct S3GenSessionCache::State {
358 explicit State(engine::core::BackendConfig backend_value)
359 : backend(std::move(backend_value)),
360 token_capacity_controller(runtime::GraphCapacityMode::Grow),
361 flow_cache(backend) {}
362
363 struct PreparedCapacity {
364 int64_t token_capacity = 0;
365 int64_t frame_capacity = 0;
366 std::unique_ptr<S3TokenEmbeddingGraph> token_embedding;
367 std::unique_ptr<S3Token2MelPrepareGraph> token2mel_prepare;
368 };
369
370 runtime::MappedGraphCapacityAdapter make_token_capacity_adapter(
371 const S3FlowEncoderWeights & weights,
372 const engine::core::BackendConfig & backend_config) {
373 const int64_t quantum = token_capacity_quantum(backend_config);
374 return runtime::MappedGraphCapacityAdapter(
375 quantum,
376 quantum,
377 [quantum](int64_t request_size) {
378 return round_up_capacity(request_size, quantum);
379 },
380 [this]() {
381 std::vector<int64_t> capacities;
382 if (prepared_capacity.token_embedding && prepared_capacity.token2mel_prepare) {
383 capacities.push_back(prepared_capacity.token_capacity);
384 }
385 return capacities;
386 },
387 [this, &weights](int64_t capacity) {
388 prepare_token_capacity(weights, capacity);
389 });
390 }
391
392 void prepare_token_capacity(
393 const S3FlowEncoderWeights & weights,
394 int64_t token_capacity) {
395 if (token_capacity <= 0) {
396 throw std::runtime_error("S3 token capacity must be positive");
397 }
398 if (prepared_capacity.token_embedding &&
399 prepared_capacity.token2mel_prepare &&
400 prepared_capacity.token_capacity == token_capacity) {
401 return;

Callers

nothing calls this directly

Calls 2

ensure_preparedMethod · 0.80

Tested by

no test coverage detected