Some preparations for Wii AX (much work remains)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1101 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-11-09 16:19:30 +00:00
parent 530fb9ba3d
commit 860ffe9541
4 changed files with 341 additions and 295 deletions

View File

@ -301,7 +301,7 @@ void CUCode_AX::Logging(short* _pBuffer, int _iSize, int a)
}
else
{
Conditions = (numberRunning.at(i) > 0 || PBs[i].audio_addr.looping);
Conditions = numberRunning.at(i) > 0 || PBs[i].audio_addr.looping;
}
// --------------

View File

@ -28,7 +28,6 @@
#include "UCode_AXStructs.h"
#include "UCode_AX.h"
// ---------------------------------------------------------------------------------------
// Externals
// -----------
@ -43,7 +42,6 @@ bool gReset = false; // used externally
extern CDebugger* m_frame;
// -----------
CUCode_AX::CUCode_AX(CMailHandler& _rMailHandler, bool wii)
: IUCode(_rMailHandler)
, m_addressPBs(0xFFFFFFFF)
@ -76,7 +74,7 @@ void CUCode_AX::HandleMail(u32 _uMail)
}
}
s16 CUCode_AX::ADPCM_Step(AXParamBlock& pb, u32& samplePos, u32 newSamplePos, u16 frac)
s16 ADPCM_Step(AXParamBlock& pb, u32& samplePos, u32 newSamplePos, u16 frac)
{
PBADPCMInfo &adpcm = pb.adpcm;
@ -158,37 +156,14 @@ u16 ADPCM_Vol(u16 vol, u16 delta, u16 mixer_control)
}
// ==============
void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
void MixAddVoice(AXParamBlock &pb, int *templbuffer, int *temprbuffer, int _iSize)
{
AXParamBlock PBs[NUMBER_OF_PBS];
if (_iSize > 1024 * 1024)
_iSize = 1024 * 1024;
memset(templbuffer, 0, _iSize * sizeof(int));
memset(temprbuffer, 0, _iSize * sizeof(int));
// read out pbs
int numberOfPBs = ReadOutPBs(1, PBs, NUMBER_OF_PBS);
#ifdef _WIN32
ratioFactor = 32000.0f / (float)DSound::DSound_GetSampleRate();
#else
ratioFactor = 32000.0f / 44100.0f;
#endif
// write logging data to debugger
if(m_frame)
{
CUCode_AX::Logging(_pBuffer, _iSize, 0);
}
for (int i = 0; i < numberOfPBs; i++)
{
AXParamBlock& pb = PBs[i];
// get necessary values
const u32 sampleEnd = (pb.audio_addr.end_addr_hi << 16) | pb.audio_addr.end_addr_lo;
const u32 loopPos = (pb.audio_addr.loop_addr_hi << 16) | pb.audio_addr.loop_addr_lo;
@ -196,7 +171,6 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
const u16 updpar = Memory_Read_U16(updaddr);
const u16 upddata = Memory_Read_U16(updaddr + 2);
// =======================================================================================
/*
Fix problems introduced with the SSBM fix - Sometimes when a music stream ended sampleEnd
@ -218,7 +192,7 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
pb.audio_addr.end_addr_hi = 0; pb.audio_addr.end_addr_lo = 0;
pb.audio_addr.loop_addr_hi = 0; pb.audio_addr.loop_addr_lo = 0;
pb.src.cur_addr_frac = 0; PBs[i].src.ratio_hi = 0; PBs[i].src.ratio_lo = 0;
pb.src.cur_addr_frac = 0; pb.src.ratio_hi = 0; pb.src.ratio_lo = 0;
pb.adpcm.pred_scale = 0; pb.adpcm.yn1 = 0; pb.adpcm.yn2 = 0;
pb.audio_addr.looping = 0;
@ -279,7 +253,7 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
pb.audio_addr.end_addr_hi = 0; pb.audio_addr.end_addr_lo = 0;
pb.audio_addr.loop_addr_hi = 0; pb.audio_addr.loop_addr_lo = 0;
pb.src.cur_addr_frac = 0; PBs[i].src.ratio_hi = 0; PBs[i].src.ratio_lo = 0;
pb.src.cur_addr_frac = 0; pb.src.ratio_hi = 0; pb.src.ratio_lo = 0;
pb.adpcm.pred_scale = 0; pb.adpcm.yn1 = 0; pb.adpcm.yn2 = 0;
pb.audio_addr.looping = 0;
@ -287,8 +261,6 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
pb.adpcm_loop_info.yn1 = 0; pb.adpcm_loop_info.yn2 = 0;
}
// =============
if (pb.running)
{
// =======================================================================================
@ -302,8 +274,6 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
u32 frac = pb.src.cur_addr_frac;
// =============
// =======================================================================================
// Handle no-src streams - No src streams have pb.src_type == 2 and have pb.src.ratio_hi = 0
// and pb.src.ratio_lo = 0. We handle that by setting the sampling ratio integer to 1. This
@ -343,7 +313,6 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
}
// ==============
// =======================================================================================
// Walk through _iSize. _iSize = numSamples. If the game goes slow _iSize will be higher to
// compensate for that. _iSize can be as low as 100 or as high as 2000 some cases.
@ -353,7 +322,6 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
frac += ratio;
u32 newSamplePos = samplePos + (frac >> 16); //whole number of frac
// =======================================================================================
// Process sample format
// --------------
@ -395,7 +363,6 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
}
// ================
// =======================================================================================
// Volume control
frac &= 0xffff;
@ -416,11 +383,8 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
int leftmix = pb.mixer.volume_left >> 5;
int rightmix = pb.mixer.volume_right >> 5;
// ===============
int left = sample * leftmix >> 8;
int right = sample * rightmix >> 8;
//adpcm has to walk from oldSamplePos to samplePos here
templbuffer[s] += left;
temprbuffer[s] += right;
@ -441,19 +405,45 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
}
} // end of the _iSize loop
// ============
if (gVolume) // allow us to turn this off in the debugger
{
pb.mixer.volume_left = ADPCM_Vol(pb.mixer.volume_left, pb.mixer.unknown, pb.mixer_control);
pb.mixer.volume_right = ADPCM_Vol(pb.mixer.volume_right, pb.mixer.unknown2, pb.mixer_control);
}
pb.src.cur_addr_frac = (u16)frac;
pb.audio_addr.cur_addr_hi = samplePos >> 16;
pb.audio_addr.cur_addr_lo = (u16)samplePos;
}
}
void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
{
AXParamBlock PBs[NUMBER_OF_PBS];
// read out pbs
int numberOfPBs = ReadOutPBs(1, PBs, NUMBER_OF_PBS);
if (_iSize > 1024 * 1024)
_iSize = 1024 * 1024;
memset(templbuffer, 0, _iSize * sizeof(int));
memset(temprbuffer, 0, _iSize * sizeof(int));
// write logging data to debugger
if (m_frame)
{
CUCode_AX::Logging(_pBuffer, _iSize, 0);
}
for (int i = 0; i < numberOfPBs; i++)
{
AXParamBlock& pb = PBs[i];
MixAddVoice(pb, templbuffer, temprbuffer, _iSize);
}
// write back out pbs
WriteBackPBs(PBs, numberOfPBs);
for (int i = 0; i < _iSize; i++)
{
// Clamp into 16-bit. Maybe we should add a volume compressor here.
@ -467,9 +457,6 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
*_pBuffer++ = right;
}
// write back out pbs
WriteBackPBs(PBs, numberOfPBs);
// write logging data to debugger again after the update
if (m_frame)
{
@ -477,6 +464,7 @@ void CUCode_AX::MixAdd(short* _pBuffer, int _iSize)
}
}
void CUCode_AX::Update()
{
// check if we have to sent something

View File

@ -20,6 +20,11 @@
#include "UCode_AXStructs.h"
enum
{
NUMBER_OF_PBS = 64
};
class CUCode_AX : public IUCode
{
public:
@ -34,12 +39,6 @@ public:
void Logging(short* _pBuffer, int _iSize, int a);
private:
enum
{
NUMBER_OF_PBS = 64
};
enum
{
MAIL_AX_ALIST = 0xBABE0000,
@ -64,7 +63,6 @@ private:
void SendMail(u32 _uMail);
int ReadOutPBs(int a, AXParamBlock *_pPBs, int _num);
void WriteBackPBs(AXParamBlock *_pPBs, int _num);
s16 ADPCM_Step(AXParamBlock& pb, u32& samplePos, u32 newSamplePos, u16 frac);
};
#endif // _UCODE_AX

View File

@ -29,6 +29,17 @@ struct PBMixer
u16 unknown4[6];
};
struct PBMixerWii
{
u16 volume_left;
u16 unknown;
u16 volume_right;
u16 unknown2;
u16 unknown3[12];
u16 unknown4[8];
};
struct PBInitialTimeDelay
{
u16 on;
@ -51,11 +62,23 @@ struct PBUpdates
u16 data_lo;
};
struct PBUnknown
struct PBUpdatesWii
{
u16 num_updates[3];
u16 data_hi; // These point to main RAM. Not sure about the structure of the data.
u16 data_lo;
};
struct PBDpop
{
s16 unknown[9];
};
struct PBDpopWii
{
s16 unknown[12];
};
struct PBVolumeEnvelope
{
u16 cur_volume;
@ -121,7 +144,7 @@ struct AXParamBlock
/* 9 */ PBMixer mixer;
/* 27 */ PBInitialTimeDelay initial_time_delay;
/* 34 */ PBUpdates updates;
/* 41 */ PBUnknown unknown2;
/* 41 */ PBDpop dpop;
/* 50 */ PBVolumeEnvelope vol_env;
/* 52 */ PBUnknown2 unknown3;
/* 55 */ PBAudioAddr audio_addr;
@ -131,6 +154,43 @@ struct AXParamBlock
/* 93 */ u16 unknown_maybe_padding[3];
};
struct PBLpf
{
u16 enabled;
u16 yn1;
u16 a0;
u16 b0;
};
struct AXParamBlockWii
{
u16 next_pb_hi;
u16 next_pb_lo;
u16 this_pb_hi;
u16 this_pb_lo;
u16 src_type; // Type of sample rate converter (none, ?, linear)
u16 coef_select;
u16 mixer_control;
u16 running; // 1=RUN 0=STOP
u16 is_stream; // 1 = stream, 0 = one shot
PBMixerWii mixer;
PBInitialTimeDelay initial_time_delay;
PBUpdatesWii updates;
PBDpopWii dpop;
PBVolumeEnvelope vol_env;
PBUnknown2 unknown3;
PBAudioAddr audio_addr;
PBADPCMInfo adpcm;
PBSampleRateConverter src;
PBADPCMLoopInfo adpcm_loop_info;
PBLpf lpf;
u16 pad[22];
};
enum {
AUDIOFORMAT_ADPCM = 0,
AUDIOFORMAT_PCM8 = 0x19,