99#include "synthesis.h"
1010#include "effects.h"
1111#include "external.h"
12+ #include <stdio.h>
1213
1314void note_set_resampling_rate (struct Note * note , f32 resamplingRateInput );
1415
@@ -46,6 +47,10 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbV
4647 pan &= unkMask ;
4748#endif
4849
50+ // Store pan as u8 (0=left, 128=center, 255=right) for surround effect
51+ // EU pan is 0-127, scale to 0-255
52+ note -> pan = pan * 2 ;
53+
4954 if (note -> noteSubEu .stereoHeadsetEffects && gSoundMode == SOUND_MODE_HEADSET ) {
5055#ifdef VERSION_SH
5156 smallPanIndex = pan >> 1 ;
@@ -114,6 +119,24 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbV
114119 } else if (gSoundMode == SOUND_MODE_MONO ) {
115120 volLeft = 0.707f ;
116121 volRight = 0.707f ;
122+ } else if (sub -> stereoHeadsetEffects && gSoundMode == SOUND_MODE_SURROUND ) {
123+ // TEMPORARY: Surround mode behaves like stereo to test if glitch persists
124+ sub -> headsetPanLeft = 0 ;
125+ sub -> headsetPanRight = 0 ;
126+ sub -> usesHeadsetPanEffects = FALSE;
127+ volLeft = gStereoPanVolume [pan ];
128+ volRight = gStereoPanVolume [127 - pan ];
129+ // Use same thresholds as stereo (0x20/0x60)
130+ if (pan < 0x20 ) {
131+ sub -> stereoStrongLeft = TRUE;
132+ sub -> stereoStrongRight = FALSE;
133+ } else if (pan > 0x60 ) {
134+ sub -> stereoStrongRight = TRUE;
135+ sub -> stereoStrongLeft = FALSE;
136+ } else {
137+ sub -> stereoStrongLeft = FALSE;
138+ sub -> stereoStrongRight = FALSE;
139+ }
117140 } else {
118141 volLeft = gDefaultPanVolume [pan ];
119142 volRight = gDefaultPanVolume [127 - pan ];
@@ -1151,6 +1174,11 @@ void note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLaye
11511174#endif
11521175 sub -> stereoHeadsetEffects = seqLayer -> seqChannel -> stereoHeadsetEffects ;
11531176 sub -> reverbIndex = seqLayer -> seqChannel -> reverbIndex & 3 ;
1177+ note -> surroundEffectIndex = seqLayer -> seqChannel -> surroundEffectIndex ;
1178+ note -> combFilterGain = seqLayer -> seqChannel -> combFilterGain ;
1179+ note -> combFilterSize = seqLayer -> seqChannel -> combFilterSize ;
1180+ // EU pan is s32 0-127, scale to u8 0-254
1181+ note -> pan = (u8 )(seqLayer -> seqChannel -> pan * 2 );
11541182}
11551183#else
11561184s32 note_init_for_layer (struct Note * note , struct SequenceChannelLayer * seqLayer ) {
@@ -1172,6 +1200,13 @@ s32 note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLayer
11721200 build_synthetic_wave (note , seqLayer );
11731201 }
11741202 note_init (note );
1203+ // Copy surround index after note_init to avoid being reset by note_init_volume
1204+ note -> surroundEffectIndex = seqLayer -> seqChannel -> surroundEffectIndex ;
1205+ // Copy comb filter settings for height-based surround effect
1206+ note -> combFilterGain = seqLayer -> seqChannel -> combFilterGain ;
1207+ note -> combFilterSize = seqLayer -> seqChannel -> combFilterSize ;
1208+ // Non-EU pan is f32 0.0-1.0, scale to u8 0-255
1209+ note -> pan = (u8 )(seqLayer -> seqChannel -> pan * 255.0f );
11751210 return FALSE;
11761211}
11771212#endif
@@ -1414,6 +1449,9 @@ void note_init_all(void) {
14141449 note = & gNotes [i ];
14151450#if defined(VERSION_EU ) || defined(VERSION_SH )
14161451 note -> noteSubEu = gZeroNoteSub ;
1452+ note -> combFilterGain = 0 ;
1453+ note -> combFilterSize = 0 ;
1454+ note -> synthesisState .combFilterNeedsInit = TRUE;
14171455#else
14181456 note -> enabled = FALSE;
14191457 note -> stereoStrongRight = FALSE;
@@ -1437,7 +1475,10 @@ void note_init_all(void) {
14371475 note -> targetVolLeft = 0 ;
14381476 note -> targetVolRight = 0 ;
14391477 note -> frequency = 0.0f ;
1440- note -> unused1 = 0x3f ;
1478+ note -> surroundEffectIndex = 0 ;
1479+ note -> combFilterGain = 0 ;
1480+ note -> combFilterSize = 0 ;
1481+ note -> combFilterNeedsInit = TRUE;
14411482#endif
14421483 note -> attributes .velocity = 0.0f ;
14431484 note -> adsrVolScale = 0 ;
0 commit comments