Fix music playback. Attempt at fixing reverb.

This commit is contained in:
Tortuga veloz
2025-03-12 14:20:31 +01:00
committed by Alejandro Asenjo Nitti
parent 86fd2b4375
commit 638616a67e
4 changed files with 17 additions and 16 deletions
+1 -1
View File
@@ -6,4 +6,4 @@
url = https://github.com/HarbourMasters/Torch
[submodule "libultraship"]
path = libultraship
url = https://github.com/dcampora/libultraship.git
url = https://github.com/Kenix3/libultraship.git
+5 -10
View File
@@ -140,11 +140,8 @@ void Audio_InitNoteSub(Note* note, NoteAttributes* noteAttr) {
}
} else {
// Surround 5.1
const float vol_voice = 0.8f;
const float vol_music = 0.707f;
if (stereo.s.is_voice) { // VOICE
panVolumeCenter = vol_voice;
panVolumeCenter = 1.0f;
}
else if (stereo.s.is_sfx) { // SFX
float pan_angle = (float)(pan + 64) / 128 * 2 * M_PI;
@@ -164,13 +161,11 @@ void Audio_InitNoteSub(Note* note, NoteAttributes* noteAttr) {
panVolumeRight = fmaxf(0, cosf(pan_angle - front_right)); // Front Right
panVolumeRearLeft = fmaxf(0, cosf(pan_angle - rear_left)); // Rear Left
panVolumeRearRight = fmaxf(0, cosf(pan_angle - rear_right)); // Rear Right
// printf("pan: %d, pan_angle: %f, left: %f, right: %f, rleft: %f, rright: %f\n", pan, pan_angle, panVolumeLeft, panVolumeRight, panVolumeRearLeft, panVolumeRearRight);
} else { // MUSIC
panVolumeLeft = vol_music;
panVolumeRight = vol_music;
panVolumeRearLeft = vol_music;
panVolumeRearRight = vol_music;
panVolumeLeft = gStereoPanVolume[pan];
panVolumeRight = gStereoPanVolume[ARRAY_COUNT(gStereoPanVolume) - 1 - pan];
panVolumeRearLeft = gStereoPanVolume[pan];
panVolumeRearRight = gStereoPanVolume[ARRAY_COUNT(gStereoPanVolume) - 1 - pan];
}
}
+7 -2
View File
@@ -727,6 +727,11 @@ Acmd* AudioSynth_LoadReverbSamples(Acmd* aList, s32 aiBufLen, s16 reverbIndex, s
s16 sp62;
s16 sp60;
u16 left_channel = DMEM_LEFT_CH;
if (GetNumAudioChannels() == 6) {
left_channel = DMEM_REAR_LEFT_CH;
}
aClearBuffer(aList++, DMEM_WET_LEFT_CH, DMEM_2CH_SIZE);
if (gSynthReverbs[reverbIndex].downsampleRate == 1) {
@@ -735,7 +740,7 @@ Acmd* AudioSynth_LoadReverbSamples(Acmd* aList, s32 aiBufLen, s16 reverbIndex, s
aList =
AudioSynth_LoadRingBufferPart(aList, sp64->lengthA + DMEM_WET_LEFT_CH, 0, sp64->lengthB, reverbIndex);
}
aAddMixer(aList++, DMEM_2CH_SIZE, DMEM_WET_LEFT_CH, DMEM_LEFT_CH);
aAddMixer(aList++, DMEM_2CH_SIZE, DMEM_WET_LEFT_CH, left_channel);
aMix(aList++, 0x30, gSynthReverbs[reverbIndex].decayRatio + 0x8000, DMEM_WET_LEFT_CH, DMEM_WET_LEFT_CH);
} else {
sp62 = (sp64->startPos & 7) * 2;
@@ -751,7 +756,7 @@ Acmd* AudioSynth_LoadReverbSamples(Acmd* aList, s32 aiBufLen, s16 reverbIndex, s
aSetBuffer(aList++, 0, sp62 + DMEM_UNCOMPRESSED_NOTE, DMEM_WET_RIGHT_CH, aiBufLen * 2);
aResample(aList++, gSynthReverbs[reverbIndex].resampleFlags, gSynthReverbs[reverbIndex].unk_0A,
OS_K0_TO_PHYSICAL(gSynthReverbs[reverbIndex].unk_34));
aAddMixer(aList++, DMEM_2CH_SIZE, DMEM_WET_LEFT_CH, DMEM_LEFT_CH);
aAddMixer(aList++, DMEM_2CH_SIZE, DMEM_WET_LEFT_CH, left_channel);
aMix(aList++, 0x30, gSynthReverbs[reverbIndex].decayRatio + 0x8000, DMEM_WET_LEFT_CH, DMEM_WET_LEFT_CH);
}
+4 -3
View File
@@ -710,9 +710,10 @@ void aEnvMixerImpl(uint16_t in_addr, uint16_t n_samples, bool swap_reverb,
*dry[j] = clamp16(*dry[j] + samples[j]);
dry[j]++;
if (j >= 4) {
// Apply reverb only to the rear channels (4 and 5)
*wet[j] = clamp16(*wet[j] + (samples[swapped[j % 2]] * vol_wet >> 16));
if (j < 2) {
// Apply reverb only to the front stereo channels wet
// They will be mixed with the rear channels later
*wet[j] = clamp16(*wet[j] + (samples[swapped[j]] * vol_wet >> 16));
wet[j]++;
}
}