#pragma once #include "engine/community_models/realtime_reuse/runtime.h" #include "engine/framework/audio/dsp.h" #include "engine/framework/audio/fft.h" #include #include namespace engine::models::realtime_reuse { struct Spectrum { audio::STFTConfig config; audio::AudioTensor spectrum; std::vector features; int64_t samples = 0, frames = 0, bins = 0; }; Spectrum analyze_spectrum(const std::vector & waveform, int sample_rate, size_t threads); std::vector synthesize_spectrum(Spectrum & input, const std::array, 3> & heads, size_t threads); std::vector restore(Runtime & runtime, const std::vector & waveform, int sample_rate, size_t threads); class StreamingFrontend { public: StreamingFrontend(Runtime & runtime, int sample_rate, size_t threads); std::vector push(const std::vector & samples, bool final); private: void analyze(bool final, std::vector & output); void infer(std::vector & output, bool final = false); Runtime & runtime_; size_t threads_; int64_t fft_, hop_, bins_; int64_t received_ = 0, input_offset_ = 0, analyzed_ = 0, synthesized_ = 0, emitted_ = 0; bool finished_ = false; int64_t batch_frames_ = 1; std::shared_ptr plan_; std::vector window_, frame_, overlap_, denominator_; std::vector> spectrum_; std::deque input_, pending_audio_; std::deque> features_; }; } // namespace engine::models::realtime_reuse