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

Method encode_acoustic_batch

src/models/vibevoice/tokenizer_audio.cpp:1771–1821  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1769}
1770
1771std::vector<VibeVoiceTokenizerLatents> VibeVoiceTokenizerWeightsRuntime::encode_acoustic_batch(
1772 const std::vector<runtime::AudioBuffer> & audio) const {
1773 if (audio.empty()) {
1774 throw std::runtime_error("VibeVoice acoustic tokenizer requires at least one audio prompt");
1775 }
1776 std::vector<std::vector<float>> waveforms;
1777 waveforms.reserve(audio.size());
1778 int64_t sample_count = 0;
1779 for (const auto & item : audio) {
1780 if (item.sample_rate <= 0 || item.channels <= 0 || item.samples.empty()) {
1781 throw std::runtime_error("VibeVoice acoustic tokenizer requires non-empty audio");
1782 }
1783 auto waveform = convert_vibevoice_audio_to_mono_resampled(
1784 item,
1785 kTokenizerSampleRate,
1786 "VibeVoice acoustic prompt");
1787 if (waveform.empty()) {
1788 throw std::runtime_error("VibeVoice acoustic tokenizer resampled audio is empty");
1789 }
1790 waveform = normalize_vibevoice_prompt_waveform(std::move(waveform), assets_->processor);
1791 sample_count = std::max(sample_count, static_cast<int64_t>(waveform.size()));
1792 waveforms.push_back(std::move(waveform));
1793 }
1794 const int64_t batch_size = static_cast<int64_t>(waveforms.size());
1795 std::vector<float> padded(static_cast<size_t>(batch_size * sample_count), 0.0F);
1796 for (int64_t batch = 0; batch < batch_size; ++batch) {
1797 const auto & waveform = waveforms[static_cast<size_t>(batch)];
1798 std::copy(
1799 waveform.begin(),
1800 waveform.end(),
1801 padded.begin() + static_cast<std::ptrdiff_t>(batch * sample_count));
1802 }
1803 if (acoustic_encoder_graph_ == nullptr ||
1804 !acoustic_encoder_graph_->matches(weights_->acoustic.encoder, batch_size, sample_count, backend_, threads_)) {
1805 acoustic_encoder_graph_.reset();
1806 acoustic_encoder_graph_ = std::make_unique<VibeVoiceTokenizerEncoderGraph>(
1807 weights_,
1808 weights_->acoustic.encoder,
1809 assets_->config.acoustic_tokenizer,
1810 "vibevoice.tokenizer.acoustic_encoder",
1811 batch_size,
1812 sample_count,
1813 backend_,
1814 backend_type_,
1815 threads_,
1816 *acoustic_encoder_constants_,
1817 1024ull * 1024ull * 1024ull);
1818 }
1819 auto encoded = acoustic_encoder_graph_->run(padded);
1820 return encoded;
1821}
1822
1823VibeVoiceTokenizerLatents VibeVoiceTokenizerWeightsRuntime::encode_semantic(const runtime::AudioBuffer & audio) const {
1824 if (audio.sample_rate <= 0 || audio.channels <= 0 || audio.samples.empty()) {

Callers 2

Calls 11

maxFunction · 0.85
copyFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
matchesMethod · 0.45
resetMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected