Skip to content

Commit

Permalink
use continuous copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Yosshi999 committed Nov 21, 2024
1 parent b55720f commit cd6e72e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions crates/voicevox_core_c_api/src/compatible_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,17 @@ pub unsafe extern "C" fn generate_full_intermediate(
);
match result {
Ok(output_arr) => {
let output_len = (length + 2 * margin_width) * feature_dim;
if output_arr.len() != output_len {
panic!("expected {}, got {}", output_len, output_arr.len());
}
let output_arr = output_arr.as_standard_layout();
// SAFETY: The safety contract must be upheld by the caller.
let output_slice = unsafe {
std::slice::from_raw_parts_mut(output, (length + 2 * margin_width) * feature_dim)
};
output_slice.clone_from_slice(&output_arr.into_raw_vec());
unsafe {
output_arr
.as_ptr()
.copy_to_nonoverlapping(output, output_len);
}
true
}
Err(err) => {
Expand All @@ -414,7 +420,7 @@ pub unsafe extern "C" fn generate_full_intermediate(
///
/// - `audio_feature`はRustの`&[f32; (length * feature_dim) as usize]`として解釈できなければならない。
/// - `speaker_id`はRustの`&[i64; 1]`として解釈できなければならない。
/// - `output`はRustの`&mut [f32; length as usize * 256]`として解釈できなければならない。
/// - `output`はRustの`&mut [MaybeUninit<f32>; length as usize * 256]`として解釈できなければならない。
#[unsafe(no_mangle)] // SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない
pub unsafe extern "C" fn render_audio_segment(
length: i64,
Expand All @@ -426,6 +432,7 @@ pub unsafe extern "C" fn render_audio_segment(
init_logger_once();
assert_aligned(audio_feature);
assert_aligned(speaker_id);
assert_aligned(output);
let length = length as usize;
let feature_dim = feature_dim as usize;
let synthesizer = &*lock_synthesizer();
Expand Down

0 comments on commit cd6e72e

Please sign in to comment.