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

Method encode

src/models/miocodec/graphs.cpp:184–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182 }
183
184 MioCodecContentEmbedding encode(const std::vector<float> & ssl_features, int64_t ssl_frames) const {
185 if (ssl_frames <= 0 || ssl_frames > ssl_frame_capacity_ ||
186 static_cast<int64_t>(ssl_features.size()) != ssl_frames * 768) {
187 throw std::runtime_error("MioCodec content encoder input shape mismatch");
188 }
189 const int64_t content_frames = conv1d_output_frames(weights_->conv_downsample.config, ssl_frames);
190 if (content_frames <= 0 || content_frames > content_frame_capacity_) {
191 throw std::runtime_error("MioCodec content encoder output frame count exceeds graph capacity");
192 }
193 auto timing_start = Clock::now();
194 core::write_tensor_f32(input_, ssl_features);
195 core::write_tensor_f32(
196 attention_mask_,
197 local_attention_mask(
198 1,
199 ssl_frame_capacity_,
200 weights_->local_encoder.window_size,
201 ssl_frames));
202 engine::debug::timing_log_scalar("miocodec.content_encoder.input_upload_ms", engine::debug::elapsed_ms(timing_start));
203 timing_start = Clock::now();
204 if (core::compute_backend_graph(backend_, graph_) != GGML_STATUS_SUCCESS) {
205 throw std::runtime_error("MioCodec content encoder graph execution failed");
206 }
207 engine::debug::timing_log_scalar("miocodec.content_encoder.graph.compute_ms", engine::debug::elapsed_ms(timing_start));
208 MioCodecContentEmbedding out;
209 out.frames = content_frames;
210 out.dim = output_->ne[0];
211 timing_start = Clock::now();
212 out.values = core::read_tensor_f32(output_);
213 out.values.resize(static_cast<size_t>(out.frames * out.dim));
214 engine::debug::timing_log_scalar("miocodec.content_encoder.output_read_ms", engine::debug::elapsed_ms(timing_start));
215 return out;
216 }
217
218private:
219 std::unique_ptr<ggml_context, GgmlContextDeleter> ctx_;

Callers

nothing calls this directly

Calls 9

local_attention_maskFunction · 0.85
compute_backend_graphFunction · 0.85
read_tensor_f32Function · 0.85
conv1d_output_framesFunction · 0.70
write_tensor_f32Function · 0.50
timing_log_scalarFunction · 0.50
elapsed_msFunction · 0.50
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected