CDDA,My Code, Can ya Help?

mrkotfw

Mid Boss
hey guys, i was wondering if you guys can explain to me how CDDA works, whats in there... if theres a compression thingy in the file and how to use it on the sega saturn... and how to create them

for some reason it doesn't really play (i use girigiri)

ok for those of you who dont want to read, this is what i want to do and/or know how to do:

1. what is CDDA

2. how do i create CDDA

3. how do i use CDDA on the Sega Saturn?

4. Reading Audio Files from CD in Sega Saturn

Code:
#include "sgl.h"

#include "sgl_cd.h"

#include "sddrvs.dat"

#include "level1.c"

#include "sclfunc.c"

#include "sprite.c"

#define	MAX_FILE	128

extern TEXTURE texture[];

extern PICTURE sprite[];

extern SPR_ATTR sprite_attr[];

extern FIXED pos[][];

extern FIXED ang[];

extern unsigned short sspal[];

extern unsigned short sprite_pal[];

PerAnalog * ana_pre;

Uint16 data;

Sint32 dirwork[SLCD_WORK_SIZE(MAX_FILE)];

Uint8 sdmap[]={

	0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x80, 0x00,

	0x10, 0x01, 0x30, 0x00, 0x00, 0x00, 0x10, 0x00,

	0x11, 0x01, 0x40, 0x00, 0x00, 0x00, 0x20, 0x00,

	0x20, 0x01, 0x60, 0x00, 0x00, 0x00, 0x06, 0x00,

	0x21, 0x01, 0x68, 0x00, 0x00, 0x00, 0x06, 0x00,

	0x22, 0x01, 0x70, 0x00, 0x00, 0x00, 0x06, 0x00,

	0x23, 0x01, 0x78, 0x00, 0x00, 0x00, 0x06, 0x00,

	0x24, 0x01, 0x80, 0x00, 0x00, 0x00, 0x06, 0x00,

	0x01, 0x01, 0x86, 0x00, 0x00, 0x04, 0x00, 0x00,

	0x30, 0x05, 0xA0, 0x00, 0x00, 0x02, 0x00, 0x00,

	0xFF, 0xFF

  };

int ss_main(void){

	Sint32	ndir;

	CDHN	cdhn;

	CDBUF	buf[2];

	CDKEY	key[2];

	Sint32	stat;

FIXED scrollx=toFIXED(0.0);

FIXED scrolly=toFIXED(0.0);

slInitSystem(TV_320x240,texture,1);

slInitSound(sddrvstsk,sizeof(sddrvstsk),sdmap,sizeof(sdmap));

slCDDAOn(127,127,0,0);

slTVOff();

slColRAMMode(CRM16_1024);

slBack1ColSet((void *)VDP2_VRAM_A1+0x1fffe,0);

	ndir=slCdInit(MAX_FILE,dirwork);

	key[0].cn=CDKEY_NONE;

	key[0].sm=CDKEY_NONE;

	key[0].ci=CDKEY_NONE;

	key[1].cn=CDKEY_TERM;

	cdhn=slCdOpen("CDDA1.CDA",key);

	buf[0].type=CDBUF_COPY;

	buf[0].trans.copy.addr=NULL;

	buf[0].trans.copy.unit=CDBUF_FORM1;

	buf[0].trans.copy.size=0;

	buf[1].type=CDBUF_TERM;

	slCdLoadFile(cdhn,buf);

	LoadSprite(sprite,2);

	slInitBitMap(bmNBG1,BM_512x256,(void *)VDP2_VRAM_B0);

	slBMPaletteNbg1(1);

	slBMPut(-160,-120,159,119,level1);

	slScrPosNbg1(scrollx,scrolly);

	slScrAutoDisp(NBG0ON|NBG1ON);

	Pal2CRAM((Uint16 *)sspal,(void *)VDP2_COLRAM,256);

	Pal2CRAM((Uint16 *)sprite_pal,(void *)VDP2_COLRAM,256);

 slTVOn();

 while(1){

 pos[0][1]=toFIXED(59.0);

 data=Smpc_Peripheral[0].data;

 if(!(data & PER_DGT_KR)){

 	pos[0][0]+=toFIXED(10.0);

 }

 if(!(data & PER_DGT_KL)){

 	pos[0][0]-=toFIXED(10.0);

 }

 DisplaySprite(0);

 stat=slCdGetStatus(cdhn,NULL);

 if(stat==CDSTAT_COMPLETED){

 	slPrint("CDDA1 Track Loaded!",slLocate(1,1));

 }

 slSynch();

 }

	}

