aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/sound__driver__al_8cpp-source.html
blob: 30cbf218e264bbf8b103ffb5a863cf2dc7032051 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
	<TITLE>nevrax.org : docs</TITLE>
	<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">

<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0>
 <TR>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
 </TR>
</TABLE> 

<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 WIDTH=100%>
 <TR><TD  BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>

<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 height=100%>
 <TR>
	<TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

		<!------ Begin Box ------>
		<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0  cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
		<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td  colspan=2 bgcolor=#FFFFFF>
		<TABLE cellspacing=0 cellpadding=1 border=0>
			<tr><td ALIGN=middle><a  class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

	</TD>
	<TD WIDTH=15><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
	<TD ALIGN=left valign=top><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

<!-- title -->
<TABLE  background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG  SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
&nbsp;

<!-- block -->
<TABLE  bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
	<TD><B>Documentation</B></TD>
	<TD ALIGN=RIGHT>&nbsp;</td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>sound_driver_al.cpp</h1><a href="sound__driver__al_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025 
00026 <font class="preprocessor">#include "<a class="code" href="stdopenal_8h.html">stdopenal.h</a>"</font>
00027 
00028 <font class="preprocessor">#include "<a class="code" href="buffer__al_8h.html">buffer_al.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="listener__al_8h.html">listener_al.h</a>"</font>
00030 
00031 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00032 
00033 
00034 <font class="keyword">namespace </font>NLSOUND {
00035 
00036 
00037 <font class="preprocessor">#ifdef EAX_AVAILABLE</font>
00038 <font class="preprocessor"></font><font class="comment">// EAXSet global function</font>
00039 EAXSet                                  EAXSetProp = NULL;
00040 
00041 <font class="comment">// EAXGet global function</font>
00042 EAXGet                                  EAXGetProp = NULL;
00043 <font class="preprocessor">#endif</font>
00044 <font class="preprocessor"></font>
00045 
00046 <font class="comment">// Currently, the OpenAL headers are different between Windows and Linux versions !</font>
00047 <font class="comment">// AL_INVALID_XXXX are part of the spec, though.</font>
00048 <font class="preprocessor">#ifdef NL_OS_UNIX</font>
00049 <font class="preprocessor"></font><font class="preprocessor">#define AL_INVALID_ENUM AL_ILLEGAL_ENUM  </font>
00050 <font class="preprocessor"></font><font class="preprocessor">#define AL_INVALID_OPERATION AL_ILLEGAL_COMMAND </font>
00051 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00052 <font class="preprocessor"></font>
00053 
00054 <font class="preprocessor">#ifdef NL_DEBUG</font>
00055 <font class="preprocessor"></font><font class="comment">// Test error in debug mode</font>
00056 <font class="keywordtype">void</font> <a class="code" href="sound__driver__al_8h.html#a0">TestALError</a>()
00057 {
00058         ALuint errcode = alGetError();
00059         <font class="keywordflow">switch</font>( errcode )
00060         {
00061         <font class="keywordflow">case</font> AL_NO_ERROR : <font class="keywordflow">break</font>;
00062         <font class="keywordflow">case</font> AL_INVALID_NAME : <a class="code" href="debug_8h.html#a3">nlerror</a>( <font class="stringliteral">"OpenAL: Invalid name"</font> );
00063         <font class="keywordflow">case</font> AL_INVALID_ENUM  : <a class="code" href="debug_8h.html#a3">nlerror</a>( <font class="stringliteral">"OpenAL: Invalid enum"</font> );
00064         <font class="keywordflow">case</font> AL_INVALID_VALUE  : <a class="code" href="debug_8h.html#a3">nlerror</a>( <font class="stringliteral">"OpenAL: Invalid value"</font> );
00065         <font class="keywordflow">case</font> AL_INVALID_OPERATION  : <a class="code" href="debug_8h.html#a3">nlerror</a>( <font class="stringliteral">"OpenAL: Invalid operation"</font> );
00066         <font class="keywordflow">case</font> AL_OUT_OF_MEMORY  : <a class="code" href="debug_8h.html#a3">nlerror</a>( <font class="stringliteral">"OpenAL: Out of memory"</font> );
00067         <font class="comment">// alGetString( errcode ) seems to fail !</font>
00068         }
00069 }
00070 <font class="preprocessor">#endif</font>
00071 <font class="preprocessor"></font>
00072 
<a name="l00073"></a><a class="code" href="sound__driver__al_8cpp.html#a0">00073</a> <font class="preprocessor">#define INITIAL_BUFFERS 8</font>
<a name="l00074"></a><a class="code" href="sound__driver__al_8cpp.html#a1">00074</a> <font class="preprocessor"></font><font class="preprocessor">#define INITIAL_SOURCES 8</font>
<a name="l00075"></a><a class="code" href="sound__driver__al_8cpp.html#a2">00075</a> <font class="preprocessor"></font><font class="preprocessor">#define BUFFER_ALLOC_RATE 8</font>
<a name="l00076"></a><a class="code" href="sound__driver__al_8cpp.html#a3">00076</a> <font class="preprocessor"></font><font class="preprocessor">#define SOURCE_ALLOC_RATE 8</font>
00077 <font class="preprocessor"></font>
<a name="l00078"></a><a class="code" href="sound__driver__al_8cpp.html#a4">00078</a> <font class="preprocessor">#define ROLLOFF_FACTOR_DEFAULT 1.0f</font>
00079 <font class="preprocessor"></font>
00080 <font class="comment">/*</font>
00081 <font class="comment"> * Sound driver instance creation</font>
00082 <font class="comment"> */</font>
00083 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00084 <font class="preprocessor"></font>        
00085 __declspec(dllexport) ISoundDriver *NLSOUND_createISoundDriverInstance()
00086 {
00087         CSoundDriverAL *driver = <font class="keyword">new</font> CSoundDriverAL();
00088         driver-&gt;init();
00089         <font class="keywordflow">return</font> driver;
00090 }
00091 
00092 __declspec(dllexport) <a class="code" href="types__nl_8h.html#a9">uint32</a> NLSOUND_interfaceVersion ()
00093 {
00094         <font class="keywordflow">return</font> ISoundDriver::InterfaceVersion;
00095 }
00096 
00097 <font class="preprocessor">#elif defined (NL_OS_UNIX)</font>
00098 <font class="preprocessor"></font>
00099 <font class="keyword">extern</font> <font class="stringliteral">"C"</font>
00100 {
00101 ISoundDriver* NLSOUND_createISoundDriverInstance ()
00102 {
00103         CSoundDriverAL *driver = <font class="keyword">new</font> CSoundDriverAL();
00104         driver-&gt;init();
00105         <font class="keywordflow">return</font> driver;
00106 }
00107 
00108 <a class="code" href="types__nl_8h.html#a9">uint32</a> NLSOUND_interfaceVersion ()
00109 {
00110         <font class="keywordflow">return</font> ISoundDriver::InterfaceVersion;
00111 }
00112 }
00113 
00114 <font class="preprocessor">#endif // NL_OS_UNIX</font>
00115 <font class="preprocessor"></font>
00116 
00117 <font class="comment">// The instance of the singleton</font>
<a name="l00118"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#r0">00118</a> CSoundDriverAL  *CSoundDriverAL::_Instance = NULL;
00119 
00120 
00121 <font class="comment">/*</font>
00122 <font class="comment"> * Constructor</font>
00123 <font class="comment"> */</font>
<a name="l00124"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#a0">00124</a> CSoundDriverAL::CSoundDriverAL() :
00125         ISoundDriver(), _NbExpBuffers( 0 ), _NbExpSources( 0 ), _RolloffFactor( 1.0f )
00126 {
00127         <font class="keywordflow">if</font> ( <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#r0">_Instance</a> == NULL )
00128         {
00129                 <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#r0">_Instance</a> = <font class="keyword">this</font>;
00130         }
00131         <font class="keywordflow">else</font>
00132         {
00133                 <a class="code" href="debug_8h.html#a3">nlerror</a>( <font class="stringliteral">"Sound driver singleton instanciated twice"</font> );
00134         }
00135 }
00136 
00137 
00138 <font class="comment">/*</font>
00139 <font class="comment"> * Destructor</font>
00140 <font class="comment"> */</font>
<a name="l00141"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#a7">00141</a> CSoundDriverAL::~CSoundDriverAL()
00142 {
00143         <font class="comment">// Remove the allocated (but not exported) source and buffer names</font>
00144         alDeleteSources( <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b6">compactAliveNames</a>( <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o1">_Sources</a>, alIsSource ), &amp;*<a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o1">_Sources</a>.begin() );
00145         alDeleteBuffers( <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b6">compactAliveNames</a>( <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o0">_Buffers</a>, alIsBuffer ), &amp;*<a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o0">_Buffers</a>.begin() );
00146 
00147         <font class="comment">// OpenAL exit</font>
00148         alutExit();
00149 
00150         <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#r0">_Instance</a> = NULL;
00151 }
00152 
00153 
00154 <font class="comment">/*</font>
00155 <font class="comment"> * Initialization</font>
00156 <font class="comment"> */</font>
<a name="l00157"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#a1">00157</a> <font class="keywordtype">bool</font>            CSoundDriverAL::init()
00158 {
00159         <font class="comment">// OpenAL initialization</font>
00160         alutInit( NULL, NULL );
00161 
00162         <font class="comment">// Display version information</font>
00163         <font class="keyword">const</font> ALubyte *alversion, *alrenderer, *alvendor, *alext;
00164         alversion = alGetString( AL_VERSION );
00165         alrenderer = alGetString( AL_RENDERER );
00166         alvendor = alGetString( AL_VENDOR );
00167         alext = alGetString( AL_EXTENSIONS );
00168         <a class="code" href="sound__driver__al_8h.html#a0">TestALError</a>();
00169         <a class="code" href="debug_8h.html#a1">nlinfo</a>( <font class="stringliteral">"Loading OpenAL lib: %s, %s, %s"</font>, alversion, alrenderer, alvendor );
00170         <a class="code" href="debug_8h.html#a1">nlinfo</a>( <font class="stringliteral">"Listing extensions: %s"</font>, alext );
00171 
00172 <font class="preprocessor">#ifdef EAX_AVAILABLE</font>
00173 <font class="preprocessor"></font>    <font class="comment">// Set EAX environment if EAX is available</font>
00174         <font class="keywordflow">if</font> ( alIsExtensionPresent((ALubyte *)<font class="stringliteral">"EAX"</font>) == AL_TRUE ) <font class="comment">// or EAX2.0</font>
00175         {
00176                 <a class="code" href="debug_8h.html#a1">nlinfo</a>( <font class="stringliteral">"Initializing EAX"</font> );
00177             EAXSetProp = (EAXSet)alGetProcAddress((ALubyte*)<font class="stringliteral">"EAXSet"</font>);
00178                 EAXGetProp = (EAXGet)alGetProcAddress((ALubyte*)<font class="stringliteral">"EAXGet"</font>);
00179                 <font class="keywordflow">if</font> ( EAXSetProp != NULL )
00180                 {
00181                         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulEAXVal;
00182                         <font class="keywordtype">long</font> lGlobalReverb;
00183                     lGlobalReverb = 0;
00184                         EAXSetProp( &amp;DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ROOM, 0, &amp;lGlobalReverb, <font class="keyword">sizeof</font>(<font class="keywordtype">unsigned</font> <font class="keywordtype">long</font>) );
00185                         ulEAXVal = EAX_ENVIRONMENT_GENERIC;
00186                         EAXSetProp( &amp;DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ENVIRONMENT, 0, &amp;ulEAXVal, <font class="keyword">sizeof</font>(<font class="keywordtype">unsigned</font> <font class="keywordtype">long</font>) );
00187                 }
00188         }
00189         <font class="keywordflow">else</font>
00190 <font class="preprocessor">#endif</font>
00191 <font class="preprocessor"></font>        {
00192                 <a class="code" href="debug_8h.html#a1">nlinfo</a>( <font class="stringliteral">"EAX not available"</font> );
00193         }
00194 
00195         <font class="comment">// Choose the I3DL2 model (same as DirectSound3D)</font>
00196         alDistanceModel( AL_INVERSE_DISTANCE_CLAMPED );
00197         <a class="code" href="sound__driver__al_8h.html#a0">TestALError</a>();
00198 
00199         <font class="comment">// Initial buffers and sources allocation</font>
00200         <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b4">allocateNewItems</a>( alGenBuffers, alIsBuffer, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o0">_Buffers</a>, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o2">_NbExpBuffers</a>, <a class="code" href="sound__driver__al_8cpp.html#a0">INITIAL_BUFFERS</a> );
00201         <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b4">allocateNewItems</a>( alGenSources, alIsSource, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o1">_Sources</a>, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o3">_NbExpSources</a>, <a class="code" href="sound__driver__al_8cpp.html#a1">INITIAL_SOURCES</a> );
00202 
00203         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00204 }
00205 
00206 
00207 <font class="comment">/*</font>
00208 <font class="comment"> * Allocate nb new items</font>
00209 <font class="comment"> */</font>
<a name="l00210"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b4">00210</a> <font class="keywordtype">void</font>            CSoundDriverAL::allocateNewItems( <a class="code" href="namespaceNLSOUND.html#a12">TGenFunctionAL</a> algenfunc, <a class="code" href="namespaceNLSOUND.html#a13">TTestFunctionAL</a> altestfunc,
00211                                                                                           vector&lt;ALuint&gt;&amp; names, <a class="code" href="types__nl_8h.html#a13">uint</a> <a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a>, <a class="code" href="types__nl_8h.html#a13">uint</a> nb )
00212 {
00213         <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a> == names.size() );
00214         names.resize( <a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a> + nb );
00215         <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b5">generateItems</a>( algenfunc, altestfunc, nb, &amp;(names[<a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a>]) );
00216 }
00217 
00218 
00219 <font class="comment">/*</font>
00220 <font class="comment"> * throwGenException</font>
00221 <font class="comment"> */</font>
00222 <font class="keywordtype">void</font> <a class="code" href="namespaceNLSOUND.html#a48">ThrowGenException</a>( <a class="code" href="namespaceNLSOUND.html#a12">TGenFunctionAL</a> algenfunc )
00223 {
00224         <font class="keywordflow">if</font> ( algenfunc == alGenBuffers )
00225                 <font class="keywordflow">throw</font> ESoundDriverGenBuf();
00226         <font class="keywordflow">else</font> <font class="keywordflow">if</font> ( algenfunc == alGenSources )
00227                 <font class="keywordflow">throw</font> ESoundDriverGenSrc();
00228         <font class="keywordflow">else</font>
00229                 <a class="code" href="debug_8h.html#a12">nlstop</a>;
00230 }
00231 
00232 <font class="comment">/*</font>
00233 <font class="comment"> * Generate nb buffers/sources</font>
00234 <font class="comment"> */</font>
<a name="l00235"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b5">00235</a> <font class="keywordtype">void</font>            CSoundDriverAL::generateItems( <a class="code" href="namespaceNLSOUND.html#a12">TGenFunctionAL</a> algenfunc, <a class="code" href="namespaceNLSOUND.html#a13">TTestFunctionAL</a> altestfunc, <a class="code" href="types__nl_8h.html#a13">uint</a> nb, ALuint *array )
00236 {
00237         algenfunc( nb, array );
00238 
00239         <font class="comment">// Error handling</font>
00240         <font class="keywordflow">if</font> ( alGetError() != AL_NO_ERROR )
00241         {
00242                 <a class="code" href="namespaceNLSOUND.html#a48">ThrowGenException</a>( algenfunc );
00243         }
00244 
00245         <font class="comment">// Check buffers</font>
00246         <a class="code" href="types__nl_8h.html#a13">uint</a> i;
00247         <font class="keywordflow">for</font> ( i=0; i!=nb; i++ )
00248         {
00249                 <font class="keywordflow">if</font> ( ! altestfunc( array[i] ) )
00250                 {
00251                         <a class="code" href="namespaceNLSOUND.html#a48">ThrowGenException</a>( algenfunc );
00252                 }
00253         }
00254 }
00255 
00256 
00257 <font class="comment">/*</font>
00258 <font class="comment"> * Create a sound buffer</font>
00259 <font class="comment"> */</font>
<a name="l00260"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#a2">00260</a> IBuffer                 *CSoundDriverAL::createBuffer()
00261 {
00262         <font class="keywordflow">return</font> <font class="keyword">new</font> CBufferAL( <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b7">createItem</a>( alGenBuffers, alIsBuffer, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o0">_Buffers</a>, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o2">_NbExpBuffers</a>, <a class="code" href="sound__driver__al_8cpp.html#a2">BUFFER_ALLOC_RATE</a> ) );
00263 }
00264 
00265 
00266 <font class="comment">/*</font>
00267 <font class="comment"> * Create a source</font>
00268 <font class="comment"> */</font>
<a name="l00269"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#a4">00269</a> ISource                 *CSoundDriverAL::createSource()
00270 {
00271         CSourceAL *sourceal = <font class="keyword">new</font> CSourceAL( <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b7">createItem</a>( alGenSources, alIsSource, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o1">_Sources</a>, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o3">_NbExpSources</a>, <a class="code" href="sound__driver__al_8cpp.html#a3">SOURCE_ALLOC_RATE</a> ) );
00272         <font class="keywordflow">if</font> ( <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o4">_RolloffFactor</a> != <a class="code" href="sound__driver__al_8cpp.html#a4">ROLLOFF_FACTOR_DEFAULT</a> )
00273         {
00274                 alSourcef( sourceal-&gt;sourceName(), AL_ROLLOFF_FACTOR, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o4">_RolloffFactor</a> );
00275         }
00276         <font class="keywordflow">return</font> sourceal;
00277 }
00278 
00279 
00280 <font class="comment">/*</font>
00281 <font class="comment"> * Create a sound buffer or a sound source</font>
00282 <font class="comment"> */</font>
<a name="l00283"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b7">00283</a> ALuint                  CSoundDriverAL::createItem( <a class="code" href="namespaceNLSOUND.html#a12">TGenFunctionAL</a> algenfunc, <a class="code" href="namespaceNLSOUND.html#a13">TTestFunctionAL</a> altestfunc,
00284                                                                                         vector&lt;ALuint&gt;&amp; names, <a class="code" href="types__nl_8h.html#a13">uint</a>&amp; <a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a>, <a class="code" href="types__nl_8h.html#a13">uint</a> allocrate )
00285 {
00286         <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a> &lt;= names.size() );
00287         <font class="keywordflow">if</font> ( <a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a> == names.size() )
00288         {
00289                 <font class="comment">// Generate new items</font>
00290                 <a class="code" href="types__nl_8h.html#a13">uint</a> nbalive = <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b6">compactAliveNames</a>( names, altestfunc );
00291                 <font class="keywordflow">if</font> ( nbalive == names.size() )
00292                 {
00293                         <font class="comment">// Extend vector of names</font>
00294                         <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b4">allocateNewItems</a>( algenfunc, altestfunc, names, <a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a>, allocrate );
00295                 }
00296                 <font class="keywordflow">else</font>
00297                 {
00298                         <font class="comment">// Take the room of the deleted names</font>
00299                         <a class="code" href="debug_8h.html#a6">nlassert</a>( nbalive &lt; names.size() );
00300                         <a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a> = nbalive;
00301                         <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b5">generateItems</a>( algenfunc, altestfunc, names.size() - nbalive, &amp;(names[nbalive]) );
00302                 }
00303         }
00304 
00305         <font class="comment">// Return the name of the item</font>
00306         <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a> &lt; names.size() );
00307         ALuint itemname = names[<a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a>];
00308         <a class="code" href="driver__opengl__extension__def_8h.html#a225">index</a>++;
00309         <font class="keywordflow">return</font> itemname;
00310 }
00311 
00312 
00313 <font class="comment">/*</font>
00314 <font class="comment"> * Remove names of deleted buffers and return the number of valid buffers</font>
00315 <font class="comment"> */</font>
<a name="l00316"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b6">00316</a> <a class="code" href="types__nl_8h.html#a13">uint</a>                    CSoundDriverAL::compactAliveNames( vector&lt;ALuint&gt;&amp; names, <a class="code" href="namespaceNLSOUND.html#a13">TTestFunctionAL</a> altestfunc )
00317 {
00318         vector&lt;ALuint&gt;::iterator iball, ibcompacted;
00319         <font class="keywordflow">for</font> ( iball=names.begin(), ibcompacted=names.begin(); iball!=names.end(); ++iball )
00320         {
00321                 <font class="comment">// iball is incremented every iteration</font>
00322                 <font class="comment">// ibcompacted is not incremented if a buffer is not valid anymore</font>
00323                 <font class="keywordflow">if</font> ( altestfunc( *iball ) )
00324                 {
00325                         *ibcompacted = *iball;
00326                         ++ibcompacted;
00327                 }
00328         }
00329         <a class="code" href="debug_8h.html#a6">nlassert</a>( ibcompacted &lt;= names.end() );
00330         <font class="keywordflow">return</font> ibcompacted - names.begin();
00331 }
00332 
00333 
00334 <font class="comment">/*</font>
00335 <font class="comment"> * Remove a buffer</font>
00336 <font class="comment"> */</font>
<a name="l00337"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b2">00337</a> <font class="keywordtype">void</font>                    CSoundDriverAL::removeBuffer( IBuffer *buffer )
00338 {
00339         <a class="code" href="debug_8h.html#a6">nlassert</a>( buffer != NULL );
00340         CBufferAL *bufferAL = dynamic_cast&lt;CBufferAL*&gt;(buffer);
00341         <font class="keywordflow">if</font> ( ! <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b8">deleteItem</a>( bufferAL-&gt;bufferName(), alDeleteBuffers, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o0">_Buffers</a> ) )
00342         {
00343                 <a class="code" href="debug_8h.html#a2">nlwarning</a>( <font class="stringliteral">"Deleting buffer: name not found"</font> );
00344         }
00345 }
00346 
00347 
00348 <font class="comment">/*</font>
00349 <font class="comment"> * Remove a source</font>
00350 <font class="comment"> */</font>
<a name="l00351"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b3">00351</a> <font class="keywordtype">void</font>                    CSoundDriverAL::removeSource( ISource *source )
00352 {
00353         <a class="code" href="debug_8h.html#a6">nlassert</a>( source != NULL );
00354         CSourceAL *sourceAL = dynamic_cast&lt;CSourceAL*&gt;(source);
00355         <font class="keywordflow">if</font> ( ! <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b8">deleteItem</a>( sourceAL-&gt;sourceName(), alDeleteSources, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o1">_Sources</a> ) )
00356         {
00357                 <a class="code" href="debug_8h.html#a2">nlwarning</a>( <font class="stringliteral">"Deleting source: name not found"</font> );
00358         }
00359 }
00360 
00361 
00362 <font class="comment">/*</font>
00363 <font class="comment"> * Delete a buffer or a source</font>
00364 <font class="comment"> */</font>
<a name="l00365"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#b8">00365</a> <font class="keywordtype">bool</font>                    CSoundDriverAL::deleteItem( ALuint name, <a class="code" href="namespaceNLSOUND.html#a12">TGenFunctionAL</a> aldeletefunc, vector&lt;ALuint&gt;&amp; names )
00366 {
00367         vector&lt;ALuint&gt;::iterator ibn = find( names.begin(), names.end(), name );
00368         <font class="keywordflow">if</font> ( ibn == names.end() )
00369         {
00370                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00371         }
00372         aldeletefunc( 1, &amp;*ibn );
00373         *ibn = AL_NONE;
00374         <a class="code" href="sound__driver__al_8h.html#a0">TestALError</a>();
00375         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00376 }
00377 
00378 
00379 <font class="comment">/*</font>
00380 <font class="comment"> * Create the listener instance</font>
00381 <font class="comment"> */</font>
<a name="l00382"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#a3">00382</a> IListener               *CSoundDriverAL::createListener()
00383 {
00384         <a class="code" href="debug_8h.html#a6">nlassert</a>( CListenerAL::instance() == NULL );
00385         <font class="keywordflow">return</font> <font class="keyword">new</font> CListenerAL();
00386 }
00387 
00388 
00389 <font class="comment">/*</font>
00390 <font class="comment"> * Apply changes of rolloff factor to all sources</font>
00391 <font class="comment"> */</font>
<a name="l00392"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#a5">00392</a> <font class="keywordtype">void</font>                    CSoundDriverAL::applyRolloffFactor( <font class="keywordtype">float</font> f )
00393 {
00394         <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o4">_RolloffFactor</a> = f;
00395         vector&lt;ALuint&gt;::iterator ibn;
00396         <font class="keywordflow">for</font> ( ibn=<a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o1">_Sources</a>.begin(); ibn!=<a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o1">_Sources</a>.end(); ++ibn )
00397         {
00398                 alSourcef( *ibn, AL_ROLLOFF_FACTOR, <a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#o4">_RolloffFactor</a> );
00399         }
00400         <a class="code" href="sound__driver__al_8h.html#a0">TestALError</a>();
00401 }
00402 
00403 
00404 <font class="comment">/*</font>
00405 <font class="comment"> * Helper for loadWavFile()</font>
00406 <font class="comment"> */</font>
00407 <a class="code" href="namespaceNLSOUND.html#a51">TSampleFormat</a> <a class="code" href="namespaceNLSOUND.html#a49">ALtoNLSoundFormat</a>( ALenum alformat )
00408 {
00409         <font class="keywordflow">switch</font> ( alformat )
00410         {
00411         <font class="keywordflow">case</font> AL_FORMAT_MONO8 : <font class="keywordflow">return</font> <a class="code" href="namespaceNLSOUND.html#a51a8">Mono8</a>;
00412         <font class="keywordflow">case</font> AL_FORMAT_MONO16 : <font class="keywordflow">return</font> <a class="code" href="namespaceNLSOUND.html#a51a9">Mono16</a>;
00413         <font class="keywordflow">case</font> AL_FORMAT_STEREO8 : <font class="keywordflow">return</font> <a class="code" href="namespaceNLSOUND.html#a51a10">Stereo8</a>;
00414         <font class="keywordflow">case</font> AL_FORMAT_STEREO16 : <font class="keywordflow">return</font> <a class="code" href="namespaceNLSOUND.html#a51a11">Stereo16</a>;
00415         <font class="keywordflow">default</font> : <a class="code" href="debug_8h.html#a12">nlstop</a>; <font class="keywordflow">return</font> <a class="code" href="namespaceNLSOUND.html#a51a8">Mono8</a>;
00416         }
00417 }
00418 
00419 
00420 <font class="comment">/*</font>
00421 <font class="comment"> * Temp</font>
00422 <font class="comment"> */</font>
<a name="l00423"></a><a class="code" href="classNLSOUND_1_1CSoundDriverAL.html#a6">00423</a> <font class="keywordtype">bool</font>                    CSoundDriverAL::loadWavFile( IBuffer *destbuffer, <font class="keyword">const</font> <font class="keywordtype">char</font> *filename )
00424 {
00425 <font class="comment">// Currently, the OpenAL UT headers are different between Windows and Linux versions</font>
00426 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00427 <font class="preprocessor"></font>        ALsizei <a class="code" href="lexlang_8cpp.html#a56">size</a>,freq;
00428         ALenum <a class="code" href="driver__opengl__extension__def_8h.html#a259">format</a>;
00429         ALvoid *<a class="code" href="driver__opengl__extension__def_8h.html#a255">data</a>;
00430         ALboolean loop;
00431         alutLoadWAVFile( const_cast&lt;char*&gt;(filename), &amp;<a class="code" href="driver__opengl__extension__def_8h.html#a259">format</a>, &amp;<a class="code" href="driver__opengl__extension__def_8h.html#a255">data</a>, &amp;<a class="code" href="lexlang_8cpp.html#a56">size</a>, &amp;freq, &amp;loop ); <font class="comment">// last arg in some al.h</font>
00432 <font class="preprocessor">#else</font>
00433 <font class="preprocessor"></font>        ALsizei bits;
00434         ALsizei <a class="code" href="lexlang_8cpp.html#a56">size</a>,freq;
00435         ALsizei <a class="code" href="driver__opengl__extension__def_8h.html#a259">format</a>;
00436         ALvoid *<a class="code" href="driver__opengl__extension__def_8h.html#a255">data</a>;
00437         alutLoadWAV( const_cast&lt;char*&gt;(filename), &amp;<a class="code" href="driver__opengl__extension__def_8h.html#a255">data</a>, &amp;<a class="code" href="driver__opengl__extension__def_8h.html#a259">format</a>, &amp;<a class="code" href="lexlang_8cpp.html#a56">size</a>, &amp;bits, &amp;freq ); 
00438 <font class="preprocessor">#endif</font>
00439 <font class="preprocessor"></font>        <font class="keywordflow">if</font> ( <a class="code" href="driver__opengl__extension__def_8h.html#a255">data</a> == NULL )
00440         {
00441                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00442         }
00443         destbuffer-&gt;setFormat( <a class="code" href="namespaceNLSOUND.html#a49">ALtoNLSoundFormat</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a259">format</a>), freq );
00444         destbuffer-&gt;fillBuffer( <a class="code" href="driver__opengl__extension__def_8h.html#a255">data</a>, <a class="code" href="lexlang_8cpp.html#a56">size</a> );
00445 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00446 <font class="preprocessor"></font>        alutUnloadWAV(<a class="code" href="driver__opengl__extension__def_8h.html#a259">format</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a255">data</a>,<a class="code" href="lexlang_8cpp.html#a56">size</a>,freq); <font class="comment">// Where is it on Linux ?!?</font>
00447 <font class="preprocessor">#endif</font>
00448 <font class="preprocessor"></font>        <font class="keywordflow">return</font> <font class="keyword">true</font>;
00449 }
00450 
00451 
00452 } <font class="comment">// NLSOUND</font>
</pre></div>

<!-- footer -->
<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </FONT>
</TD>
<TD WIDTH=15><IMG  SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>