Mercurial > audio-send
comparison html/send.html @ 0:f9476ff7637e
initial forking of open-al to create multiple listeners
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 13:02:31 -0700 (2011-10-25) |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f9476ff7637e |
---|---|
1 <?xml version="1.0" encoding="utf-8"?> | |
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
4 <html xmlns="http://www.w3.org/1999/xhtml" | |
5 lang="en" xml:lang="en"> | |
6 <head> | |
7 <title>send.c</title> | |
8 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | |
9 <meta name="generator" content="Org-mode"/> | |
10 <meta name="generated" content="2011-10-20 15:48:47 MST"/> | |
11 <meta name="author" content="Robert McIntyre"/> | |
12 <meta name="description" content="some code I wrote to extend open-al"/> | |
13 <meta name="keywords" content=""/> | |
14 <style type="text/css"> | |
15 <!--/*--><![CDATA[/*><!--*/ | |
16 html { font-family: Times, serif; font-size: 12pt; } | |
17 .title { text-align: center; } | |
18 .todo { color: red; } | |
19 .done { color: green; } | |
20 .tag { background-color: #add8e6; font-weight:normal } | |
21 .target { } | |
22 .timestamp { color: #bebebe; } | |
23 .timestamp-kwd { color: #5f9ea0; } | |
24 .right {margin-left:auto; margin-right:0px; text-align:right;} | |
25 .left {margin-left:0px; margin-right:auto; text-align:left;} | |
26 .center {margin-left:auto; margin-right:auto; text-align:center;} | |
27 p.verse { margin-left: 3% } | |
28 pre { | |
29 border: 1pt solid #AEBDCC; | |
30 background-color: #F3F5F7; | |
31 padding: 5pt; | |
32 font-family: courier, monospace; | |
33 font-size: 90%; | |
34 overflow:auto; | |
35 } | |
36 table { border-collapse: collapse; } | |
37 td, th { vertical-align: top; } | |
38 th.right { text-align:center; } | |
39 th.left { text-align:center; } | |
40 th.center { text-align:center; } | |
41 td.right { text-align:right; } | |
42 td.left { text-align:left; } | |
43 td.center { text-align:center; } | |
44 dt { font-weight: bold; } | |
45 div.figure { padding: 0.5em; } | |
46 div.figure p { text-align: center; } | |
47 textarea { overflow-x: auto; } | |
48 .linenr { font-size:smaller } | |
49 .code-highlighted {background-color:#ffff00;} | |
50 .org-info-js_info-navigation { border-style:none; } | |
51 #org-info-js_console-label { font-size:10px; font-weight:bold; | |
52 white-space:nowrap; } | |
53 .org-info-js_search-highlight {background-color:#ffff00; color:#000000; | |
54 font-weight:bold; } | |
55 /*]]>*/--> | |
56 </style> | |
57 <link rel="stylesheet" type="text/css" href="/aurellem/css/aurellem.css" /> | |
58 <script type="text/javascript"> | |
59 <!--/*--><![CDATA[/*><!--*/ | |
60 function CodeHighlightOn(elem, id) | |
61 { | |
62 var target = document.getElementById(id); | |
63 if(null != target) { | |
64 elem.cacheClassElem = elem.className; | |
65 elem.cacheClassTarget = target.className; | |
66 target.className = "code-highlighted"; | |
67 elem.className = "code-highlighted"; | |
68 } | |
69 } | |
70 function CodeHighlightOff(elem, id) | |
71 { | |
72 var target = document.getElementById(id); | |
73 if(elem.cacheClassElem) | |
74 elem.className = elem.cacheClassElem; | |
75 if(elem.cacheClassTarget) | |
76 target.className = elem.cacheClassTarget; | |
77 } | |
78 /*]]>*///--> | |
79 </script> | |
80 | |
81 </head> | |
82 <body> | |
83 | |
84 <div id="content"> | |
85 | |
86 | |
87 | |
88 <div class="header"> | |
89 <div class="float-right"> | |
90 <!-- | |
91 <form> | |
92 <input type="text"/><input type="submit" value="search the blog »"/> | |
93 </form> | |
94 --> | |
95 </div> | |
96 | |
97 <h1>aurellem <em>☉</em></h1> | |
98 <ul class="nav"> | |
99 <li><a href="/">read the blog »</a></li> | |
100 <!-- li><a href="#">learn about us »</a></li--> | |
101 </ul> | |
102 </div> | |
103 | |
104 <h1 class="title">send.c</h1> | |
105 <div class="author">Written by <author>Robert McIntyre</author></div> | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 <pre class="src src-C"><span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"config.h"</span> | |
114 <span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;"><stdlib.h></span> | |
115 <span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"alMain.h"</span> | |
116 <span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"AL/al.h"</span> | |
117 <span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"AL/alc.h"</span> | |
118 <span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"alSource.h"</span> | |
119 <span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;"><jni.h></span> | |
120 | |
121 <span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">Summary</span> | |
122 | |
123 <span style="color: #f0dfaf; font-weight: bold;">struct</span> <span style="color: #dfdfbf; font-weight: bold;">send_data</span>; | |
124 <span style="color: #f0dfaf; font-weight: bold;">struct</span> <span style="color: #dfdfbf; font-weight: bold;">context_data</span>; | |
125 | |
126 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">addContext</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *); | |
127 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">syncContexts</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">master</span>, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">slave</span>); | |
128 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">syncSources</span>(<span style="color: #dfdfbf; font-weight: bold;">ALsource</span> *<span style="color: #f0dfaf;">master</span>, <span style="color: #dfdfbf; font-weight: bold;">ALsource</span> *<span style="color: #f0dfaf;">slave</span>, | |
129 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">masterCtx</span>, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">slaveCtx</span>); | |
130 | |
131 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">syncSourcei</span>(<span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">master</span>, <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">slave</span>, | |
132 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">masterCtx</span>, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">ctx2</span>, <span style="color: #dfdfbf; font-weight: bold;">ALenum</span> <span style="color: #f0dfaf;">param</span>); | |
133 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">syncSourcef</span>(<span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">master</span>, <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">slave</span>, | |
134 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">masterCtx</span>, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">ctx2</span>, <span style="color: #dfdfbf; font-weight: bold;">ALenum</span> <span style="color: #f0dfaf;">param</span>); | |
135 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">syncSource3f</span>(<span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">master</span>, <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">slave</span>, | |
136 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">masterCtx</span>, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">ctx2</span>, <span style="color: #dfdfbf; font-weight: bold;">ALenum</span> <span style="color: #f0dfaf;">param</span>); | |
137 | |
138 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">swapInContext</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *, <span style="color: #f0dfaf; font-weight: bold;">struct</span> <span style="color: #dfdfbf; font-weight: bold;">context_data</span> *); | |
139 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">saveContext</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *, <span style="color: #f0dfaf; font-weight: bold;">struct</span> <span style="color: #dfdfbf; font-weight: bold;">context_data</span> *); | |
140 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">limitContext</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *); | |
141 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">unLimitContext</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *); | |
142 | |
143 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">init</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *); | |
144 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">renderData</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *, <span style="color: #dfdfbf; font-weight: bold;">int</span> <span style="color: #f0dfaf;">samples</span>); | |
145 | |
146 <span style="color: #8cd0d3;">#define</span> <span style="color: #f0dfaf;">UNUSED</span>(<span style="color: #f0dfaf;">x</span>) (<span style="color: #dfdfbf; font-weight: bold;">void</span>)(x) | |
147 | |
148 <span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">State</span> | |
149 | |
150 <span style="color: #f0dfaf; font-weight: bold;">typedef</span> <span style="color: #f0dfaf; font-weight: bold;">struct</span> <span style="color: #dfdfbf; font-weight: bold;">context_data</span> { | |
151 <span style="color: #dfdfbf; font-weight: bold;">ALfloat</span> <span style="color: #f0dfaf;">ClickRemoval</span>[MAXCHANNELS]; | |
152 <span style="color: #dfdfbf; font-weight: bold;">ALfloat</span> <span style="color: #f0dfaf;">PendingClicks</span>[MAXCHANNELS]; | |
153 <span style="color: #dfdfbf; font-weight: bold;">ALvoid</span> *<span style="color: #f0dfaf;">renderBuffer</span>; | |
154 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">ctx</span>; | |
155 } <span style="color: #f0dfaf;">context_data</span>; | |
156 | |
157 <span style="color: #f0dfaf; font-weight: bold;">typedef</span> <span style="color: #f0dfaf; font-weight: bold;">struct</span> <span style="color: #dfdfbf; font-weight: bold;">send_data</span> { | |
158 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">size</span>; | |
159 <span style="color: #dfdfbf; font-weight: bold;">context_data</span> **<span style="color: #f0dfaf;">contexts</span>; | |
160 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">numContexts</span>; | |
161 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">maxContexts</span>; | |
162 } <span style="color: #f0dfaf;">send_data</span>; | |
163 | |
164 | |
165 | |
166 <span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">Context Creation / Synchronization</span> | |
167 | |
168 <span style="color: #8cd0d3;">#define</span> <span style="color: #f0dfaf;">_MAKE_SYNC</span>(<span style="color: #f0dfaf;">NAME</span>, <span style="color: #f0dfaf;">INIT_EXPR</span>, <span style="color: #f0dfaf;">GET_EXPR</span>, <span style="color: #f0dfaf;">SET_EXPR</span>) \ | |
169 <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">NAME</span> (<span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">sourceID1</span>, <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">sourceID2</span>, \ | |
170 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">ctx1</span>, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">ctx2</span>, \ | |
171 <span style="color: #dfdfbf; font-weight: bold;">ALenum</span> <span style="color: #f0dfaf;">param</span>){ \ | |
172 INIT_EXPR; \ | |
173 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); \ | |
174 alcMakeContextCurrent(ctx1); \ | |
175 GET_EXPR; \ | |
176 alcMakeContextCurrent(ctx2); \ | |
177 SET_EXPR; \ | |
178 alcMakeContextCurrent(current); \ | |
179 } | |
180 | |
181 <span style="color: #8cd0d3;">#define</span> <span style="color: #f0dfaf;">MAKE_SYNC</span>(<span style="color: #f0dfaf;">NAME</span>, <span style="color: #f0dfaf;">TYPE</span>, <span style="color: #f0dfaf;">GET</span>, <span style="color: #f0dfaf;">SET</span>) \ | |
182 _MAKE_SYNC(NAME, \ | |
183 <span style="color: #dfdfbf; font-weight: bold;">TYPE</span> <span style="color: #f0dfaf;">value</span>, \ | |
184 GET(sourceID1, param, &value), \ | |
185 SET(sourceID2, param, value)) | |
186 | |
187 <span style="color: #8cd0d3;">#define</span> <span style="color: #f0dfaf;">MAKE_SYNC3</span>(<span style="color: #f0dfaf;">NAME</span>, <span style="color: #f0dfaf;">TYPE</span>, <span style="color: #f0dfaf;">GET</span>, <span style="color: #f0dfaf;">SET</span>) \ | |
188 _MAKE_SYNC(NAME, \ | |
189 <span style="color: #dfdfbf; font-weight: bold;">TYPE</span> <span style="color: #f0dfaf;">value1</span>; <span style="color: #dfdfbf; font-weight: bold;">TYPE</span> <span style="color: #f0dfaf;">value2</span>; <span style="color: #dfdfbf; font-weight: bold;">TYPE</span> <span style="color: #f0dfaf;">value3</span>;, \ | |
190 GET(sourceID1, param, &value1, &value2, &value3), \ | |
191 SET(sourceID2, param, value1, value2, value3)) | |
192 | |
193 MAKE_SYNC( syncSourcei, ALint, alGetSourcei, alSourcei); | |
194 MAKE_SYNC( syncSourcef, ALfloat, alGetSourcef, alSourcef); | |
195 MAKE_SYNC3(syncSource3i, ALint, alGetSource3i, alSource3i); | |
196 MAKE_SYNC3(syncSource3f, ALfloat, alGetSource3f, alSource3f); | |
197 | |
198 <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">syncSources</span>(<span style="color: #dfdfbf; font-weight: bold;">ALsource</span> *<span style="color: #f0dfaf;">masterSource</span>, <span style="color: #dfdfbf; font-weight: bold;">ALsource</span> *<span style="color: #f0dfaf;">slaveSource</span>, | |
199 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">masterCtx</span>, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">slaveCtx</span>){ | |
200 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">master</span> = masterSource->source; | |
201 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">slave</span> = slaveSource->source; | |
202 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); | |
203 | |
204 syncSourcef(master,slave,masterCtx,slaveCtx,AL_PITCH); | |
205 syncSourcef(master,slave,masterCtx,slaveCtx,AL_GAIN); | |
206 syncSourcef(master,slave,masterCtx,slaveCtx,AL_MAX_DISTANCE); | |
207 syncSourcef(master,slave,masterCtx,slaveCtx,AL_ROLLOFF_FACTOR); | |
208 syncSourcef(master,slave,masterCtx,slaveCtx,AL_REFERENCE_DISTANCE); | |
209 syncSourcef(master,slave,masterCtx,slaveCtx,AL_MIN_GAIN); | |
210 syncSourcef(master,slave,masterCtx,slaveCtx,AL_MAX_GAIN); | |
211 syncSourcef(master,slave,masterCtx,slaveCtx,AL_CONE_OUTER_GAIN); | |
212 syncSourcef(master,slave,masterCtx,slaveCtx,AL_CONE_INNER_ANGLE); | |
213 syncSourcef(master,slave,masterCtx,slaveCtx,AL_CONE_OUTER_ANGLE); | |
214 syncSourcef(master,slave,masterCtx,slaveCtx,AL_SEC_OFFSET); | |
215 syncSourcef(master,slave,masterCtx,slaveCtx,AL_SAMPLE_OFFSET); | |
216 syncSourcef(master,slave,masterCtx,slaveCtx,AL_BYTE_OFFSET); | |
217 | |
218 syncSource3f(master,slave,masterCtx,slaveCtx,AL_POSITION); | |
219 syncSource3f(master,slave,masterCtx,slaveCtx,AL_VELOCITY); | |
220 syncSource3f(master,slave,masterCtx,slaveCtx,AL_DIRECTION); | |
221 | |
222 syncSourcei(master,slave,masterCtx,slaveCtx,AL_SOURCE_RELATIVE); | |
223 syncSourcei(master,slave,masterCtx,slaveCtx,AL_LOOPING); | |
224 | |
225 alcMakeContextCurrent(masterCtx); | |
226 <span style="color: #dfdfbf; font-weight: bold;">ALint</span> <span style="color: #f0dfaf;">source_type</span>; | |
227 alGetSourcei(master, AL_SOURCE_TYPE, &source_type); | |
228 | |
229 <span style="color: #708070;">// </span><span style="color: #7f9f7f;">Only static sources are currently synchronized! </span> | |
230 <span style="color: #f0dfaf; font-weight: bold;">if</span> (AL_STATIC == source_type){ | |
231 <span style="color: #dfdfbf; font-weight: bold;">ALint</span> <span style="color: #f0dfaf;">master_buffer</span>; | |
232 <span style="color: #dfdfbf; font-weight: bold;">ALint</span> <span style="color: #f0dfaf;">slave_buffer</span>; | |
233 alGetSourcei(master, AL_BUFFER, &master_buffer); | |
234 alcMakeContextCurrent(slaveCtx); | |
235 alGetSourcei(slave, AL_BUFFER, &slave_buffer); | |
236 <span style="color: #f0dfaf; font-weight: bold;">if</span> (master_buffer != slave_buffer){ | |
237 alSourcei(slave, AL_BUFFER, master_buffer); | |
238 } | |
239 } | |
240 | |
241 <span style="color: #708070;">// </span><span style="color: #7f9f7f;">Synchronize the state of the two sources.</span> | |
242 alcMakeContextCurrent(masterCtx); | |
243 <span style="color: #dfdfbf; font-weight: bold;">ALint</span> <span style="color: #f0dfaf;">masterState</span>; | |
244 <span style="color: #dfdfbf; font-weight: bold;">ALint</span> <span style="color: #f0dfaf;">slaveState</span>; | |
245 | |
246 alGetSourcei(master, AL_SOURCE_STATE, &masterState); | |
247 alcMakeContextCurrent(slaveCtx); | |
248 alGetSourcei(slave, AL_SOURCE_STATE, &slaveState); | |
249 | |
250 <span style="color: #f0dfaf; font-weight: bold;">if</span> (masterState != slaveState){ | |
251 <span style="color: #f0dfaf; font-weight: bold;">switch</span> (masterState){ | |
252 <span style="color: #f0dfaf; font-weight: bold;">case</span> AL_INITIAL : alSourceRewind(slave); <span style="color: #f0dfaf; font-weight: bold;">break</span>; | |
253 <span style="color: #f0dfaf; font-weight: bold;">case</span> AL_PLAYING : alSourcePlay(slave); <span style="color: #f0dfaf; font-weight: bold;">break</span>; | |
254 <span style="color: #f0dfaf; font-weight: bold;">case</span> AL_PAUSED : alSourcePause(slave); <span style="color: #f0dfaf; font-weight: bold;">break</span>; | |
255 <span style="color: #f0dfaf; font-weight: bold;">case</span> AL_STOPPED : alSourceStop(slave); <span style="color: #f0dfaf; font-weight: bold;">break</span>; | |
256 } | |
257 } | |
258 <span style="color: #708070;">// </span><span style="color: #7f9f7f;">Restore whatever context was previously active.</span> | |
259 alcMakeContextCurrent(current); | |
260 } | |
261 | |
262 | |
263 <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">syncContexts</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">master</span>, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">slave</span>){ | |
264 <span style="color: #708070;">/* </span><span style="color: #7f9f7f;">If there aren't sufficient sources in slave to mirror </span> | |
265 <span style="color: #7f9f7f;"> the sources in master, create them. </span><span style="color: #708070;">*/</span> | |
266 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); | |
267 | |
268 <span style="color: #dfdfbf; font-weight: bold;">UIntMap</span> *<span style="color: #f0dfaf;">masterSourceMap</span> = &(master->SourceMap); | |
269 <span style="color: #dfdfbf; font-weight: bold;">UIntMap</span> *<span style="color: #f0dfaf;">slaveSourceMap</span> = &(slave->SourceMap); | |
270 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">numMasterSources</span> = masterSourceMap->size; | |
271 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">numSlaveSources</span> = slaveSourceMap->size; | |
272 | |
273 alcMakeContextCurrent(slave); | |
274 <span style="color: #f0dfaf; font-weight: bold;">if</span> (numSlaveSources < numMasterSources){ | |
275 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">numMissingSources</span> = numMasterSources - numSlaveSources; | |
276 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">newSources</span>[numMissingSources]; | |
277 alGenSources(numMissingSources, newSources); | |
278 } | |
279 | |
280 <span style="color: #708070;">/* </span><span style="color: #7f9f7f;">Now, slave is gauranteed to have at least as many sources</span> | |
281 <span style="color: #7f9f7f;"> as master. Sync each source from master to the corresponding</span> | |
282 <span style="color: #7f9f7f;"> source in slave. </span><span style="color: #708070;">*/</span> | |
283 <span style="color: #dfdfbf; font-weight: bold;">int</span> <span style="color: #f0dfaf;">i</span>; | |
284 <span style="color: #f0dfaf; font-weight: bold;">for</span>(i = 0; i < masterSourceMap->size; i++){ | |
285 syncSources((<span style="color: #dfdfbf; font-weight: bold;">ALsource</span>*)masterSourceMap->array[i].value, | |
286 (<span style="color: #dfdfbf; font-weight: bold;">ALsource</span>*)slaveSourceMap->array[i].value, | |
287 master, slave); | |
288 } | |
289 alcMakeContextCurrent(current); | |
290 } | |
291 | |
292 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">addContext</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span>, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">context</span>){ | |
293 <span style="color: #dfdfbf; font-weight: bold;">send_data</span> *<span style="color: #f0dfaf;">data</span> = (<span style="color: #dfdfbf; font-weight: bold;">send_data</span>*)Device->ExtraData; | |
294 <span style="color: #708070;">// </span><span style="color: #7f9f7f;">expand array if necessary</span> | |
295 <span style="color: #f0dfaf; font-weight: bold;">if</span> (data->numContexts >= data->maxContexts){ | |
296 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">newMaxContexts</span> = data->maxContexts*2 + 1; | |
297 data->contexts = realloc(data->contexts, newMaxContexts*<span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(context_data)); | |
298 data->maxContexts = newMaxContexts; | |
299 } | |
300 <span style="color: #708070;">// </span><span style="color: #7f9f7f;">create context_data and add it to the main array</span> | |
301 <span style="color: #dfdfbf; font-weight: bold;">context_data</span> *<span style="color: #f0dfaf;">ctxData</span>; | |
302 ctxData = (<span style="color: #dfdfbf; font-weight: bold;">context_data</span>*)calloc(1, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(*ctxData)); | |
303 ctxData->renderBuffer = malloc(data->size); | |
304 ctxData->ctx = context; | |
305 | |
306 data->contexts[data->numContexts] = ctxData; | |
307 data->numContexts++; | |
308 } | |
309 | |
310 | |
311 <span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">Context Switching </span> | |
312 | |
313 <span style="color: #708070;">/* </span><span style="color: #7f9f7f;">A device brings along with it two pieces of state</span> | |
314 <span style="color: #7f9f7f;"> * which have to be swapped in and out with each context.</span> | |
315 <span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> | |
316 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">swapInContext</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span>, <span style="color: #dfdfbf; font-weight: bold;">context_data</span> *<span style="color: #f0dfaf;">ctxData</span>){ | |
317 memcpy(Device->ClickRemoval, ctxData->ClickRemoval, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(ALfloat)*MAXCHANNELS); | |
318 memcpy(Device->PendingClicks, ctxData->PendingClicks, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(ALfloat)*MAXCHANNELS); | |
319 } | |
320 | |
321 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">saveContext</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span>, <span style="color: #dfdfbf; font-weight: bold;">context_data</span> *<span style="color: #f0dfaf;">ctxData</span>){ | |
322 memcpy(ctxData->ClickRemoval, Device->ClickRemoval, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(ALfloat)*MAXCHANNELS); | |
323 memcpy(ctxData->PendingClicks, Device->PendingClicks, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(ALfloat)*MAXCHANNELS); | |
324 } | |
325 | |
326 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> **<span style="color: #f0dfaf;">currentContext</span>; | |
327 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">currentNumContext</span>; | |
328 | |
329 <span style="color: #708070;">/* </span><span style="color: #7f9f7f;">By default, all contexts are rendered at once for each call to aluMixData.</span> | |
330 <span style="color: #7f9f7f;"> * This function uses the internals of the ALCdecice struct to temporarly </span> | |
331 <span style="color: #7f9f7f;"> * cause aluMixData to only render the chosen context.</span> | |
332 <span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> | |
333 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">limitContext</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span>, <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">ctx</span>){ | |
334 currentContext = Device->Contexts; | |
335 currentNumContext = Device->NumContexts; | |
336 Device->Contexts = &ctx; | |
337 Device->NumContexts = 1; | |
338 } | |
339 | |
340 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">unLimitContext</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span>){ | |
341 Device->Contexts = currentContext; | |
342 Device->NumContexts = currentNumContext; | |
343 } | |
344 | |
345 | |
346 <span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">Main Device Loop</span> | |
347 | |
348 <span style="color: #708070;">/* </span><span style="color: #7f9f7f;">Establish the LWJGL context as the main context, which will</span> | |
349 <span style="color: #7f9f7f;"> * be synchronized to all the slave contexts</span> | |
350 <span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> | |
351 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">init</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span>){ | |
352 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">masterContext</span> = alcGetCurrentContext(); | |
353 addContext(Device, masterContext); | |
354 } | |
355 | |
356 | |
357 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">renderData</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span>, <span style="color: #dfdfbf; font-weight: bold;">int</span> <span style="color: #f0dfaf;">samples</span>){ | |
358 <span style="color: #f0dfaf; font-weight: bold;">if</span>(<span style="color: #f0dfaf; font-weight: bold;">!</span>Device->Connected){<span style="color: #f0dfaf; font-weight: bold;">return</span>;} | |
359 <span style="color: #dfdfbf; font-weight: bold;">send_data</span> *<span style="color: #f0dfaf;">data</span> = (<span style="color: #dfdfbf; font-weight: bold;">send_data</span>*)Device->ExtraData; | |
360 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); | |
361 | |
362 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">i</span>; | |
363 <span style="color: #f0dfaf; font-weight: bold;">for</span> (i = 1; i < data->numContexts; i++){ | |
364 syncContexts(data->contexts[0]->ctx , data->contexts[i]->ctx); | |
365 } | |
366 | |
367 <span style="color: #f0dfaf; font-weight: bold;">if</span> ((<span style="color: #dfdfbf; font-weight: bold;">uint</span>) samples > Device->UpdateSize){ | |
368 printf(<span style="color: #cc9393;">"exceeding internal buffer size; dropping samples\n"</span>); | |
369 printf(<span style="color: #cc9393;">"requested %d; available %d\n"</span>, samples, Device->UpdateSize); | |
370 samples = (<span style="color: #dfdfbf; font-weight: bold;">int</span>) Device->UpdateSize; | |
371 } | |
372 | |
373 <span style="color: #f0dfaf; font-weight: bold;">for</span> (i = 0; i < data->numContexts; i++){ | |
374 <span style="color: #dfdfbf; font-weight: bold;">context_data</span> *<span style="color: #f0dfaf;">ctxData</span> = data->contexts[i]; | |
375 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">ctx</span> = ctxData->ctx; | |
376 alcMakeContextCurrent(ctx); | |
377 limitContext(Device, ctx); | |
378 swapInContext(Device, ctxData); | |
379 aluMixData(Device, ctxData->renderBuffer, samples); | |
380 saveContext(Device, ctxData); | |
381 unLimitContext(Device); | |
382 } | |
383 alcMakeContextCurrent(current); | |
384 } | |
385 | |
386 | |
387 <span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">JNI Methods</span> | |
388 | |
389 <span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"com_jme3_capture_AudioSend.h"</span> | |
390 | |
391 <span style="color: #708070;">/*</span> | |
392 <span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> | |
393 <span style="color: #7f9f7f;"> * Method: nstep</span> | |
394 <span style="color: #7f9f7f;"> * Signature: (JI)V</span> | |
395 <span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> | |
396 JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_nstep | |
397 (JNIEnv *env, <span style="color: #dfdfbf; font-weight: bold;">jclass</span> <span style="color: #f0dfaf;">clazz</span>, <span style="color: #dfdfbf; font-weight: bold;">jlong</span> <span style="color: #f0dfaf;">device</span>, <span style="color: #dfdfbf; font-weight: bold;">jint</span> <span style="color: #f0dfaf;">samples</span>){ | |
398 UNUSED(env);UNUSED(clazz);UNUSED(device); | |
399 renderData((<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span>*)((<span style="color: #dfdfbf; font-weight: bold;">intptr_t</span>)device), samples); | |
400 } | |
401 | |
402 <span style="color: #708070;">/*</span> | |
403 <span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> | |
404 <span style="color: #7f9f7f;"> * Method: ngetSamples</span> | |
405 <span style="color: #7f9f7f;"> * Signature: (JLjava/nio/ByteBuffer;III)V</span> | |
406 <span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> | |
407 JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_ngetSamples | |
408 (JNIEnv *env, <span style="color: #dfdfbf; font-weight: bold;">jclass</span> <span style="color: #f0dfaf;">clazz</span>, <span style="color: #dfdfbf; font-weight: bold;">jlong</span> <span style="color: #f0dfaf;">device</span>, <span style="color: #dfdfbf; font-weight: bold;">jobject</span> <span style="color: #f0dfaf;">buffer</span>, <span style="color: #dfdfbf; font-weight: bold;">jint</span> <span style="color: #f0dfaf;">position</span>, | |
409 <span style="color: #dfdfbf; font-weight: bold;">jint</span> <span style="color: #f0dfaf;">samples</span>, <span style="color: #dfdfbf; font-weight: bold;">jint</span> <span style="color: #f0dfaf;">n</span>){ | |
410 UNUSED(clazz); | |
411 | |
412 <span style="color: #dfdfbf; font-weight: bold;">ALvoid</span> *<span style="color: #f0dfaf;">buffer_address</span> = | |
413 ((<span style="color: #dfdfbf; font-weight: bold;">ALbyte</span> *)(((<span style="color: #dfdfbf; font-weight: bold;">char</span>*)(*env)->GetDirectBufferAddress(env, buffer)) + position)); | |
414 <span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">recorder</span> = (<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span>*) ((<span style="color: #dfdfbf; font-weight: bold;">intptr_t</span>)device); | |
415 <span style="color: #dfdfbf; font-weight: bold;">send_data</span> *<span style="color: #f0dfaf;">data</span> = (<span style="color: #dfdfbf; font-weight: bold;">send_data</span>*)recorder->ExtraData; | |
416 <span style="color: #f0dfaf; font-weight: bold;">if</span> ((<span style="color: #dfdfbf; font-weight: bold;">ALuint</span>)n > data->numContexts){<span style="color: #f0dfaf; font-weight: bold;">return</span>;} | |
417 <span style="color: #f0dfaf; font-weight: bold;">if</span> ((<span style="color: #dfdfbf; font-weight: bold;">uint</span>) samples > data->size){ | |
418 samples = (<span style="color: #dfdfbf; font-weight: bold;">int</span>) data->size; | |
419 } | |
420 memcpy(buffer_address, data->contexts[n]->renderBuffer, samples*<span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(ALfloat)); | |
421 } | |
422 | |
423 <span style="color: #708070;">/*</span> | |
424 <span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> | |
425 <span style="color: #7f9f7f;"> * Method: naddListener</span> | |
426 <span style="color: #7f9f7f;"> * Signature: (J)V</span> | |
427 <span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> | |
428 JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_naddListener | |
429 (JNIEnv *env, <span style="color: #dfdfbf; font-weight: bold;">jclass</span> <span style="color: #f0dfaf;">clazz</span>, <span style="color: #dfdfbf; font-weight: bold;">jlong</span> <span style="color: #f0dfaf;">device</span>){ | |
430 UNUSED(env); UNUSED(clazz); | |
431 printf(<span style="color: #cc9393;">"creating new context via naddListener\n"</span>); | |
432 <span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span> = (<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span>*) ((<span style="color: #dfdfbf; font-weight: bold;">intptr_t</span>)device); | |
433 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">new</span> = alcCreateContext(Device, <span style="color: #dca3a3; font-weight: bold;">NULL</span>); | |
434 addContext(Device, new); | |
435 } | |
436 | |
437 <span style="color: #708070;">/*</span> | |
438 <span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> | |
439 <span style="color: #7f9f7f;"> * Method: nsetNthListener3f</span> | |
440 <span style="color: #7f9f7f;"> * Signature: (IFFFJI)V</span> | |
441 <span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> | |
442 JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_nsetNthListener3f | |
443 (JNIEnv *env, <span style="color: #dfdfbf; font-weight: bold;">jclass</span> <span style="color: #f0dfaf;">clazz</span>, <span style="color: #dfdfbf; font-weight: bold;">jint</span> <span style="color: #f0dfaf;">param</span>, | |
444 <span style="color: #dfdfbf; font-weight: bold;">jfloat</span> <span style="color: #f0dfaf;">v1</span>, <span style="color: #dfdfbf; font-weight: bold;">jfloat</span> <span style="color: #f0dfaf;">v2</span>, <span style="color: #dfdfbf; font-weight: bold;">jfloat</span> <span style="color: #f0dfaf;">v3</span>, <span style="color: #dfdfbf; font-weight: bold;">jlong</span> <span style="color: #f0dfaf;">device</span>, <span style="color: #dfdfbf; font-weight: bold;">jint</span> <span style="color: #f0dfaf;">contextNum</span>){ | |
445 UNUSED(env);UNUSED(clazz); | |
446 | |
447 <span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span> = (<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span>*) ((<span style="color: #dfdfbf; font-weight: bold;">intptr_t</span>)device); | |
448 <span style="color: #dfdfbf; font-weight: bold;">send_data</span> *<span style="color: #f0dfaf;">data</span> = (<span style="color: #dfdfbf; font-weight: bold;">send_data</span>*)Device->ExtraData; | |
449 | |
450 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); | |
451 <span style="color: #f0dfaf; font-weight: bold;">if</span> ((<span style="color: #dfdfbf; font-weight: bold;">ALuint</span>)contextNum > data->numContexts){<span style="color: #f0dfaf; font-weight: bold;">return</span>;} | |
452 alcMakeContextCurrent(data->contexts[contextNum]->ctx); | |
453 alListener3f(param, v1, v2, v3); | |
454 alcMakeContextCurrent(current); | |
455 } | |
456 | |
457 <span style="color: #708070;">/*</span> | |
458 <span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> | |
459 <span style="color: #7f9f7f;"> * Method: nsetNthListenerf</span> | |
460 <span style="color: #7f9f7f;"> * Signature: (IFJI)V</span> | |
461 <span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> | |
462 JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_nsetNthListenerf | |
463 (JNIEnv *env, <span style="color: #dfdfbf; font-weight: bold;">jclass</span> <span style="color: #f0dfaf;">clazz</span>, <span style="color: #dfdfbf; font-weight: bold;">jint</span> <span style="color: #f0dfaf;">param</span>, <span style="color: #dfdfbf; font-weight: bold;">jfloat</span> <span style="color: #f0dfaf;">v1</span>, <span style="color: #dfdfbf; font-weight: bold;">jlong</span> <span style="color: #f0dfaf;">device</span>, | |
464 <span style="color: #dfdfbf; font-weight: bold;">jint</span> <span style="color: #f0dfaf;">contextNum</span>){ | |
465 | |
466 UNUSED(env);UNUSED(clazz); | |
467 | |
468 <span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span> = (<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span>*) ((<span style="color: #dfdfbf; font-weight: bold;">intptr_t</span>)device); | |
469 <span style="color: #dfdfbf; font-weight: bold;">send_data</span> *<span style="color: #f0dfaf;">data</span> = (<span style="color: #dfdfbf; font-weight: bold;">send_data</span>*)Device->ExtraData; | |
470 | |
471 <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); | |
472 <span style="color: #f0dfaf; font-weight: bold;">if</span> ((<span style="color: #dfdfbf; font-weight: bold;">ALuint</span>)contextNum > data->numContexts){<span style="color: #f0dfaf; font-weight: bold;">return</span>;} | |
473 alcMakeContextCurrent(data->contexts[contextNum]->ctx); | |
474 alListenerf(param, v1); | |
475 alcMakeContextCurrent(current); | |
476 } | |
477 | |
478 <span style="color: #708070;">/*</span> | |
479 <span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> | |
480 <span style="color: #7f9f7f;"> * Method: ninitDevice</span> | |
481 <span style="color: #7f9f7f;"> * Signature: (J)V</span> | |
482 <span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> | |
483 JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_ninitDevice | |
484 (JNIEnv *env, <span style="color: #dfdfbf; font-weight: bold;">jclass</span> <span style="color: #f0dfaf;">clazz</span>, <span style="color: #dfdfbf; font-weight: bold;">jlong</span> <span style="color: #f0dfaf;">device</span>){ | |
485 UNUSED(env);UNUSED(clazz); | |
486 | |
487 <span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span> = (<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span>*) ((<span style="color: #dfdfbf; font-weight: bold;">intptr_t</span>)device); | |
488 init(Device); | |
489 | |
490 } | |
491 | |
492 | |
493 <span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">Device Initilization / Management</span> | |
494 | |
495 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #f0dfaf; font-weight: bold;">const</span> <span style="color: #dfdfbf; font-weight: bold;">ALCchar</span> <span style="color: #f0dfaf;">sendDevice</span>[] = <span style="color: #cc9393;">"Multiple Audio Send"</span>; | |
496 | |
497 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">ALCboolean</span> <span style="color: #f0dfaf;">send_open_playback</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">device</span>, | |
498 <span style="color: #f0dfaf; font-weight: bold;">const</span> <span style="color: #dfdfbf; font-weight: bold;">ALCchar</span> *<span style="color: #f0dfaf;">deviceName</span>) | |
499 { | |
500 <span style="color: #dfdfbf; font-weight: bold;">send_data</span> *<span style="color: #f0dfaf;">data</span>; | |
501 <span style="color: #708070;">// </span><span style="color: #7f9f7f;">stop any buffering for stdout, so that I can </span> | |
502 <span style="color: #708070;">// </span><span style="color: #7f9f7f;">see the printf statements in my terminal immediatley</span> | |
503 setbuf(stdout, <span style="color: #dca3a3; font-weight: bold;">NULL</span>); | |
504 | |
505 <span style="color: #f0dfaf; font-weight: bold;">if</span>(<span style="color: #f0dfaf; font-weight: bold;">!</span>deviceName) | |
506 deviceName = sendDevice; | |
507 <span style="color: #f0dfaf; font-weight: bold;">else</span> <span style="color: #f0dfaf; font-weight: bold;">if</span>(strcmp(deviceName, sendDevice) != 0) | |
508 <span style="color: #f0dfaf; font-weight: bold;">return</span> ALC_FALSE; | |
509 data = (<span style="color: #dfdfbf; font-weight: bold;">send_data</span>*)calloc(1, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(*data)); | |
510 device->szDeviceName = strdup(deviceName); | |
511 device->ExtraData = data; | |
512 <span style="color: #f0dfaf; font-weight: bold;">return</span> ALC_TRUE; | |
513 } | |
514 | |
515 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">send_close_playback</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">device</span>) | |
516 { | |
517 <span style="color: #dfdfbf; font-weight: bold;">send_data</span> *<span style="color: #f0dfaf;">data</span> = (<span style="color: #dfdfbf; font-weight: bold;">send_data</span>*)device->ExtraData; | |
518 alcMakeContextCurrent(<span style="color: #dca3a3; font-weight: bold;">NULL</span>); | |
519 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">i</span>; | |
520 <span style="color: #708070;">// </span><span style="color: #7f9f7f;">Destroy all slave contexts. LWJGL will take care of </span> | |
521 <span style="color: #708070;">// </span><span style="color: #7f9f7f;">its own context.</span> | |
522 <span style="color: #f0dfaf; font-weight: bold;">for</span> (i = 1; i < data->numContexts; i++){ | |
523 <span style="color: #dfdfbf; font-weight: bold;">context_data</span> *<span style="color: #f0dfaf;">ctxData</span> = data->contexts[i]; | |
524 alcDestroyContext(ctxData->ctx); | |
525 free(ctxData->renderBuffer); | |
526 free(ctxData); | |
527 } | |
528 free(data); | |
529 device->ExtraData = <span style="color: #dca3a3; font-weight: bold;">NULL</span>; | |
530 } | |
531 | |
532 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">ALCboolean</span> <span style="color: #f0dfaf;">send_reset_playback</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">device</span>) | |
533 { | |
534 <span style="color: #dfdfbf; font-weight: bold;">send_data</span> *<span style="color: #f0dfaf;">data</span> = (<span style="color: #dfdfbf; font-weight: bold;">send_data</span>*)device->ExtraData; | |
535 <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">channels</span>=0, <span style="color: #f0dfaf;">bits</span>=0; | |
536 device->FmtType = DevFmtShort; | |
537 bits = BytesFromDevFmt(device->FmtType) * 8; | |
538 channels = ChannelsFromDevFmt(device->FmtChans); | |
539 data->size = device->UpdateSize * channels * bits / 8; | |
540 | |
541 <span style="color: #f0dfaf; font-weight: bold;">return</span> ALC_TRUE; | |
542 } | |
543 | |
544 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">send_stop_playback</span>(<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span> *<span style="color: #f0dfaf;">Device</span>){ | |
545 UNUSED(Device); | |
546 } | |
547 | |
548 <span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #f0dfaf; font-weight: bold;">const</span> <span style="color: #dfdfbf; font-weight: bold;">BackendFuncs</span> <span style="color: #f0dfaf;">send_funcs</span> = { | |
549 send_open_playback, | |
550 send_close_playback, | |
551 send_reset_playback, | |
552 send_stop_playback, | |
553 <span style="color: #dca3a3; font-weight: bold;">NULL</span>, | |
554 <span style="color: #dca3a3; font-weight: bold;">NULL</span>, <span style="color: #708070;">/* </span><span style="color: #7f9f7f;">These would be filled with functions to </span><span style="color: #708070;">*/</span> | |
555 <span style="color: #dca3a3; font-weight: bold;">NULL</span>, <span style="color: #708070;">/* </span><span style="color: #7f9f7f;">handle capturing audio if we we into that </span><span style="color: #708070;">*/</span> | |
556 <span style="color: #dca3a3; font-weight: bold;">NULL</span>, <span style="color: #708070;">/* </span><span style="color: #7f9f7f;">sort of thing... </span><span style="color: #708070;">*/</span> | |
557 <span style="color: #dca3a3; font-weight: bold;">NULL</span>, | |
558 <span style="color: #dca3a3; font-weight: bold;">NULL</span> | |
559 }; | |
560 | |
561 <span style="color: #dfdfbf; font-weight: bold;">ALCboolean</span> <span style="color: #f0dfaf;">alc_send_init</span>(<span style="color: #dfdfbf; font-weight: bold;">BackendFuncs</span> *<span style="color: #f0dfaf;">func_list</span>){ | |
562 *func_list = send_funcs; | |
563 <span style="color: #f0dfaf; font-weight: bold;">return</span> ALC_TRUE; | |
564 } | |
565 | |
566 <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">alc_send_deinit</span>(<span style="color: #dfdfbf; font-weight: bold;">void</span>){} | |
567 | |
568 <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">alc_send_probe</span>(<span style="color: #f0dfaf; font-weight: bold;">enum</span> <span style="color: #dfdfbf; font-weight: bold;">DevProbe</span> <span style="color: #f0dfaf;">type</span>) | |
569 { | |
570 <span style="color: #f0dfaf; font-weight: bold;">switch</span>(type) | |
571 { | |
572 <span style="color: #f0dfaf; font-weight: bold;">case</span> DEVICE_PROBE: | |
573 AppendDeviceList(sendDevice); | |
574 <span style="color: #f0dfaf; font-weight: bold;">break</span>; | |
575 <span style="color: #f0dfaf; font-weight: bold;">case</span> ALL_DEVICE_PROBE: | |
576 AppendAllDeviceList(sendDevice); | |
577 <span style="color: #f0dfaf; font-weight: bold;">break</span>; | |
578 <span style="color: #f0dfaf; font-weight: bold;">case</span> CAPTURE_DEVICE_PROBE: | |
579 <span style="color: #f0dfaf; font-weight: bold;">break</span>; | |
580 } | |
581 } | |
582 | |
583 | |
584 | |
585 </pre> | |
586 | |
587 | |
588 | |
589 | |
590 | |
591 <div id="postamble"> | |
592 <p class="date">Date: 2011-10-20 15:48:47 MST</p> | |
593 <p class="author">Author: Robert McIntyre</p> | |
594 <p class="creator">Org version 7.6 with Emacs version 23</p> | |
595 <a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a> | |
596 </div> | |
597 </div> | |
598 </body> | |
599 </html> |