Thanks guys.........

and BTW, i dont understand why i got to have an char array for SOUND

Code:
Uint8 sdmap[]={

0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x80, 0x00,

0x10, 0x01, 0x30, 0x00, 0x00, 0x00, 0x10, 0x00,

0x11, 0x01, 0x40, 0x00, 0x00, 0x00, 0x20, 0x00,

0x20, 0x01, 0x60, 0x00, 0x00, 0x00, 0x06, 0x00,

0x21, 0x01, 0x68, 0x00, 0x00, 0x00, 0x06, 0x00,

0x22, 0x01, 0x70, 0x00, 0x00, 0x00, 0x06, 0x00,

0x23, 0x01, 0x78, 0x00, 0x00, 0x00, 0x06, 0x00,

0x24, 0x01, 0x80, 0x00, 0x00, 0x00, 0x06, 0x00,

0x01, 0x01, 0x86, 0x00, 0x00, 0x04, 0x00, 0x00,

0x30, 0x05, 0xA0, 0x00, 0x00, 0x02, 0x00, 0x00,

0xFF, 0xFF

  };

can anyone explain that
biggrin.gif
 
Umm... CDDA is just another name for audio tracks. (Compact Disc Digital Audio). As for how you play it on a saturn from code I do not know. There are probably some functions to control the CD audio playback.
 
Originally posted by nescphp@May 22, 2003 @ 01:15 AM

Code:
slInitSound(sddrvstsk,sizeof(sddrvstsk),sdmap,sizeof(sdmap));

slCDDAOn(127,127,0,0);


First of all, CDDA sound is like gameboy900 said, another name for audio tracks. It's what you can find on lots of game CDs, from SegaCD to the newest PC games.
wink.gif


CDDA files/tracks are usually very large, because they are the native audio format of the CD. They contain 16bit audio data at 44.1kHz, which is kind of a "high quality" audio... just like on normal audio CDs. Loading files like these into memory is not a good idea, since even short files will be too big to fit into the Saturns memory. Therefore CDDA files are played using the CD interface of the Saturn, which simply streams the CDDA data to the proper channels needed in order to generate a sound, completely ignoring the 68000 (also called Sound CPU).

What is happening in the code above is to initialize the Sound CPU with the slInitSound() call, and then call up some CDDA initialization with slCDDAOn(). AFAIK, the 68000 has nothing to do with the CDDA being played, instead it handles the PCM/FM type of sound, which you can control via slPCMOn() and similar calls. So please don't confuse the two.
wink.gif
I have no idea why GiriGiri doesn't play it, but you might have more luck with a real Saturn. The actual playing of the CDDA file will start after issuing the slCdLoadFile(cdhn,buf) call.

Make sure the file you want to play exists on the game CD, because there is no error handling and you won't know why it failed... I guess you can remove the 68000 handling from the program and try it again as it shouldn't have any effect on CDDA.

keep on programming...
 
wow, beautiful explanation. i get it now. ya thats what i was thinking if i can use PCM functions to control it. i dont know how burn CDDA onto the ISO! can you please show me an example printf? and how to create CDDA files? thank you
biggrin.gif
thanks, you encouraged me to keep on coding! i wont quit
biggrin.gif
 
I've been wondering today (what a coincidence
smile.gif
) how to play CDDA without the SGL/SBL... is there some simple register command or a way to call the CD player software to perform the required functions?
 
Originally posted by nescphp@May 22, 2003 @ 02:01 PM

wow, beautiful explanation. i get it now. ya thats what i was thinking if i can use PCM functions to control it. i dont know how burn CDDA onto the ISO! can you please show me an example printf? and how to create CDDA files? thank you :D thanks, you encouraged me to keep on coding! i wont quit :D

Get your ISO, a few .WAV files and use Sega Cue Maker to make a .CUE file, then mount the .CUE in a virtual CD drive using either Daemon tools or Alcohol 120%.
 
I'll elaborate on M3dion's explanation.
smile.gif


