music.c
changeset 381 2064088ea781
parent 357 d6d0cfdbea65
child 382 50501e45c57b
equal deleted inserted replaced
380:161aa45d00c2 381:2064088ea781
  1414 	m=Player_LoadGeneric((MREADER*)&lmmmr,maxchan,0);
  1414 	m=Player_LoadGeneric((MREADER*)&lmmmr,maxchan,0);
  1415 	return m;
  1415 	return m;
  1416 }
  1416 }
  1417 # endif
  1417 # endif
  1418 
  1418 
  1419 Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw) {
  1419 Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw)
       
  1420 {
  1420 	Uint8 magic[5];	  /*Apparently there is no way to check if the file is really a MOD,*/
  1421 	Uint8 magic[5];	  /*Apparently there is no way to check if the file is really a MOD,*/
  1421 	/*		    or there are too many formats supported by MikMod or MikMod does */
  1422 	/*		    or there are too many formats supported by MikMod or MikMod does */
  1422 	/*		    this check by itself. If someone implements other formats (e.g. MP3) */
  1423 	/*		    this check by itself. If someone implements other formats (e.g. MP3) */
  1423 	/*		    the check can be uncommented */
  1424 	/*		    the check can be uncommented */
       
  1425 	Uint8 moremagic[9];
  1424 	Mix_Music *music;
  1426 	Mix_Music *music;
  1425 	int start;
  1427 	int start;
  1426 
  1428 
  1427 	if (!rw) {
  1429 	if (!rw) {
  1428 		Mix_SetError("RWops pointer is NULL");
  1430 		Mix_SetError("RWops pointer is NULL");
  1429 		return NULL;
  1431 		return NULL;
  1430 	}
  1432 	}
  1431 
  1433 
  1432 	/* Figure out what kind of file this is */
  1434 	/* Figure out what kind of file this is */
  1433 	start = SDL_RWtell(rw);
  1435 	start = SDL_RWtell(rw);
  1434 	if (SDL_RWread(rw,magic,1,4)!=4) {
  1436 	if ( SDL_RWread(rw,magic,1,4) != 4 ||
       
  1437 	     SDL_RWread(rw,moremagic,1,8) != 8 ) {
  1435 		Mix_SetError("Couldn't read from RWops");
  1438 		Mix_SetError("Couldn't read from RWops");
  1436 		return NULL;
  1439 		return NULL;
  1437 	}
  1440 	}
  1438 	SDL_RWseek(rw, start, SEEK_SET);
  1441 	SDL_RWseek(rw, start, SEEK_SET);
  1439 	magic[4]='\0';
  1442 	magic[4]='\0';
       
  1443 	moremagic[8] = '\0';
  1440 
  1444 
  1441 	/* Allocate memory for the music structure */
  1445 	/* Allocate memory for the music structure */
  1442 	music=(Mix_Music *)malloc(sizeof(Mix_Music));
  1446 	music=(Mix_Music *)malloc(sizeof(Mix_Music));
  1443 	if (music==NULL ) {
  1447 	if (music==NULL ) {
  1444 		Mix_SetError("Out of memory");
  1448 		Mix_SetError("Out of memory");
  1445 		return(NULL);
  1449 		return(NULL);
  1446 	}
  1450 	}
  1447 	music->error = 0;
  1451 	music->error = 0;
  1448 
  1452 
       
  1453 #ifdef WAV_MUSIC
       
  1454 	/* WAVE files have the magic four bytes "RIFF"
       
  1455 	   AIFF files have the magic 12 bytes "FORM" XXXX "AIFF"
       
  1456 	 */
       
  1457 	if ( ((strcmp((char *)magic, "RIFF") == 0) && (strcmp((char *)(moremagic+4), "WAVE") == 0)) ||
       
  1458 	     (strcmp((char *)magic, "FORM") == 0) ) {
       
  1459 		music->type = MUS_WAV;
       
  1460 		music->data.wave = WAVStream_LoadSong_RW(rw, (char *)magic);
       
  1461 		if ( music->data.wave == NULL ) {
       
  1462 			music->error = 1;
       
  1463 		}
       
  1464 
       
  1465 	} else
       
  1466 #endif
  1449 #ifdef OGG_MUSIC
  1467 #ifdef OGG_MUSIC
  1450 	/* Ogg Vorbis files have the magic four bytes "OggS" */
  1468 	/* Ogg Vorbis files have the magic four bytes "OggS" */
  1451 	if ( strcmp((char *)magic, "OggS") == 0 ) {
  1469 	if ( strcmp((char *)magic, "OggS") == 0 ) {
  1452 		music->type = MUS_OGG;
  1470 		music->type = MUS_OGG;
  1453 		music->data.ogg = OGG_new_RW(rw);
  1471 		music->data.ogg = OGG_new_RW(rw);