2 /* Test the SDL CD-ROM audio functions */
11 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
12 static void quit(int rc
)
18 static void PrintStatus(int driveindex
, SDL_CD
*cdrom
)
23 status
= SDL_CDStatus(cdrom
);
26 status_str
= "tray empty";
29 status_str
= "stopped";
32 status_str
= "playing";
35 status_str
= "paused";
38 status_str
= "error state";
41 printf("Drive %d status: %s\n", driveindex
, status_str
);
42 if ( status
>= CD_PLAYING
) {
44 FRAMES_TO_MSF(cdrom
->cur_frame
, &m
, &s
, &f
);
45 printf("Currently playing track %d, %d:%2.2d\n",
46 cdrom
->track
[cdrom
->cur_track
].id
, m
, s
);
50 static void ListTracks(SDL_CD
*cdrom
)
57 printf("Drive tracks: %d\n", cdrom
->numtracks
);
58 for ( i
=0; i
<cdrom
->numtracks
; ++i
) {
59 FRAMES_TO_MSF(cdrom
->track
[i
].length
, &m
, &s
, &f
);
62 switch(cdrom
->track
[i
].type
)
74 printf("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i
,
75 cdrom
->track
[i
].id
, m
, s
, cdrom
->track
[i
].length
, trtype
);
79 static void PrintUsage(char *argv0
)
81 fprintf(stderr
, "Usage: %s [drive#] [command] [command] ...\n", argv0
);
82 fprintf(stderr
, "Where 'command' is one of:\n");
83 fprintf(stderr
, " -status\n");
84 fprintf(stderr
, " -list\n");
85 fprintf(stderr
, " -play [first_track] [first_frame] [num_tracks] [num_frames]\n");
86 fprintf(stderr
, " -pause\n");
87 fprintf(stderr
, " -resume\n");
88 fprintf(stderr
, " -stop\n");
89 fprintf(stderr
, " -eject\n");
90 fprintf(stderr
, " -sleep <milliseconds>\n");
93 int main(int argc
, char *argv
[])
99 /* Initialize SDL first */
100 if ( SDL_Init(SDL_INIT_CDROM
) < 0 ) {
101 fprintf(stderr
, "Couldn't initialize SDL: %s\n",SDL_GetError());
105 /* Find out how many CD-ROM drives are connected to the system */
106 if ( SDL_CDNumDrives() == 0 ) {
107 printf("No CD-ROM devices detected\n");
110 printf("Drives available: %d\n", SDL_CDNumDrives());
111 for ( i
=0; i
<SDL_CDNumDrives(); ++i
) {
112 printf("Drive %d: \"%s\"\n", i
, SDL_CDName(i
));
115 /* Open the CD-ROM */
118 if ( argv
[i
] && isdigit(argv
[i
][0]) ) {
119 drive
= atoi(argv
[i
++]);
121 cdrom
= SDL_CDOpen(drive
);
122 if ( cdrom
== NULL
) {
123 fprintf(stderr
, "Couldn't open drive %d: %s\n", drive
,
131 /* Find out which function to perform */
132 for ( ; argv
[i
]; ++i
) {
133 if ( strcmp(argv
[i
], "-status") == 0 ) {
134 /* PrintStatus(drive, cdrom); */
136 if ( strcmp(argv
[i
], "-list") == 0 ) {
139 if ( strcmp(argv
[i
], "-play") == 0 ) {
144 if ( argv
[i
+1] && isdigit(argv
[i
+1][0]) ) {
145 strack
= atoi(argv
[++i
]);
148 if ( argv
[i
+1] && isdigit(argv
[i
+1][0]) ) {
149 sframe
= atoi(argv
[++i
]);
152 if ( argv
[i
+1] && isdigit(argv
[i
+1][0]) ) {
153 ntrack
= atoi(argv
[++i
]);
156 if ( argv
[i
+1] && isdigit(argv
[i
+1][0]) ) {
157 nframe
= atoi(argv
[++i
]);
159 if ( CD_INDRIVE(SDL_CDStatus(cdrom
)) ) {
160 if ( SDL_CDPlayTracks(cdrom
, strack
, sframe
,
161 ntrack
, nframe
) < 0 ) {
163 "Couldn't play tracks %d/%d for %d/%d: %s\n",
164 strack
, sframe
, ntrack
, nframe
, SDL_GetError());
167 fprintf(stderr
, "No CD in drive!\n");
170 if ( strcmp(argv
[i
], "-pause") == 0 ) {
171 if ( SDL_CDPause(cdrom
) < 0 ) {
172 fprintf(stderr
, "Couldn't pause CD: %s\n",
176 if ( strcmp(argv
[i
], "-resume") == 0 ) {
177 if ( SDL_CDResume(cdrom
) < 0 ) {
178 fprintf(stderr
, "Couldn't resume CD: %s\n",
182 if ( strcmp(argv
[i
], "-stop") == 0 ) {
183 if ( SDL_CDStop(cdrom
) < 0 ) {
184 fprintf(stderr
, "Couldn't eject CD: %s\n",
188 if ( strcmp(argv
[i
], "-eject") == 0 ) {
189 if ( SDL_CDEject(cdrom
) < 0 ) {
190 fprintf(stderr
, "Couldn't eject CD: %s\n",
194 if ( (strcmp(argv
[i
], "-sleep") == 0) &&
195 (argv
[i
+1] && isdigit(argv
[i
+1][0])) ) {
196 SDL_Delay(atoi(argv
[++i
]));
197 printf("Delayed %d milliseconds\n", atoi(argv
[i
]));
204 PrintStatus(drive
, cdrom
);