Skip to content

feat: SrcChannel, AudiocodecDecoder, and MP3 utilities#7

Merged
AndrewAltimit merged 1 commit intomainfrom
feat/audiocodec-src-channel
Feb 15, 2026
Merged

feat: SrcChannel, AudiocodecDecoder, and MP3 utilities#7
AndrewAltimit merged 1 commit intomainfrom
feat/audiocodec-src-channel

Conversation

@AndrewAltimit
Copy link
Owner

Summary

  • SrcChannel in audio.rs -- RAII wrapper for the PSP's global SRC (Sample Rate Conversion) channel, a singleton separate from the 8 regular PCM channels. Essential for kernel plugins providing background audio without conflicting with game audio.
  • AudiocodecDecoder in new audiocodec.rs -- High-level sceAudiocodec wrapper with RAII EDRAM management. Documents the reverse-engineered 65-word codec buffer field layout (indices [3-10, 14]) discovered from Sony's mp3play.prx disassembly. Supports MP3, AAC, ATRAC3, and ATRAC3plus.
  • find_sync() and skip_id3v2() in mp3.rs -- MP3 frame sync detection with MPEG version/layer validation, and ID3v2 tag skipping.
  • Removed incorrect kernel feature gate from sys/codec.rs -- sceAudiocodec* and sceVideocodec* work in user mode when AVCODEC modules are loaded via sceUtilityLoadModule. The kernel gate was overly restrictive.
  • AudioCodec enum -- Added #[derive(Debug, Clone, Copy, PartialEq, Eq)] and #[repr(i32)].

Test plan

  • cargo +nightly build --features kernel -p psp -- builds cleanly (no new warnings)
  • cargo +nightly build -p psp -- builds cleanly without kernel feature (validates codec gate removal)
  • cargo +nightly fmt --all -- formatted
  • Cross-compiled oasis-plugin-psp PRX against this branch -- builds successfully

Generated with Claude Code

- audio.rs: Add SrcChannel RAII wrapper for the PSP's global SRC (Sample
  Rate Conversion) channel, separate from the 8 PCM channels. Includes
  OutputFrequency enum mirroring sys::AudioOutputFrequency.

- audiocodec.rs: New high-level sceAudiocodec wrapper with RAII EDRAM
  management. Documents the reverse-engineered 65-word codec buffer layout
  (field indices [3-10, 14]) discovered from Sony's mp3play.prx. Supports
  MP3, AAC, ATRAC3, and ATRAC3plus decoding.

- mp3.rs: Add find_sync() for locating MP3 frame sync positions with
  MPEG version/layer validation, and skip_id3v2() for parsing ID3v2 tags.

- sys/codec.rs: Remove incorrect kernel-only feature gate (sceAudiocodec
  works in user mode with AVCODEC modules loaded). Add derives and
  #[repr(i32)] to AudioCodec enum. Update documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

Gemini AI Code Review

Issues

  • [BUG] psp/src/audiocodec.rs:141 - Missing alignment verification for src and dst buffers.

    • Hardware audio codecs on the PSP typically require 64-byte alignment for both input (compressed) and output (PCM) buffers as they are processed by the Media Engine (ME) via DMA. Providing unaligned buffers can cause hardware exceptions or silent failures.
    • Consider adding a debug assertion or returning an error if src.as_ptr() or dst.as_ptr() are not 64-byte aligned.
  • [WARNING] psp/src/audio.rs:268 - Opaque error code -1.

    • AudioError(-1) is used when the buffer is too small, but -1 is a generic SCE error.
    • Use a more specific error if available, or document that this signifies a local validation failure rather than a syscall error.

Previous Issues

(none)

Suggestions

  • psp/src/audiocodec.rs:48 - Avoid duplicating the codec enum.

    • CodecType is identical to crate::sys::AudioCodec. Reuse the existing enum from the sys module to maintain a single source of truth for hardware constants.
  • psp/src/audiocodec.rs:133 - Use core::mem::size_of_val for clarity.

    • let dst_bytes = dst.len() * 2; is correct for i16, but core::mem::size_of_val(dst) is more idiomatic and robust.

Notes

  • SrcChannel correctly implements !Send and !Sync via PhantomData<*const ()>, ensuring the hardware singleton isn't shared across threads unsafely.
  • Removing the feature = "kernel" gate from sys/codec.rs is correct; these modules are accessible in user mode via sceUtilityLoadModule.
  • The documentation for the reverse-engineered 65-word codec buffer layout is excellent and provides high value for maintainability.

Reaction


Generated by Gemini AI (gemini-3-flash-preview). Supplementary to human reviews.

@AndrewAltimit
Copy link
Owner Author

Review Response Agent (Iteration 1)

Status: No changes needed

Fixed Issues

  • (none)

Ignored Issues

  • [BUG] audiocodec.rs:141 - Missing alignment verification for src/dst buffers: Speculative. PSP's sceAudiocodecDecode handles DMA internally via ME firmware. Sony's own mp3play.prx uses regular heap buffers. The codec buffer itself is already 64-byte aligned. No evidence that user-provided src/dst buffers require alignment.
  • [WARNING] audio.rs:283 - Opaque error code -1: AudioError(-1) is an established pattern in this file, already used at lines 114 and 140 for identical buffer-too-short validation. Consistent with existing code.
  • Suggestion to reuse sys::AudioCodec instead of CodecType: Intentional pattern — high-level modules define their own ergonomic types, matching OutputFrequency/AudioFormat pattern in audio.rs.
  • Suggestion to use size_of_val: Stylistic preference, not a bug. dst.len() * 2 with // i16 -> bytes comment is clear.

Deferred to Human

  • (none)

Notes

  • Codex review failed due to OpenAI rate limits (429), so only Gemini feedback was available.
  • All Gemini feedback was either speculative hardware concerns, stylistic suggestions, or changes that would break consistency with existing patterns in the codebase. No actionable bugs found.

The agent reviewed feedback but determined no code changes were required.

@AndrewAltimit AndrewAltimit merged commit b44a1c2 into main Feb 15, 2026
7 checks passed
@AndrewAltimit AndrewAltimit deleted the feat/audiocodec-src-channel branch February 15, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant