Crappy CD performance SDL/win32

My program basically boils down to the program below, I recently added
the CD parts and when I did the performance goes from a comfortable
~60fps to a appalling .25 fps. Plus the CD does’nt play until after I
exit my program. Am I using the functions right? Has anyone had
success with code and the cd functions in windows? BTW: It does the
same thing without the call to SDL_CDstatus also.

CD calls are slow. Do them every few seconds instead of every pass
through the game loop.

See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

My program basically boils down to the program below, I recently added
the CD parts and when I did the performance goes from a comfortable
~60fps to a appalling .25 fps. Plus the CD does’nt play until after I
exit my program. Am I using the functions right? Has anyone had
success with code and the cd functions in windows? BTW: It does the
same thing without the call to SDL_CDstatus also.

#include <stdio.h>
#include “SDL.h”

int main(int argc, char *argv[]) {
Uint8 *keys;
SDL_Event event;
SDL_CD *cd;

if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_CDROM) < 0 ){
	fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
	exit(1);
}
atexit(SDL_Quit);

if( (screen = SDL_SetVideoMode( WIDTH, HEIGHT, 0, 0)) == NULL ) {
	fprintf(stderr, "Couldn't set mode: %s\n", SDL_GetError());
	exit(1);
}

cd = SDL_CDOpen(0);
SDL_CDStatus(cd);

/* main loop */
while(!done) {
	keys = SDL_GetKeyState(NULL); 
	buttons=SDL_GetRelativeMouseState(&x, &y);  

	if(keys[SDLK_ESCAPE] == SDL_PRESSED ) {
		done=1;

	SDL_CDStatus(cd);
	if(cd->status!=CD_PLAYING) {
		SDL_CDPlayTracks(cd, rand()%cd->numtracks, 0, 1, 0);
	}
	// Do graphics stuff and flip buffer here
}

SDL_CDStop(cd);
SDL_Quit();
return 0;

}

I got it to play, but everytime I call SDL_CDStatus() the status is
always returned as 0. So I can’t use SDL_CDStatus to tell if the CD
is still playing. I worked around it, but it is rather annoying.

I got it to play, but everytime I call SDL_CDStatus() the status is
always returned as 0. So I can’t use SDL_CDStatus to tell if the CD
is still playing. I worked around it, but it is rather annoying.

Can you post the sample code for testing?

Thanks!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

This is essentially what I tested with. I did it with and without a 4
second delay. If I’m still doing something wrong then when I get
everything working I’m gonna write a tutorial on it for the SDL doc
project.

#include <stdio.h>
#include “SDL.h”

int main(int argc, char *argv[]) {
Uint8 *keys;
SDL_Event event;
SDL_CD *cd;

if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_CDROM) < 0 ){
	fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
	exit(1);
}
atexit(SDL_Quit);

if( (screen = SDL_SetVideoMode( WIDTH, HEIGHT, 0, 0)) == NULL ) {
	fprintf(stderr, "Couldn't set mode: %s\n", SDL_GetError());
	exit(1);
}

cd = SDL_CDOpen(0);
SDL_CDStatus(cd);
SDL_CDPlayTracks(cd, rand()%cd->numtracks, 0, 1, 0);

/* main loop */
while(!done) {
	keys = SDL_GetKeyState(NULL); 
	buttons=SDL_GetRelativeMouseState(&x, &y);  

	if(keys[SDLK_ESCAPE] == SDL_PRESSED ) {
		done=1;

	SDL_CDStatus(cd);
	fprintf(stdout, "/n*%i %i*/n", cd->status, CD_PLAYING) {
	}
	// Do graphics stuff and flip buffer here
}

SDL_CDStop(cd);
SDL_Quit();
return 0;

}

This is essentially what I tested with.

Thanks. This was a silly bug. The return value of SDL_CDStatus() is
correct, but the status is never saved in the CD structure. It’s now
fixed in CVS.

Thanks!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software