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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
|
<!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> <A CLASS=uplinks HREF=><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </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>
<!-- 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> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>sound_driver_dsound.cpp</h1><a href="sound__driver__dsound_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
00027 <font class="comment">// The one and only INITGUID</font>
<a name="l00028"></a><a class="code" href="sound__driver__dsound_8cpp.html#a0">00028</a> <font class="preprocessor">#define INITGUID</font>
00029 <font class="preprocessor"></font>
00030 <font class="preprocessor">#include "<a class="code" href="stddsound_8h.html">stddsound.h</a>"</font>
00031
00032
00033 <font class="preprocessor">#include "<a class="code" href="sound__driver__dsound_8h.html">sound_driver_dsound.h</a>"</font>
00034 <font class="preprocessor">#include "<a class="code" href="listener__dsound_8h.html">listener_dsound.h</a>"</font>
00035 <font class="preprocessor">#include <math.h></font>
00036
00037
00038 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00039 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00040
00041
00042 <font class="keyword">namespace </font>NLSOUND {
00043
<a name="l00044"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#r0">00044</a> CSoundDriverDSound* CSoundDriverDSound::_Instance = NULL;
<a name="l00045"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#r1">00045</a> uint32 CSoundDriverDSound::_TimerPeriod = 100;
00046 HINSTANCE <a class="code" href="namespaceNLSOUND.html#a25">CSoundDriverDllHandle</a> = 0;
00047 HWND <a class="code" href="namespaceNLSOUND.html#a26">CSoundDriverWnd</a> = 0;
00048
00049
00050 <font class="comment">// ******************************************************************</font>
00051 <font class="comment">// The main entry of the DLL. It's used to get a hold of the hModule handle.</font>
00052
00053 BOOL WINAPI <a class="code" href="namespaceNLSOUND.html#a76">DllMain</a>(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
00054 {
00055 <a class="code" href="namespaceNLSOUND.html#a25">CSoundDriverDllHandle</a> = (HINSTANCE) hModule;
00056 <font class="keywordflow">return</font> TRUE;
00057 }
00058
00059
00060 <font class="comment">// ******************************************************************</font>
00061 <font class="comment">// The event handling procedure of the invisible window created below. </font>
00062
00063 <font class="keywordtype">long</font> FAR PASCAL <a class="code" href="namespaceNLSOUND.html#a77">CSoundDriverCreateWindowProc</a>(HWND hWnd, <font class="keywordtype">unsigned</font> message, WPARAM wParam, LPARAM lParam)
00064 {
00065 <font class="keywordflow">return</font> DefWindowProc(hWnd, message, wParam, lParam);
00066 }
00067
00068 <font class="comment">// ******************************************************************</font>
00069
00070 <a class="code" href="namespaceNLSOUND.html#a78">__declspec</a>(dllexport) ISoundDriver *NLSOUND_createISoundDriverInstance()
00071 {
00072 <font class="keyword">static</font> <font class="keywordtype">bool</font> Registered = <font class="keyword">false</font>;
00073
00074 <font class="keywordflow">if</font> (!Registered)
00075 {
00076 <font class="comment">// Don't ask me why we have to create a window to do sound!</font>
00077 <font class="comment">// echo <your comment> | mail support@microsoft.com -s "F#%@cking window"</font>
00078 WNDCLASS myClass;
00079 myClass.hCursor = LoadCursor( NULL, IDC_ARROW );
00080 myClass.hIcon = NULL;
00081 myClass.lpszMenuName = (LPSTR) NULL;
00082 myClass.lpszClassName = (LPSTR) <font class="stringliteral">"CSoundDriver"</font>;
00083 myClass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
00084 myClass.hInstance = <a class="code" href="namespaceNLSOUND.html#a25">CSoundDriverDllHandle</a>;
00085 myClass.style = CS_GLOBALCLASS;
00086 myClass.lpfnWndProc = <a class="code" href="namespaceNLSOUND.html#a77">CSoundDriverCreateWindowProc</a>;
00087 myClass.cbClsExtra = 0;
00088 myClass.cbWndExtra = 0;
00089
00090 <font class="keywordflow">if</font> (!RegisterClass(&myClass))
00091 {
00092 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Failed to initialize the sound driver (RegisterClass)"</font>);
00093 <font class="keywordflow">return</font> 0;
00094 }
00095
00096 Registered = <font class="keyword">true</font>;
00097 }
00098
00099 <a class="code" href="namespaceNLSOUND.html#a26">CSoundDriverWnd</a> = CreateWindow((LPSTR) <font class="stringliteral">"CSoundDriver"</font>, (LPSTR) <font class="stringliteral">"CSoundDriver"</font>, WS_OVERLAPPEDWINDOW,
00100 CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, (HWND) NULL, (HMENU) NULL,
00101 <a class="code" href="namespaceNLSOUND.html#a25">CSoundDriverDllHandle</a>, (LPSTR) NULL);
00102
00103 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLSOUND.html#a26">CSoundDriverWnd</a> == NULL)
00104 {
00105 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Failed to initialize the sound driver (CreateWindow)"</font>);
00106 <font class="keywordflow">return</font> 0;
00107 }
00108
00109 CSoundDriverDSound *driver = <font class="keyword">new</font> CSoundDriverDSound();
00110 driver->init(<a class="code" href="namespaceNLSOUND.html#a26">CSoundDriverWnd</a>);
00111
00112 <font class="keywordflow">return</font> driver;
00113 }
00114
00115 <font class="comment">// ******************************************************************</font>
00116
00117 <a class="code" href="namespaceNLSOUND.html#a78">__declspec</a>(dllexport) uint32 NLSOUND_interfaceVersion()
00118 {
00119 <font class="keywordflow">return</font> ISoundDriver::InterfaceVersion;
00120 }
00121
00122 <font class="comment">// ******************************************************************</font>
00123
00124 <a class="code" href="namespaceNLSOUND.html#a78">__declspec</a>(dllexport) <font class="keywordtype">void</font> NLSOUND_outputProfile(ostream &out)
00125 {
00126 CSoundDriverDSound::instance()->writeProfile(out);
00127 }
00128
00129
00130
00131
00132
00133 <font class="comment">// ******************************************************************</font>
00134
<a name="l00135"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a0">00135</a> CSoundDriverDSound::CSoundDriverDSound() : ISoundDriver()
00136 {
00137 <font class="keywordflow">if</font> ( <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#r0">_Instance</a> == NULL )
00138 {
00139 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#r0">_Instance</a> = <font class="keyword">this</font>;
00140
00141 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a> = NULL;
00142 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a> = NULL;
00143 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o4">_SourceCount</a> = 0;
00144 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o5">_TimerID</a> = NULL;
00145
00146 <font class="preprocessor">#if NLSOUND_PROFILE</font>
00147 <font class="preprocessor"></font> _TimerIntervalCount = 0;
00148 _TotalTime = 0.0;
00149 _TotalUpdateTime = 0.0;
00150 _UpdateCount = 0;
00151 _UpdateSources = 0;
00152 _UpdateExec = 0;
00153 <font class="preprocessor">#endif</font>
00154 <font class="preprocessor"></font>
00155 }
00156 <font class="keywordflow">else</font>
00157 {
00158 <a class="code" href="debug_8h.html#a3">nlerror</a>(<font class="stringliteral">"Sound driver singleton instanciated twice"</font>);
00159 }
00160 }
00161
00162 <font class="comment">// ******************************************************************</font>
00163
<a name="l00164"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a1">00164</a> CSoundDriverDSound::~CSoundDriverDSound()
00165 {
00166 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Destroying DirectSound driver"</font>);
00167
00168 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o5">_TimerID</a> != NULL)
00169 {
00170 timeKillEvent(<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o5">_TimerID</a>);
00171 timeEndPeriod(<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o6">_TimerResolution</a>);
00172 }
00173
00174
00175 <font class="comment">// Assure that the remaining sources have released all their DSBuffers </font>
00176 <font class="comment">// before closing down DirectSound</font>
00177 set<CSourceDSound*>::iterator iter;
00178
00179 <font class="keywordflow">for</font> (iter = <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.begin(); iter != <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.end(); iter++)
00180 {
00181 (*iter)->release();
00182 }
00183
00184
00185 <font class="comment">// Assure that the listener has released all resources before closing </font>
00186 <font class="comment">// down DirectSound</font>
00187 <font class="keywordflow">if</font> (CListenerDSound::instance() != 0)
00188 {
00189 CListenerDSound::instance()->release();
00190 }
00191
00192
00193 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a> != NULL)
00194 {
00195 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a>->Release();
00196 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a> = NULL;
00197 }
00198
00199 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a> != NULL)
00200 {
00201 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>->Release();
00202 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a> = NULL;
00203 }
00204
00205 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#r0">_Instance</a> = 0;
00206 }
00207
00208 <font class="comment">// ******************************************************************</font>
00209
<a name="l00210"></a><a class="code" href="classNLSOUND_1_1CDeviceDescription.html">00210</a> <font class="keyword">class </font>CDeviceDescription
00211 {
00212 <font class="keyword">public</font>:
00213
00214 <font class="keyword">static</font> <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#a0">CDeviceDescription</a>* <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#p0">_List</a>;
00215
<a name="l00216"></a><a class="code" href="classNLSOUND_1_1CDeviceDescription.html#a0">00216</a> <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#a0">CDeviceDescription</a>(LPGUID guid, <font class="keyword">const</font> <font class="keywordtype">char</font>* descr)
00217 {
00218 <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m2">_Guid</a> = guid;
00219 <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m0">_Description</a> = strdup(descr);
00220 <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m1">_Next</a> = _List;
00221 _List = <font class="keyword">this</font>;
00222 }
00223
<a name="l00224"></a><a class="code" href="classNLSOUND_1_1CDeviceDescription.html#a1">00224</a> <font class="keyword">virtual</font> <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#a1">~CDeviceDescription</a>()
00225 {
00226 <font class="keywordflow">if</font> (_Description)
00227 {
00228 free(<a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m0">_Description</a>);
00229 }
00230 <font class="keywordflow">if</font> (_Next)
00231 {
00232 <font class="keyword">delete</font> <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m1">_Next</a>;
00233 }
00234 }
00235
<a name="l00236"></a><a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m0">00236</a> <font class="keywordtype">char</font>* <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m0">_Description</a>;
<a name="l00237"></a><a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m1">00237</a> <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#a0">CDeviceDescription</a>* <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m1">_Next</a>;
<a name="l00238"></a><a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m2">00238</a> LPGUID <a class="code" href="classNLSOUND_1_1CDeviceDescription.html#m2">_Guid</a>;
00239 };
00240
<a name="l00241"></a><a class="code" href="classNLSOUND_1_1CDeviceDescription.html#p0">00241</a> CDeviceDescription* CDeviceDescription::_List = 0;
00242
00243
00244 BOOL CALLBACK <a class="code" href="namespaceNLSOUND.html#a79">CSoundDriverDSoundEnumCallback</a>(LPGUID guid, LPCSTR description, PCSTR module, LPVOID context)
00245 {
00246 <font class="keyword">new</font> CDeviceDescription(guid, description);
00247 <font class="keywordflow">return</font> TRUE;
00248 }
00249
00250 <font class="comment">// ******************************************************************</font>
00251
<a name="l00252"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a3">00252</a> <font class="keywordtype">bool</font> CSoundDriverDSound::init(HWND wnd)
00253 {
00254 <font class="keywordflow">if</font> (FAILED(DirectSoundEnumerate(<a class="code" href="namespaceNLSOUND.html#a79">CSoundDriverDSoundEnumCallback</a>, <font class="keyword">this</font>)))
00255 {
00256 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to enumerate the DirectSound devices"</font>);
00257 }
00258
00259 <font class="comment">// Create a DirectSound object and set the cooperative level.</font>
00260
00261 <font class="keywordflow">if</font> (DirectSoundCreate(NULL, &<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>, NULL) != DS_OK)
00262 {
00263 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to create the DirectSound object"</font>);
00264 }
00265
00266
00267 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>->SetCooperativeLevel(wnd, DSSCL_PRIORITY) != DS_OK)
00268 {
00269 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to set the cooperative level"</font>);
00270 }
00271
00272
00273 <font class="comment">// Analyse the capabilities of the sound driver/device</font>
00274
00275 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o2">_Caps</a>.dwSize = <font class="keyword">sizeof</font>(_Caps);
00276
00277 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>->GetCaps(&<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o2">_Caps</a>) != DS_OK)
00278 {
00279 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to query the sound device caps"</font>);
00280 }
00281
00282
00283 <font class="comment">// Create primary buffer </font>
00284
00285 DSBUFFERDESC desc;
00286
00287 ZeroMemory(&desc, <font class="keyword">sizeof</font>(DSBUFFERDESC));
00288 desc.dwSize = <font class="keyword">sizeof</font>(DSBUFFERDESC);
00289
00290
00291 <font class="comment">// First, try to allocate a 3D hardware buffer.</font>
00292 <font class="comment">// If we can't get a 3D hardware buffer, use a 2D hardware buffer.</font>
00293 <font class="comment">// As last option, use a 2D software buffer.</font>
00294
00295 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a9">countHw3DBuffers</a>() > 0)
00296 {
00297 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Primary buffer: Allocating 3D buffer in hardware"</font>);
00298 desc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_LOCHARDWARE | DSBCAPS_CTRL3D | DSBCAPS_CTRLVOLUME;
00299 }
00300 <font class="keywordflow">else</font>
00301 {
00302 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Primary buffer: Allocating 3D buffer in software"</font>);
00303 desc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_LOCSOFTWARE | DSBCAPS_CTRL3D | DSBCAPS_CTRLVOLUME;
00304 desc.guid3DAlgorithm = DS3DALG_NO_VIRTUALIZATION;
00305 }
00306
00307
00308 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>->CreateSoundBuffer(&desc, &<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a>, NULL) != DS_OK)
00309 {
00310
00311 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Primary buffer: Failed to create a buffer with 3D capabilities."</font>);
00312
00313 ZeroMemory(&desc, <font class="keyword">sizeof</font>(DSBUFFERDESC));
00314 desc.dwSize = <font class="keyword">sizeof</font>(DSBUFFERDESC);
00315
00316 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a10">countHw2DBuffers</a>() > 0)
00317 {
00318 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Primary buffer: Allocating 2D buffer in hardware"</font>);
00319 desc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_LOCHARDWARE | DSBCAPS_CTRLVOLUME;
00320 }
00321 <font class="keywordflow">else</font>
00322 {
00323 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Primary buffer: Allocating 2D buffer in software"</font>);
00324 desc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_LOCSOFTWARE | DSBCAPS_CTRLVOLUME;
00325 }
00326
00327 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>->CreateSoundBuffer(&desc, &<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a>, NULL) != DS_OK)
00328 {
00329 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to create the primary buffer"</font>);
00330 }
00331 }
00332
00333
00334 <font class="comment">// Set the format of the primary buffer</font>
00335
00336 WAVEFORMATEX <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>;
00337
00338 <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.cbSize = <font class="keyword">sizeof</font>(WAVEFORMATEX);
00339
00340 <font class="comment">// Make sure the sound card accepts the default settings.</font>
00341 <font class="comment">// For now, only the default settings are accepted. Fallback</font>
00342 <font class="comment">// strategy will be handled later.</font>
00343
00344 <font class="keywordflow">if</font> ((<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o2">_Caps</a>.dwMinSecondarySampleRate > 22050) && (22050 > <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o2">_Caps</a>.dwMaxSecondarySampleRate)) {
00345 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Unsupported sample rate range"</font>);
00346 }
00347
00348 <font class="keywordflow">if</font> ((<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o2">_Caps</a>.dwFlags & DSCAPS_PRIMARY16BIT) == 0) {
00349 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Unsupported sample size [16bits]"</font>);
00350 }
00351
00352 <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.wBitsPerSample = 16;
00353 <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.nChannels = 1;
00354 <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.nSamplesPerSec = 22050;
00355 <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.nBlockAlign = <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.nChannels * <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.wBitsPerSample / 8;
00356 <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.nAvgBytesPerSec = <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.nSamplesPerSec * <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.nBlockAlign;
00357 <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.wFormatTag = WAVE_FORMAT_PCM;
00358
00359
00360 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a>->SetFormat(&<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>) != DS_OK)
00361 {
00362 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to create set the format of the primary buffer"</font>);
00363 }
00364
00365
00366 uint32 numBuffers = <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a9">countHw3DBuffers</a>();
00367 <font class="keywordflow">if</font> (numBuffers == 0)
00368 {
00369 numBuffers = 31;
00370 }
00371
00372 <font class="comment">/*</font>
00373 <font class="comment"> _Sources = new CSourceDSound*[numBuffers];</font>
00374 <font class="comment"></font>
00375 <font class="comment"></font>
00376 <font class="comment"> for (uint i = 0; i < numBuffers; i++) </font>
00377 <font class="comment"> {</font>
00378 <font class="comment"> _Sources[i] = 0;</font>
00379 <font class="comment"> }</font>
00380 <font class="comment"></font>
00381 <font class="comment"> try</font>
00382 <font class="comment"> {</font>
00383 <font class="comment"> for (i = 0; i < numBuffers; i++) </font>
00384 <font class="comment"> {</font>
00385 <font class="comment"> _Sources[i] = new CSourceDSound(i);</font>
00386 <font class="comment"> _Sources[i]->init(_DirectSound);</font>
00387 <font class="comment"> _SourceCount++;</font>
00388 <font class="comment"> }</font>
00389 <font class="comment"> }</font>
00390 <font class="comment"> catch (ESoundDriver& e)</font>
00391 <font class="comment"> {</font>
00392 <font class="comment"> // Okay, here's the situation: I'm listening to WinAmp while debugging.</font>
00393 <font class="comment"> // The caps told me there were 31 buffers available. In reality, there were</font>
00394 <font class="comment"> // only 30 available because WinAmp was using one. Somehow DirectSound didn't</font>
00395 <font class="comment"> // notice. So when creating buffer 31, an exception was thrown. </font>
00396 <font class="comment"> // If something like this happens, don't bother and go on with the buffers we've </font>
00397 <font class="comment"> // got. If no buffers are created at all, throw the exception again.</font>
00398 <font class="comment"></font>
00399 <font class="comment"> if (_Sources == 0)</font>
00400 <font class="comment"> {</font>
00401 <font class="comment"> throw e;</font>
00402 <font class="comment"> }</font>
00403 <font class="comment"> }</font>
00404 <font class="comment"></font>
00405 <font class="comment">*/</font>
00406
00407
00408 TIMECAPS tcaps;
00409
00410 timeGetDevCaps(&tcaps, <font class="keyword">sizeof</font>(TIMECAPS));
00411 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o6">_TimerResolution</a> = (tcaps.wPeriodMin > 10)? tcaps.wPeriodMin : 10;
00412 timeBeginPeriod(<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o6">_TimerResolution</a>);
00413
00414
00415
00416 <font class="preprocessor">#if NLSOUND_PROFILE</font>
00417 <font class="preprocessor"></font> <font class="keywordflow">for</font> (uint i = 0; i < 1024; i++)
00418 {
00419 _TimerInterval[i] = 0;
00420 }
00421
00422 _TimerDate = CTime::getPerformanceTime();
00423 <font class="preprocessor">#endif</font>
00424 <font class="preprocessor"></font>
00425
00426
00427
00428 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o5">_TimerID</a> = timeSetEvent(<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#r1">_TimerPeriod</a>, 0, &CSoundDriverDSound::TimerCallback, (DWORD)<font class="keyword">this</font>, TIME_CALLBACK_FUNCTION | TIME_PERIODIC);
00429
00430 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o5">_TimerID</a> == NULL)
00431 {
00432 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to create the timer"</font>);
00433 }
00434
00435
00436
00437
00438 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00439 }
00440
00441 <font class="comment">// ******************************************************************</font>
00442
<a name="l00443"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a8">00443</a> uint CSoundDriverDSound::countMaxSources()
00444 {
00445 <font class="comment">// Try the hardware 3d buffers first</font>
00446 uint n = <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a9">countHw3DBuffers</a>();
00447 <font class="keywordflow">if</font> (n > 0)
00448 {
00449 <font class="keywordflow">return</font> n;
00450 }
00451
00452 <font class="comment">// If not, try the hardware 2d buffers first</font>
00453 n = <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a10">countHw2DBuffers</a>();
00454 <font class="keywordflow">if</font> (n > 0)
00455 {
00456 <font class="keywordflow">return</font> n;
00457 }
00458
00459 <font class="comment">// Okay, we'll use 32 software buffers</font>
00460 <font class="keywordflow">return</font> 32;
00461 }
00462
00463 <font class="comment">// ******************************************************************</font>
00464
<a name="l00465"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a13">00465</a> <font class="keywordtype">void</font> CSoundDriverDSound::writeProfile(ostream& out)
00466 {
00467 <font class="comment">// Write the available sound devices</font>
00468 CDeviceDescription* list = CDeviceDescription::_List;
00469 <font class="keywordflow">while</font> (list) {
00470 out << list->_Description << <font class="stringliteral">"\n"</font>;
00471 list = list->_Next;
00472 }
00473
00474 out << <font class="stringliteral">"\n"</font>;
00475
00476 <font class="comment">// Write the buffers sizes</font>
00477 out << <font class="stringliteral">"buffer size: "</font> << CSourceDSound::_SecondaryBufferSize << <font class="stringliteral">"\n"</font>;
00478 out << <font class="stringliteral">"copy size: "</font> << CSourceDSound::_UpdateCopySize << <font class="stringliteral">"\n"</font>;
00479 out << <font class="stringliteral">"swap size: "</font> << CSourceDSound::_SwapCopySize << <font class="stringliteral">"\n"</font>;
00480 out << <font class="stringliteral">"\n"</font>;
00481
00482 <font class="comment">// Write the number of hardware buffers </font>
00483 DSCAPS caps;
00484 caps.dwSize = <font class="keyword">sizeof</font>(caps);
00485 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>->GetCaps(&caps);
00486
00487 cout << <font class="stringliteral">"3d hw buffers: "</font> << caps.dwMaxHw3DAllBuffers << <font class="stringliteral">"\n"</font>;
00488 cout << <font class="stringliteral">"2d hw buffers: "</font> << caps.dwMaxHwMixingAllBuffers << <font class="stringliteral">"\n"</font>;
00489 out << <font class="stringliteral">"\n"</font>;
00490
00491 <font class="comment">// Write the number of hardware buffers </font>
00492 <font class="preprocessor">#if NLSOUND_PROFILE</font>
00493 <font class="preprocessor"></font> out << <font class="stringliteral">"update time total --- "</font> << getAverageUpdateTime()<< <font class="stringliteral">"\n"</font>;
00494 out << <font class="stringliteral">"update time source --- "</font> << CSourceDSound::getAverageUpdateTime() << <font class="stringliteral">"\n"</font>;
00495 out << <font class="stringliteral">"update --- t: "</font> << CSourceDSound::getAverageCumulTime();
00496 out << <font class="stringliteral">" - p: "</font> << CSourceDSound::getAveragePosTime();
00497 out << <font class="stringliteral">" - l: "</font> << CSourceDSound::getAverageLockTime();
00498 out << <font class="stringliteral">" - c: "</font> << CSourceDSound::getAverageCopyTime();
00499 out << <font class="stringliteral">" - u: "</font> << CSourceDSound::getAverageUnlockTime() << <font class="stringliteral">"\n"</font>;
00500 out << <font class="stringliteral">"update percentage: --- "</font> << getUpdatePercentage() << <font class="stringliteral">"\n"</font>;
00501 out << <font class="stringliteral">"update num sources --- "</font> << getAverageUpdateSources() << <font class="stringliteral">"\n"</font>;
00502 out << <font class="stringliteral">"update byte size --- "</font> << CSourceDSound::getAverageUpdateSize() << <font class="stringliteral">"\n"</font>;
00503 out << <font class="stringliteral">"swap time --- "</font> << CSourceDSound::getTestAverage() << <font class="stringliteral">"\n"</font>;
00504 out << <font class="stringliteral">"src --- "</font> << <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a11">countPlayingSources</a>() << <font class="stringliteral">"\n"</font>;
00505 <font class="preprocessor">#endif</font>
00506 <font class="preprocessor"></font>}
00507
00508
<a name="l00509"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#f0">00509</a> <font class="keywordtype">void</font> CALLBACK CSoundDriverDSound::TimerCallback(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
00510 {
00511 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a0">CSoundDriverDSound</a>* driver = (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a0">CSoundDriverDSound</a>*) dwUser;
00512 driver->update();
00513 }
00514
00515 <font class="comment">// ******************************************************************</font>
00516
<a name="l00517"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a12">00517</a> <font class="keywordtype">void</font> CSoundDriverDSound::update()
00518 {
00519 <font class="preprocessor">#if NLSOUND_PROFILE</font>
00520 <font class="preprocessor"></font> <a class="code" href="namespaceNLMISC.html#a184">TTicks</a> now = CTime::getPerformanceTime();
00521 <font class="preprocessor">#endif</font>
00522 <font class="preprocessor"></font>
00523 set<CSourceDSound*>::iterator iter;
00524
00525 iter = <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.begin();
00526
00527 <font class="keywordflow">if</font> ((iter != <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.end()) && (*iter)->needsUpdate())
00528 {
00529 <font class="keywordflow">while</font> (iter != <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.end())
00530 {
00531 <font class="keywordflow">if</font> ((*iter)->update2()) {
00532 <font class="preprocessor">#if NLSOUND_PROFILE</font>
00533 <font class="preprocessor"></font> _UpdateSources++;
00534 <font class="preprocessor">#endif</font>
00535 <font class="preprocessor"></font> }
00536 iter++;
00537 }
00538 }
00539
00540
00541 <font class="preprocessor">#if NLSOUND_PROFILE</font>
00542 <font class="preprocessor"></font> _TotalUpdateTime += 1000.0 * CTime::ticksToSecond(CTime::getPerformanceTime() - now);
00543 _UpdateCount++;
00544 <font class="preprocessor">#endif</font>
00545 <font class="preprocessor"></font>}
00546
00547 <font class="comment">// ******************************************************************</font>
00548
<a name="l00549"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a9">00549</a> uint CSoundDriverDSound::countHw3DBuffers()
00550 {
00551 DSCAPS caps;
00552 caps.dwSize = <font class="keyword">sizeof</font>(caps);
00553
00554 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>->GetCaps(&caps) != DS_OK)
00555 {
00556 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to query the sound device caps"</font>);
00557 }
00558
00559 <font class="keywordflow">return</font> caps.dwFreeHw3DStreamingBuffers;
00560 }
00561
00562 <font class="comment">// ******************************************************************</font>
00563
<a name="l00564"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a10">00564</a> uint CSoundDriverDSound::countHw2DBuffers()
00565 {
00566 DSCAPS caps;
00567 caps.dwSize = <font class="keyword">sizeof</font>(caps);
00568
00569 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>->GetCaps(&caps) != DS_OK)
00570 {
00571 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to query the sound device caps"</font>);
00572 }
00573
00574 <font class="keywordflow">return</font> caps.dwFreeHwMixingStreamingBuffers;
00575 }
00576
00577 <font class="comment">// ******************************************************************</font>
00578
<a name="l00579"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a2">00579</a> IListener *CSoundDriverDSound::createListener()
00580 {
00581 LPDIRECTSOUND3DLISTENER dsoundListener;
00582
00583 <font class="keywordflow">if</font> (CListenerDSound::instance() != NULL)
00584 {
00585 <font class="keywordflow">return</font> CListenerDSound::instance();
00586 }
00587
00588 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a> == 0)
00589 {
00590 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Corrupt driver"</font>);
00591 }
00592
00593 <font class="keywordflow">if</font> (FAILED(<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a>->QueryInterface(IID_IDirectSound3DListener, (LPVOID *) &dsoundListener)))
00594 {
00595 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"The 3D listener interface is not available."</font>);
00596 <font class="keywordflow">return</font> <font class="keyword">new</font> CListenerDSound(NULL);
00597 }
00598
00599 <font class="keywordflow">return</font> <font class="keyword">new</font> CListenerDSound(dsoundListener);
00600 }
00601
00602 <font class="comment">// ******************************************************************</font>
00603
<a name="l00604"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a4">00604</a> IBuffer *CSoundDriverDSound::createBuffer()
00605 {
00606 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a> == 0)
00607 {
00608 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Corrupt driver"</font>);
00609 }
00610
00611
00612 <font class="comment">// FIXME: set buffer ID</font>
00613 <font class="keywordflow">return</font> <font class="keyword">new</font> CBufferDSound();
00614 }
00615
00616 <font class="comment">// ******************************************************************</font>
00617
<a name="l00618"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#c2">00618</a> <font class="keywordtype">void</font> CSoundDriverDSound::removeBuffer(IBuffer *buffer)
00619 {
00620 }
00621
00622 <font class="comment">// ******************************************************************</font>
00623
<a name="l00624"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a5">00624</a> <font class="keywordtype">bool</font> CSoundDriverDSound::loadWavFile(IBuffer *destbuffer, <font class="keyword">const</font> <font class="keywordtype">char</font> *filename)
00625 {
00626 <font class="keywordflow">return</font> ((CBufferDSound*) destbuffer)->loadWavFile(filename);
00627 }
00628
00629 <font class="comment">// ******************************************************************</font>
00630
<a name="l00631"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a6">00631</a> ISource *CSoundDriverDSound::createSource()
00632 {
00633 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a> == 0)
00634 {
00635 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Corrupt driver"</font>);
00636 }
00637
00638
00639 CSourceDSound* <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a> = <font class="keyword">new</font> CSourceDSound(0);
00640 <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>->init(<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>);
00641 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.insert(<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>);
00642
00643 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>;
00644 }
00645
00646
00647 <font class="comment">// ******************************************************************</font>
00648
<a name="l00649"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#c3">00649</a> <font class="keywordtype">void</font> CSoundDriverDSound::removeSource(ISource *source)
00650 {
00651 <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.erase((CSourceDSound*) source);
00652 }
00653
00654 <font class="comment">// ******************************************************************</font>
00655
<a name="l00656"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a7">00656</a> <font class="keywordtype">void</font> CSoundDriverDSound::commit3DChanges()
00657 {
00658 CListenerDSound* listener = CListenerDSound::instance();
00659 listener->commit3DChanges();
00660
00661
00662 <font class="keyword">const</font> CVector &origin = listener->getPos();
00663
00664 set<CSourceDSound*>::iterator iter;
00665
00666 <font class="comment">// We handle the volume of the source according to the distance</font>
00667 <font class="comment">// ourselves. Call updateVolume() to, well..., update the volume</font>
00668 <font class="comment">// according to, euh ..., the new distance!</font>
00669 <font class="keywordflow">for</font> (iter = <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.begin(); iter != <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.end(); iter++)
00670 {
00671 <font class="keywordflow">if</font> ((*iter)->isPlaying())
00672 {
00673 (*iter)->updateVolume(origin);
00674 }
00675 }
00676 }
00677
00678
00679 <font class="comment">// ******************************************************************</font>
00680
<a name="l00681"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a11">00681</a> uint CSoundDriverDSound::countPlayingSources()
00682 {
00683 uint n = 0;
00684 set<CSourceDSound*>::iterator iter;
00685
00686 <font class="keywordflow">for</font> (iter = <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.begin(); iter != <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o3">_Sources</a>.end(); iter++)
00687 {
00688 <font class="keywordflow">if</font> ((*iter)->isPlaying())
00689 {
00690 n++;
00691 }
00692 }
00693
00694 <font class="keywordflow">return</font> n;
00695 }
00696
00697
00698 <font class="comment">// ******************************************************************</font>
00699
<a name="l00700"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a14">00700</a> <font class="keywordtype">void</font> CSoundDriverDSound::setGain( <font class="keywordtype">float</font> gain )
00701 {
00702 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a> != 0)
00703 {
00704 <font class="keywordflow">if</font> (gain < 0.00001f)
00705 {
00706 gain = 0.00001f;
00707 }
00708
00709 <font class="comment">/* convert from linear amplitude to hundredths of decibels */</font>
00710 LONG volume = (LONG)(100.0 * 20.0 * log10(gain));
00711
00712 <font class="keywordflow">if</font> (volume < DSBVOLUME_MIN)
00713 {
00714 volume = DSBVOLUME_MIN;
00715 }
00716 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (volume > DSBVOLUME_MAX)
00717 {
00718 volume = DSBVOLUME_MAX;
00719 }
00720
00721 HRESULT hr = <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a>->SetVolume(volume);
00722
00723 <font class="keywordflow">if</font> (hr != DS_OK)
00724 {
00725 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Failed to set the volume"</font>);
00726 }
00727 }
00728 }
00729
00730 <font class="comment">// ******************************************************************</font>
00731
<a name="l00732"></a><a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#a15">00732</a> <font class="keywordtype">float</font> CSoundDriverDSound::getGain()
00733 {
00734 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a> != 0)
00735 {
00736 <font class="comment">/* convert from hundredths of decibels to linear amplitude */</font>
00737 LONG volume;
00738 HRESULT hr = <a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o1">_PrimaryBuffer</a>->GetVolume(&volume);
00739
00740 <font class="keywordflow">if</font> (hr != DS_OK)
00741 {
00742 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Failed to get the volume"</font>);
00743 <font class="keywordflow">return</font> 1.0;
00744 }
00745
00746 <font class="keywordflow">return</font> (float) pow(10, (<font class="keywordtype">double</font>) volume / 20.0 / 100.0);
00747 }
00748
00749 <font class="keywordflow">return</font> 1.0;
00750 }
00751
00752
00753
00754 <font class="preprocessor">#if NLSOUND_PROFILE</font>
00755 <font class="preprocessor"></font>
00756 <font class="comment">// ******************************************************************</font>
00757
00758 uint CSoundDriverDSound::countTimerIntervals()
00759 {
00760 <font class="keywordflow">return</font> 1024;
00761 }
00762
00763 <font class="comment">// ******************************************************************</font>
00764
00765 uint CSoundDriverDSound::getTimerIntervals(uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>)
00766 {
00767 <font class="keywordflow">return</font> _TimerInterval[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>];
00768 }
00769
00770 <font class="comment">// ******************************************************************</font>
00771
00772 <font class="keywordtype">void</font> CSoundDriverDSound::addTimerInterval(uint32 dt)
00773 {
00774 <font class="keywordflow">if</font> (_TimerIntervalCount >= 1024)
00775 {
00776 _TimerIntervalCount = 0;
00777 }
00778
00779 _TimerInterval[_TimerIntervalCount++] = dt;
00780 }
00781
00782 <font class="comment">// ******************************************************************</font>
00783
00784 <font class="keywordtype">double</font> CSoundDriverDSound::getCPULoad()
00785 {
00786 <font class="keywordflow">return</font> (_TotalTime > 0.0)? 100.0 * _TotalUpdateTime / _TotalTime : 0.0;
00787 }
00788
00789 <font class="comment">// ******************************************************************</font>
00790
00791 <font class="keywordtype">void</font> CSoundDriverDSound::printDriverInfo(FILE* fp)
00792 {
00793 CDeviceDescription* list = CDeviceDescription::_List;
00794
00795 <font class="keywordflow">while</font> (list) {
00796 fprintf(fp, <font class="stringliteral">"%s\n"</font>, list->_Description);
00797 list = list->_Next;
00798 }
00799
00800 fprintf(fp, <font class="stringliteral">"\n"</font>);
00801
00802 fprintf(fp, <font class="stringliteral">"buffer size: %d\n"</font>
00803 <font class="stringliteral">"copy size: %d\n"</font>
00804 <font class="stringliteral">"swap size: %d\n"</font>,
00805 CSourceDSound::_SecondaryBufferSize,
00806 CSourceDSound::_UpdateCopySize,
00807 CSourceDSound::_SwapCopySize);
00808
00809 fprintf(fp, <font class="stringliteral">"\n"</font>);
00810
00811 DSCAPS caps;
00812 caps.dwSize = <font class="keyword">sizeof</font>(caps);
00813
00814 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSoundDriverDSound.html#o0">_DirectSound</a>->GetCaps(&caps) != DS_OK)
00815 {
00816 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to query the sound device caps"</font>);
00817 }
00818
00819
00820 fprintf(fp, <font class="stringliteral">"3d hw buffers: %d\n"</font> <font class="stringliteral">"2d hw buffers: %d\n\n"</font>, caps.dwMaxHw3DAllBuffers, caps.dwMaxHwMixingAllBuffers);
00821 }
00822
00823 <font class="preprocessor">#endif</font>
00824 <font class="preprocessor"></font>
00825
00826 } <font class="comment">// NLSOUND</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|