fix: pulseaudio sample rate by detecting optimal system value#1456
fix: pulseaudio sample rate by detecting optimal system value#1456joshuatam wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughPulseAudioComponent now queries the device's audio output sample rate dynamically via AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE when starting PulseAudio, falling back to 44.1kHz. The manual ChangesDynamic Audio Sample Rate Detection
Sequence Diagram(s)sequenceDiagram
participant PulseAudioComponent
participant AndroidAudioManager
participant PulseAudioProcess
PulseAudioComponent->>AndroidAudioManager: getProperty(PROPERTY_OUTPUT_SAMPLE_RATE)
AndroidAudioManager-->>PulseAudioComponent: "48000" or null
PulseAudioComponent->>PulseAudioProcess: execPulseAudio(rate=bitRate, /* -vvv optional */)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@app/src/main/java/com/winlator/xenvironment/components/PulseAudioComponent.java`:
- Around line 35-39: The getOptimalSampleRate method should defensively handle
null or non-numeric values from
AudioManager.getProperty(PROPERTY_OUTPUT_SAMPLE_RATE): check for null/empty,
trim the string, attempt to parse inside a try/catch for NumberFormatException,
and fall back to 44100 on any failure; update the method (referencing
getOptimalSampleRate, AudioManager, environment.getContext(), and
PROPERTY_OUTPUT_SAMPLE_RATE) to return the parsed int when valid, otherwise
return the safe default.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 03f37b5f-48a9-4c0f-a4e0-86b9b46a4278
📒 Files selected for processing (2)
app/src/main/assets/pulseaudio-gamenative.tzstapp/src/main/java/com/winlator/xenvironment/components/PulseAudioComponent.java
|
Question - the new tzst has been added but will only apply for new games right? It will not fix pulse on existing games? |
The pulseaudio sample rate is now dynamically detected from the Android AudioManager, ensuring the use of the optimal output sample rate for the device. This improves audio compatibility and quality compared to using a fixed rate. The bundled pulseaudio binary (`pulseaudio-gamenative.tzst`) has also been updated, removed exclusive stream config for better compatibility.
5df39d0 to
6c32134
Compare
No, whenever updating this tzst, it will always replace the installed files in files dir. Check this code: GameNative/app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt Lines 4227 to 4228 in 5cacc3b and GameNative/app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt Lines 4371 to 4373 in 5cacc3b |
Description
The pulseaudio sample rate is now dynamically detected from the Android AudioManager, ensuring the use of the optimal output sample rate for the device. This improves audio compatibility and quality compared to using a fixed rate.
The bundled pulseaudio binary (
pulseaudio-gamenative.tzst) has also been updated, removed exclusive stream config for better compatibility.Recording
None
Type of Change
Checklist
#code-changes, I have discussed this change there and it has been green-lighted. If I do not have access, I have still provided clear context in this PR. If I skip both, I accept that this change may face delays in review, may not be reviewed at all, or may be closed.CONTRIBUTING.md.Summary by cubic
Detects the device’s output sample rate via Android
AudioManagerand configures PulseAudio to use it instead of a fixed value. This avoids resampling and improves audio compatibility and quality across devices.AudioManager.PROPERTY_OUTPUT_SAMPLE_RATEwith a 44100 Hz fallback.module-aaudio-sinkin generateddefault.pa.pulseaudio-gamenative.tzstto remove exclusive stream config for broader device support.Written for commit 6c32134. Summary will update on new commits. Review in cubic
Summary by CodeRabbit