CDDA is stored on a CD as audio tracks separate from the ISO (data) track, not really as files. It IS possible (and in the case of Saturn games, rather common) to place pseudo-files into the ISO9660 directory structure whose LBAs (logical block addresses) point to the first sector of each audio track. But other than that, CDDA is wholly separate from the ISO.

All you're doing when burning an iso/wav image via a cuesheet is creating a mixed-mode disc. Mixed-mode because the ISO becomes a Mode 1, 2048-bytes-per-sector track (track 1), and the wav files become CDDA audio tracks with 2352 bytes/sector, normally starting at track 2.

So in order to "create a CDDA", all you do is come up with a wave file at 44.1kHz 16-bit stereo, and burn it.
smile.gif
 
heh, i get that...but! how do i load them ??? I mean I use the CD functions to Load a *file*, what you guys said it sounds like it embeds itself in the cd instead of being a file... im a little confused...
 
Originally posted by nescphp@May 22, 2003 @ 06:55 PM

heh, i get that...but! how do i load them ??? I mean I use the CD functions to Load a *file*, what you guys said it sounds like it embeds itself in the cd instead of being a file... im a little confused...

You only use the file entry in the data track to point to the audio track you'd like to play. It should be possible to create a game CD with audio tracks/CDDA files by using the Sega CD tools (buildcd or what it's called). From there, you'd treat it just like any other file, but instead of loading it into memory, the SGL/SBL functions will know what to do with the audio data, in this case playing the sound. That's right, if you point to audio tracks, the 'read' function will actually start playing something!
wink.gif
It's confusing, yes. But the CD-ROM system in the Saturn can tell the difference between a normal file and audio tracks, so it's basically the same way of programming it, which makes things a lot easier for you.
 
thanks man, i now understand listen....

you think i can see a *.cti file with some CDDA tracks included please? i deleted mine.... ALSO i have a problem i just want to know

Code:
slBitMapNbg0(COL_TYPE_1M,BM_1024x512,(void *)VDP2_VRAM_B0);

slBMPut(-160,-120,159,119,1st_read);

Thats what i have, but in the BITMAP.DOC it tells me that you need slInitBitMap(); and it only supports 256 colors! i know you guys explained this A MILLION times but takaissilly's code didnt work, I dont get that bmp15bit Demo by Cyber Warrior X, where did he put the 2d DATA?!!! whoa... confusing!

Function:

Sets the bit map screen to the 256-color mode. The screen is not cleared.

i guess if DONT use this function it wont set it to 256 colors... lol im an idiot...
biggrin.gif
thanks guys for all your support, keep it coming im learning by every post!
tongue.gif


BAH i forgot

for PCM sounds can i use slBGM* functions??? and for CDDA as well? i just need ta know
biggrin.gif
and *.snd ? and *.ton ? if i have CDDA mixed with PCM will a slBGM function to fade it, will it both fade the CDDA+PCM or just one?
 
Originally posted by nescphp@May 23, 2003 @ 01:00 AM

you think i can see a *.cti file with some CDDA tracks included please? i deleted mine.... ALSO i have a problem i just want to know


I don't know if there are any *.cti files with audio tracks available, you might want to ask someone who has already built a disc with those tools, I didn't do so.

Code:
slBitMapNbg0(COL_TYPE_1M,BM_1024x512,(void *)VDP2_VRAM_B0);

slBMPut(-160,-120,159,119,1st_read);

Thats what i have, but in the BITMAP.DOC it tells me that you need slInitBitMap(); and it only supports 256 colors! i know you guys explained this A MILLION times but takaissilly's code didnt work, I dont get that bmp15bit Demo by Cyber Warrior X, where did he put the 2d DATA?!!! whoa... confusing!

i guess if DONT use this function it wont set it to 256 colors... lol im an idiot...
biggrin.gif
thanks guys for all your support, keep it coming im learning by every post!
tongue.gif



