Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio panning attempt 2 #1469

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Source/AliveLibAE/Sound/PsxSpuApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,9 @@ EXPORT s32 CC MIDI_PlayMidiNote_4FCB30(s32 vabId, s32 program, s32 note, s32 lef
{
MIDI_Wait_4FCE50();
}


// reuse a field that is never accessed for passing the samples pan
GetSpuApiVars()->sSoundEntryTable16().table[vabId][pVagIter->field_10_vag].field_1F = pVagIter->field_11_pad;
GetSoundAPI().SND_PlayEx(
&gSpuVars->sSoundEntryTable16().table[vabId][pVagIter->field_10_vag],
panLeft,
Expand Down
31 changes: 31 additions & 0 deletions Source/AliveLibAE/Sound/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,39 @@ EXPORT s32 CC SND_PlayEx_4EF740(const SoundEntry* pSnd, s32 panLeft, s32 panRigh
pDSoundBuffer->SetFrequency(freqHz);
pDSoundBuffer->SetVolume(sVolumeTable_BBBD38[panRightConverted]);

// OLD PAN
const s32 panConverted = (DSBPAN_RIGHT * (panLeft2 - panRight)) / 127; // From PSX pan range to DSound pan range
pDSoundBuffer->SetPan(-panConverted); // Fix Inverted Stereo
// OLD PAN END

// NEW PAN
// If the sample is panned we must use the pan of the sample.
// It seems all sfx are center and only music samples are panned.
s8 samplePan = pSnd->field_1F;
if (samplePan < 64)
{
panRight = ((s32) (panRight * (samplePan / 64.0)));
}
else if (samplePan > 64)
{
panLeft = ((s32) ((panLeft * (64 - (samplePan - 64))) / 64.0));
}

// convert the 0-64-127 pan value into a value
// that makes sense for SDL
s32 sdlPan = 0;
if (panRight < panLeft)
{
double p = (double) panRight / panLeft * DSBPAN_RIGHT;
sdlPan = -(DSBPAN_RIGHT - ((s32) p));
}
else if (panRight > panLeft)
{
double p = (double) panLeft / panRight * DSBPAN_RIGHT;
sdlPan = DSBPAN_RIGHT - ((s32) p);
}
pDSoundBuffer->SetPan(sdlPan);
// NEW PAN END

if (playFlags & DSBPLAY_LOOPING)
{
Expand Down
5 changes: 4 additions & 1 deletion Source/AliveLibAO/Midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ EXPORT s32 CC MIDI_PlayerPlayMidiNote_49D730(s32 vabId, s32 program, s32 note, s
auto v29 = pVagOff->field_A_shift_cen;
pChannel->field_1C_adsr.field_2_note_byte1 = BYTE1(note) & 0x7F;
auto freq = pow(1.059463094359, (f64)(note - v29) * 0.00390625);
pChannel->field_10_freq = (f32) freq;
pChannel->field_10_freq = (f32) freq;

// reuse a field that is never accessed for passing the samples pan
GetSpuApiVars()->sSoundEntryTable16().table[vabId][vag_num].field_1F = pVagOff->field_11_pad;
SND_PlayEx_493040(
&GetSpuApiVars()->sSoundEntryTable16().table[vabId][vag_num],
panLeft,
Expand Down