xref: /haiku/src/kits/game/StreamingGameSound.cpp (revision 0c93c0a807b27096abbfad677436afb7d1712d4a)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		StreamingGameSound.cpp
23 //	Author:			Christopher ML Zumwalt May (zummy@users.sf.net)
24 //	Description:	BStreamingGameSound is a class for all kinds of streaming
25 //					(data not known beforehand) game sounds.
26 //------------------------------------------------------------------------------
27 
28 // Standard Includes -----------------------------------------------------------
29 
30 // System Includes -------------------------------------------------------------
31 
32 // Project Includes ------------------------------------------------------------
33 #include "GameSoundDevice.h"
34 
35 // Local Includes --------------------------------------------------------------
36 #include "StreamingGameSound.h"
37 
38 // Local Defines ---------------------------------------------------------------
39 BStreamingGameSound::BStreamingGameSound(size_t inBufferFrameCount,
40 										 const gs_audio_format *format,
41 										 size_t inBufferCount,
42 										 BGameSoundDevice *device)
43  	:	BGameSound(device),
44  		fStreamHook(NULL),
45  		fStreamCookie(NULL)
46 {
47 	if (InitCheck() == B_OK)
48 	{
49 		status_t error = SetParameters(inBufferFrameCount, format, inBufferCount);
50 		SetInitError(error);
51 	}
52 }
53 
54 
55 BStreamingGameSound::BStreamingGameSound(BGameSoundDevice *device)
56  	:	BGameSound(device),
57  		fStreamHook(NULL),
58  		fStreamCookie(NULL)
59 {
60 }
61 
62 
63 BStreamingGameSound::~BStreamingGameSound()
64 {
65 }
66 
67 
68 BGameSound *
69 BStreamingGameSound::Clone() const
70 {
71 	return NULL;
72 }
73 
74 
75 status_t
76 BStreamingGameSound::SetStreamHook(void (*hook)(void * inCookie, void * inBuffer, size_t inByteCount, BStreamingGameSound * me),
77 								   void * cookie)
78 {
79 	fStreamHook = hook;
80 	fStreamCookie = cookie;
81 
82 	return B_OK;
83 }
84 
85 
86 void
87 BStreamingGameSound::FillBuffer(void *inBuffer,
88 								size_t inByteCount)
89 {
90 	if (fStreamHook)
91 		(fStreamHook)(fStreamCookie, inBuffer, inByteCount, this);
92 }
93 
94 
95 status_t
96 BStreamingGameSound::Perform(int32 selector,
97 							 void *data)
98 {
99 	return B_ERROR;
100 }
101 
102 
103 status_t
104 BStreamingGameSound::SetAttributes(gs_attribute * inAttributes,
105 									size_t inAttributeCount)
106 {
107 	return BGameSound::SetAttributes(inAttributes, inAttributeCount);
108 }
109 
110 
111 status_t
112 BStreamingGameSound::SetParameters(size_t inBufferFrameCount,
113 						  const gs_audio_format *format,
114 						  size_t inBufferCount)
115 {
116 	gs_id sound;
117 	status_t error = Device()->CreateBuffer(&sound, this, format);
118 	if (error != B_OK) return error;
119 
120 	return BGameSound::Init(sound);
121 }
122 
123 
124 bool
125 BStreamingGameSound::Lock()
126 {
127 	return fLock.Lock();
128 }
129 
130 
131 void
132 BStreamingGameSound::Unlock()
133 {
134 	fLock.Unlock();
135 }
136 
137 
138 /* unimplemented for protection of the user:
139  *
140  * BStreamingGameSound::BStreamingGameSound()
141  * BStreamingGameSound::BStreamingGameSound(const BStreamingGameSound &)
142  * BStreamingGameSound &BStreamingGameSound::operator=(const BStreamingGameSound &)
143  */
144 
145 
146 status_t
147 BStreamingGameSound::_Reserved_BStreamingGameSound_0(int32 arg, ...)
148 {
149 	return B_ERROR;
150 }
151 
152 
153 status_t
154 BStreamingGameSound::_Reserved_BStreamingGameSound_1(int32 arg, ...)
155 {
156 	return B_ERROR;
157 }
158 
159 
160 status_t
161 BStreamingGameSound::_Reserved_BStreamingGameSound_2(int32 arg, ...)
162 {
163 	return B_ERROR;
164 }
165 
166 
167 status_t
168 BStreamingGameSound::_Reserved_BStreamingGameSound_3(int32 arg, ...)
169 {
170 	return B_ERROR;
171 }
172 
173 
174 status_t
175 BStreamingGameSound::_Reserved_BStreamingGameSound_4(int32 arg, ...)
176 {
177 	return B_ERROR;
178 }
179 
180 
181 status_t
182 BStreamingGameSound::_Reserved_BStreamingGameSound_5(int32 arg, ...)
183 {
184 	return B_ERROR;
185 }
186 
187 
188 status_t
189 BStreamingGameSound::_Reserved_BStreamingGameSound_6(int32 arg, ...)
190 {
191 	return B_ERROR;
192 }
193 
194 
195 status_t
196 BStreamingGameSound::_Reserved_BStreamingGameSound_7(int32 arg, ...)
197 {
198 	return B_ERROR;
199 }
200 
201 
202 status_t
203 BStreamingGameSound::_Reserved_BStreamingGameSound_8(int32 arg, ...)
204 {
205 	return B_ERROR;
206 }
207 
208 
209 status_t
210 BStreamingGameSound::_Reserved_BStreamingGameSound_9(int32 arg, ...)
211 {
212 	return B_ERROR;
213 }
214 
215 
216 status_t
217 BStreamingGameSound::_Reserved_BStreamingGameSound_10(int32 arg, ...)
218 {
219 	return B_ERROR;
220 }
221 
222 
223 status_t
224 BStreamingGameSound::_Reserved_BStreamingGameSound_11(int32 arg, ...)
225 {
226 	return B_ERROR;
227 }
228 
229 
230 status_t
231 BStreamingGameSound::_Reserved_BStreamingGameSound_12(int32 arg, ...)
232 {
233 	return B_ERROR;
234 }
235 
236 
237 status_t
238 BStreamingGameSound::_Reserved_BStreamingGameSound_13(int32 arg, ...)
239 {
240 	return B_ERROR;
241 }
242 
243 
244 status_t
245 BStreamingGameSound::_Reserved_BStreamingGameSound_14(int32 arg, ...)
246 {
247 	return B_ERROR;
248 }
249 
250 
251 status_t
252 BStreamingGameSound::_Reserved_BStreamingGameSound_15(int32 arg, ...)
253 {
254 	return B_ERROR;
255 }
256 
257 
258 status_t
259 BStreamingGameSound::_Reserved_BStreamingGameSound_16(int32 arg, ...)
260 {
261 	return B_ERROR;
262 }
263 
264 
265 status_t
266 BStreamingGameSound::_Reserved_BStreamingGameSound_17(int32 arg, ...)
267 {
268 	return B_ERROR;
269 }
270 
271 
272 status_t
273 BStreamingGameSound::_Reserved_BStreamingGameSound_18(int32 arg, ...)
274 {
275 	return B_ERROR;
276 }
277 
278 
279 status_t
280 BStreamingGameSound::_Reserved_BStreamingGameSound_19(int32 arg, ...)
281 {
282 	return B_ERROR;
283 }
284 
285 
286 status_t
287 BStreamingGameSound::_Reserved_BStreamingGameSound_20(int32 arg, ...)
288 {
289 	return B_ERROR;
290 }
291 
292 
293 status_t
294 BStreamingGameSound::_Reserved_BStreamingGameSound_21(int32 arg, ...)
295 {
296 	return B_ERROR;
297 }
298 
299 
300 status_t
301 BStreamingGameSound::_Reserved_BStreamingGameSound_22(int32 arg, ...)
302 {
303 	return B_ERROR;
304 }
305 
306 
307 status_t
308 BStreamingGameSound::_Reserved_BStreamingGameSound_23(int32 arg, ...)
309 {
310 	return B_ERROR;
311 }
312 
313 
314