To use more than 256 colors, you will need to set up the VDP2 plane accordingly on your own, and transfer the data you'd like to see displayed with a simple for loop. Taka's code was only an example, it's not actual code. CyberWarriorX's bitmap demo for 24 bit (haven't looked at his 15bit bitmap demo) is a little difficult to understand, but if you read it again you will see he writes the 24bit data into VRAM and uses the SGL functions for VDP2 setup. You can compile his demo and try a picture, if you don't use his plotpixel function in the 24bit demo (he is calculating the colors).
smile.gif


for PCM sounds can i use slBGM* functions??? and for CDDA as well? i just need ta know
biggrin.gif
and *.snd ? and *.ton ? if i have CDDA mixed with PCM will a slBGM function to fade it, will it both fade the CDDA+PCM or just one?


I believe *.snd and *.ton files are for FM music only, and that would be slBGM*. PCM is only handled by the slPCM* functions I guess, but you might want to read up on that or try the PCM example code. CDDA needs its own fading, and that should be inside the slCDDA* functions.
cool.gif
 
Thanks for clearing that up man, thank you very much. i guess i can ask in #gbadev for a workaround with the 24-bit... BTW where in the living F*CK is the data for the 2d??? LOL
biggrin.gif
i guess i can try to figure this out

also, im moving back to linux... i cant stand the freezing and BSODs!!! OMFG im going crazy. but how am i gonna test my Bins?? i dont have a Action Replay+comms link.... if anyone.... anyone will be so generous to sell me (and they have to be trusted) a Action Replay + Pc Comms Link extremely cheap, dirt cheap, so cheap your practicly giving it to me!
biggrin.gif
biggrin.gif
biggrin.gif
biggrin.gif
tongue.gif
 
Originally posted by nescphp@May 24, 2003 @ 08:33 PM

Thanks for clearing that up man, thank you very much. i guess i can ask in #gbadev for a workaround with the 24-bit... BTW where in the living F*CK is the data for the 2d??? LOL
biggrin.gif
i guess i can try to figure this out


CyberWarriorX didn't include any 2d data. The colors he needs for each pixel are calculated before PlotPixel is called, and that function simply puts the data in the format so it can be seen. You might want to check this in the code again, it's in 15bit and 24bit demo.

also, im moving back to linux... i cant stand the freezing and BSODs!!! OMFG im going crazy. but how am i gonna test my Bins??


No idea. There was a Linux Saturn emulator a few years ago, but I don't think it works ok. Maybe WINE will do what you want?

i dont have a Action Replay+comms link.... if anyone.... anyone will be so generous to sell me (and they have to be trusted) a Action Replay + Pc Comms Link extremely cheap, dirt cheap, so cheap your practicly giving it to me!
biggrin.gif
biggrin.gif
biggrin.gif
biggrin.gif
tongue.gif



You should check the auction pages in your country first, you might get a cheap card from some PSX guy in your country or city.
cool.gif
For the Action Replay/PAR, you should prepare for $35 including shipping. Lik Sang and Lan Kwei still have them I think, or maybe someone here got a spare one. But still, don't expect them to sell it to you for $5 or so...
 
Windows isnt good, but I havent had a BSOD in couple of years. It could have something to do with your configuration, windows isnt at all forgiving. Everything has to be just so. The only hard locks ive had in some time have been caused by the half-life engine, and even then pretty rarely. Though that game doesnt seem to like being minimized on a lot of computers.

Anyway, use whatever works for you, but I highly doubt you'll be satified with using Wine/WineX to run windows-based saturn emus. They're buggy and slow enough to begin with. If you eventually get a comms link and PAR, you could just test that way of course.
 
hey thanks man, thanks everyone... but i quit on CDDA for now... i'll keep this for a future reference... later i'll need all of this
biggrin.gif
... ok ANOTHER stupid question, im looking into making a water effect... is there a tutorial ? or any other effects? i googled but found nothing useful
 
Code:
#include "sgl.h"

#include "sgl_cd.h"

#include "sddrvs.dat"

#include "st_read.c"

extern Uint8	st_read[];

extern Uint16	st_read_p[];

#define	MAX_FILE	128

Uint8 sdmap[]={

	0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x80, 0x00,

	0x10, 0x01, 0x30, 0x00, 0x00, 0x00, 0x10, 0x00,

	0x11, 0x01, 0x40, 0x00, 0x00, 0x00, 0x20, 0x00,

	0x20, 0x01, 0x60, 0x00, 0x00, 0x00, 0x06, 0x00,

	0x21, 0x01, 0x68, 0x00, 0x00, 0x00, 0x06, 0x00,

	0x22, 0x01, 0x70, 0x00, 0x00, 0x00, 0x06, 0x00,

	0x23, 0x01, 0x78, 0x00, 0x00, 0x00, 0x06, 0x00,

	0x24, 0x01, 0x80, 0x00, 0x00, 0x00, 0x06, 0x00,

	0x01, 0x01, 0x86, 0x00, 0x00, 0x04, 0x00, 0x00,

	0x30, 0x05, 0xA0, 0x00, 0x00, 0x02, 0x00, 0x00,

	0xFF, 0xFF

	};

Uint16	data;

Sint32	dirwork[SLCD_WORK_SIZE(MAX_FILE)];

Sint32	stat;

Sint32	ndir;

CDHN	cdhn;

CDBUF	buf[2];

CDKEY	key[2];

void Pal2CRAM(Uint16 *Pal_Data,void *Col_Adr,Uint32 suu);

PerAnalog *ana_pre;

int ss_main(void){

	slInitSystem(TV_320x224,NULL,1);

	slInitSound(sddrvstsk,sizeof(sddrvstsk),sdmap,sizeof(sdmap));

	slCDDAOn(127,127,0,0);

	ndir=slCdInit(MAX_FILE,dirwork);

	key[0].cn=CDKEY_NONE;

	key[0].sm=CDKEY_NONE;

	key[0].ci=CDKEY_NONE;

	key[1].cn=CDKEY_TERM;

	cdhn=slCdOpen("CDDA.001",key);

  buf[0].type=CDBUF_COPY;

  buf[0].trans.copy.addr=NULL;

  buf[0].trans.copy.unit=CDBUF_FORM1;

  buf[0].trans.copy.size=0;

  buf[1].type=CDBUF_TERM;

  slCdLoadFile(cdhn,buf);

	slTVOff();

	slColRAMMode(CRM16_1024);

	slBack1ColSet((void *)VDP2_VRAM_A1+0x1fffe,0);

	slInitBitMap((Uint16)bmNBG0,(Uint16)BM_512x512,(void *)VDP2_VRAM_B0);

	slBitMapNbg0(COL_TYPE_256,BM_512x512,(void *)VDP2_VRAM_B0);

	slBMPut(-160,-120,159,119,st_read);

	slScrPosNbg0(toFIXED(0.0),toFIXED(0.0));

	slScrAutoDisp(NBG0ON|NBG1ON);

	Pal2CRAM((Uint16 *)st_read_p,(void *)VDP2_COLRAM,256);

	slTVOn();

	while(1){

	slScrPosNbg0(toFIXED(0.0),toFIXED(0.0));

	data=Smpc_Peripheral[0].data;

 if(!(data & PER_DGT_TA)){

 LoadFile("X_LEVEL1.BIN");

 }

 if(!(data & PER_DGT_TB)){

 LoadFile("X_ABOUT.BIN");

 }

 stat=slCdGetStatus(cdhn,NULL);

 if(stat==CDSTAT_COMPLETED) break;

 }

	}

void Pal2CRAM(Uint16 *Pal_Data,void *Col_Adr,Uint32 suu){

	Uint16 i;

	Uint16 *VRAM;

	VRAM=(Uint16 *)Col_Adr;

	for(i=0; i<suu; i++)

 *(VRAM++)=*(Pal_Data++);

	}

Code:
ss_main.o: In function `ss_main':

ss_main.c:70: undefined reference to `slCdInit'

ss_main.c(.text+0xc0): undefined reference to `slCdOpen'

ss_main.c(.text+0xc4): undefined reference to `slCdLoadFile'

ss_main.c(.text+0xcc): undefined reference to `slCdGetStatus'

make.exe: *** [sl.coff] Error 1

HELP!!!
biggrin.gif
nothing works
 
Originally posted by nescphp@May 26, 2003 @ 02:38 PM

Code:
ss_main.o: In function `ss_main':

ss_main.c:70: undefined reference to `slCdInit'

ss_main.c(.text+0xc0): undefined reference to `slCdOpen'

ss_main.c(.text+0xc4): undefined reference to `slCdLoadFile'

ss_main.c(.text+0xcc): undefined reference to `slCdGetStatus'

make.exe: *** [sl.coff] Error 1

HELP!!!
biggrin.gif
nothing works

You sure everything you want to include is there? I don't see why it shouldn't work, but if the CD functions are missing it might be due to a wrong include statement, or maybe the file is damaged?
 
Back
Top