Skip to content

SoundFont 2: add option to keep length-mismatched stereo-linked samples as mono#169

Open
douglas-carmichael wants to merge 1 commit into
git-moss:mainfrom
douglas-carmichael:sf2-stereo-pair-length-mismatch
Open

SoundFont 2: add option to keep length-mismatched stereo-linked samples as mono#169
douglas-carmichael wants to merge 1 commit into
git-moss:mainfrom
douglas-carmichael:sf2-stereo-pair-length-mismatch

Conversation

@douglas-carmichael

@douglas-carmichael douglas-carmichael commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Problem

Some SoundFonts — in particular commercial E-mu banks such as the "Orbit" bank — carry unreliable stereo metadata: samples are flagged as left/right and linked (wSampleLink) to partners they are not actually the stereo halves of. When such a bank is converted, combineToStereo tries to weld these "pairs" back together.

compareSampleFormat already declines the merge when the two samples differ in pitch or sample rate, but a length mismatch only logged a warning and then merged them anyway — so two unrelated sounds ended up hard-panned into the left and right channels of a single stereo sample (the shorter one truncating the longer). Converting one such bank also produced a wall of warnings.

Change (updated per review)

Per @git-moss's feedback that some banks contain genuine stereo pairs whose left/right channels differ in length, the length-mismatch behaviour is now opt-in and off by default:

  • New "Keep mismatched stereo samples as mono" option (Sf2KeepMismatchedStereoAsMono, off by default). When enabled, a length mismatch declines the stereo merge just like a pitch/sample-rate mismatch, so the two samples are kept as the separate mono samples they actually are. Off by default a length-mismatched pair still combines, so genuine different-length stereo pairs are unaffected.
  • The pitch / sample-rate / length "left and right samples do not match" notices are now shown only when the existing Log unused SF2 generators option is enabled, so a normal conversion of a quirky bank stays clean while the detail is still available on request.

Since the stereo-combining happens while reading the SoundFont, the checkbox lives in the SF2 source options (next to "Log unused SF2 generators"); happy to move it if you'd prefer it elsewhere.

Rebased onto current main. The diff is limited to Sf2Detector.java, Sf2DetectorUI.java, Strings.properties, and the changelog / format docs.

Verification

Tested against a commercial E-mu "Orbit" SoundFont, converting every preset to WAV:

  • Off (default): the 3 length-mismatched pairs are each combined into a single stereo file (unchanged from before this PR).
  • On (Sf2KeepMismatchedStereoAsMono=1): those 3 pairs are instead kept as their 6 separate full-length mono samples (+3 files); the channel that was previously truncated keeps its full length.

Pitch- and sample-rate-mismatched pairs remain mono in both cases (unchanged).

douglas-carmichael added a commit to douglas-carmichael/ConvertWithMoss that referenced this pull request Jul 7, 2026
…sub-folder + sample grouping fix (git-moss#170)

SoundFont 2: a length mismatch between two samples a SoundFont links as a stereo pair now declines the merge (they are kept as mono), and the pitch/rate/length mismatch notices are gated behind the log-unsupported-attributes option. Synthstrom Deluge: writing into a SYNTHS/KITS sub-folder now writes the preset there and its samples into a matching sub-folder of the card-root SAMPLES, instead of nesting a SYNTHS/SAMPLES pair inside the chosen folder.
@git-moss

git-moss commented Jul 8, 2026

Copy link
Copy Markdown
Owner

I have several examples where the left/right channels have different lengths. I suggest to add this as a destination option (which is off by default).

…es as mono

Some SoundFonts - in particular commercial E-mu banks such as the "Orbit"
bank - carry unreliable stereo metadata: samples are flagged as left/right
and linked to partners they are not the stereo halves of. compareSampleFormat
already declines the merge when two samples differ in pitch or sample rate,
but a length mismatch only logged a warning and then merged them anyway,
welding two unrelated sounds into the left and right channels of a single
stereo sample.

Add a "Keep mismatched stereo samples as mono" source option
(Sf2KeepMismatchedStereoAsMono, off by default) that treats a length mismatch
the same way, keeping the two samples as the separate mono samples they
actually are. It is off by default because some banks contain genuine stereo
pairs whose left/right channels differ slightly in length, so those keep
combining unless the option is enabled.

Also gate the pitch / sample-rate / length "do not match" notices behind the
existing "Log unused SF2 generators" option, so a normal conversion of a
quirky bank is no longer flooded with warnings while the detail is still
available on request.
@douglas-carmichael douglas-carmichael force-pushed the sf2-stereo-pair-length-mismatch branch from 89e0c31 to b9cbdce Compare July 8, 2026 13:33
@douglas-carmichael douglas-carmichael changed the title SoundFont 2: keep length-mismatched stereo-linked samples as mono SoundFont 2: add option to keep length-mismatched stereo-linked samples as mono Jul 8, 2026
@douglas-carmichael

Copy link
Copy Markdown
Contributor Author

Thanks! Updated per your suggestion: this is now an opt-in "Keep mismatched stereo samples as mono" option, off by default, so banks with genuine different-length stereo pairs keep combining exactly as before — only when it's enabled does a length mismatch keep the two samples separate (matching how a pitch or sample-rate mismatch already behaves).

Since the stereo-combining happens while reading the SoundFont (combineToStereo in the detector), I put the checkbox in the SF2 source options next to "Log unused SF2 generators" rather than on the destination side, as the destination formats never see the split-mono pair — happy to move it if you'd prefer it elsewhere.

Verified on the E-mu "Orbit" bank: off (the default) combines the 3 length-mismatched pairs as before; on keeps them as their separate full-length mono samples. Rebased onto current main.

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