VAG (or alternative) Audio Playback HELP NEEDED!

Audio and Music (Sound Processing Unit) based area of development, including VAB, XA, etc
Post Reply
NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: Jun 07, 2016
I am a: Student
Location: Croatia

VAG (or alternative) Audio Playback HELP NEEDED!

Post by NaughtyCow » June 7th, 2016, 8:22 am

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)

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » June 7th, 2016, 8:32 am

Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: Jun 07, 2016
I am a: Student
Location: Croatia

Post by NaughtyCow » June 7th, 2016, 8:33 am

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?

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » June 7th, 2016, 8:33 am

Can you send me your entire project so I can check out what you're doing exactly?
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: Jun 07, 2016
I am a: Student
Location: Croatia

Post by NaughtyCow » June 7th, 2016, 8:39 am

Here, sorry for (relatively) late response, I had to power on my virtual machine :D
You do not have the required permissions to view the files attached to this post.

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » June 7th, 2016, 8:40 am

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.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

NaughtyCow
Curious PSXDEV User
Curious PSXDEV User
Posts: 15
Joined: Jun 07, 2016
I am a: Student
Location: Croatia

Post by NaughtyCow » June 7th, 2016, 9:51 am

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.

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » June 10th, 2016, 4:22 am

Okay, here you are. Enjoy :)
You'll have to port this or add in the controller/graphic stuff you had.
You do not have the required permissions to view the files attached to this post.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests