aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/source__dsound_8cpp-source.html
blob: d11b29055b936dda7135b29eaca53914f682bb59 (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
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
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
<!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>source_dsound.cpp</h1><a href="source__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="preprocessor">#include "<a class="code" href="stddsound_8h.html">stddsound.h</a>"</font>
00028 <font class="preprocessor">#include "<a class="code" href="source__dsound_8h.html">source_dsound.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="sound__driver__dsound_8h.html">sound_driver_dsound.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="buffer__dsound_8h.html">buffer_dsound.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="listener__dsound_8h.html">listener_dsound.h</a>"</font>
00032 
00033 
00034 
00035 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00036 
00037 
00038 <font class="keyword">namespace </font>NLSOUND {
00039 
00040 
00041 <font class="preprocessor">#if NLSOUND_PROFILE</font>
00042 <font class="preprocessor"></font>
00043 <font class="preprocessor">        #define INITTIME(_var)   TTicks _var = CTime::getPerformanceTime()</font>
00044 <font class="preprocessor"></font>
00045 <font class="preprocessor">        #define DEBUG_POSITIONS  1</font>
00046 <font class="preprocessor"></font>
00047 <font class="preprocessor">        #if DEBUG_POSITIONS</font>
00048 <font class="preprocessor"></font><font class="preprocessor">        #define DBGPOS(_a) nldebug ## _a</font>
00049 <font class="preprocessor"></font><font class="preprocessor">        #else</font>
00050 <font class="preprocessor"></font><font class="preprocessor">        #define DBGPOS(_a) </font>
00051 <font class="preprocessor"></font><font class="preprocessor">        #endif</font>
00052 <font class="preprocessor"></font>
00053 <font class="preprocessor">#else</font>
<a name="l00054"></a><a class="code" href="source__dsound_8cpp.html#a0">00054</a> <font class="preprocessor"></font><font class="preprocessor">        #define INITTIME(_var)</font>
<a name="l00055"></a><a class="code" href="source__dsound_8cpp.html#a1">00055</a> <font class="preprocessor"></font><font class="preprocessor">        #define DBGPOS(_a) </font>
00056 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00057 <font class="preprocessor"></font>
00058 
00059 
<a name="l00060"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">00060</a> uint32 CSourceDSound::_SecondaryBufferSize = 65536;
<a name="l00061"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#r1">00061</a> uint32 CSourceDSound::_SwapCopySize = 32768;
<a name="l00062"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#r0">00062</a> uint32 CSourceDSound::_UpdateCopySize = 16384;
<a name="l00063"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#r5">00063</a> uint32 CSourceDSound::_XFadeSize = 64;
<a name="l00064"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#r2">00064</a> uint CSourceDSound::_DefaultChannels = 1;
<a name="l00065"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#r3">00065</a> uint CSourceDSound::_DefaultSampleRate = 22050;
<a name="l00066"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#r4">00066</a> uint CSourceDSound::_DefaultSampleSize = 16;
00067 
00068 
00069 
<a name="l00070"></a><a class="code" href="source__dsound_8cpp.html#a2">00070</a> <font class="preprocessor">#define NLSOUND_MIN(_a,_b)        (((_a) &lt; (_b)) ? (_a) : (_b))</font>
<a name="l00071"></a><a class="code" href="source__dsound_8cpp.html#a3">00071</a> <font class="preprocessor"></font><font class="preprocessor">#define NLSOUND_DISTANCE(_from, _to, _period)   (((_to) &gt; (_from)) ? (_to) - (_from) : (_period) + (_to) - (_from))</font>
00072 <font class="preprocessor"></font>
00073 
00074 <font class="preprocessor">#if NLSOUND_PROFILE</font>
00075 <font class="preprocessor"></font>
00076 <font class="comment">// Static variables used for profiling</font>
00077 <font class="keywordtype">double</font> CSourceDSound::_LastSwapTime = 0.0;
00078 <font class="keywordtype">double</font> CSourceDSound::_TotalSwapTime = 0.0;
00079 <font class="keywordtype">double</font> CSourceDSound::_MaxSwapTime = 0.0;
00080 <font class="keywordtype">double</font> CSourceDSound::_MinSwapTime = 1000000.0;
00081 uint32 CSourceDSound::_SwapCount = 0;
00082 <font class="keywordtype">double</font> CSourceDSound::_PosTime = 0.0;
00083 <font class="keywordtype">double</font> CSourceDSound::_LockTime = 0.0;
00084 <font class="keywordtype">double</font> CSourceDSound::_CopyTime = 0.0;
00085 <font class="keywordtype">double</font> CSourceDSound::_UnlockTime = 0.0;
00086 uint32 CSourceDSound::_CopyCount = 0;
00087 <font class="keywordtype">double</font> CSourceDSound::_TotalUpdateTime = 0.0;
00088 <font class="keywordtype">double</font> CSourceDSound::_MaxUpdateTime = 0.0;
00089 <font class="keywordtype">double</font> CSourceDSound::_MinUpdateTime = 1000000.0;
00090 uint32 CSourceDSound::_UpdateCount = 0;
00091 uint32 CSourceDSound::_TotalUpdateSize = 0;
00092 <font class="preprocessor">#endif</font>
00093 <font class="preprocessor"></font>
00094 
00095 
00096 <font class="comment">// ******************************************************************</font>
00097 
<a name="l00098"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#a0">00098</a> CSourceDSound::CSourceDSound( uint sourcename ) : ISource(), _SourceName(sourcename)
00099 {
00100         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> = 0;
00101         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a> = 0;
00102         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> = 0;
00103         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a29">NL_DSOUND_SILENCED</a>;
00104         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> = 0;
00105         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> = 0;
00106         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = 0;
00107         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> = 0;
00108         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o3">_Loop</a> = <font class="keyword">false</font>;
00109         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a> = 0;
00110         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a> = <a class="code" href="namespaceNLSOUND.html#a86a33">NL_DSOUND_TAIL1</a>;
00111         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> = <a class="code" href="namespaceNLSOUND.html#a85a32">NL_DSOUND_STOPPED</a>;
00112         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o14">_Freq</a> = 1.0f;
00113         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o15">_SampleRate</a> = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r3">_DefaultSampleRate</a>;
00114         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o16">_IsUsed</a> = <font class="keyword">false</font>;
00115         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o18">_Gain</a> = 1.0f;
00116         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o17">_Volume</a> = 0;
00117         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o19">_Alpha</a> = 0.0;
00118         InitializeCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>);
00119 }
00120 
00121 
00122 <font class="comment">// ******************************************************************</font>
00123 
<a name="l00124"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#a1">00124</a> CSourceDSound::~CSourceDSound()
00125 {
00126         <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Destroying DirectSound source"</font>);
00127 
00128         CSoundDriverDSound::instance()-&gt;removeSource(<font class="keyword">this</font>);
00129 
00130         EnterCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00131 
00132         <font class="comment">// Release the DirectSound buffer within the critical zone</font>
00133         <font class="comment">// to avoid a call to update during deconstruction</font>
00134         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c0">release</a>();
00135 
00136         LeaveCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00137         DeleteCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>);
00138 }
00139 
00140 
00141 <font class="comment">// ******************************************************************</font>
00142 
<a name="l00143"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c0">00143</a> <font class="keywordtype">void</font> CSourceDSound::release()
00144 {
00145         <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> = 0;
00146 
00147         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> != 0)
00148         {
00149                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Stop();
00150         }
00151 
00152         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != 0)
00153         {
00154                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;Release();
00155                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> = 0;
00156         }
00157 
00158         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> != 0)
00159         {
00160                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Release();
00161                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> = 0;
00162         }
00163 
00164 }
00165 
00166 <font class="comment">// ******************************************************************</font>
00167 
<a name="l00168"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#a2">00168</a> <font class="keywordtype">void</font> CSourceDSound::init(LPDIRECTSOUND directSound)
00169 {
00170 
00171         <font class="comment">// Initialize the buffer format</font>
00172         WAVEFORMATEX <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>;
00173 
00174         <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.cbSize = <font class="keyword">sizeof</font>(WAVEFORMATEX);
00175         <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.nChannels = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r2">_DefaultChannels</a>;
00176         <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.wBitsPerSample = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r4">_DefaultSampleSize</a>;
00177         <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.nSamplesPerSec = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r3">_DefaultSampleRate</a>;
00178         <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;
00179         <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;
00180         <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>.wFormatTag = WAVE_FORMAT_PCM;
00181 
00182 
00183         <font class="comment">// Initialize the buffer description </font>
00184 
00185         DSBUFFERDESC desc;
00186 
00187         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#l0">CSoundDriverDSound</a>* driver = CSoundDriverDSound::instance();
00188 
00189 
00190         ZeroMemory(&amp;desc, <font class="keyword">sizeof</font>(DSBUFFERDESC));
00191         desc.dwSize = <font class="keyword">sizeof</font>(DSBUFFERDESC);
00192         desc.lpwfxFormat = &amp;<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>;
00193         desc.dwBufferBytes = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;      
00194         desc.dwReserved = 0; 
00195 
00196         <font class="keywordflow">if</font> (driver-&gt;countHw3DBuffers() &gt; 0)
00197         {
00198                 <font class="comment">//nldebug("Source: Allocating 3D buffer in hardware");</font>
00199                 desc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCHARDWARE | DSBCAPS_GETCURRENTPOSITION2 
00200                                                 | DSBCAPS_CTRL3D | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_MUTE3DATMAXDISTANCE;
00201         } 
00202         <font class="keywordflow">else</font>
00203         {
00204                 <font class="comment">//nldebug("Source: Allocating 3D buffer in software");</font>
00205                 desc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCSOFTWARE | DSBCAPS_GETCURRENTPOSITION2 
00206                                                 | DSBCAPS_CTRL3D | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_MUTE3DATMAXDISTANCE;
00207                 desc.guid3DAlgorithm = DS3DALG_NO_VIRTUALIZATION;
00208                 <font class="comment">//desc.guid3DAlgorithm = DS3DALG_HRTF_FULL;</font>
00209         }
00210 
00211 
00212         <font class="comment">// Allocate the secondary buffer</font>
00213  
00214         <font class="keywordflow">if</font> (FAILED(directSound-&gt;CreateSoundBuffer(&amp;desc, &amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>, NULL))) 
00215         {
00216                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Source: Failed to create a buffer with 3D capabilities."</font>);
00217 
00218                 ZeroMemory(&amp;desc, <font class="keyword">sizeof</font>(DSBUFFERDESC));
00219                 desc.dwSize = <font class="keyword">sizeof</font>(DSBUFFERDESC);
00220                 desc.lpwfxFormat = &amp;<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>;
00221                 desc.dwBufferBytes = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;      
00222                 desc.dwReserved = 0; 
00223 
00224                 <font class="keywordflow">if</font> (driver-&gt;countHw2DBuffers() &gt; 0)
00225                 {
00226                         <font class="comment">//nldebug("Source: Allocating 2D buffer in hardware");</font>
00227                         desc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCHARDWARE | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
00228                 } 
00229                 <font class="keywordflow">else</font>
00230                 {
00231                         <font class="comment">//nldebug("Source: Allocating 2D buffer in software");</font>
00232                         desc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCSOFTWARE | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
00233                 }
00234 
00235                 <font class="keywordflow">if</font> (FAILED(directSound-&gt;CreateSoundBuffer(&amp;desc, &amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>, NULL))) 
00236                 {
00237                         <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to allocate the DirectSound secondary buffer"</font>);
00238                 }
00239         }
00240 
00241 
00242         <font class="comment">// Fill the buffer with silence</font>
00243 
00244         LPVOID ptr;
00245         DWORD bytes;
00246 
00247         <font class="keywordflow">if</font> (FAILED(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Lock(0, 0, &amp;ptr, &amp;bytes, NULL, NULL, DSBLOCK_ENTIREBUFFER)))
00248         {
00249                 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to lock the DirectSound secondary buffer"</font>);
00250         }
00251 
00252         memset(ptr, 0, bytes);
00253         
00254         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Unlock(ptr, bytes, 0, 0);
00255 
00256         <font class="comment">// Allocate the 3D interface, if necessary</font>
00257 
00258         <font class="keywordflow">if</font> (FAILED(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;QueryInterface(IID_IDirectSound3DBuffer, (LPVOID *) &amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>)))
00259         {
00260            <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to allocate the DirectSound 3D buffer"</font>);
00261         }
00262 
00263 
00264         <font class="keywordflow">if</font> (FAILED(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Play(0, 0, DSBPLAY_LOOPING)))
00265         {
00266                 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Play failed"</font>);
00267         }
00268 
00269 }
00270 
00271 <font class="comment">// ******************************************************************</font>
00272 
<a name="l00273"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#a5">00273</a> <font class="keywordtype">void</font> CSourceDSound::reset()
00274 {
00275         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_8">setPitch</a>(1.0f);
00276         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_0">setLooping</a>(<font class="keyword">false</font>);
00277         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_6">setGain</a>(1.0f);
00278 }
00279 
00280 
00281 <font class="comment">// ******************************************************************</font>
00282 
<a name="l00283"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z968_0">00283</a> <font class="keywordtype">void</font> CSourceDSound::setStaticBuffer( IBuffer *buffer )
00284 {
00285         EnterCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00286 
00287         <font class="comment">// If the user calls setStaticBuffer with a null buffer,</font>
00288         <font class="comment">// stop the currently playing buffer and set it to null.</font>
00289         <font class="comment">// Otherwise, store the buffer in the swap buffer variable.</font>
00290         <font class="comment">// A crossfade between the current buffer and the swap buffer</font>
00291         <font class="comment">// will be done when the user calls play.</font>
00292         <font class="keywordflow">if</font> (buffer == 0)
00293         {
00294                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_3">stop</a>();
00295                 <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> = 0;
00296                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> = 0;
00297                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = 0;
00298         }
00299 
00300         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a> = <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> = buffer;
00301 
00302         LeaveCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00303 }
00304 
00305 
00306 
00307 <font class="comment">// ******************************************************************</font>
00308 
<a name="l00309"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_0">00309</a> <font class="keywordtype">void</font> CSourceDSound::setLooping( <font class="keywordtype">bool</font> <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a> )
00310 {
00311         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o3">_Loop</a> = <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>;
00312 }
00313 
00314 
00315 <font class="comment">// ******************************************************************</font>
00316 
<a name="l00317"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_1">00317</a> <font class="keywordtype">bool</font> CSourceDSound::getLooping()<font class="keyword"> const</font>
00318 <font class="keyword"></font>{
00319         <font class="keywordflow">return</font> <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o3">_Loop</a>;
00320 }
00321 
00322 
00323 <font class="comment">// ******************************************************************</font>
00324 
<a name="l00325"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c3">00325</a> <font class="keywordtype">void</font> CSourceDSound::swap()
00326 {
00327         <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a>;
00328         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> = <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a>-&gt;getSize();
00329         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = 0;
00330         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a> = 0;
00331 }
00332 
00333 <font class="comment">// ******************************************************************</font>
00334 
<a name="l00335"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_2">00335</a> <font class="keywordtype">bool</font> CSourceDSound::play()
00336 {
00337         EnterCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00338 
00339         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> == 0 || ((CBufferDSound*) <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a>)-&gt;getData() == 0)
00340         {
00341                 <font class="comment">// the sample has been unloaded, can't play!</font>
00342 
00343                 LeaveCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00344                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00345         }
00346 
00347 
00348         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] PLAY: Enter, buffer state = %u"</font>, <font class="keyword">this</font>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a>));
00349         <font class="keywordflow">switch</font> (_SecondaryBufferState)
00350         {
00351         <font class="keywordflow">case</font> <a class="code" href="namespaceNLSOUND.html#a84a27">NL_DSOUND_FILLING</a>:
00352                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a> != 0)
00353                 {
00354                         <font class="comment">// crossfade to the new sound </font>
00355                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] PLAY: XFading 1"</font>, <font class="keyword">this</font>));
00356                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c7">crossFade</a>();
00357                 }
00358                 <font class="keywordflow">break</font>;
00359 
00360         <font class="keywordflow">case</font> <a class="code" href="namespaceNLSOUND.html#a84a28">NL_DSOUND_SILENCING</a>:
00361                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a> != 0)
00362                 {
00363                         <font class="keywordflow">if</font> ((<a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> != 0) &amp;&amp; (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> == <a class="code" href="namespaceNLSOUND.html#a85a30">NL_DSOUND_PLAYING</a>))
00364                         {
00365                                 <font class="comment">// crossfade to the new sound</font>
00366                                 <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] PLAY: XFading 2"</font>, <font class="keyword">this</font>));
00367                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c7">crossFade</a>();
00368                         }
00369                         <font class="keywordflow">else</font>
00370                         {
00371                                 <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] PLAY: Swap &amp; fadein 1"</font>, <font class="keyword">this</font>));
00372                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c3">swap</a>();
00373                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c9">fadeIn</a>();
00374                         }
00375                 }
00376                 <font class="keywordflow">else</font>
00377                 {
00378                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] PLAY: Fadein"</font>, <font class="keyword">this</font>));
00379                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = 0;
00380                         <font class="comment">// start the old sound again</font>
00381                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c9">fadeIn</a>();
00382                 }
00383 
00384                 <font class="keywordflow">break</font>;
00385 
00386 
00387         <font class="keywordflow">case</font> <a class="code" href="namespaceNLSOUND.html#a84a29">NL_DSOUND_SILENCED</a>:
00388                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a> != 0)
00389                 {
00390                         <font class="comment">// fade in to the new sound</font>
00391                                 <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] PLAY: Swap &amp; fadein 2"</font>, <font class="keyword">this</font>));
00392                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c3">swap</a>();
00393                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c9">fadeIn</a>();
00394                 }
00395                 <font class="keywordflow">else</font>
00396                 {
00397                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] PLAY: Fadein"</font>, <font class="keyword">this</font>));
00398                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = 0;
00399                         <font class="comment">// start the old sound again</font>
00400                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c9">fadeIn</a>();
00401                 }
00402         }
00403 
00404         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> = <a class="code" href="namespaceNLSOUND.html#a85a30">NL_DSOUND_PLAYING</a>;
00405         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] PLAY: PLAYING"</font>, <font class="keyword">this</font>));
00406 
00407         <font class="comment">//nldebug ("NLSOUND: %p play", this);</font>
00408 
00409         LeaveCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00410 
00411         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00412 }
00413 
00414 
00415 <font class="comment">// ******************************************************************</font>
00416 
<a name="l00417"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_3">00417</a> <font class="keywordtype">void</font> CSourceDSound::stop()
00418 {
00419         EnterCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00420 
00421         <a class="code" href="namespaceNLSOUND.html#a85">TSourceDSoundUserState</a> old = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a>;
00422 
00423         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> = <a class="code" href="namespaceNLSOUND.html#a85a32">NL_DSOUND_STOPPED</a>;
00424         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] STOP: STOPPED"</font>, <font class="keyword">this</font>));
00425 
00426         <font class="comment">//nldebug ("NLSOUND: %p stop", this);</font>
00427 
00428         <font class="keywordflow">if</font> (old == <a class="code" href="namespaceNLSOUND.html#a85a30">NL_DSOUND_PLAYING</a>)
00429         {
00430                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c8">fadeOut</a>();
00431         }
00432 
00433         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = 0;
00434 
00435         LeaveCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00436 }
00437 
00438 <font class="comment">// ******************************************************************</font>
00439 
<a name="l00440"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_4">00440</a> <font class="keywordtype">void</font> CSourceDSound::pause()
00441 {
00442         EnterCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00443 
00444         <a class="code" href="namespaceNLSOUND.html#a85">TSourceDSoundUserState</a> old = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a>;
00445 
00446         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> = <a class="code" href="namespaceNLSOUND.html#a85a31">NL_DSOUND_PAUSED</a>;
00447         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] PAUZ: PAUSED"</font>, <font class="keyword">this</font>));
00448 
00449         <font class="comment">//nldebug ("NLOUND: pause %p", this);</font>
00450 
00451         <font class="keywordflow">if</font> (old == <a class="code" href="namespaceNLSOUND.html#a85a30">NL_DSOUND_PLAYING</a>)
00452         {
00453                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c8">fadeOut</a>();
00454         }
00455 
00456         LeaveCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00457 }
00458 
00459 <font class="comment">// ******************************************************************</font>
00460 
<a name="l00461"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_5">00461</a> <font class="keywordtype">bool</font> CSourceDSound::isPlaying()<font class="keyword"> const</font>
00462 <font class="keyword"></font>{
00463         <font class="keywordflow">return</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> == <a class="code" href="namespaceNLSOUND.html#a85a30">NL_DSOUND_PLAYING</a>);
00464 }
00465 
00466 
00467 <font class="comment">// ******************************************************************</font>
00468 
<a name="l00469"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_7">00469</a> <font class="keywordtype">bool</font> CSourceDSound::isPaused()<font class="keyword"> const</font>
00470 <font class="keyword"></font>{
00471         <font class="keywordflow">return</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> == <a class="code" href="namespaceNLSOUND.html#a85a31">NL_DSOUND_PAUSED</a>);
00472 }
00473 
00474 
00475 <font class="comment">// ******************************************************************</font>
00476 
<a name="l00477"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_6">00477</a> <font class="keywordtype">bool</font> CSourceDSound::isStopped()<font class="keyword"> const</font>
00478 <font class="keyword"></font>{
00479         <font class="keywordflow">return</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> == <a class="code" href="namespaceNLSOUND.html#a85a32">NL_DSOUND_STOPPED</a>);
00480 }
00481 
00482 
00483 <font class="comment">// ******************************************************************</font>
00484 
<a name="l00485"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c10">00485</a> <font class="keywordtype">bool</font> CSourceDSound::needsUpdate()
00486 {
00487         DWORD playPos, writePos;
00488         uint32 space;
00489         
00490         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> == 0)
00491         {
00492                 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00493         }
00494 
00495         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;GetCurrentPosition(&amp;playPos, &amp;writePos);
00496 
00497                 
00498         <font class="keywordflow">if</font> (playPos == <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>)
00499         {
00500                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00501         }
00502         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (playPos &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>) 
00503         {
00504                 space = playPos - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>;
00505         }
00506         <font class="keywordflow">else</font>
00507         {
00508                 space = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a> + playPos - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>;
00509         }
00510         
00511         <font class="comment">// Don't bother if the number of samples is smaller than the copy size.</font>
00512         <font class="keywordflow">return</font> (space &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r0">_UpdateCopySize</a>);
00513 }
00514 
00515 
00516 
00517 <font class="comment">// ******************************************************************</font>
00518 
<a name="l00519"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_8">00519</a> <font class="keywordtype">void</font> CSourceDSound::update()
00520 {
00521         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_9">update2</a>();
00522 }
00523 
00524 <font class="comment">// ******************************************************************</font>
00525 
<a name="l00526"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z969_9">00526</a> <font class="keywordtype">bool</font> CSourceDSound::update2()
00527 {
00528         <font class="keywordtype">bool</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = <font class="keyword">false</font>;
00529 
00530 
00531 
00532         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(start);
00533 
00534         <font class="comment">//</font>
00535         <font class="comment">// Enter critical region</font>
00536         <font class="comment">//</font>
00537         EnterCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>);
00538 
00539 
00540         <font class="keywordflow">switch</font> (_SecondaryBufferState)
00541         {
00542 
00543 
00544         <font class="keywordflow">case</font> <a class="code" href="namespaceNLSOUND.html#a84a29">NL_DSOUND_SILENCED</a>:
00545                 {
00546                         <font class="comment">// Just pretend were writing silence by advancing the next </font>
00547                         <font class="comment">// write position.</font>
00548                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> += <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r0">_UpdateCopySize</a>;
00549                         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>)
00550                         {
00551                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>  -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;
00552                         }
00553                 }
00554                 <font class="keywordflow">break</font>;
00555 
00556 
00557         <font class="keywordflow">case</font> <a class="code" href="namespaceNLSOUND.html#a84a27">NL_DSOUND_FILLING</a>:
00558                 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c5">fill</a>();   
00559                 <font class="keywordflow">break</font>;
00560 
00561 
00562         <font class="keywordflow">case</font> <a class="code" href="namespaceNLSOUND.html#a84a28">NL_DSOUND_SILENCING</a>:
00563                 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c6">silence</a>();        
00564                 <font class="keywordflow">break</font>;
00565 
00566         }
00567 
00568 
00569         <font class="comment">//</font>
00570         <font class="comment">// Leave critical region</font>
00571         <font class="comment">//</font>
00572         LeaveCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
00573 
00574 
00575 <font class="preprocessor">#if NLSOUND_PROFILE</font>
00576 <font class="preprocessor"></font>        <font class="keywordtype">double</font> dt = CTime::ticksToSecond(CTime::getPerformanceTime() - start);;
00577         _TotalUpdateTime += dt;
00578         _MaxUpdateTime = (dt &gt; _MaxUpdateTime) ? dt : _MaxUpdateTime;
00579         _MinUpdateTime = (dt &lt; _MinUpdateTime) ? dt : _MinUpdateTime;
00580         _UpdateCount++;
00581 <font class="preprocessor">#endif</font>
00582 <font class="preprocessor"></font>
00583         <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
00584 }
00585 
00586 
00587 
00588 <font class="comment">// ******************************************************************</font>
00589 
<a name="l00590"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_0">00590</a> <font class="keywordtype">void</font> CSourceDSound::setPos( <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>&amp; pos, <font class="keywordtype">bool</font> deferred )
00591 {
00592         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o20">_Pos</a> = pos;
00593         <font class="comment">// Coordinate system: conversion from NeL to OpenAL/GL:</font>
00594         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != NULL)
00595         {
00596                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;SetPosition(pos.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, pos.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a>, pos.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>, deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE) != DS_OK)
00597                 {
00598                         <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"SetPosition failed"</font>);
00599                 }
00600                 <font class="keywordflow">else</font>
00601                 {
00602                         <font class="comment">//nlwarning ("%p set source NEL(p:%.2f/%.2f/%.2f) DS(p:%.2f/%.2f/%.2f)", this, pos.x, pos.y, pos.z, pos.x, pos.z, pos.y);</font>
00603                 }
00604         }
00605 }
00606 
00607 
00608 <font class="comment">// ******************************************************************</font>
00609 
<a name="l00610"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_1">00610</a> <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> &amp;CSourceDSound::getPos()<font class="keyword"> const</font>
00611 <font class="keyword"></font>{
00612         <font class="keywordflow">return</font> <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o20">_Pos</a>;
00613         <font class="comment">// Coordinate system: conversion from NeL to OpenAL/GL:</font>
00614 <font class="comment">/*      if (_3DBuffer != NULL)</font>
00615 <font class="comment">        {</font>
00616 <font class="comment">                D3DVECTOR v;</font>
00617 <font class="comment">                HRESULT hr = _3DBuffer-&gt;GetPosition(&amp;v);</font>
00618 <font class="comment"></font>
00619 <font class="comment">                if (hr != DS_OK)</font>
00620 <font class="comment">                {</font>
00621 <font class="comment">                        nlwarning ("GetPosition failed");</font>
00622 <font class="comment">                        pos.set(0, 0, 0);       </font>
00623 <font class="comment">                }</font>
00624 <font class="comment">                else</font>
00625 <font class="comment">                {</font>
00626 <font class="comment">                        pos.set(v.x, v.z, v.y);</font>
00627 <font class="comment">                }</font>
00628 <font class="comment">        }</font>
00629 <font class="comment">        else</font>
00630 <font class="comment">        {</font>
00631 <font class="comment">                pos.set(0, 0, 0);       </font>
00632 <font class="comment">        }</font>
00633 <font class="comment">*/</font>
00634 }
00635 
00636 
00637 <font class="comment">// ******************************************************************</font>
00638 
<a name="l00639"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_2">00639</a> <font class="keywordtype">void</font> CSourceDSound::setVelocity( <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>&amp; vel, <font class="keywordtype">bool</font> deferred )
00640 {
00641         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != NULL)
00642         {
00643                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;SetVelocity(vel.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, vel.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a>, vel.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>, deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE) != DS_OK)
00644                 {
00645                         <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"SetVelocity failed"</font>);
00646                 }
00647         }
00648 }
00649 
00650 
00651 <font class="comment">// ******************************************************************</font>
00652 
<a name="l00653"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_3">00653</a> <font class="keywordtype">void</font> CSourceDSound::getVelocity( <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>&amp; vel )<font class="keyword"> const</font>
00654 <font class="keyword"></font>{
00655         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != NULL)
00656         {
00657                 D3DVECTOR <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00658 
00659                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;GetVelocity(&amp;<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>) != DS_OK)
00660                 {
00661                         <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"GetVelocity failed"</font>);
00662                         vel.<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a>(0, 0, 0);       
00663                 }
00664                 <font class="keywordflow">else</font>
00665                 {
00666                         vel.<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.x, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.z, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.y);
00667                 }
00668         }
00669         <font class="keywordflow">else</font>
00670         {
00671                 vel.<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a>(0, 0, 0);       
00672         }
00673 }
00674 
00675 
00676 <font class="comment">// ******************************************************************</font>
00677 
<a name="l00678"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_4">00678</a> <font class="keywordtype">void</font> CSourceDSound::setDirection( <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>&amp; dir )
00679 {
00680         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != 0)
00681         {
00682                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;SetConeOrientation(dir.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, dir.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a>, dir.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>, DS3D_DEFERRED) != DS_OK)
00683                 {
00684                         <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"SetConeOrientation failed (x=%.2f, y=%.2f, z=%.2f)"</font>, dir.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, dir.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>, dir.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a>);
00685                 }
00686                 <font class="keywordflow">else</font>
00687                 {
00688                         <font class="comment">//nlwarning ("NLSOUND: %p set source direction NEL(p:%.2f/%.2f/%.2f) DS(p:%.2f/%.2f/%.2f)", this, dir.x, dir.y, dir.z, dir.x, dir.z, dir.y);</font>
00689                 }
00690         }
00691 }
00692 
00693 
00694 <font class="comment">// ******************************************************************</font>
00695 
<a name="l00696"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_5">00696</a> <font class="keywordtype">void</font> CSourceDSound::getDirection( <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>&amp; dir )<font class="keyword"> const</font>
00697 <font class="keyword"></font>{
00698         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != NULL)
00699         {
00700                 D3DVECTOR <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00701 
00702                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;GetConeOrientation(&amp;<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>) != DS_OK)
00703                 {
00704                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"GetConeOrientation failed"</font>);
00705                         dir.<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a>(0, 0, 1);       
00706                 }
00707                 <font class="keywordflow">else</font>
00708                 {
00709                         dir.<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.x, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.z, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.y);
00710                 }
00711         }
00712         <font class="keywordflow">else</font>
00713         {
00714                 dir.<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a>(0, 0, 1);       
00715         }
00716 }
00717 
00718 
00719 <font class="comment">// ******************************************************************</font>
00720 
<a name="l00721"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_6">00721</a> <font class="keywordtype">void</font> CSourceDSound::setGain( <font class="keywordtype">float</font> gain )
00722 {
00723         <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(gain, 0.00001f, 1.0f);
00724         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o18">_Gain</a> = gain;
00725 
00726         <font class="comment">/* convert from linear amplitude to hundredths of decibels */</font>
00727         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o17">_Volume</a> = (uint32)(100.0 * 20.0 * log10(gain));
00728         <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o17">_Volume</a>, DSBVOLUME_MIN, DSBVOLUME_MAX);
00729 
00730         <font class="comment">//nlwarning ("set gain %f vol %d", gain, _Volume);</font>
00731 
00732         <font class="comment">/*</font>
00733 <font class="comment">        if ((_SecondaryBuffer != 0) &amp;&amp; (_SecondaryBuffer-&gt;SetVolume(_Volume) != DS_OK))</font>
00734 <font class="comment">        {</font>
00735 <font class="comment">                nlwarning("SetVolume failed");</font>
00736 <font class="comment">        }</font>
00737 <font class="comment">        */</font>
00738 }
00739 
00740 
00741 <font class="comment">/*</font>
00742 <font class="comment"> * Get the gain</font>
00743 <font class="comment"> */</font>
<a name="l00744"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_7">00744</a> <font class="keywordtype">float</font> CSourceDSound::getGain()<font class="keyword"> const</font>
00745 <font class="keyword"></font>{
00746         <font class="keywordflow">return</font> <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o18">_Gain</a>;
00747 }
00748 
00749 
00750 <font class="comment">// ******************************************************************</font>
00751 
<a name="l00752"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_8">00752</a> <font class="keywordtype">void</font> CSourceDSound::setPitch( <font class="keywordtype">float</font> coeff )
00753 {
00754 <font class="comment">//      _Freq = coeff;</font>
00755 
00756         <font class="keywordflow">if</font> ((<a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> != 0) &amp;&amp; (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> != 0))
00757         {
00758                 <a class="code" href="namespaceNLSOUND.html#a83">TSampleFormat</a> <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>;
00759                 uint freq;
00760 
00761                 <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a>-&gt;getFormat(<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, freq);
00762 
00763                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o15">_SampleRate</a> = (uint32) (coeff * (float) freq);
00764 
00765                 <font class="comment">//nlwarning("Freq=%d", newfreq);</font>
00766 
00767                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;SetFrequency(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o15">_SampleRate</a>) != DS_OK)
00768                 {
00769 <font class="comment">//                      nlwarning("SetFrequency failed (buffer freq=%d, NeL freq=%.5f, DSound freq=%d)", freq, coeff, newfreq);</font>
00770                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"SetFrequency"</font>);
00771                 }
00772         }
00773 }
00774 
00775 
00776 <font class="comment">// ******************************************************************</font>
00777 
<a name="l00778"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_9">00778</a> <font class="keywordtype">float</font> CSourceDSound::getPitch()<font class="keyword"> const</font>
00779 <font class="keyword"></font>{
00780         <font class="keywordflow">if</font> ((<a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> != 0) &amp;&amp; (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> != 0))
00781         {
00782                 <a class="code" href="namespaceNLSOUND.html#a83">TSampleFormat</a> <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>;
00783                 uint freq0;
00784                 DWORD freq;
00785 
00786                 <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a>-&gt;getFormat(<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, freq0);
00787 
00788                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;GetFrequency(&amp;freq) != DS_OK)
00789                 {
00790                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"GetFrequency failed"</font>);
00791                         <font class="keywordflow">return</font> 1.0;
00792                 }
00793 
00794                 <font class="keywordflow">return</font> ((float) freq / (float) freq0);
00795         }
00796 
00797         <font class="keywordflow">return</font> 1.0;
00798 }
00799 
00800 
00801 <font class="comment">// ******************************************************************</font>
00802 
<a name="l00803"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_10">00803</a> <font class="keywordtype">void</font> CSourceDSound::setSourceRelativeMode( <font class="keywordtype">bool</font> mode )
00804 {
00805         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != 0)
00806         {
00807                 HRESULT hr;
00808 
00809                 <font class="keywordflow">if</font> (mode)
00810                 {
00811                         hr = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;SetMode(DS3DMODE_HEADRELATIVE, DS3D_IMMEDIATE);
00812                 }
00813                 <font class="keywordflow">else</font>
00814                 {
00815                         hr = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;SetMode(DS3DMODE_NORMAL, DS3D_IMMEDIATE);
00816                 }
00817 
00818                 <font class="keywordflow">if</font> (hr != DS_OK)
00819                 {
00820                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"SetMode failed"</font>);
00821                 }
00822         }
00823         <font class="keywordflow">else</font>
00824         {
00825                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Requested setSourceRelativeMode on a non-3D source"</font>);
00826         }
00827 }
00828 
00829 
00830 <font class="comment">// ******************************************************************</font>
00831 
<a name="l00832"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_11">00832</a> <font class="keywordtype">bool</font> CSourceDSound::getSourceRelativeMode()<font class="keyword"> const</font>
00833 <font class="keyword"></font>{
00834         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != 0)
00835         {
00836                 DWORD mode;
00837 
00838                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;GetMode(&amp;mode) != DS_OK)
00839                 {
00840                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"GetMode failed"</font>);
00841                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00842                 }
00843 
00844                 <font class="keywordflow">return</font> (mode == DS3DMODE_HEADRELATIVE);
00845         }
00846         <font class="keywordflow">else</font>
00847         {
00848                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Requested setSourceRelativeMode on a non-3D source"</font>);
00849                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00850         }
00851 }
00852 
00853 
00854 <font class="comment">// ******************************************************************</font>
00855 
<a name="l00856"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_12">00856</a> <font class="keywordtype">void</font> CSourceDSound::setMinMaxDistances( <font class="keywordtype">float</font> mindist, <font class="keywordtype">float</font> maxdist, <font class="keywordtype">bool</font> deferred )
00857 {
00858         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != 0)
00859         {
00860                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;SetMinDistance(mindist, deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE) != DS_OK)
00861                 {
00862                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"SetMinDistance (%f) failed"</font>, mindist);
00863                 }
00864                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;SetMaxDistance(maxdist, deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE) != DS_OK)
00865                 {
00866                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"SetMaxDistance (%f) failed"</font>, maxdist);
00867                 }
00868         }
00869         <font class="keywordflow">else</font>
00870         {
00871                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Requested setMinMaxDistances on a non-3D source"</font>);
00872         }
00873 }
00874 
00875 
00876 <font class="comment">// ******************************************************************</font>
00877 
<a name="l00878"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_13">00878</a> <font class="keywordtype">void</font> CSourceDSound::getMinMaxDistances( <font class="keywordtype">float</font>&amp; mindist, <font class="keywordtype">float</font>&amp; maxdist )<font class="keyword"> const</font>
00879 <font class="keyword"></font>{
00880         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != 0)
00881         {
00882                 D3DVALUE <a class="code" href="bit__set_8cpp.html#a0">min</a>, max;
00883 
00884                 <font class="keywordflow">if</font> ((<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;GetMinDistance(&amp;<a class="code" href="bit__set_8cpp.html#a0">min</a>) != DS_OK)
00885                         || (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;GetMaxDistance(&amp;max) != DS_OK))
00886                 {
00887                         mindist = 0.0f;
00888                         maxdist = 0.0f;
00889                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"GetMinDistance or GetMaxDistance failed"</font>);
00890                 }
00891                 <font class="keywordflow">else</font>
00892                 {
00893                         mindist = <a class="code" href="bit__set_8cpp.html#a0">min</a>;
00894                         maxdist = max;
00895                 }
00896         }
00897         <font class="keywordflow">else</font>
00898         {
00899                 mindist = 0.0f;
00900                 maxdist = 0.0f;
00901                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Requested getMinMaxDistances on a non-3D source"</font>);
00902         }
00903 }
00904 
00905 <font class="comment">// ******************************************************************</font>
00906 
<a name="l00907"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#a6">00907</a> <font class="keywordtype">void</font> CSourceDSound::updateVolume( <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>&amp; listener )
00908 {
00909         CVector pos = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_1">getPos</a>();
00910         pos -= listener;
00911 
00912         <font class="keywordtype">float</font> sqrdist = pos.<a class="code" href="classNLMISC_1_1CVector.html#z331_3">sqrnorm</a>();
00913         <font class="keywordtype">float</font> <a class="code" href="bit__set_8cpp.html#a0">min</a>, max;
00914 
00915         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_13">getMinMaxDistances</a>(<a class="code" href="bit__set_8cpp.html#a0">min</a>, max);
00916 
00917         <font class="keywordflow">if</font> (sqrdist &lt; <a class="code" href="bit__set_8cpp.html#a0">min</a> * <a class="code" href="bit__set_8cpp.html#a0">min</a>) 
00918         {
00919                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;SetVolume(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o17">_Volume</a>);
00920                 <font class="comment">//nlwarning("VOLUME = %ddB, rolloff = %0.2f", _Volume/100, CListenerDSound::instance()-&gt;getRolloffFactor());</font>
00921         }
00922         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (sqrdist &gt; max * max)
00923         {
00924                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;SetVolume(DSBVOLUME_MIN);
00925                 <font class="comment">//nlwarning("VOLUME = %ddB, rolloff = %0.2f", DSBVOLUME_MIN/100, CListenerDSound::instance()-&gt;getRolloffFactor());</font>
00926         }
00927         <font class="keywordflow">else</font>
00928         {
00929                 sint32 db = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o17">_Volume</a>;
00930 
00931                 <font class="keywordtype">double</font> dist = (double) sqrt(sqrdist);
00932 
00933                 <font class="comment">// linearly descending volume on a dB scale</font>
00934                 <font class="keywordtype">double</font> db1 = DSBVOLUME_MIN * (dist - <a class="code" href="bit__set_8cpp.html#a0">min</a>) / (max - <a class="code" href="bit__set_8cpp.html#a0">min</a>);
00935 
00936                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o19">_Alpha</a> == 0.0) {
00937                         db += (sint32) db1;
00938 
00939                 } <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o19">_Alpha</a> &gt; 0.0) {
00940                         <font class="keywordtype">double</font> amp2 = 0.0001 + 0.9999 * (max - dist) / (max - <a class="code" href="bit__set_8cpp.html#a0">min</a>); <font class="comment">// linear amp between 0.00001 and 1.0</font>
00941                         <font class="keywordtype">double</font> db2 = 2000.0 * log10(amp2); <font class="comment">// covert to 1/100th decibels</font>
00942                         db += (sint32) ((1.0 - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o19">_Alpha</a>) * db1 + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o19">_Alpha</a> * db2);
00943 
00944                 } <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o19">_Alpha</a> &lt; 0.0) {
00945                         <font class="keywordtype">double</font> amp3 = <a class="code" href="bit__set_8cpp.html#a0">min</a> / dist; <font class="comment">// linear amplitude is 1/distance</font>
00946                         <font class="keywordtype">double</font> db3 = 2000.0 * log10(amp3); <font class="comment">// covert to 1/100th decibels</font>
00947                         db += (sint32) ((1.0 + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o19">_Alpha</a>) * db1 - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o19">_Alpha</a> * db3);
00948                 }
00949 
00950                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(db, DSBVOLUME_MIN, DSBVOLUME_MAX);
00951 
00952                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;SetVolume(db);
00953 
00954 <font class="comment">/*              LONG tmp;</font>
00955 <font class="comment">                _SecondaryBuffer-&gt;GetVolume(&amp;tmp);</font>
00956 <font class="comment">*/</font>
00957                 
00958                 <font class="comment">//nlwarning("VOLUME = %d dB, rolloff = %0.2f", db/100, CListenerDSound::instance()-&gt;getRolloffFactor());</font>
00959         }
00960 
00961 }
00962 
00963 <font class="comment">// ******************************************************************</font>
00964 
<a name="l00965"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_14">00965</a> <font class="keywordtype">void</font> CSourceDSound::setCone( <font class="keywordtype">float</font> innerAngle, <font class="keywordtype">float</font> outerAngle, <font class="keywordtype">float</font> outerGain )
00966 {
00967         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != 0)
00968         {
00969                 <font class="comment">// Set the cone angles</font>
00970 
00971                 <font class="comment">// Convert from radians to degrees</font>
00972                 DWORD inner = (DWORD)(180.0 * innerAngle / <a class="code" href="namespaceNLMISC.html#a7">Pi</a>);
00973                 DWORD outer = (DWORD)(180.0 * outerAngle / <a class="code" href="namespaceNLMISC.html#a7">Pi</a>);
00974 
00975 
00976                 <font class="comment">// Sanity check: wrap the angles in the [0,360] interval</font>
00977                 <font class="keywordflow">if</font> (outer &lt; inner)
00978                 {
00979                         outer = inner;
00980                 }
00981 
00982                 <font class="keywordflow">while</font> (inner &lt; DS3D_MINCONEANGLE) 
00983                 {
00984                         inner += 360;
00985                 }
00986 
00987                 <font class="keywordflow">while</font> (inner &gt; DS3D_MAXCONEANGLE)
00988                 {
00989                         inner -= 360;
00990                 }
00991 
00992                 <font class="keywordflow">while</font> (outer &lt; DS3D_MINCONEANGLE) 
00993                 {
00994                         outer += 360;
00995                 }
00996 
00997                 <font class="keywordflow">while</font> (outer &gt; DS3D_MAXCONEANGLE)
00998                 {
00999                         outer -= 360;
01000                 }
01001 
01002                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;SetConeAngles(inner, outer, DS3D_DEFERRED) != DS_OK)
01003                 {
01004                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"SetConeAngles failed"</font>);                      
01005                 }
01006 
01007                 <font class="comment">// Set the outside volume</font>
01008                 <font class="keywordflow">if</font> (outerGain &lt; 0.00001f)
01009                 {
01010                         outerGain = 0.00001f;
01011                 }
01012 
01013                 <font class="comment">// convert from linear amplitude to hundredths of decibels </font>
01014                 LONG volume = (LONG)(100.0 * 20.0 * log10(outerGain));
01015 
01016                 <font class="keywordflow">if</font> (volume &lt; DSBVOLUME_MIN) 
01017                 {
01018                         volume = DSBVOLUME_MIN;
01019                 }
01020                 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (volume &gt; DSBVOLUME_MAX) 
01021                 {
01022                         volume = DSBVOLUME_MAX;
01023                 }
01024 
01025                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;SetConeOutsideVolume(volume, DS3D_DEFERRED) != DS_OK)
01026                 {
01027                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"SetConeOutsideVolume failed"</font>);               
01028                 }
01029 
01030         }
01031         <font class="keywordflow">else</font>
01032         {
01033                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Requested setCone on a non-3D source"</font>);
01034         }
01035 }
01036 
01037 <font class="comment">// ******************************************************************</font>
01038 
<a name="l01039"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_15">01039</a> <font class="keywordtype">void</font> CSourceDSound::getCone( <font class="keywordtype">float</font>&amp; innerAngle, <font class="keywordtype">float</font>&amp; outerAngle, <font class="keywordtype">float</font>&amp; outerGain )<font class="keyword"> const</font>
01040 <font class="keyword"></font>{
01041         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a> != 0)
01042         {
01043                 DWORD inner, outer;
01044                 LONG volume;
01045 
01046                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;GetConeAngles(&amp;inner, &amp;outer) != DS_OK)
01047                 {
01048                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"GetConeAngles failed"</font>);                      
01049                         innerAngle = outerAngle = (float)(2.0 * <a class="code" href="namespaceNLMISC.html#a7">Pi</a>);
01050                 }
01051                 <font class="keywordflow">else</font>
01052                 {
01053                         innerAngle = (float)(<a class="code" href="namespaceNLMISC.html#a7">Pi</a> * inner / 180.0);
01054                         outerAngle = (float)(<a class="code" href="namespaceNLMISC.html#a7">Pi</a> * outer / 180.0);
01055                 }
01056 
01057                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o7">_3DBuffer</a>-&gt;GetConeOutsideVolume(&amp;volume) != DS_OK)
01058                 {
01059                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"GetConeOutsideVolume failed"</font>);               
01060                         outerGain = 0.0f;
01061                 }
01062                 <font class="keywordflow">else</font>
01063                 {
01064                         outerGain = (float) pow(10, (<font class="keywordtype">double</font>) volume / 20.0 / 100.0);
01065                 }
01066         }
01067         <font class="keywordflow">else</font>
01068         {
01069                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Requested getCone on a non-3D source"</font>);
01070         }
01071 }
01072 
01073 <font class="comment">// ******************************************************************</font>
01074 
<a name="l01075"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_16">01075</a> <font class="keywordtype">void</font> CSourceDSound::setEAXProperty( uint prop, <font class="keywordtype">void</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>, uint valuesize )
01076 {
01077 <font class="preprocessor">#ifdef EAX_AVAILABLE</font>
01078 <font class="preprocessor"></font>        <font class="keywordflow">if</font> ( EAXSetProp != NULL )
01079         {
01080                 EAXSetProp( &amp;DSPROPSETID_EAX_SourceProperties, prop, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o0">_SourceName</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>, valuesize );
01081         }
01082 <font class="preprocessor">#endif</font>
01083 <font class="preprocessor"></font>}
01084 
01085 
01086 <font class="comment">// ******************************************************************</font>
01087 
<a name="l01088"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#a4">01088</a> IBuffer *CSourceDSound::getBuffer()
01089 {       
01090         <font class="keywordflow">return</font> <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a>;
01091 }
01092 
01093 
01094 <font class="comment">// ******************************************************************</font>
01095 
<a name="l01096"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c1">01096</a> <font class="keywordtype">bool</font> CSourceDSound::lock(uint32 writePos, uint32 size, uint8* &amp;ptr1, DWORD &amp;bytes1, uint8* &amp;ptr2, DWORD &amp;bytes2)
01097 {
01098         HRESULT hr = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Lock(writePos, size, (LPVOID*) &amp;ptr1, &amp;bytes1, (LPVOID*) &amp;ptr2, &amp;bytes2, 0);
01099 
01100         <font class="keywordflow">if</font> (hr == DSERR_BUFFERLOST)
01101         {
01102                 <font class="comment">// If the buffer got lost somehow, try to restore it.</font>
01103                 <font class="keywordflow">if</font> (FAILED(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Restore()))
01104                 {
01105                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Lock failed (1)"</font>);
01106                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
01107                 }
01108                 <font class="keywordflow">if</font> (FAILED(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Lock(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r0">_UpdateCopySize</a>, (LPVOID*) &amp;ptr1, &amp;bytes1, (LPVOID*) &amp;ptr2, &amp;bytes2, 0)))
01109                 {
01110                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Lock failed (2)"</font>);
01111                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
01112                 }
01113         } 
01114         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (hr != DS_OK)
01115         {
01116                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Lock failed (3)"</font>);
01117                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
01118         }
01119 
01120         <font class="keywordflow">return</font> <font class="keyword">true</font>;
01121 }
01122 
01123 <font class="comment">// ******************************************************************</font>
01124 
<a name="l01125"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c2">01125</a> <font class="keywordtype">bool</font> CSourceDSound::unlock(uint8* ptr1, DWORD bytes1, uint8* ptr2, DWORD bytes2)
01126 {
01127         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Unlock(ptr1, bytes1, ptr2, bytes2);
01128         <font class="keywordflow">return</font> <font class="keyword">true</font>;
01129 }
01130 
01131 
01132 
01133 <font class="comment">/***************************************************************************</font>
01134 <font class="comment"> </font>
01135 <font class="comment"></font>
01136 <font class="comment">  Buffer operations</font>
01137 <font class="comment"></font>
01138 <font class="comment">  There are five buffer operation: fill, silence, fadeOut, crossFade</font>
01139 <font class="comment">  and fadeIn. fill and silence are called by the update function. The</font>
01140 <font class="comment">  others are called by the user state functions (play, stop, pause).</font>
01141 <font class="comment"></font>
01142 <font class="comment"></font>
01143 <font class="comment">                        NW         P   W</font>
01144 <font class="comment">   +--------+------+---+-----------------------+</font>
01145 <font class="comment">   |........|      |xxx|.......................|</font>
01146 <font class="comment">   +--------+------+---+-----------------------+</font>
01147 <font class="comment"></font>
01148 <font class="comment">  The source maintains the next write position (_NextWritePos, NW in figure</font>
01149 <font class="comment">  above). That is the position at which new samples or silemce is written.</font>
01150 <font class="comment">  DirectSound maintaines a play cursor and a write cursor (P and W in figure).</font>
01151 <font class="comment">  The data between P and W is scheduled for playing and cannot be touched.</font>
01152 <font class="comment">  The data between W and NW are unplayed sample data that the source copied</font>
01153 <font class="comment">  into the DirectSound buffer.</font>
01154 <font class="comment"></font>
01155 <font class="comment">  The update functions (fill, silence) refresh the buffer with new samples</font>
01156 <font class="comment">  or silence. That insert the sample data at the next write position NW. This </font>
01157 <font class="comment">  write position is maintained as closely behind the DirectSound play cursor </font>
01158 <font class="comment">  as possible to keep the buffer filled with data.</font>
01159 <font class="comment"></font>
01160 <font class="comment">  The user functions (the fades) modify the sample data that is right after</font>
01161 <font class="comment">  the write cursor W maintained by DirectSound. The data has to be written </font>
01162 <font class="comment">  after W to hear the changes as soon as possible. When a fade is done, the</font>
01163 <font class="comment">  date already written in the buffer has to be overwritten. The function</font>
01164 <font class="comment">  getFadeOutSize() helps to found out how many samples are writen between</font>
01165 <font class="comment">  W and NW and to what section of the original audio data they correspond.</font>
01166 <font class="comment"></font>
01167 <font class="comment">  All the buffer functions below have the same pattern:</font>
01168 <font class="comment"></font>
01169 <font class="comment">        - get current play and write cursors (P and W)</font>
01170 <font class="comment">        - lock the buffer</font>
01171 <font class="comment">        - copy samples</font>
01172 <font class="comment">        - unlock buffer</font>
01173 <font class="comment">        - update state variables</font>
01174 <font class="comment"></font>
01175 <font class="comment">  The differences between the functions are due to different operation</font>
01176 <font class="comment">  (fades), position and size of the buffer to lock, handling of silence</font>
01177 <font class="comment">  and looping.</font>
01178 <font class="comment"></font>
01179 <font class="comment">  Enjoy!</font>
01180 <font class="comment"></font>
01181 <font class="comment">  PH</font>
01182 <font class="comment"></font>
01183 <font class="comment"></font>
01184 <font class="comment">************************************************************************/</font>
01185 
<a name="l01186"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c5">01186</a> <font class="keywordtype">bool</font> CSourceDSound::fill()
01187 {
01188         <font class="keywordtype">bool</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = <font class="keyword">false</font>;
01189         uint8 *ptr1, *ptr2;
01190         DWORD bytes1, bytes2;
01191         DWORD playPos, writePos;
01192         uint32 space;
01193 
01194 
01195         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> == NULL)
01196         {
01197                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a28">NL_DSOUND_SILENCING</a>;
01198                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> = <a class="code" href="namespaceNLSOUND.html#a85a32">NL_DSOUND_STOPPED</a>;
01199                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
01200         }
01201 
01202         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> == 0)
01203         {
01204                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
01205         }
01206 
01207 
01208         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startPos);
01209 
01210 
01211         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;GetCurrentPosition(&amp;playPos, &amp;writePos);
01212 
01213         <font class="keywordflow">if</font> (playPos == <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>)
01214         {
01215                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
01216         }
01217         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (playPos &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>) 
01218         {
01219                 space = playPos - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>;
01220         }
01221         <font class="keywordflow">else</font>
01222         {
01223                 space = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a> + playPos - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>;
01224         }
01225 
01226         <font class="comment">// Don't bother if the number of samples that can be written is too small.</font>
01227         <font class="keywordflow">if</font> (space &lt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r0">_UpdateCopySize</a>)
01228         {
01229                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
01230         }
01231 
01232 
01233         uint8* <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> = ((CBufferDSound*) <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a>)-&gt;getData();
01234         uint32 available = (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> &lt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a>) ? <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> : 0;
01235 
01236 
01237         <font class="comment">// The number of samples bytes that will be copied. If bytes is 0</font>
01238         <font class="comment">// than write silence to the buffer.</font>
01239         uint32 bytes = <a class="code" href="source__dsound_8cpp.html#a2">NLSOUND_MIN</a>(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#r0">_UpdateCopySize</a>, available);
01240         uint32 clear = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r0">_UpdateCopySize</a> - available;
01241 
01242 
01243         <font class="comment">// Lock the buffer</font>
01244 
01245         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startLock);
01246 
01247 
01248         <font class="keywordflow">if</font> (!<a class="code" href="classNLSOUND_1_1CSourceDSound.html#c1">lock</a>(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r0">_UpdateCopySize</a>, ptr1, bytes1, ptr2, bytes2))
01249         {
01250                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
01251         }
01252 
01253 
01254         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startCopy);
01255 
01256         <font class="comment">// Start copying the samples</font>
01257 
01258         <font class="keywordflow">if</font> (bytes1 &lt;= bytes) {
01259 
01260                 CFastMem::memcpy(ptr1, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, bytes1);
01261                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += bytes1;
01262                 bytes -= bytes1;
01263 
01264                 <font class="keywordflow">if</font> (ptr2)
01265                 {
01266                         <font class="keywordflow">if</font> (bytes &gt; 0)
01267                         {
01268                                 CFastMem::memcpy(ptr2, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, bytes);                                    
01269                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += bytes;
01270                         }
01271 
01272                         <font class="keywordflow">if</font> (bytes &lt; bytes2)
01273                         {
01274                                 <font class="keywordflow">if</font> (_Loop)
01275                                 {
01276                                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FILL: LOOP"</font>, <font class="keyword">this</font>));
01277 
01278                                         CFastMem::memcpy(ptr2 + bytes, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a>, bytes2 - bytes); 
01279                                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = bytes2 - bytes;
01280                                 }
01281                                 <font class="keywordflow">else</font>
01282                                 {
01283                                         memset(ptr2 + bytes, 0, bytes2 - bytes); 
01284                                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> = bytes2 - bytes;
01285                                 }
01286                         }
01287                 }
01288         }
01289         <font class="keywordflow">else</font>
01290         {
01291                 <font class="keywordflow">if</font> (bytes &gt; 0)
01292                 {
01293                         CFastMem::memcpy(ptr1, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, bytes);
01294                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += bytes;
01295                 }
01296 
01297                 <font class="keywordflow">if</font> (_Loop)
01298                 {
01299                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FILL: LOOP"</font>, <font class="keyword">this</font>));
01300 
01301                         CFastMem::memcpy(ptr1 + bytes, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a>, bytes1 - bytes);                                    
01302                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = bytes1 - bytes;
01303 
01304                         <font class="keywordflow">if</font> (ptr2)
01305                         {
01306                                 CFastMem::memcpy(ptr2, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, bytes2);                                    
01307                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += bytes2;
01308                         }
01309 
01310                 } 
01311                 <font class="keywordflow">else</font>
01312                 {
01313                         memset(ptr1 + bytes, 0, bytes1 - bytes);                                        
01314                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> = bytes1 - bytes;
01315 
01316                         <font class="keywordflow">if</font> (ptr2)
01317                         {
01318                                 memset(ptr2, 0, bytes2);                                        
01319                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> += bytes2;
01320                         }
01321                 }
01322 
01323         }
01324 
01325 
01326 
01327 
01328         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startUnlock);
01329 
01330         <font class="comment">// Unlock the buffer</font>
01331         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Unlock(ptr1, bytes1, ptr2, bytes2);
01332 
01333 
01334         <font class="comment">// Update the state variables</font>
01335 
01336         <font class="comment">// Check if we've reached the end of the file</font>
01337         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> == <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a>) 
01338         {
01339                 <font class="keywordflow">if</font> (_Loop)
01340                 {
01341                         <font class="comment">// If we're looping, start all over again</font>
01342                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FILL: LOOP"</font>, <font class="keyword">this</font>));
01343                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = 0;
01344                 }
01345                 <font class="keywordflow">else</font>
01346                 {
01347                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a28">NL_DSOUND_SILENCING</a>;
01348 
01349                         <font class="comment">// Keep track of where tha last sample was written and the position</font>
01350                         <font class="comment">// of the play cursor relative to the end position. if the _EndState</font>
01351                         <font class="comment">// is 0, the play cursor is after the end position, 1 otherwise.</font>
01352                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a> = writePos + bytes;
01353                         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a> &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>)
01354                         {
01355                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a> -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;
01356                         }
01357 
01358                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a> = (playPos &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a>)? <a class="code" href="namespaceNLSOUND.html#a86a33">NL_DSOUND_TAIL1</a> : <a class="code" href="namespaceNLSOUND.html#a86a34">NL_DSOUND_TAIL2</a>;
01359 
01360                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FILL: SILENCING"</font>, <font class="keyword">this</font>));
01361                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FILL: ENDSTATE=%d, E=%d, P=%d"</font>, <font class="keyword">this</font>, (<font class="keywordtype">int</font>) <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a>, playPos));
01362                 }
01363         }
01364 
01365 
01366         <font class="comment">// Update the write pointer</font>
01367         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> += bytes1 + bytes2;
01368         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>)
01369         {
01370                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>  -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;
01371         }
01372  
01373         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FILL: P=%d, W=%d, NW=%d, SZ=%d, BW=%d, S=%d, B=%d"</font>, <font class="keyword">this</font>, playPos, writePos, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a>, bytes1 + bytes2));
01374 
01375 
01376 <font class="preprocessor">#if NLSOUND_PROFILE</font>
01377 <font class="preprocessor"></font>        _TotalUpdateSize += bytes1 + bytes2;
01378         _PosTime += CTime::ticksToSecond(startLock - startPos);
01379         _LockTime += CTime::ticksToSecond(startCopy - startLock);
01380         _CopyTime += CTime::ticksToSecond(startUnlock - startCopy);
01381         _UnlockTime += CTime::ticksToSecond(CTime::getPerformanceTime() - startUnlock);
01382         _CopyCount++;
01383 <font class="preprocessor">#endif</font>
01384 <font class="preprocessor"></font>
01385 
01386         <font class="keywordflow">return</font> <font class="keyword">true</font>;
01387 }
01388 
01389 
01390 
01391 
01392 <font class="comment">// ******************************************************************</font>
01393 
<a name="l01394"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c6">01394</a> <font class="keywordtype">bool</font> CSourceDSound::silence()
01395 {
01396         uint8 *ptr1, *ptr2;
01397         DWORD bytes1, bytes2;
01398         DWORD playPos, writePos;
01399         uint32 space;
01400 
01401         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> == 0)
01402         {
01403                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
01404         }
01405                 
01406         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startPos);
01407 
01408         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;GetCurrentPosition(&amp;playPos, &amp;writePos);
01409 
01410         <font class="keywordflow">if</font> (playPos == <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>)
01411         {
01412                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
01413         }
01414         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (playPos &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>) 
01415         {
01416                 space = playPos - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>;
01417         }
01418         <font class="keywordflow">else</font>
01419         {
01420                 space = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a> + playPos - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>;
01421         }
01422 
01423         <font class="comment">// Don't bother if the number of samples that can be written is too small.</font>
01424         <font class="keywordflow">if</font> (space &lt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r0">_UpdateCopySize</a>)
01425         {
01426                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
01427         }
01428 
01429                 <font class="comment">// Lock the buffer</font>
01430 
01431         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startLock);
01432 
01433         <font class="keywordflow">if</font> (!<a class="code" href="classNLSOUND_1_1CSourceDSound.html#c1">lock</a>(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r0">_UpdateCopySize</a>, ptr1, bytes1, ptr2, bytes2))
01434         {
01435                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
01436         }
01437 
01438 
01439         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startCopy);
01440    
01441         <font class="comment">// Silence the buffer</font>
01442         memset(ptr1, 0, bytes1);
01443         memset(ptr2, 0, bytes2);
01444 
01445                 <font class="comment">// Unlock the buffer</font>
01446 
01447         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startUnlock);
01448 
01449         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Unlock(ptr1, bytes1, ptr2, bytes2);
01450 
01451 
01452         <font class="comment">// Update the next write position</font>
01453         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> += bytes1 + bytes2;
01454         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>)
01455         {
01456                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>  -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;
01457         }
01458 
01459 
01460         <font class="comment">// Check if all the samples in the buffer are played</font>
01461         <font class="keywordflow">if</font> ((playPos &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a>) &amp;&amp; (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a> == <a class="code" href="namespaceNLSOUND.html#a86a34">NL_DSOUND_TAIL2</a>)) 
01462         {
01463                 <font class="comment">// The buffer played passed the last sample. Flag the source as stopped.</font>
01464                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a> = <a class="code" href="namespaceNLSOUND.html#a86a35">NL_DSOUND_ENDED</a>;
01465                 <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] SLNC: ENDED"</font>, <font class="keyword">this</font>));
01466 
01467                 <font class="comment">// If the buffer was playing, mark it as stopped</font>
01468                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> == <a class="code" href="namespaceNLSOUND.html#a85a30">NL_DSOUND_PLAYING</a>)
01469                 {
01470                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> = <a class="code" href="namespaceNLSOUND.html#a85a32">NL_DSOUND_STOPPED</a>;
01471                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] SLNC: STOPPED"</font>, <font class="keyword">this</font>));
01472                 }
01473         }
01474         <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((playPos &lt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a>) &amp;&amp; (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a> == <a class="code" href="namespaceNLSOUND.html#a86a33">NL_DSOUND_TAIL1</a>))
01475         {
01476                 <font class="comment">// The play cursor wrapped around the buffer and is now before the end position</font>
01477                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a> = <a class="code" href="namespaceNLSOUND.html#a86a34">NL_DSOUND_TAIL2</a>;
01478                 <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FILL: ENDSTATE=%d, E=%d, P=%d"</font>, <font class="keyword">this</font>, (<font class="keywordtype">int</font>) <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a>, playPos));
01479         }
01480 
01481 
01482         <font class="comment">// Update the amount of silence written</font>
01483         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> += bytes1 + bytes2;
01484         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>)
01485         {
01486                 <font class="comment">// The buffer is now completely filled with silence</font>
01487                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a29">NL_DSOUND_SILENCED</a>;
01488                 <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] SLNC: SILENCED"</font>, <font class="keyword">this</font>));
01489 
01490                 <font class="comment">// If the buffer was playing, mark it as stopped</font>
01491                 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> == <a class="code" href="namespaceNLSOUND.html#a85a30">NL_DSOUND_PLAYING</a>)
01492                 {
01493                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> = <a class="code" href="namespaceNLSOUND.html#a85a32">NL_DSOUND_STOPPED</a>;
01494                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] SLNC: STOPPED*"</font>, <font class="keyword">this</font>));
01495                 }
01496         }
01497 
01498         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] SLNC: P=%d, W=%d, NW=%d, SZ=%d, BW=%d, S=%d, B=%d"</font>, <font class="keyword">this</font>, playPos, writePos, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a>, bytes1 + bytes2));
01499 
01500 
01501 <font class="preprocessor">#if NLSOUND_PROFILE</font>
01502 <font class="preprocessor"></font>        _TotalUpdateSize += bytes1 + bytes2;
01503         _PosTime += CTime::ticksToSecond(startLock - startPos);
01504         _LockTime += CTime::ticksToSecond(startCopy - startLock);
01505         _CopyTime += CTime::ticksToSecond(startUnlock - startCopy);
01506         _UnlockTime += CTime::ticksToSecond(CTime::getPerformanceTime() - startUnlock);
01507         _CopyCount++;
01508 <font class="preprocessor">#endif</font>
01509 <font class="preprocessor"></font>
01510         <font class="keywordflow">return</font> <font class="keyword">true</font>;
01511 }
01512 
01513 
01514 <font class="comment">// ******************************************************************</font>
01515 
<a name="l01524"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c4">01524</a>  <font class="keywordtype">void</font> CSourceDSound::getFadeOutSize(uint32 writePos, uint32 &amp;xfadeSize, sint16* &amp;in1, uint32 &amp;writtenTooMuch)
01525 {
01526         <font class="comment">// The number of samples over which we will do the crossfade</font>
01527         xfadeSize = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r5">_XFadeSize</a>;
01528 
01529 
01530         <font class="comment">// The tricky part of this method is to figger out how many samples of the old</font>
01531         <font class="comment">// buffer were written after the write cursor and figger our with what position </font>
01532         <font class="comment">// in the old buffer the write cursor corresponds. We have to consider the following</font>
01533         <font class="comment">// cases:</font>
01534         <font class="comment">//</font>
01535         <font class="comment">// - the old buffer just looped, </font>
01536         <font class="comment">// - the old buffer is finished, but stil has samples in the DirectSound buffer</font>
01537         <font class="comment">// - the default case, i.e. the old buffer is playing somewhere in the middle.</font>
01538         <font class="comment">//</font>
01539 
01540         <font class="comment">// How many bytes did we write after the write position?</font>
01541 
01542         writtenTooMuch = <a class="code" href="source__dsound_8cpp.html#a3">NLSOUND_DISTANCE</a>(writePos, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>);
01543 
01544         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FADE: TOO=%d"</font>, <font class="keyword">this</font>, writtenTooMuch));
01545 
01546 
01547         uint8* <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> = ((CBufferDSound*) <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a>)-&gt;getData();
01548 
01549         <font class="comment">// If the sound is finished and all the samples are written in the</font>
01550         <font class="comment">// buffer, it's possible that there are still samples after the write</font>
01551         <font class="comment">// position. If this is the case, we have to do a fade out. If there is</font>
01552         <font class="comment">// only silence, we only need to copy without fade.</font>
01553 
01554         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> &gt; 0)
01555         {
01556                 
01557                 <font class="keywordflow">if</font> (writtenTooMuch &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a>)
01558                 {
01559                         writtenTooMuch -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a>;
01560                         in1 = (sint16*) (<a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> - writtenTooMuch) ;
01561 
01562                         <font class="keywordflow">if</font> (writtenTooMuch &lt; 2 * xfadeSize)
01563                         {
01564                                 xfadeSize = writtenTooMuch / 2;
01565                         }
01566                 }
01567                 <font class="keywordflow">else</font>
01568                 {
01569                         xfadeSize = 0;                                                    
01570                 }
01571 
01572                 <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FADE: END, TOO=%d, S=%d, F=%d"</font>, <font class="keyword">this</font>, writtenTooMuch, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a>, xfadeSize));
01573         }
01574         
01575         <font class="comment">// If the sound looped, it's possible that the number of samples</font>
01576         <font class="comment">// written is small. In that case, the write cursor is still inside</font>
01577         <font class="comment">// the previous loop. All we have to do is fade out the last part</font>
01578         <font class="comment">// of the previous loop. </font>
01579 
01580         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (writtenTooMuch &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>)
01581         {
01582 
01583                 writtenTooMuch -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>;
01584 
01585                 in1 = (sint16*) (<a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> - writtenTooMuch) ;
01586 
01587                 <font class="keywordflow">if</font> (writtenTooMuch &lt; 2 * xfadeSize)
01588                 {
01589                         xfadeSize = writtenTooMuch / 2;
01590                 }
01591 
01592                 <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FADE: LOOPED, TOO=%d, F=%d"</font>, <font class="keyword">this</font>, writtenTooMuch, xfadeSize));
01593 
01594         }
01595 
01596         <font class="comment">// This is the default case. Simply fade from the previous to the next buffer.</font>
01597         <font class="comment">// The variable writtenTooMuch tells us how much of the previous sound has</font>
01598         <font class="comment">// been written after the current write cursor. We just have to check there</font>
01599         <font class="comment">// are enough samples available for the fade.</font>
01600 
01601         <font class="keywordflow">else</font>
01602         {
01603                 in1 = (sint16*) (<a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + (sint32) <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> - writtenTooMuch);
01604 
01605                 <font class="keywordflow">if</font> (xfadeSize &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>)
01606                 {
01607                         xfadeSize = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>;
01608                 }
01609 
01610                 <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FADE: STD, TOO=%d, F=%d"</font>, <font class="keyword">this</font>, writtenTooMuch, xfadeSize));
01611         }
01612 }
01613 
01614 
01615 
01616 <font class="comment">// ******************************************************************</font>
01617 
<a name="l01618"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c7">01618</a> <font class="keywordtype">void</font> CSourceDSound::crossFade()
01619 {
01620         uint8 *ptr1, *ptr2;
01621         DWORD bytes1, bytes2;
01622         DWORD playPos, writePos;
01623         uint32 i;
01624 
01625 
01626 
01627         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> == NULL)
01628         {
01629                 <font class="keywordflow">return</font>;
01630         }
01631 
01632         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> == 0)
01633         {
01634                 <font class="keywordflow">return</font>;
01635         }
01636 
01637 
01638         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(start); 
01639         
01640 
01641         EnterCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>); 
01642 
01643 
01644 
01645         <font class="comment">// The source is currently playing an other buffer. We will do a hot</font>
01646         <font class="comment">// swap between the old and the new buffer. DirectSound maintains two</font>
01647         <font class="comment">// cursors into the buffer: the play cursor and the write cursor.</font>
01648         <font class="comment">// The write cursor indicates where we can start writing the new samples.</font>
01649         <font class="comment">// To avoid clicks, we have to do a cross fade between the old buffer and</font>
01650         <font class="comment">// the new buffer.</font>
01651         
01652         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;GetCurrentPosition(&amp;playPos, &amp;writePos);
01653 
01654 
01655         <font class="comment">// The number of bytes we will write to the DirectSound buffer</font>
01656         uint32 bytes = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r1">_SwapCopySize</a>;
01657         <font class="keywordflow">if</font> (bytes &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a>-&gt;getSize())
01658         {
01659                 bytes = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a>-&gt;getSize();
01660         }
01661 
01662 
01663         <font class="comment">// Lock the DirectSound buffer</font>
01664 
01665         <font class="keywordflow">if</font> (FAILED(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Lock(writePos, bytes, (LPVOID*) &amp;ptr1, &amp;bytes1, (LPVOID*) &amp;ptr2, &amp;bytes2, 0)))
01666         {
01667                 LeaveCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>);
01668                 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to lock the DirectSound secondary buffer"</font>);
01669         }
01670 
01671         
01672         sint16* in1;
01673         uint8* data1 = ((CBufferDSound*) <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a>)-&gt;getData();
01674         uint8* data2 = ((CBufferDSound*) <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a>)-&gt;getData();
01675         sint16* in2 = (sint16*) data2;
01676         sint16* out = (sint16*) ptr1;
01677 
01678         <font class="comment">// The number of samples over which we will do the crossfade</font>
01679         uint32 xfadeSize;
01680         uint32 xfadeByteSize;
01681         uint32 writtenTooMuch;
01682 
01683         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c4">getFadeOutSize</a>(writePos, xfadeSize, in1, writtenTooMuch);
01684         xfadeByteSize = 2 * xfadeSize;
01685 
01686 <font class="preprocessor">#define MIX 1</font>
01687 <font class="preprocessor"></font>
01688 
01689 <font class="preprocessor">#if MIX</font>
01690 <font class="preprocessor"></font>        <font class="keywordtype">float</font> incr, amp1, amp2;
01691 
01692         <font class="keywordflow">if</font> (xfadeSize == 0)
01693         {
01694                 amp1 = 0.0f;
01695                 amp2 = 1.0f;
01696                 incr = 0.0f;
01697         }
01698         <font class="keywordflow">else</font>
01699         {
01700                 amp1 = 1.0f;
01701                 amp2 = 0.0f;
01702                 incr = 1.0f / xfadeSize;
01703         }
01704 
01705 <font class="preprocessor">#else</font>
01706 <font class="preprocessor"></font>        <font class="keywordtype">float</font> incr, amp1;
01707 
01708         <font class="keywordflow">if</font> (xfadeSize == 0)
01709         {
01710                 amp1 = 0.0f;
01711                 incr = 0.0f;
01712         }
01713         <font class="keywordflow">else</font>
01714         {
01715                 amp1 = 1.0f;
01716                 incr = 1.0f / xfadeSize;
01717         }
01718 
01719 <font class="preprocessor">#endif</font>
01720 <font class="preprocessor"></font>
01721 
01722         <font class="comment">// Start copying the samples</font>
01723         
01724 
01725         <font class="comment">// In the first case, the cross fade is completely contained in the first buffer</font>
01726         <font class="comment">// pointed to by ptr1.</font>
01727         <font class="keywordflow">if</font> (xfadeByteSize &lt; bytes1)
01728         {
01729 
01730                 <font class="comment">// Do cross fade</font>
01731 
01732                 <font class="keywordflow">for</font> (i = 0; i &lt; xfadeSize; i++) 
01733                 {
01734 <font class="preprocessor">#if MIX</font>
01735 <font class="preprocessor"></font>                        out[i] = (sint16) (amp1 * in1[i] + amp2 * in2[i]);
01736                         amp1 -= incr;
01737                         amp2 += incr;
01738 <font class="preprocessor">#else</font>
01739 <font class="preprocessor"></font>                        out[i] = (sint16) (amp1 * in1[i]);
01740                         amp1 -= incr;
01741 <font class="preprocessor">#endif</font>
01742 <font class="preprocessor"></font>                }
01743 
01744                 <font class="comment">// Copy remaining samples</font>
01745 
01746 <font class="preprocessor">#if MIX</font>
01747 <font class="preprocessor"></font>                CFastMem::memcpy(ptr1 + xfadeByteSize, data2 + xfadeByteSize, bytes1 - xfadeByteSize);
01748                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = bytes1;
01749 <font class="preprocessor">#else</font>
01750 <font class="preprocessor"></font>                CFastMem::memcpy(ptr1 + xfadeByteSize, data2, bytes1 - xfadeByteSize);
01751                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = bytes1 - xfadeByteSize;
01752 <font class="preprocessor">#endif</font>
01753 <font class="preprocessor"></font>
01754                 <font class="keywordflow">if</font> (ptr2)
01755                 {
01756                         CFastMem::memcpy(ptr2, data2 + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, bytes2);
01757                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += bytes2;
01758                 }
01759 
01760         }
01761 
01762         <font class="comment">// In the second case, the cross fade stretches over the first and the second buffers.</font>
01763         <font class="keywordflow">else</font>
01764         {
01765 
01766                 uint32 fade1 = bytes1 / 2;
01767                 uint32 fade2 = xfadeSize - fade1;
01768 
01769                 <font class="comment">// Do cross fade</font>
01770 
01771                 <font class="comment">// Part 1, start at ptr1</font>
01772                 <font class="keywordflow">for</font> (i = 0; i &lt; fade1; i++) 
01773                 {
01774 <font class="preprocessor">#if MIX</font>
01775 <font class="preprocessor"></font>                        out[i] = (sint16) (amp1 * in1[i] + amp2 * in2[i]);
01776                         amp1 -= incr;
01777                         amp2 += incr;
01778 <font class="preprocessor">#else</font>
01779 <font class="preprocessor"></font>                        out[i] = (sint16) (amp1 * in1[i]);
01780                         amp1 -= incr;
01781 <font class="preprocessor">#endif</font>
01782 <font class="preprocessor"></font>                }
01783 <font class="preprocessor">#if MIX</font>
01784 <font class="preprocessor"></font>                <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = bytes1;
01785 <font class="preprocessor">#else</font>
01786 <font class="preprocessor"></font>                <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = 0;
01787 <font class="preprocessor">#endif</font>
01788 <font class="preprocessor"></font>
01789 
01790                 <font class="keywordflow">if</font> (ptr2)
01791                 {
01792                         out = (sint16*) ptr2;
01793 
01794                         <font class="comment">// Part 2, ontinue at ptr2</font>
01795                         <font class="keywordflow">for</font> (uint32 k = 0; i &lt; xfadeSize; i++, k++) 
01796                         {
01797 <font class="preprocessor">#if MIX</font>
01798 <font class="preprocessor"></font>                                out[k] = (sint16) (amp1 * in1[i] + amp2 * in2[i]);
01799                                 amp1 -= incr;
01800                                 amp2 += incr;
01801 <font class="preprocessor">#else</font>
01802 <font class="preprocessor"></font>                                out[k] = (sint16) (amp1 * in1[i]);
01803                                 amp1 -= incr;
01804 <font class="preprocessor">#endif</font>
01805 <font class="preprocessor"></font>                        }
01806 
01807                         <font class="comment">// Copy remaining samples</font>
01808 <font class="preprocessor">#if MIX</font>
01809 <font class="preprocessor"></font>                        CFastMem::memcpy(ptr2 + 2 * k, data2 + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> + 2 * k, bytes2 - 2 * k);
01810                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += bytes2;
01811 <font class="preprocessor">#else</font>
01812 <font class="preprocessor"></font>                        CFastMem::memcpy(ptr2 + 2 * k, data2, bytes2 - 2 * k);
01813                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = bytes2 - 2 * k;
01814 <font class="preprocessor">#endif</font>
01815 <font class="preprocessor"></font>                }
01816         }
01817 
01818 
01819         <font class="comment">// Unlock the DirectSound buffer</font>
01820         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Unlock(ptr1, bytes1, ptr2, bytes2);
01821 
01822         
01823         <font class="comment">// Update the state variables</font>
01824 
01825         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> = 0;
01826 
01827         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> = (writePos + bytes1 + bytes2);
01828         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>)
01829         {
01830                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;
01831         }
01832 
01833 
01834 
01835         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a27">NL_DSOUND_FILLING</a>;
01836 
01837 
01838         <font class="comment">// Swap the two buffers</font>
01839         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a>-&gt;getSize();
01840         <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a>;
01841         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o2">_SwapBuffer</a> = 0;
01842 
01843         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_8">setPitch</a>(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o14">_Freq</a>);
01844 
01845         <font class="comment">// Check if we've reached the end of the file</font>
01846         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> == <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a>) 
01847         {
01848                 <font class="keywordflow">if</font> (_Loop)
01849                 {
01850                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = 0;
01851                 }
01852                 <font class="keywordflow">else</font>
01853                 {
01854                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a28">NL_DSOUND_SILENCING</a>;
01855                 }
01856         }
01857 
01858 
01859         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] XFADE"</font>, <font class="keyword">this</font>));
01860         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] P=%d, W=%d, NW=%d, SZ=%d, BW=%d, B=%d"</font>, <font class="keyword">this</font>, playPos, writePos, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, bytes1 + bytes2));
01861 
01862         
01863 
01864         LeaveCriticalSection(&amp;<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o8">_CriticalSection</a>);
01865 
01866 
01867 <font class="preprocessor">#if NLSOUND_PROFILE</font>
01868 <font class="preprocessor"></font>        _LastSwapTime = CTime::ticksToSecond(CTime::getPerformanceTime() - start);
01869         _TotalSwapTime += _LastSwapTime;
01870         _MaxSwapTime = (_LastSwapTime &gt; _MaxSwapTime) ? _LastSwapTime : _MaxSwapTime;
01871         _MinSwapTime = (_LastSwapTime &lt; _MinSwapTime) ? _LastSwapTime : _MinSwapTime;
01872         _SwapCount++;
01873 <font class="preprocessor">#endif</font>
01874 <font class="preprocessor"></font>
01875 }
01876 
01877 
01878 
01879 <font class="comment">// ******************************************************************</font>
01880 
<a name="l01881"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c8">01881</a> <font class="keywordtype">void</font> CSourceDSound::fadeOut()
01882 {
01883         uint8 *ptr1, *ptr2;
01884         DWORD bytes1, bytes2;
01885         DWORD playPos, writePos;
01886         uint32 i;
01887 
01888 
01889         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> == NULL)
01890         {
01891                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a28">NL_DSOUND_SILENCING</a>;
01892                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> = <a class="code" href="namespaceNLSOUND.html#a85a32">NL_DSOUND_STOPPED</a>;
01893                 <font class="keywordflow">return</font>;
01894         }
01895 
01896         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> == 0)
01897         {
01898                 <font class="keywordflow">return</font>;
01899         }
01900 
01901         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(start);
01902         
01903 
01904         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;GetCurrentPosition(&amp;playPos, &amp;writePos);
01905 
01906 
01907         <font class="comment">// Lock the DirectSound buffer</font>
01908 
01909         <font class="keywordflow">if</font> (FAILED(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Lock(writePos, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r1">_SwapCopySize</a>, (LPVOID*) &amp;ptr1, &amp;bytes1, (LPVOID*) &amp;ptr2, &amp;bytes2, 0)))
01910         {
01911                 <font class="keywordflow">throw</font> ESoundDriver(<font class="stringliteral">"Failed to lock the DirectSound secondary buffer"</font>);
01912         }
01913 
01914         
01915 
01916         <font class="comment">// in1 points to the position in the old buffer where the fade out starts</font>
01917         sint16* in1;
01918         sint16* out = (sint16*) ptr1;
01919 
01920         <font class="comment">// The number of samples over which we will do the crossfade</font>
01921         uint32 xfadeSize;
01922         uint32 xfadeByteSize;
01923         uint32 writtenTooMuch;
01924 
01925         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#c4">getFadeOutSize</a>(writePos, xfadeSize, in1, writtenTooMuch);
01926         xfadeByteSize = 2 * xfadeSize;
01927 
01928         <font class="keywordtype">float</font> amp1, incr;
01929 
01930         <font class="keywordflow">if</font> (xfadeSize == 0)
01931         {
01932                 amp1 = 0.0f;
01933                 incr = 0.0f;
01934         }
01935         <font class="keywordflow">else</font>
01936         {
01937                 amp1 = 1.0f;
01938                 incr = 1.0f / xfadeSize;
01939         }
01940 
01941 
01942         <font class="keywordflow">if</font> (writtenTooMuch &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>)
01943         {
01944                 <font class="comment">// The buffer looped. Count backwards from the end of the file.</font>
01945                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> - writtenTooMuch;
01946         }
01947         <font class="keywordflow">else</font>
01948         {
01949                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> -= writtenTooMuch;
01950         }
01951 
01952 
01953         <font class="comment">// Start copying the samples</font>
01954         
01955 
01956         <font class="comment">// In the first case, the fade out is completely contained in the first buffer</font>
01957         <font class="comment">// pointed to by ptr1.</font>
01958         <font class="keywordflow">if</font> (xfadeByteSize &lt; bytes1)
01959         {
01960 
01961                 <font class="comment">// Do cross fade</font>
01962 
01963                 <font class="keywordflow">for</font> (i = 0; i &lt; xfadeSize; i++) 
01964                 {
01965                         out[i] = (sint16) (amp1 * in1[i]);
01966                         amp1 -= incr;
01967                 }
01968 
01969                 <font class="comment">// Copy remaining samples</font>
01970 
01971                 memset(ptr1 + xfadeByteSize, 0, bytes1 - xfadeByteSize);
01972                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> = bytes1 - xfadeByteSize;
01973 
01974                 <font class="keywordflow">if</font> (ptr2)
01975                 {
01976                         memset(ptr2, 0, bytes2);
01977                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> += bytes2;
01978                 }
01979 
01980         }
01981 
01982         <font class="comment">// In the second case, the fade out stretches over the first and the second buffers.</font>
01983         <font class="keywordflow">else</font>
01984         {
01985 
01986                 uint32 fade1 = bytes1 / 2;
01987                 uint32 fade2 = xfadeSize - fade1;
01988 
01989                 <font class="comment">// Do cross fade</font>
01990 
01991                 <font class="comment">// Part 1, start at ptr1</font>
01992                 <font class="keywordflow">for</font> (i = 0; i &lt; fade1; i++) 
01993                 {
01994                         out[i] = (sint16) (amp1 * in1[i]);
01995                         amp1 -= incr;
01996                 }
01997 
01998 
01999                 <font class="keywordflow">if</font> (ptr2)
02000                 {
02001                         out = (sint16*) ptr2;
02002 
02003                         <font class="comment">// Part 2, continue at ptr2</font>
02004                         <font class="keywordflow">for</font> (uint32 k = 0; i &lt; xfadeSize; i++, k++) 
02005                         {
02006                                 out[k] = (sint16) (amp1 * in1[i]);
02007                                 amp1 -= incr;
02008                         }
02009 
02010                         <font class="comment">// Clear remaining samples</font>
02011                         memset(ptr2 + 2 * k, 0, bytes2 - 2 * k);
02012                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> = bytes2 - 2 * k;
02013                 }
02014 
02015         }
02016 
02017 
02018         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += xfadeByteSize;
02019 
02020 
02021         <font class="comment">// Unlock the DirectSound buffer</font>
02022         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Unlock(ptr1, bytes1, ptr2, bytes2);
02023 
02024         
02025         <font class="comment">// Update the next write position</font>
02026         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> = (writePos + bytes1 + bytes2);
02027         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>)
02028         {
02029                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;
02030         }
02031 
02032 
02033         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a28">NL_DSOUND_SILENCING</a>;
02034         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FDOU: SILENCING"</font>, <font class="keyword">this</font>));
02035 
02036         <font class="comment">// Keep track of where tha last sample was written and the position</font>
02037         <font class="comment">// of the play cursor relative to the end position. if the _EndState</font>
02038         <font class="comment">// is 0, the play cursor is after the end position, 1 otherwise.</font>
02039         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a> = writePos + xfadeSize;
02040         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a> &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>)
02041         {
02042                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a> -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;
02043         }
02044 
02045         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a> = (playPos &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a>)? <a class="code" href="namespaceNLSOUND.html#a86a33">NL_DSOUND_TAIL1</a> : <a class="code" href="namespaceNLSOUND.html#a86a34">NL_DSOUND_TAIL2</a>;
02046         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FDOU: ENDSTATE=%d, E=%d, P=%d"</font>, <font class="keyword">this</font>, (<font class="keywordtype">int</font>) <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a>, playPos));
02047 
02048 
02049         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FDOU: P=%d, W=%d, NW=%d, SZ=%d, BW=%d, S=%d, B=%d"</font>, <font class="keyword">this</font>, playPos, writePos, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a>, bytes1 + bytes2));
02050 
02051 
02052 
02053 <font class="preprocessor">#if NLSOUND_PROFILE</font>
02054 <font class="preprocessor"></font>        _LastSwapTime = CTime::ticksToSecond(CTime::getPerformanceTime() - start);
02055         _TotalSwapTime += _LastSwapTime;
02056         _MaxSwapTime = (_LastSwapTime &gt; _MaxSwapTime) ? _LastSwapTime : _MaxSwapTime;
02057         _MinSwapTime = (_LastSwapTime &lt; _MinSwapTime) ? _LastSwapTime : _MinSwapTime;
02058         _SwapCount++;
02059 <font class="preprocessor">#endif</font>
02060 <font class="preprocessor"></font>
02061 }
02062 
02063 <font class="comment">// ******************************************************************</font>
02064 
<a name="l02065"></a><a class="code" href="classNLSOUND_1_1CSourceDSound.html#c9">02065</a> <font class="keywordtype">void</font> CSourceDSound::fadeIn()
02066 {
02067         <font class="keywordtype">bool</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = <font class="keyword">false</font>;
02068         uint8 *ptr1, *ptr2;
02069         DWORD bytes1, bytes2;
02070         DWORD playPos, writePos;
02071 
02072 
02073         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a> == NULL)
02074         {
02075                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a28">NL_DSOUND_SILENCING</a>;
02076                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o4">_UserState</a> = <a class="code" href="namespaceNLSOUND.html#a85a32">NL_DSOUND_STOPPED</a>;
02077                 <font class="keywordflow">return</font>;
02078         }
02079 
02080         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a> == 0)
02081         {
02082                 <font class="keywordflow">return</font>;
02083         }
02084 
02085         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startPos);
02086 
02087         <font class="comment">// Set the correct pitch for this sound</font>
02088         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#z970_8">setPitch</a>(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o14">_Freq</a>);
02089 
02090         <font class="comment">// Set the correct volume</font>
02091         <font class="comment">// FIXME: a bit of a hack</font>
02092         <font class="keyword">const</font> CVector &amp;pos = CListenerDSound::instance()-&gt;getPos();
02093         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#a6">updateVolume</a>(pos);
02094 
02095 
02096         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;GetCurrentPosition(&amp;playPos, &amp;writePos);
02097 
02098         uint8* <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> = ((CBufferDSound*) <a class="code" href="classNLSOUND_1_1ISource.html#n0">_Buffer</a>)-&gt;getData();
02099         uint32 available = (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> &lt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a>) ? <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a> - <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> : 0;
02100         uint32 bytes = <a class="code" href="source__dsound_8cpp.html#a2">NLSOUND_MIN</a>(<a class="code" href="classNLSOUND_1_1CSourceDSound.html#r1">_SwapCopySize</a>, available);
02101 <font class="comment">//      uint32 clear = _SwapCopySize - available;</font>
02102 
02103 
02104         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> = 0;
02105 
02106         <font class="comment">// Lock the buffer</font>
02107 
02108         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startLock);
02109 
02110 
02111         <font class="keywordflow">if</font> (!<a class="code" href="classNLSOUND_1_1CSourceDSound.html#c1">lock</a>(writePos, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r1">_SwapCopySize</a>, ptr1, bytes1, ptr2, bytes2))
02112         {
02113                 <font class="keywordflow">return</font>;
02114         }
02115 
02116 
02117         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startCopy);
02118 
02119         <font class="comment">// Start copying the samples</font>
02120 
02121         <font class="keywordflow">if</font> (bytes1 &lt;= bytes) {
02122 
02123                 CFastMem::memcpy(ptr1, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, bytes1);
02124                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += bytes1;
02125                 bytes -= bytes1;
02126 
02127                 <font class="keywordflow">if</font> (ptr2)
02128                 {
02129                         <font class="keywordflow">if</font> (bytes &gt; 0)
02130                         {
02131                                 CFastMem::memcpy(ptr2, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, bytes);                                    
02132                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += bytes;
02133                         }
02134 
02135                         <font class="keywordflow">if</font> (bytes &lt; bytes2)
02136                         {
02137                                 <font class="keywordflow">if</font> (_Loop)
02138                                 {
02139                                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FDIN: LOOP"</font>, <font class="keyword">this</font>));
02140 
02141                                         CFastMem::memcpy(ptr2 + bytes, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a>, bytes2 - bytes); 
02142                                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = bytes2 - bytes;
02143                                 }
02144                                 <font class="keywordflow">else</font>
02145                                 {
02146                                         memset(ptr2 + bytes, 0, bytes2 - bytes); 
02147                                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> = bytes2 - bytes;
02148                                 }
02149                         }
02150                 }
02151         }
02152         <font class="keywordflow">else</font>
02153         {
02154                 <font class="keywordflow">if</font> (bytes &gt; 0)
02155                 {
02156                         CFastMem::memcpy(ptr1, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, bytes);
02157                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += bytes;
02158                 }
02159 
02160                 <font class="keywordflow">if</font> (_Loop)
02161                 {
02162                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FDIN: LOOP"</font>, <font class="keyword">this</font>));
02163 
02164                         CFastMem::memcpy(ptr1 + bytes, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a>, bytes1 - bytes);                                    
02165                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = bytes1 - bytes;
02166 
02167                         <font class="keywordflow">if</font> (ptr2)
02168                         {
02169                                 CFastMem::memcpy(ptr2, <a class="code" href="driver__opengl__extension__def_8h.html#a394">data</a> + <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, bytes2);                                    
02170                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> += bytes2;
02171                         }
02172                 } 
02173                 <font class="keywordflow">else</font>
02174                 {
02175                         memset(ptr1 + bytes, 0, bytes1 - bytes);                                        
02176                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> = bytes1 - bytes;
02177 
02178                         <font class="keywordflow">if</font> (ptr2)
02179                         {
02180                                 memset(ptr2, 0, bytes2);                                        
02181                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a> += bytes2;
02182                         }
02183                 }
02184         }
02185 
02186 
02187         <a class="code" href="source__dsound_8cpp.html#a0">INITTIME</a>(startUnlock);
02188 
02189         <font class="comment">// Unlock the buffer</font>
02190         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o5">_SecondaryBuffer</a>-&gt;Unlock(ptr1, bytes1, ptr2, bytes2);
02191 
02192 
02193         <font class="comment">// Update the state variables</font>
02194 
02195         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a27">NL_DSOUND_FILLING</a>;
02196         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FDIN: FILLING"</font>, <font class="keyword">this</font>));
02197 
02198 
02199         <font class="comment">// Check if we've reached the end of the file</font>
02200         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> == <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a>) 
02201         {
02202                 <font class="keywordflow">if</font> (_Loop)
02203                 {
02204                         <font class="comment">// If we're looping, start all over again</font>
02205                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FDIN: LOOP"</font>, <font class="keyword">this</font>));
02206                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a> = 0;
02207                 }
02208                 <font class="keywordflow">else</font>
02209                 {
02210                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o6">_SecondaryBufferState</a> = <a class="code" href="namespaceNLSOUND.html#a84a28">NL_DSOUND_SILENCING</a>;
02211 
02212                         <font class="comment">// Keep track of where tha last sample was written and the position</font>
02213                         <font class="comment">// of the play cursor relative to the end position. if the _EndState</font>
02214                         <font class="comment">// is NL_DSOUND_TAIL1, the play cursor is after the end position, </font>
02215                         <font class="comment">// NL_DSOUND_TAIL2 otherwise.</font>
02216                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a> = writePos + bytes;
02217                         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a> &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>)
02218                         {
02219                                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a> -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;
02220                         }
02221 
02222                         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a> = (playPos &gt; <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a>)? <a class="code" href="namespaceNLSOUND.html#a86a33">NL_DSOUND_TAIL1</a> : <a class="code" href="namespaceNLSOUND.html#a86a34">NL_DSOUND_TAIL2</a>;
02223 
02224                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FDIN: SILENCING"</font>, <font class="keyword">this</font>));
02225                         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FDIN: ENDSTATE=%d, E=%d, P=%d"</font>, <font class="keyword">this</font>, (<font class="keywordtype">int</font>) <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o13">_EndState</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o12">_EndPosition</a>, playPos));
02226                 }
02227         }
02228 
02229 
02230         <font class="comment">// Update the write pointer</font>
02231         <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> = writePos + bytes1 + bytes2;
02232         <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a> &gt;= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>)
02233         {
02234                 <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>  -= <a class="code" href="classNLSOUND_1_1CSourceDSound.html#r6">_SecondaryBufferSize</a>;
02235         }
02236  
02237         <a class="code" href="source__dsound_8cpp.html#a1">DBGPOS</a>((<font class="stringliteral">"[%p] FDIN: P=%d, W=%d, NW=%d, SZ=%d, BW=%d, S=%d, B=%d"</font>, <font class="keyword">this</font>, playPos, writePos, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o9">_NextWritePos</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o1">_BufferSize</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o10">_BytesWritten</a>, <a class="code" href="classNLSOUND_1_1CSourceDSound.html#o11">_SilenceWritten</a>, bytes1 + bytes2));
02238 
02239 
02240 <font class="preprocessor">#if NLSOUND_PROFILE</font>
02241 <font class="preprocessor"></font>        _TotalUpdateSize += bytes1 + bytes2;
02242         _PosTime += CTime::ticksToSecond(startLock - startPos);
02243         _LockTime += CTime::ticksToSecond(startCopy - startLock);
02244         _CopyTime += CTime::ticksToSecond(startUnlock - startCopy);
02245         _UnlockTime += CTime::ticksToSecond(CTime::getPerformanceTime() - startUnlock);
02246         _CopyCount++;
02247 <font class="preprocessor">#endif</font>
02248 <font class="preprocessor"></font>
02249 
02250 }
02251 
02252 
02253 
02254 } <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>