annotate html/send.html @ 9:a988ea53d982

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