1 /* $Id: rbaudio.c,v 1.8 2003-03-21 01:57:58 btb Exp $ */
4 * SDL CD Audio functions
19 #include <sys/ioctl.h>
20 #include <linux/cdrom.h>
28 static SDL_CD *s_cd = NULL;
29 static int initialised = 0;
42 if (initialised) return;
43 if (FindArg("-nocdrom")) return;
45 if (SDL_Init(SDL_INIT_CDROM) < 0)
47 Warning("SDL library initialisation failed: %s.",SDL_GetError());
51 if (SDL_CDNumDrives() == 0)
53 Warning("No cdrom drives found!\n");
58 Warning("Could not open cdrom for redbook audio!\n");
75 int RBAPlayTrack(int a)
77 if (!initialised) return -1;
79 if (CD_INDRIVE(SDL_CDStatus(s_cd)) ) {
80 SDL_CDPlayTracks(s_cd, a-1, 0, 0, 0);
87 if (!initialised) return;
91 void RBASetVolume(int volume)
95 struct cdrom_volctrl volctrl;
97 if (!initialised) return;
102 if ((level<0) || (level>255)) {
103 fprintf(stderr, "illegal volume value (allowed values 0-255)\n");
112 if ( ioctl(cdfile, CDROMVOLCTRL, &volctrl) == -1 ) {
113 fprintf(stderr, "CDROMVOLCTRL ioctl failed\n");
121 if (!initialised) return;
127 if (!initialised) return -1;
132 int RBAGetNumberOfTracks()
134 if (!initialised) return -1;
136 return s_cd->numtracks;
139 int RBAPlayTracks(int tracknum,int something)
141 if (!initialised) return -1;
142 if (CD_INDRIVE(SDL_CDStatus(s_cd)) ) {
143 SDL_CDPlayTracks(s_cd, tracknum-1, 0, 0, 0);
150 if (!initialised) return -1;
152 return s_cd->cur_track;
155 int RBAPeekPlayStatus()
157 return (SDL_CDStatus(s_cd) == CD_PLAYING);
166 static int cddb_sum(int n)
170 /* For backward compatibility this algorithm must not change */
175 ret = ret + (n % 10);
183 unsigned long RBAGetDiscID()
190 /* For backward compatibility this algorithm must not change */
194 while (i < s_cd->numtracks) {
195 n += cddb_sum(s_cd->track[i].offset / CD_FPS);
199 t = (s_cd->track[s_cd->numtracks].offset / CD_FPS) -
200 (s_cd->track[0].offset / CD_FPS);
202 return ((n % 0xff) << 24 | t << 8 | s_cd->numtracks);