more updates for CDDA mode

This commit is contained in:
nehalmistry 2002-12-06 07:24:31 +00:00
parent 102d97ba65
commit 22cf0531e1
5 changed files with 103 additions and 39 deletions

View file

@ -47,9 +47,9 @@ extern sem_t SoundThreadChannelSemaphore;
#elif defined(USE_LIBCDA)
#include "libcda.h"
#elif defined(USE_CDDA)
#include <cdda_interface.h>
#include <cdda_paranoia.h>
#include <utils.h>
#include <linux/cdrom.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#endif
/*----------------------------------------------------------------------------
@ -249,6 +249,10 @@ extern int NumCDTracks;
#elif defined(USE_CDDA)
// FIXME: fill up
extern int NumCDTracks;
extern int CDDrive;
extern struct cdrom_tochdr CDchdr;
extern struct cdrom_tocentry CDtocentry[64];
extern struct cdrom_read_audio CDdata;
#endif
extern Sample* MusicSample; /// Music samples
@ -261,6 +265,9 @@ extern Sample* LoadFlac(const char* name,int flags); /// Load a flac file
extern Sample* LoadWav(const char* name,int flags); /// Load a wav file
extern Sample* LoadOgg(const char* name,int flags); /// Load an ogg file
extern Sample* LoadMp3(const char* name,int flags); /// Load a mp3 file
#ifdef USE_CDDA
extern Sample* LoadCD(const char* name,int flags); /// Load a cd track
#endif
/// Register a sound (can be a simple sound or a group)
extern SoundId RegisterSound(char* file[],unsigned number);

View file

@ -1,3 +1,3 @@
SRC += src/sound/arts_audio.c src/sound/ccl_sound.c src/sound/flac.c src/sound/libcda.c src/sound/mad.c src/sound/music.c src/sound/ogg.c src/sound/oss_audio.c src/sound/sdl_audio.c src/sound/sound.c src/sound/sound_id.c src/sound/sound_server.c src/sound/unitsound.c src/sound/wav.c
SRC += src/sound/arts_audio.c src/sound/ccl_sound.c src/sound/flac.c src/sound/libcda.c src/sound/mad.c src/sound/music.c src/sound/ogg.c src/sound/oss_audio.c src/sound/sdl_audio.c src/sound/sound.c src/sound/sound_id.c src/sound/sound_server.c src/sound/unitsound.c src/sound/wav.c src/sound/cdda.c
HDRS +=
OBJ += src/sound/$(OBJDIR)/arts_audio.o src/sound/$(OBJDIR)/ccl_sound.o src/sound/$(OBJDIR)/flac.o src/sound/$(OBJDIR)/libcda.o src/sound/$(OBJDIR)/mad.o src/sound/$(OBJDIR)/music.o src/sound/$(OBJDIR)/ogg.o src/sound/$(OBJDIR)/oss_audio.o src/sound/$(OBJDIR)/sdl_audio.o src/sound/$(OBJDIR)/sound.o src/sound/$(OBJDIR)/sound_id.o src/sound/$(OBJDIR)/sound_server.o src/sound/$(OBJDIR)/unitsound.o src/sound/$(OBJDIR)/wav.o
OBJ += src/sound/$(OBJDIR)/arts_audio.o src/sound/$(OBJDIR)/ccl_sound.o src/sound/$(OBJDIR)/flac.o src/sound/$(OBJDIR)/libcda.o src/sound/$(OBJDIR)/mad.o src/sound/$(OBJDIR)/music.o src/sound/$(OBJDIR)/ogg.o src/sound/$(OBJDIR)/oss_audio.o src/sound/$(OBJDIR)/sdl_audio.o src/sound/$(OBJDIR)/sound.o src/sound/$(OBJDIR)/sound_id.o src/sound/$(OBJDIR)/sound_server.o src/sound/$(OBJDIR)/unitsound.o src/sound/$(OBJDIR)/wav.o src/sound/$(OBJDIR)/cdda.c

65
src/sound/cdda.cpp Normal file
View file

@ -0,0 +1,65 @@
// ___________ _________ _____ __
// \_ _____/______ ____ ____ \_ ___ \____________ _/ ____\/ |_
// | __) \_ __ \_/ __ \_/ __ \/ \ \/\_ __ \__ \\ __\\ __\
// | \ | | \/\ ___/\ ___/\ \____| | \// __ \| | | |
// \___ / |__| \___ >\___ >\______ /|__| (____ /__| |__|
// \/ \/ \/ \/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// FreeCraft - A free fantasy real time strategy game engine
//
/**@name wav.c - wav support */
//
// (c) Copyright 2002 by Lutz Sammer and Fabrice Rossi
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// $Id: wav.c,v 1.7 2002/07/20 00:09:05 johns Exp $
//@{
/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
#include "freecraft.h"
#if defined(WITH_SOUND) // {
#include "sound_server.h"
#include <stdlib.h>
/*----------------------------------------------------------------------------
-- Declaration
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
/**
** Load CD.
**
** @param name Unused.
** @param flags Track number.
**
** @return Returns the loaded sample.
**
*/
global Sample* LoadCD(const char* name, int flags)
{
Sample* sample = NULL;
return sample;
}
#endif // } WITH_SOUND
//@}

