Sonic (16-bit path): `findPitchPeriodInRange` compares in 32-bit ints that overflow on loud audio, so a badly matching pitch period can win
Maintainer thường phản hồi trong vòng 4 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- audio-video-rtc, backend
Hướng nghiên cứu
Đọc libraries/common/src/main/java/androidx/media3/common/audio/Sonic.java, đặc biệt là SonicShortImpl.findPitchPeriodInRange quanh các dòng 1114–1124. So sánh hai phép kiểm tra nhân số nguyên với phép tính long được trình bày trong issue, sau đó chạy hoặc điều chỉnh bản tái hiện PCM 16-bit âm lượng lớn ở tốc độ 1.1. Hoàn thành khi các phép so sánh tránh được tràn số và việc chọn chu kỳ cao độ khớp với kết quả tính toán long.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version
Media3 1.10.1
More version details
The same code is in Media3 1.11.1 and on main (e765dd45dbf58e67a578ae003ca64eaa449bcc28):
Devices that reproduce the issue
Every device: the issue is integer arithmetic in Sonic.java.
- Measured on the JVM, with Media3 1.10.1's own
Sonicclass (from themedia3-commonAAR) - Recorded on an Android 12 emulator (API 31, x86_64), playing through ExoPlayer at speed 1.1
- Heard on a Samsung Galaxy Note10+ running Android 12
Devices that do not reproduce the issue
No response
Reproducible in the demo app?
Not tested
Reproduction steps
-
Take loud 16-bit PCM at 44.1 kHz, stereo: speech mastered to full scale, or full-scale white noise.
-
Run it through
Sonicat speed 1.1, pitch 1 (for exampleSonicAudioProcessor.setSpeed(1.1f), or an ExoPlayer atsetPlaybackSpeed(1.1f)). -
Run the same input through a copy of
Sonicwhose two comparisons inSonicShortImpl.findPitchPeriodInRangeare made inlong:if ((long) diff * bestPeriod < (long) minDiff * period) { ... if ((long) diff * worstPeriod > (long) maxDiff * period) { -
Compare the two outputs: they differ. Scale the input down by 64, so that no product can reach 2^31, and they are identical, sample for sample.
The arithmetic alone, with values of the second pass: a poor candidate beats a good match.
int bestPeriod = 610, minDiff = 610 * 1_000; // the best so far: mean |s - p| of 1,000
int period = 600, diff = 600 * 8_000; // a poor candidate: mean |s - p| of 8,000
diff * bestPeriod < minDiff * period // true: -1366967296 < 366000000
(long) diff * bestPeriod < (long) minDiff * period // false: 2928000000 < 366000000
Expected result
The pitch search keeps the best-matching period at any level, as it does on quieter audio, in SonicFloatImpl (which holds diff, minDiff and maxDiff in doubles), and in the C library it was ported from (waywardgeek/sonic declares them unsigned long).
Suggested fix: the two casts of step 3.
Actual result
In SonicShortImpl.findPitchPeriodInRange the variables diff, minDiff, maxDiff, bestPeriod, worstPeriod and period are ints, so diff * bestPeriod < minDiff * period and diff * worstPeriod > maxDiff * period are evaluated in 32 bits. The comment above them says diff is a 24-bit number "since we skip samples". That holds for the first, down-sampled pass of findPitchPeriod. It does not hold for the second pass, which runs at the full rate (downSampleInput(positionFrames, 1) for more than one channel, the input buffer for mono) over periods of up to maxPeriod, 678 samples at 44.1 kHz. There diff sums up to 678 absolute differences of 16-bit samples, and its product with a period passes 2^31 once the mean absolute difference per sample is above about 2^31 / period² (about 13,400 at a period of 400, 4,700 at 678): any loud passage. A wrapped product decides the comparison, and a period that matches badly can be kept as the best one.
What it does to the sound: between 1x and 2x, Sonic blends the period it found into the next one. With a wrong period the two pieces are unalike, the blend partly cancels, and the level dips for a few milliseconds: a faint, rapid fluttering on a sustained voice.
Measured at speed 1.1 on a speech recording mastered to full scale (44.1 kHz stereo, −13 dBFS RMS, 120 s), 308 of 1,491 splices (21%) take another period once the comparisons are made in long, and the level dips at the splices fall:
| Level dips over 3 dB, per second (0.3–2 kHz) | as shipped | compared in long |
|---|---|---|
| the loud recording (−13 dBFS RMS, 120 s) | 1.78 | 0.97 |
| a quieter recording (−20 dBFS RMS, 175 s) | 1.49 | 1.15 |
A dip here is a run of 5 ms output frames whose level in the 0.3–2 kHz band is more than 3 dB below the best-matching place of the input; 306 of 310 dips over 1 dB lay within 12 ms of a splice.
Media
Any loud 16-bit PCM shows it (full-scale white noise is enough), so no file is attached. The measurements above used two speech recordings decoded to 44.1 kHz stereo 16-bit PCM.
No adb bugreport will follow: the issue is arithmetic and does not depend on the device.
Bug Report
- You will email the zip file produced by
adb bugreportto [email protected] after filing this issue.
- Ngôn ngữ chính
- Java
- Star
- 3.1k
- Fork
- 1k
- Merge trung bình
- 6 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của androidx/media
-
CompositionPlayer.release() leaks its playback thread and FrameProcessor when no composition was setCó thể đã có người làm @droid-girl đã nhận 15 ngày trước. Đang mởediting preview
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
androidx/media#3506 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 4 ngày
-
bug needs triage
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 4 ngày
-
RemoteCastPlayer: receiver stalls in buffering when a single setActiveMediaTracks request changes the audio and the text track during playbackCó thể đã có người làm @tanay187 đã nhận 1 ngày trước. Đang mởbug needs triage
androidx/media#3561 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 4 ngày
-
StuckPlayerException: PLAYING_NO_PROGRESS (1.10.1)Có thể đã có người làm @tonihei đã nhận 2 ngày trước. Đang mởquestion
androidx/media#3559 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 4 ngày
-
[Cast] play() right after setMediaItems() is lost when the receiver already has media, so the new item loads pausedCó thể đã có người làm @tanay187 đã nhận 3 ngày trước. Đang mở
androidx/media#3557 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của androidx/media
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
Vakore/ZappierGames#327 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Radix number block generates NaN after switching a negative or decimal number to binary, octal or hexCó thể đã có người làm @matthewalberto đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
mit-cml/appinventor-sources#4246 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
CatalogueOfLife/backend#1713 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SystemOneDecisionModel: allow sending chat_template_kwargs to /v1/systemoneCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởstatus: waiting-for-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
spring-projects/spring-ai#7427 ·
Maintainer thường phản hồi trong vòng 1 ngày