diff --git a/crates/test_util/compatible_engine.h b/crates/test_util/compatible_engine.h index 15cfb2617..2cd58b971 100644 --- a/crates/test_util/compatible_engine.h +++ b/crates/test_util/compatible_engine.h @@ -26,11 +26,10 @@ bool decode_forward(int64_t length, int64_t phoneme_size, float *f0, float *phoneme, int64_t *speaker_id, float *output); bool generate_full_intermediate(int64_t length, int64_t phoneme_size, - int64_t margin_width, int64_t feature_dim, float *f0, float *phoneme, int64_t *speaker_id, float *output); -bool render_audio_segment(int64_t length, int64_t feature_dim, float *audio_feature, - int64_t *speaker_id, float *output); +bool render_audio_segment(int64_t length, int64_t margin_width, int64_t feature_size, + float *audio_feature, int64_t *speaker_id, float *output); const char *last_error_message(); diff --git a/crates/voicevox_core_c_api/src/compatible_engine.rs b/crates/voicevox_core_c_api/src/compatible_engine.rs index d973eede6..5bcbed165 100644 --- a/crates/voicevox_core_c_api/src/compatible_engine.rs +++ b/crates/voicevox_core_c_api/src/compatible_engine.rs @@ -364,13 +364,11 @@ pub unsafe extern "C" fn decode_forward( /// - `f0`はRustの`&[f32; length as usize]`として解釈できなければならない。 /// - `phoneme`はRustの`&[f32; phoneme_size * length as usize]`として解釈できなければならない。 /// - `speaker_id`はRustの`&[i64; 1]`として解釈できなければならない。 -/// - `output`はRustの`&mut [MaybeUninit; ((length + 2 * margin_width) * feature_dim) as usize]`として解釈できなければならない。 +/// - `output`はRustの`&mut [MaybeUninit; ((length + 2 * 14) * 80) as usize]`として解釈できなければならない。 #[unsafe(no_mangle)] // SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない pub unsafe extern "C" fn generate_full_intermediate( length: i64, phoneme_size: i64, - margin_width: i64, - feature_dim: i64, f0: *mut f32, phoneme: *mut f32, speaker_id: *mut i64, @@ -383,8 +381,8 @@ pub unsafe extern "C" fn generate_full_intermediate( assert_aligned(output); let length = length as usize; let phoneme_size = phoneme_size as usize; - let margin_width = margin_width as usize; - let feature_dim = feature_dim as usize; + const MARGIN_WIDTH: usize = 14; + const FEATURE_SIZE: usize = 80; let synthesizer = &*lock_synthesizer(); let result = ensure_initialized!(synthesizer).generate_full_intermediate( length, @@ -396,7 +394,7 @@ pub unsafe extern "C" fn generate_full_intermediate( ); match result { Ok(output_arr) => { - let output_len = (length + 2 * margin_width) * feature_dim; + let output_len = (length + 2 * MARGIN_WIDTH) * FEATURE_SIZE; if output_arr.len() != output_len { panic!("expected {}, got {}", output_len, output_arr.len()); } @@ -418,13 +416,14 @@ pub unsafe extern "C" fn generate_full_intermediate( /// # Safety /// -/// - `audio_feature`はRustの`&[f32; (length * feature_dim) as usize]`として解釈できなければならない。 +/// - `audio_feature`はRustの`&[f32; (length * feature_size) as usize]`として解釈できなければならない。 /// - `speaker_id`はRustの`&[i64; 1]`として解釈できなければならない。 /// - `output`はRustの`&mut [MaybeUninit; length as usize * 256]`として解釈できなければならない。 #[unsafe(no_mangle)] // SAFETY: voicevox_core_c_apiを構成するライブラリの中に、これと同名のシンボルは存在しない pub unsafe extern "C" fn render_audio_segment( length: i64, - feature_dim: i64, + _margin_width: i64, + feature_size: i64, audio_feature: *mut f32, speaker_id: *mut i64, output: *mut f32, @@ -434,12 +433,12 @@ pub unsafe extern "C" fn render_audio_segment( assert_aligned(speaker_id); assert_aligned(output); let length = length as usize; - let feature_dim = feature_dim as usize; + let feature_size = feature_size as usize; let synthesizer = &*lock_synthesizer(); let result = ensure_initialized!(synthesizer).render_audio_segment( // SAFETY: The safety contract must be upheld by the caller. unsafe { - ndarray::ArrayView2::from_shape_ptr([length, feature_dim], audio_feature).to_owned() + ndarray::ArrayView2::from_shape_ptr([length, feature_size], audio_feature).to_owned() }, StyleId::new(unsafe { *speaker_id as u32 }), ); diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs index 2caa363d5..badf165fd 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs @@ -93,8 +93,6 @@ impl assert_cdylib::TestCase for TestCase { assert!(lib.generate_full_intermediate( EXAMPLE_DATA.intermediate.f0_length, EXAMPLE_DATA.intermediate.phoneme_size, - EXAMPLE_DATA.intermediate.margin_width, - EXAMPLE_DATA.intermediate.feature_dim, EXAMPLE_DATA.intermediate.f0_vector.as_ptr() as *mut f32, EXAMPLE_DATA.intermediate.phoneme_vector.as_ptr() as *mut f32, &mut { EXAMPLE_DATA.speaker_id } as *mut i64, @@ -102,6 +100,7 @@ impl assert_cdylib::TestCase for TestCase { )); assert!(lib.render_audio_segment( length_with_margin, + EXAMPLE_DATA.intermediate.margin_width, EXAMPLE_DATA.intermediate.feature_dim, audio_feature.as_ptr() as *mut f32, &mut { EXAMPLE_DATA.speaker_id } as *mut i64, @@ -122,8 +121,6 @@ impl assert_cdylib::TestCase for TestCase { assert!(lib.generate_full_intermediate( EXAMPLE_DATA.intermediate.f0_length, EXAMPLE_DATA.intermediate.phoneme_size, - EXAMPLE_DATA.intermediate.margin_width, - EXAMPLE_DATA.intermediate.feature_dim, EXAMPLE_DATA.intermediate.f0_vector.as_ptr() as *mut f32, EXAMPLE_DATA.intermediate.phoneme_vector.as_ptr() as *mut f32, &mut { EXAMPLE_DATA.speaker_id } as *mut i64, @@ -141,6 +138,7 @@ impl assert_cdylib::TestCase for TestCase { let mut wave_segment_with_margin = vec![0.; 256 * slice_length]; assert!(lib.render_audio_segment( slice_length as i64, + EXAMPLE_DATA.intermediate.margin_width, pitch as i64, feature_segment.as_ptr() as *mut f32, &mut { EXAMPLE_DATA.speaker_id } as *mut i64, @@ -163,8 +161,8 @@ impl assert_cdylib::TestCase for TestCase { assert!(wave.iter().copied().all(f32::is_normal)); assert!(wave2.iter().copied().all(f32::is_normal)); assert!(wave3.iter().copied().all(f32::is_normal)); - float_assert::close_l1(&wave2, &wave, 0.01); - float_assert::close_l1(&wave3, &wave, 0.01); + float_assert::close_l1(&wave2, &wave, 0.001); + float_assert::close_l1(&wave3, &wave, 0.001); lib.finalize(); Ok(())