View file

@ -66,7 +66,7 @@ global Sample* MusicSample; /// Music samples
#if defined(USE_SDLCD) || defined(USE_LIBCDA) || defined(USE_CDDA)
global char *CDMode = ":off"; /// cd play mode, ":off" ":random" or ":all"
global int CDTrack = 1; /// Current cd track
global int CDTrack = 0; /// Current cd track
#endif
#if defined(USE_SDLCD)
@ -76,6 +76,10 @@ global int NumCDTracks; /// Number of tracks on the cd
#elif defined(USE_CDDA)
// FIXME: fill up
global int NumCDTracks;
global int CDDrive;
global struct cdrom_tochdr CDchdr;
global struct cdrom_tocentry CDtocentry[64];
global struct cdrom_read_audio CDdata;
#endif
/*----------------------------------------------------------------------------
@ -375,19 +379,22 @@ local int PlayCDRom(const char* name)
*/
local int PlayCDRom(const char* name)
{
cdrom_drive *CddaDrive = NULL;
void *buf;
// cdrom_paranoia *Cdda;
int i;
Sample *sample;
if (!strcmp(CDMode, ":off")) {
if (!strncmp(name, ":", 1)) {
CddaDrive = cdda_find_a_cdrom(0, NULL);
cdda_open(CddaDrive);
// Cdda = paranoia_init(CddaDrive);
CDDrive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK);
ioctl(CDDrive, CDROMREADTOCHDR, &CDchdr);
NumCDTracks = cdda_tracks(CddaDrive);
for (i = CDchdr.cdth_trk0; i < CDchdr.cdth_trk1; ++i){
CDtocentry[i].cdte_format = CDROM_LBA;
CDtocentry[i].cdte_track = i + 1;
ioctl(CDDrive, CDROMREADTOCENTRY, &CDtocentry[i]);
}
NumCDTracks = i + 1;
if (NumCDTracks == -1) {
if (NumCDTracks == 0) {
CDMode = ":off";
return 1;
}
@ -405,19 +412,8 @@ local int PlayCDRom(const char* name)
do {
if (CDTrack > NumCDTracks)
CDTrack = 1;
} while (cdda_track_audiop(CddaDrive, ++CDTrack) == 0);
// temporary
fprintf(stderr, "AAAAAAAAAAa %d\n",CDTrack);
CDTrack = 3;
buf = malloc(512*100);
cdda_read(CddaDrive, buf, cdda_track_firstsector(CddaDrive, CDTrack), 100);
free(buf);
return 1;
CDTrack = 0;
} while (CDtocentry[++CDTrack].cdte_ctrl&CDROM_DATA_TRACK);
}
// if mode is play random tracks
if (!strcmp(name, ":random")) {
@ -425,15 +421,13 @@ local int PlayCDRom(const char* name)
do {
CDTrack = MyRand() % NumCDTracks;
} while (cdda_track_audiop(CddaDrive, ++CDTrack) == 0);
buf = malloc(512*100);
cdda_read(CddaDrive, buf, cdda_track_firstsector(CddaDrive, CDTrack), 100);
free(buf);
return 1;
} while (CDtocentry[++CDTrack].cdte_ctrl&CDROM_DATA_TRACK);
}
sample = LoadCD(NULL, CDTrack);
StopMusic();
MusicSample = sample;
PlayingMusic = 1;
return 1;
}
// FIXME: no cdrom, must stop it now!

View file

@ -699,12 +699,10 @@ global void GameMainLoop(void)
//
switch( GameCycle% ((CYCLES_PER_SECOND*VideoSyncSpeed/100)+1) ) {
case 0: // Check cd-rom
#ifdef USE_SDLCD
#if defined(USE_SDLCD)
if ( !(GameCycle%2) ) // every 2nd second
SDL_CreateThread(CDRomCheck, NULL);
#endif
#ifdef USE_LIBCDA
#elif defined(USE_LIBCDA) || defined(USE_CDDA)
CDRomCheck(NULL);
#endif
break;