Description
OscillatorNode produces no audio (or severe rolloff starting ~9.5 kHz) for frequencies
above ~9.5 kHz on Android devices where PROPERTY_OUTPUT_SAMPLE_RATE is 24 kHz
(tested Huawei Nova 3i Android 9, Samsung Galaxy S22+ Android 16).
Root cause is in PeriodicWave::getPeriodicWaveSize()
(common/cpp/audioapi/core/effects/PeriodicWave.cpp):
if (sampleRate_ <= 24000) {
return 2048; // Nyquist = 12 kHz; band-limiting culls from ~9.5 kHz
}
When AudioContext is created without an explicit sampleRate, the library falls back to
AudioManager.getDevicePreferredSampleRate(), which reads PROPERTY_OUTPUT_SAMPLE_RATE.
On affected devices this returns 24000, so BaseAudioContext::sampleRate_ = 24000 and
getPeriodicWaveSize() returns 2048 (not 4096). The smaller table cap causes
getMaxNumberOfPartials() = 1024, leaving ~1 partial at 9.5 kHz and 0 at 12 kHz.
Expected: audio at 9.5–12 kHz is audible when the device preferred sample rate is 24000.
Actual: silent above ~12 kHz, severe rolloff from ~9.5 kHz.
Fix: change <= to < in getPeriodicWaveSize() so that exactly-24000 Hz
gets the 4096-entry table. PR to follow.
Steps to reproduce
- On an affected device, create an AudioContext without specifying sampleRate:
const ctx = new AudioContext();
- Confirm ctx.sampleRate === 24000
- Create an OscillatorNode, sweep frequency from 9000-12000 Hz,
connect to destination, call start()
- Observe: rolloff from ~9.5 kHz, silence at 12 kHz
Snack or a link to a repository
https://gist.github.com/spikything/5d549db6ad7872482ef26992e60a1109
React Native Audio API version
0.12.2
React Native version
0.81.5
Platforms
Android
JavaScript runtime
Hermes
Workflow
Expo Dev Client
Architecture
Fabric (New Architecture)
Build type
Release app & production bundle
Device
Real device
Device model
Huawei Nova 3i (Android 9), Samsung Galaxy S22+ (Android 16)
Acknowledgements
Yes
Description
OscillatorNode produces no audio (or severe rolloff starting ~9.5 kHz) for frequencies
above ~9.5 kHz on Android devices where PROPERTY_OUTPUT_SAMPLE_RATE is 24 kHz
(tested Huawei Nova 3i Android 9, Samsung Galaxy S22+ Android 16).
Root cause is in PeriodicWave::getPeriodicWaveSize()
(common/cpp/audioapi/core/effects/PeriodicWave.cpp):
When AudioContext is created without an explicit sampleRate, the library falls back to
AudioManager.getDevicePreferredSampleRate(), which reads PROPERTY_OUTPUT_SAMPLE_RATE.
On affected devices this returns 24000, so BaseAudioContext::sampleRate_ = 24000 and
getPeriodicWaveSize() returns 2048 (not 4096). The smaller table cap causes
getMaxNumberOfPartials() = 1024, leaving ~1 partial at 9.5 kHz and 0 at 12 kHz.
Expected: audio at 9.5–12 kHz is audible when the device preferred sample rate is 24000.
Actual: silent above ~12 kHz, severe rolloff from ~9.5 kHz.
Fix: change
<=to<in getPeriodicWaveSize() so that exactly-24000 Hzgets the 4096-entry table. PR to follow.
Steps to reproduce
const ctx = new AudioContext();
connect to destination, call start()
Snack or a link to a repository
https://gist.github.com/spikything/5d549db6ad7872482ef26992e60a1109
React Native Audio API version
0.12.2
React Native version
0.81.5
Platforms
Android
JavaScript runtime
Hermes
Workflow
Expo Dev Client
Architecture
Fabric (New Architecture)
Build type
Release app & production bundle
Device
Real device
Device model
Huawei Nova 3i (Android 9), Samsung Galaxy S22+ (Android 16)
Acknowledgements
Yes