From fdc87707a62bd81795aa3fbaf35a5f5adbf1b7b0 Mon Sep 17 00:00:00 2001 From: zhangxin11112342 Date: Fri, 2 Feb 2024 14:59:46 +0800 Subject: [PATCH] =?UTF-8?q?fixed=209c5a711=20from=20https://gitee.com/zhan?= =?UTF-8?q?gxin11112342/chromium=5Fthird=5Fparty/pulls/137=20fixed=20beb9b?= =?UTF-8?q?15=20from=20https://gitee.com/zhangxin11112342/chromium=5Fthird?= =?UTF-8?q?=5Fparty/pulls/136=20=E4=BF=AE=E5=A4=8DCVE-2024-0224?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangxin11112342 --- blink/renderer/modules/webaudio/audio_param.cc | 13 ++++++++----- .../platform/audio/audio_delay_dsp_kernel.cc | 2 +- .../audio/cpu/arm/audio_delay_dsp_kernel_neon.cc | 7 +++++-- .../audio/cpu/x86/audio_delay_dsp_kernel_sse2.cc | 10 +++++++--- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/blink/renderer/modules/webaudio/audio_param.cc b/blink/renderer/modules/webaudio/audio_param.cc index c22648102d..974203ea0e 100644 --- a/blink/renderer/modules/webaudio/audio_param.cc +++ b/blink/renderer/modules/webaudio/audio_param.cc @@ -471,12 +471,15 @@ void AudioParam::setValue(float value) { void AudioParam::setValue(float value, ExceptionState& exception_state) { WarnIfOutsideRange("value", value); - // This is to signal any errors, if necessary, about conflicting - // automations. - setValueAtTime(value, Context()->currentTime(), exception_state); - // This is to change the value so that an immediate query for the - // value returns the expected values. + // Change the intrinsic value so that an immediate query for the value + // returns the value that the user code provided. It also clamps the value + // to the nominal range. Handler().SetValue(value); + + // Use the intrinsic value (after clamping) to schedule the actual + // automation event. + setValueAtTime(Handler().IntrinsicValue(), Context()->currentTime(), + exception_state); } float AudioParam::defaultValue() const { diff --git a/blink/renderer/platform/audio/audio_delay_dsp_kernel.cc b/blink/renderer/platform/audio/audio_delay_dsp_kernel.cc index c1da61832b..a0667f5b63 100644 --- a/blink/renderer/platform/audio/audio_delay_dsp_kernel.cc +++ b/blink/renderer/platform/audio/audio_delay_dsp_kernel.cc @@ -154,7 +154,7 @@ int AudioDelayDSPKernel::ProcessARateScalar(unsigned start, const float* delay_times = delay_times_.Data(); for (unsigned i = start; i < frames_to_process; ++i) { - double delay_time = delay_times[i]; + double delay_time = std::fmax(delay_times[i], 0); double desired_delay_frames = delay_time * sample_rate; double read_position = w_index + buffer_length - desired_delay_frames; diff --git a/blink/renderer/platform/audio/cpu/arm/audio_delay_dsp_kernel_neon.cc b/blink/renderer/platform/audio/cpu/arm/audio_delay_dsp_kernel_neon.cc index 4ac8a93785..63eed45af4 100644 --- a/blink/renderer/platform/audio/cpu/arm/audio_delay_dsp_kernel_neon.cc +++ b/blink/renderer/platform/audio/cpu/arm/audio_delay_dsp_kernel_neon.cc @@ -60,6 +60,7 @@ std::tuple AudioDelayDSPKernel::ProcessARateVector( int w_index = write_index_; const float32x4_t v_sample_rate = vdupq_n_f32(sample_rate); + const float32x4_t v_all_zeros = vdupq_n_f32(0); // The buffer length as a float and as an int so we don't need to constant // convert from one to the other. @@ -87,7 +88,8 @@ std::tuple AudioDelayDSPKernel::ProcessARateVector( int k = 0; for (int n = 0; n < number_of_loops; ++n, k += 4) { - const float32x4_t v_delay_time = vld1q_f32(delay_times + k); + const float32x4_t v_delay_time = vmaxq_f32(vld1q_f32(delay_times + k), + v_all_zeros); const float32x4_t v_desired_delay_frames = vmulq_f32(v_delay_time, v_sample_rate); @@ -100,7 +102,8 @@ std::tuple AudioDelayDSPKernel::ProcessARateVector( WrapPositionVector(v_read_position, v_buffer_length_float); // Get indices into the buffer for the samples we need for interpolation. - const int32x4_t v_read_index1 = vcvtq_s32_f32(v_read_position); + const int32x4_t v_read_index1 = WrapIndexVector( + vcvtq_s32_f32(v_read_position), v_buffer_length_int); const int32x4_t v_read_index2 = WrapIndexVector( vaddq_s32(v_read_index1, vdupq_n_s32(1)), v_buffer_length_int); diff --git a/blink/renderer/platform/audio/cpu/x86/audio_delay_dsp_kernel_sse2.cc b/blink/renderer/platform/audio/cpu/x86/audio_delay_dsp_kernel_sse2.cc index 350b48f2ae..7c50e46546 100644 --- a/blink/renderer/platform/audio/cpu/x86/audio_delay_dsp_kernel_sse2.cc +++ b/blink/renderer/platform/audio/cpu/x86/audio_delay_dsp_kernel_sse2.cc @@ -56,10 +56,10 @@ std::tuple AudioDelayDSPKernel::ProcessARateVector( const float sample_rate = SampleRate(); const float* delay_times = delay_times_.Data(); - int w_index = write_index_; const __m128 v_sample_rate = _mm_set1_ps(sample_rate); + const __m128 v_all_zeros = _mm_setzero_ps(); // The buffer length as a float and as an int so we don't need to constant // convert from one to the other. @@ -82,7 +82,10 @@ std::tuple AudioDelayDSPKernel::ProcessARateVector( int k = 0; for (int n = 0; n < number_of_loops; ++n, k += 4) { - const __m128 v_delay_time = _mm_loadu_ps(delay_times + k); + // It's possible that `delay_time` contains negative values. Make sure + // they are greater than zero. + const __m128 v_delay_time = _mm_max_ps(_mm_loadu_ps(delay_times + k), + v_all_zeros); const __m128 v_desired_delay_frames = _mm_mul_ps(v_delay_time, v_sample_rate); @@ -95,7 +98,8 @@ std::tuple AudioDelayDSPKernel::ProcessARateVector( WrapPositionVector(v_read_position, v_buffer_length_float); // Get indices into the buffer for the samples we need for interpolation. - const __m128i v_read_index1 = _mm_cvttps_epi32(v_read_position); + const __m128i v_read_index1 = WrapIndexVector( + _mm_cvttps_epi32(v_read_position), v_buffer_length_int); const __m128i v_read_index2 = WrapIndexVector( _mm_add_epi32(v_read_index1, _mm_set1_epi32(1)), v_buffer_length_int); -- Gitee