]> icculus.org git repositories - btb/d2x.git/blob - arch/sdl/rbaudio.c
stop cd audio when exiting
[btb/d2x.git] / arch / sdl / rbaudio.c
1 /* $Id: rbaudio.c,v 1.4 2003-03-15 01:28:19 btb Exp $ */
2 /*
3  *
4  * SDL CD Audio functions
5  *
6  *
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include <conf.h>
11 #endif
12
13 #include <stdio.h>
14 #include <stdlib.h>
15
16 #include <SDL.h>
17
18 #include "pstypes.h"
19 #include "error.h"
20 #include "args.h"
21 #include "rbaudio.h"
22
23 static SDL_CD *s_cd = NULL;
24 extern int Redbook_playing;
25 static int initialised = 0;
26
27 void RBAExit()
28 {
29         if (initialised)
30         {
31                 SDL_CDStop(s_cd);
32                 SDL_CDClose(s_cd);
33         }
34 }
35
36 void RBAInit()
37 {
38         if (initialised) return;
39         if (FindArg("-nocdrom")) return; 
40
41         if (SDL_Init(SDL_INIT_CDROM) < 0)
42         {
43                 Warning("SDL library initialisation failed: %s.",SDL_GetError());
44                 return;
45         }
46
47         if (SDL_CDNumDrives() == 0)
48         {
49                 Warning("No cdrom drives found!\n");
50                 return;
51         }
52         s_cd = SDL_CDOpen(0);
53         if (s_cd == NULL) {
54                 Warning("Could not open cdrom for redbook audio!\n");
55                 return;
56         }
57         atexit(RBAExit);
58         initialised = 1;
59 }
60
61 int RBAEnabled()
62 {
63  return 1;
64 }
65
66 void RBARegisterCD()
67 {
68
69 }
70
71 int RBAPlayTrack(int a)
72 {
73  if (!initialised) return -1;
74
75  if (CD_INDRIVE(SDL_CDStatus(s_cd)) ) {
76          SDL_CDPlayTracks(s_cd, a-1, 0, 0, 0);
77  }
78  return a;
79  
80 }
81
82 void RBAStop()
83 {
84   if (!initialised) return;
85   SDL_CDStop(s_cd);
86 }
87
88 void RBASetVolume(int a)
89 {
90
91 }
92
93 void RBAPause()
94 {
95   if (!initialised) return;
96   SDL_CDPause(s_cd);
97 }
98
99 int RBAResume()
100 {
101   if (!initialised) return -1;
102   SDL_CDResume(s_cd);
103   return 1;
104 }
105
106 int RBAGetNumberOfTracks()
107 {
108   if (!initialised) return -1;
109  SDL_CDStatus(s_cd);
110  return s_cd->numtracks;
111 }
112
113 int RBAPlayTracks(int tracknum,int something)
114 {
115   if (!initialised) return -1;
116  if (CD_INDRIVE(SDL_CDStatus(s_cd)) ) {
117          SDL_CDPlayTracks(s_cd, tracknum-1, 0, 0, 0);
118  }
119  return tracknum;
120 }
121
122 int RBAGetTrackNum()
123 {
124   if (!initialised) return -1;
125  SDL_CDStatus(s_cd);
126  return s_cd->cur_track;
127 }
128
129 int RBAPeekPlayStatus()
130 {
131   return (SDL_CDStatus(s_cd) == CD_PLAYING);
132 }
133
134 int CD_blast_mixer()
135 {
136  return 0;
137 }