Skip to content

SMAF Engine Enhancement - #66

Merged
dlunch merged 3 commits into
dlunch:mainfrom
Magstic:main
Jun 24, 2026
Merged

SMAF Engine Enhancement#66
dlunch merged 3 commits into
dlunch:mainfrom
Magstic:main

Conversation

@Magstic

@Magstic Magstic commented Jun 23, 2026

Copy link
Copy Markdown
Contributor
  • HPS/Mobile/Softbank tri-format full support: Unified parse_handy_like entry point, Softbank sequence data parsing, Mobile compressed format Huffman decoding
  • Yamaha MA tone library mapping: ToneMap manages channel mapping, program change, and atmosphere layer synthesis
  • MIDI event extensions: Pitch bend, SysEx parsing and playback
  • MIDI channel auto-assignment: Automatically assigns channels per track to avoid conflicts
  • Loop playback: The repeat parameter is passed through from the WIPI C/Java API all the way to the backend SmafPlayer, supporting infinite looping
  • Full test coverage: Parser format tests, PCM short format lookup table tests, and backend repeat regression tests

Some feat require modifications on the Main Emulator side and will be submitted as a PR later. : )

Test Video:

bandicam.2026-06-23.12-19-01-757.mp4

Magstic added 3 commits June 23, 2026 10:52
…ser robustness

smaf crate changes:

- Tolerate unknown top-level chunks (SmafChunk::Unknown) instead of panicking

- Skip reserved MIDI status bytes 0xA0/0xD0 in mobile format instead of panicking

- Replace panic on unknown 0xFF second_byte with catch-all Nop

- Add parse_handy_variable_number for HPS variable-length encoding

- Refactor parse_handy into parse_handy_like(input, softbank) + parse_softbank wrapper

- Add short-format lookup tables: SHORT_MOD_VALUES, SHORT_EXPRESSION_VALUES

- Add SHORT_PITCH_BEND_VALUES and SHORT_EXPRESSION_VALUES for PCM audio track

- Rewrite PCM 0x00 branch to use event_type dispatch and lookup tables

- Change NoteMessage velocity to Option<u8> (HPS notes have no velocity)

- Add pitch_bend_byte_to_midi for 8-bit to 14-bit pitch bend conversion

- Add SoftbankSequenceData variant to SmafChunk and SEQU chunk parsing

- Add Huffman decoder (huffman_decode) for MobileStandardCompress format

- Export ChannelStatus, ChannelType, parse_variable_number, parse_handy_variable_number

- Add 16 integration tests covering all new functionality
smaf_player:

- Add ToneMap struct tracking per-channel state: channel types, programs,

  volumes, expressions, velocities, bank select, forced rhythm flags, and

  atmosphere layer configuration

- Add MIDI channel allocation with melody compaction around drum channel 9

  and per-track offset for HPS multi-track files

- Add Yamaha MA program mapping (0x7c/0x01 bank voices to GM fallbacks)

  and rhythm bank detection (0x7d)

- Add HPS-specific note mapping: melody notes get +36 offset, rhythm notes

  use program number as drum key

- Add HPS expression folding into volume (CC7) instead of CC11

- Add HPS drum velocity calculation from volume * expression

- Add atmosphere voice layering for Yamaha MA ambience voice (0x7c/0x01/0x62):

  emits two layered notes on channels 14/15 with reverb, chorus, and release

  envelope extensions

- Add setup data SysEx parsing with MIDI variable-length quantity

- Add octave shift, modulation (CC1), bank select (CC0), and pitch bend

  event conversion

- Add MidiPitchBend and MidiSysEx variants to SmafEvent

- Add stable event sort ordering (control changes before program changes

  before note events at same timestamp)

- Add SoftbankSequenceData chunk handling in parse_smaf

- Fix duration accumulation: apply duration before event time

- Add 11 unit tests covering ToneMap allocation, program mapping, atmosphere

  layering, HPS rhythm/melody behavior, and duration timing
smaf_cli:

- Add MidiPitchBend and MidiSysEx event handling

- Extract play_events into reusable async fn

- Wrap playback in loop {} for default infinite BGM looping

- Use saturating_sub for time delta to prevent underflow

- Clone wave data on each iteration for repeat playback

@dlunch dlunch left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dlunch
dlunch merged commit 4c4ca83 into dlunch:main Jun 24, 2026
10 checks passed
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.

2 participants