Here are parts of code which I used:
Code: Select all
...
eData newrDara;
eAudio newAud;
eReadCDFile("\\SND01.VAG;1", &newrDara);
while (eIsReadingCDData()) { ... }
eLoadAudio(&newrDara, &newAud);
eFreeData(&newrDara);
ePlayAudio(&newAud, SPU_0CH);
while (1) { ... }
Code: Select all
typedef struct {
unsigned char* Address;
unsigned long Length;
} eData;
typedef struct {
unsigned long Address;
unsigned long Length;
} eAudio;
int eRoundMult(int Number, int Factor) {
return Number + Factor - 1 - (Number - 1) % Factor;
}
void eReadCDFile(char* FileName, eData* Data) {
CdlFILE File;
if (CdSearchFile(&File, FileName)) {
Data->Length = File.size;
Data->Address = (unsigned char*)malloc3(eRoundMult(Data->Length, 2048));
CdReadFile(FileName, (unsigned long*)Data->Address, 0);
}
}
int eIsReadingCDData() {
return CdReadSync(1, NULL) > 0;
}
void eFreeData(eData* Data) {
free3(Data->Address);
Data->Length = 0;
}
#define E_MALLOC_MAX 3
char eSPUMallocRec[SPU_MALLOC_RECSIZ * (E_MALLOC_MAX + 1)];
SpuCommonAttr eCommonSPUAttr;
SpuVoiceAttr eVoiceSPUAttr;
void eInitAudio() {
SpuInit();
SpuInitMalloc(E_MALLOC_MAX, eSPUMallocRec);
eCommonSPUAttr.mask = SPU_COMMON_MVOLL | SPU_COMMON_MVOLR;
eCommonSPUAttr.mvol.left = 0x3FFF;
eCommonSPUAttr.mvol.right = 0x3FFF;
SpuSetCommonAttr(&eCommonSPUAttr);
}
void eLoadAudio(eData* Data, eAudio* Audio) {
SpuSetTransferMode(SpuTransByDMA);
Audio->Address = SpuMalloc(Data->Length);
SpuSetTransferStartAddr(Audio->Address);
Audio->Length = SpuWrite(Data->Address, Data->Length);
SpuIsTransferCompleted(SPU_TRANSFER_WAIT);
}
void ePlayAudio(eAudio* Audio, unsigned long Voice) {
eVoiceSPUAttr.mask = SPU_VOICE_VOLL | SPU_VOICE_VOLR | SPU_VOICE_PITCH | SPU_VOICE_WDSA | SPU_VOICE_ADSR_AMODE | SPU_VOICE_ADSR_SMODE | SPU_VOICE_ADSR_RMODE | SPU_VOICE_ADSR_AR | SPU_VOICE_ADSR_DR | SPU_VOICE_ADSR_SR | SPU_VOICE_ADSR_RR | SPU_VOICE_ADSR_SL;
eVoiceSPUAttr.voice = Voice;
eVoiceSPUAttr.volume.left = 0x1FFF;
eVoiceSPUAttr.volume.right = 0x1FFF;
eVoiceSPUAttr.pitch = 0x1000;
eVoiceSPUAttr.addr = Audio->Address;
eVoiceSPUAttr.a_mode = SPU_VOICE_LINEARIncN;
eVoiceSPUAttr.s_mode = SPU_VOICE_LINEARIncN;
eVoiceSPUAttr.r_mode = SPU_VOICE_LINEARDecN;
eVoiceSPUAttr.ar = 0x0;
eVoiceSPUAttr.dr = 0x0;
eVoiceSPUAttr.sr = 0x0;
eVoiceSPUAttr.rr = 0x0;
eVoiceSPUAttr.sl = 0xF;
SpuSetVoiceAttr(&eVoiceSPUAttr);
SpuSetKey(SPU_ON, Voice);
}
EDIT: Forgot to mention that the actual problem is that the sound doesn't play. No compile errors or warnings (ccpsx)