Added support for playing PCM16 sounds, looping or non-looping.

It is a bit hacky and may have problems, but now SMG has music.
I'll try to do AFC / ADPCM for next commit.

PS: sorry. lots of stuff from latest commits will be reverted because, when updating, I got serious conflicts and everything was messed up :(
if you want I can help you with reintegrating what was lost.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3570 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
luigi2us
2009-06-28 14:22:51 +00:00
parent 900287be50
commit 1aab3252fa
5 changed files with 773 additions and 402 deletions

View File

@ -21,6 +21,46 @@
#include "Common.h"
#include "UCodes.h"
struct ZeldaVoicePB
{
// Read-Write part
u16 Status; // 0x00 | 1 = play, 0 = stop
u16 KeyOff; // 0x01 | writing 1 stops voice?
u16 RatioInt; // 0x02 | delta? ratio? integer part
u16 Unk03; // 0x03 | unknown
u16 NeedsReset; // 0x04 | indicates if some values in PB need to be reset
u16 ReachedEnd; // 0x05 | set to 1 when end reached
u16 IsBlank; // 0x06 | 0 = normal sound, 1 = samples are always the same
u16 Unk07[0x29]; // 0x07 | unknown
u16 RatioFrac; // 0x30 | ??? ratio fractional part
u16 Unk31; // 0x31 | unknown
u16 CurBlock; // 0x32 | current block?
u16 FixedSample; // 0x33 | sample value for "blank" voices
u32 RestartPos; // 0x34 | restart pos
u16 Unk36[2]; // 0x36 | unknown
u32 CurAddr; // 0x38 | current address
u32 RemLength; // 0x3A | remaining length
u16 Unk3C[0x2A]; // 0x3C | unknown
u16 YN1; // 0x66 | YN1
u16 YN2; // 0x67 | YN2
u16 Unk68[0x18]; // 0x68 | unknwon
// Read-only part
u16 Format; // 0x80 | audio format
u16 RepeatMode; // 0x81 | 0 = one-shot, non zero = loop
u16 Unk82[0x6]; // 0x82 | unknown
u32 LoopStartPos; // 0x88 | loopstart pos
u32 Length; // 0x8A | sound length
u32 StartAddr; // 0x8C | sound start address
u32 UnkAddr; // 0x8E | ???
u16 Padding[0x30]; // 0x90 | padding
};
// Here's a piece of pure guesswork, looking at random supposedly-PBs
// from Zelda Four Swords.
// These are 0x180 bytes large.
struct ZPB
{
// R/W data =============
@ -60,7 +100,7 @@ namespace {
class CUCode_Zelda : public IUCode
{
public:
CUCode_Zelda(CMailHandler& _rMailHandler);
CUCode_Zelda(CMailHandler& _rMailHandler, u32 _CRC);
virtual ~CUCode_Zelda();
void HandleMail(u32 _uMail);
@ -81,6 +121,13 @@ public:
void DumpPB(const ZPB& _rPB);
int DumpAFC(u8* pIn, const int size, const int srate);
u32 Read32()
{
u32 res = *(u32*)&m_Buffer[m_readOffset];
m_readOffset += 4;
return res;
}
private:
enum EDSP_Codes
{
@ -92,15 +139,43 @@ private:
DSP_FRAME_END = 0xDCD10005,
};
// AFC CoefTable
s16 m_AFCCoefTable[32];
u32 m_CRC;
// Command 0x2: SyncFrame
int m_NumberOfFramesToRender;
int m_CurrentFrameToRender;
s32* m_TempBuffer;
s32* m_LeftBuffer;
s32* m_RightBuffer;
// List in progress
u16 m_AFCCoefTable[32];
bool m_bSyncInProgress;
u32 m_MaxVoice;
u32 m_SyncFlags[16];
u32 m_NumVoices;
bool m_bSyncCmdPending;
u32 m_CurVoice;
u32 m_CurBuffer;
u32 m_NumBuffers;
// Those are set by command 0x1 (DsetupTable)
u32 m_VoicePBsAddr;
u32 m_UnkTableAddr;
u32 m_AFCCoefTableAddr;
u32 m_ReverbPBsAddr;
u32 m_RightBuffersAddr;
u32 m_LeftBuffersAddr;
//u32 m_unkAddr;
u32 m_pos;
// Only in SMG ucode
// Set by command 0xE (DsetDMABaseAddr)
u32 m_DMABaseAddr;
// List, buffer management =====================
u32 m_numSteps;
bool m_bListInProgress;
u32 m_step;
u8 m_Buffer[1024];
void ExecuteList();
@ -126,16 +201,12 @@ private:
u32 m_MixingBufferLeft;
u32 m_MixingBufferRight;
u32 m_MaxSyncedPB;
ZPB m_PBs[0x40];
void ReadVoicePB(u32 _Addr, ZeldaVoicePB& PB);
void WritebackVoicePB(u32 _Addr, ZeldaVoicePB& PB);
u32 Read32()
{
u32 res = *(u32*)&m_Buffer[m_readOffset];
m_readOffset += 4;
return res;
}
void MixAddVoice_PCM16(ZeldaVoicePB& PB, s32* _Buffer, int _Size);
void MixAddVoice(ZeldaVoicePB& PB, s32* _LeftBuffer, s32* _RightBuffer, int _Size);
};
#endif