1 /* $Id: rbaudio.c,v 1.9 2004-04-14 08:32:49 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 // plays tracks first through last, inclusive
140 int RBAPlayTracks(int first, int last)
145 if (CD_INDRIVE(SDL_CDStatus(s_cd)))
147 SDL_CDPlayTracks(s_cd, first - 1, 0, last - first + 1, 0);
152 // return the track number currently playing. Useful if RBAPlayTracks()
153 // is called. Returns 0 if no track playing, else track number
159 if (SDL_CDStatus(s_cd) != CD_PLAYING)
162 return s_cd->cur_track + 1;
165 int RBAPeekPlayStatus()
167 return (SDL_CDStatus(s_cd) == CD_PLAYING);
176 static int cddb_sum(int n)
180 /* For backward compatibility this algorithm must not change */
185 ret = ret + (n % 10);
193 unsigned long RBAGetDiscID()
200 /* For backward compatibility this algorithm must not change */
204 while (i < s_cd->numtracks) {
205 n += cddb_sum(s_cd->track[i].offset / CD_FPS);
209 t = (s_cd->track[s_cd->numtracks].offset / CD_FPS) -
210 (s_cd->track[0].offset / CD_FPS);
212 return ((n % 0xff) << 24 | t << 8 | s_cd->numtracks);