3 * SDL CD Audio functions
18 #include <sys/ioctl.h>
19 #include <linux/cdrom.h>
27 static SDL_CD *s_cd = NULL;
28 static int initialised = 0;
41 if (initialised) return;
42 if (FindArg("-nocdrom")) return;
44 if (SDL_Init(SDL_INIT_CDROM) < 0)
46 Warning("SDL library initialisation failed: %s.",SDL_GetError());
50 if (SDL_CDNumDrives() == 0)
52 Warning("No cdrom drives found!\n");
57 Warning("Could not open cdrom for redbook audio!\n");
61 SDL_CDStatus(s_cd); /* update the drive status */
77 int RBAPlayTrack(int a)
79 if (!initialised) return -1;
81 if (CD_INDRIVE(SDL_CDStatus(s_cd)) ) {
82 SDL_CDPlayTracks(s_cd, a-1, 0, 0, 0);
89 if (!initialised) return;
93 void RBASetVolume(int volume)
97 struct cdrom_volctrl volctrl;
99 if (!initialised) return;
104 if ((level<0) || (level>255)) {
105 fprintf(stderr, "illegal volume value (allowed values 0-255)\n");
114 if ( ioctl(cdfile, CDROMVOLCTRL, &volctrl) == -1 ) {
115 fprintf(stderr, "CDROMVOLCTRL ioctl failed\n");
123 if (!initialised) return;
129 if (!initialised) return -1;
134 int RBAGetNumberOfTracks()
136 if (!initialised) return -1;
138 return s_cd->numtracks;
141 // plays tracks first through last, inclusive
142 int RBAPlayTracks(int first, int last)
147 if (CD_INDRIVE(SDL_CDStatus(s_cd)))
149 SDL_CDPlayTracks(s_cd, first - 1, 0, last - first + 1, 0);
154 // return the track number currently playing. Useful if RBAPlayTracks()
155 // is called. Returns 0 if no track playing, else track number
161 if (SDL_CDStatus(s_cd) != CD_PLAYING)
164 return s_cd->cur_track + 1;
167 int RBAPeekPlayStatus()
169 return (SDL_CDStatus(s_cd) == CD_PLAYING);
178 static int cddb_sum(int n)
182 /* For backward compatibility this algorithm must not change */
187 ret = ret + (n % 10);
195 uint32_t RBAGetDiscID()
202 /* For backward compatibility this algorithm must not change */
206 while (i < s_cd->numtracks) {
207 n += cddb_sum(s_cd->track[i].offset / CD_FPS);
211 t = (s_cd->track[s_cd->numtracks].offset / CD_FPS) -
212 (s_cd->track[0].offset / CD_FPS);
214 return ((n % 0xff) << 24 | t << 8 | s_cd->numtracks);