Page 1 of 1

VAG (or alternative) Audio Playback HELP NEEDED!

Posted: June 7th, 2016, 8:22 am
by NaughtyCow
I ran into problems when attempting to play VAG audio file in my game. I'm using PSYQ, the VAG file is valid, and I'm using PSX CD-Gen Tool to generate a ROM image.

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) { ... }
Structs and functions mentioned above:

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);
}
CD is initialized, and as well is the heap... I know that the CD ROM files are loaded correctly since tbe test TIM image is properly rendered... Thanks in advance. I apologize if the question is too easy for you experienced coders, I'm new to PS1 and C programming in general.

EDIT: Forgot to mention that the actual problem is that the sound doesn't play. No compile errors or warnings (ccpsx)

Re: VAG (or alternative) Audio Playback HELP NEEDED!

Posted: June 7th, 2016, 8:32 am
by Shadow

Re: VAG (or alternative) Audio Playback HELP NEEDED!

Posted: June 7th, 2016, 8:33 am
by NaughtyCow
I actually used that as an reference when writing my code, but it doesn't work for me for some reason. Is there any extra procedure while building a BIN image with VAG-s?

Re: VAG (or alternative) Audio Playback HELP NEEDED!

Posted: June 7th, 2016, 8:33 am
by Shadow
Can you send me your entire project so I can check out what you're doing exactly?

Re: VAG (or alternative) Audio Playback HELP NEEDED!

Posted: June 7th, 2016, 8:39 am
by NaughtyCow
Here, sorry for (relatively) late response, I had to power on my virtual machine :D

Re: VAG (or alternative) Audio Playback HELP NEEDED!

Posted: June 7th, 2016, 8:40 am
by Shadow
Thanks. Give me a few minutes whilst I fix it all up...

*EDIT*
Okay this code is a mess. It's going to take me a few hours to clean it up.
Check back in a few hours.

Re: VAG (or alternative) Audio Playback HELP NEEDED!

Posted: June 7th, 2016, 9:51 am
by NaughtyCow
Shadow wrote:Thanks. Give me a few minutes whilst I fix it all up...

*EDIT*
Okay this code is a mess. It's going to take me a few hours to clean it up.
Check back in a few hours.
Thanks for being patient with me.

Re: VAG (or alternative) Audio Playback HELP NEEDED!

Posted: June 10th, 2016, 4:22 am
by Shadow
Okay, here you are. Enjoy :)
You'll have to port this or add in the controller/graphic stuff you had.