Mercurial > audio-send
diff 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 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/html/send.html Tue Oct 25 13:02:31 2011 -0700 1.3 @@ -0,0 +1,599 @@ 1.4 +<?xml version="1.0" encoding="utf-8"?> 1.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 1.6 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 1.7 +<html xmlns="http://www.w3.org/1999/xhtml" 1.8 +lang="en" xml:lang="en"> 1.9 +<head> 1.10 +<title>send.c</title> 1.11 +<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> 1.12 +<meta name="generator" content="Org-mode"/> 1.13 +<meta name="generated" content="2011-10-20 15:48:47 MST"/> 1.14 +<meta name="author" content="Robert McIntyre"/> 1.15 +<meta name="description" content="some code I wrote to extend open-al"/> 1.16 +<meta name="keywords" content=""/> 1.17 +<style type="text/css"> 1.18 + <!--/*--><![CDATA[/*><!--*/ 1.19 + html { font-family: Times, serif; font-size: 12pt; } 1.20 + .title { text-align: center; } 1.21 + .todo { color: red; } 1.22 + .done { color: green; } 1.23 + .tag { background-color: #add8e6; font-weight:normal } 1.24 + .target { } 1.25 + .timestamp { color: #bebebe; } 1.26 + .timestamp-kwd { color: #5f9ea0; } 1.27 + .right {margin-left:auto; margin-right:0px; text-align:right;} 1.28 + .left {margin-left:0px; margin-right:auto; text-align:left;} 1.29 + .center {margin-left:auto; margin-right:auto; text-align:center;} 1.30 + p.verse { margin-left: 3% } 1.31 + pre { 1.32 + border: 1pt solid #AEBDCC; 1.33 + background-color: #F3F5F7; 1.34 + padding: 5pt; 1.35 + font-family: courier, monospace; 1.36 + font-size: 90%; 1.37 + overflow:auto; 1.38 + } 1.39 + table { border-collapse: collapse; } 1.40 + td, th { vertical-align: top; } 1.41 + th.right { text-align:center; } 1.42 + th.left { text-align:center; } 1.43 + th.center { text-align:center; } 1.44 + td.right { text-align:right; } 1.45 + td.left { text-align:left; } 1.46 + td.center { text-align:center; } 1.47 + dt { font-weight: bold; } 1.48 + div.figure { padding: 0.5em; } 1.49 + div.figure p { text-align: center; } 1.50 + textarea { overflow-x: auto; } 1.51 + .linenr { font-size:smaller } 1.52 + .code-highlighted {background-color:#ffff00;} 1.53 + .org-info-js_info-navigation { border-style:none; } 1.54 + #org-info-js_console-label { font-size:10px; font-weight:bold; 1.55 + white-space:nowrap; } 1.56 + .org-info-js_search-highlight {background-color:#ffff00; color:#000000; 1.57 + font-weight:bold; } 1.58 + /*]]>*/--> 1.59 +</style> 1.60 +<link rel="stylesheet" type="text/css" href="/aurellem/css/aurellem.css" /> 1.61 +<script type="text/javascript"> 1.62 +<!--/*--><![CDATA[/*><!--*/ 1.63 + function CodeHighlightOn(elem, id) 1.64 + { 1.65 + var target = document.getElementById(id); 1.66 + if(null != target) { 1.67 + elem.cacheClassElem = elem.className; 1.68 + elem.cacheClassTarget = target.className; 1.69 + target.className = "code-highlighted"; 1.70 + elem.className = "code-highlighted"; 1.71 + } 1.72 + } 1.73 + function CodeHighlightOff(elem, id) 1.74 + { 1.75 + var target = document.getElementById(id); 1.76 + if(elem.cacheClassElem) 1.77 + elem.className = elem.cacheClassElem; 1.78 + if(elem.cacheClassTarget) 1.79 + target.className = elem.cacheClassTarget; 1.80 + } 1.81 +/*]]>*///--> 1.82 +</script> 1.83 + 1.84 +</head> 1.85 +<body> 1.86 + 1.87 +<div id="content"> 1.88 + 1.89 + 1.90 + 1.91 +<div class="header"> 1.92 + <div class="float-right"> 1.93 + <!-- 1.94 + <form> 1.95 + <input type="text"/><input type="submit" value="search the blog »"/> 1.96 + </form> 1.97 + --> 1.98 + </div> 1.99 + 1.100 + <h1>aurellem <em>☉</em></h1> 1.101 + <ul class="nav"> 1.102 + <li><a href="/">read the blog »</a></li> 1.103 + <!-- li><a href="#">learn about us »</a></li--> 1.104 + </ul> 1.105 +</div> 1.106 + 1.107 +<h1 class="title">send.c</h1> 1.108 +<div class="author">Written by <author>Robert McIntyre</author></div> 1.109 + 1.110 + 1.111 + 1.112 + 1.113 + 1.114 + 1.115 + 1.116 +<pre class="src src-C"><span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"config.h"</span> 1.117 +<span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;"><stdlib.h></span> 1.118 +<span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"alMain.h"</span> 1.119 +<span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"AL/al.h"</span> 1.120 +<span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"AL/alc.h"</span> 1.121 +<span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"alSource.h"</span> 1.122 +<span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;"><jni.h></span> 1.123 + 1.124 +<span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">Summary</span> 1.125 + 1.126 +<span style="color: #f0dfaf; font-weight: bold;">struct</span> <span style="color: #dfdfbf; font-weight: bold;">send_data</span>; 1.127 +<span style="color: #f0dfaf; font-weight: bold;">struct</span> <span style="color: #dfdfbf; font-weight: bold;">context_data</span>; 1.128 + 1.129 +<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> *); 1.130 +<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>); 1.131 +<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>, 1.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;">slaveCtx</span>); 1.133 + 1.134 +<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>, 1.135 + <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>); 1.136 +<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>, 1.137 + <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>); 1.138 +<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>, 1.139 + <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>); 1.140 + 1.141 +<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> *); 1.142 +<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> *); 1.143 +<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> *); 1.144 +<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> *); 1.145 + 1.146 +<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> *); 1.147 +<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>); 1.148 + 1.149 +<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) 1.150 + 1.151 +<span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">State</span> 1.152 + 1.153 +<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> { 1.154 + <span style="color: #dfdfbf; font-weight: bold;">ALfloat</span> <span style="color: #f0dfaf;">ClickRemoval</span>[MAXCHANNELS]; 1.155 + <span style="color: #dfdfbf; font-weight: bold;">ALfloat</span> <span style="color: #f0dfaf;">PendingClicks</span>[MAXCHANNELS]; 1.156 + <span style="color: #dfdfbf; font-weight: bold;">ALvoid</span> *<span style="color: #f0dfaf;">renderBuffer</span>; 1.157 + <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">ctx</span>; 1.158 +} <span style="color: #f0dfaf;">context_data</span>; 1.159 + 1.160 +<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> { 1.161 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">size</span>; 1.162 + <span style="color: #dfdfbf; font-weight: bold;">context_data</span> **<span style="color: #f0dfaf;">contexts</span>; 1.163 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">numContexts</span>; 1.164 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">maxContexts</span>; 1.165 +} <span style="color: #f0dfaf;">send_data</span>; 1.166 + 1.167 + 1.168 + 1.169 +<span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">Context Creation / Synchronization</span> 1.170 + 1.171 +<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>) \ 1.172 + <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>, \ 1.173 + <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>, \ 1.174 + <span style="color: #dfdfbf; font-weight: bold;">ALenum</span> <span style="color: #f0dfaf;">param</span>){ \ 1.175 + INIT_EXPR; \ 1.176 + <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); \ 1.177 + alcMakeContextCurrent(ctx1); \ 1.178 + GET_EXPR; \ 1.179 + alcMakeContextCurrent(ctx2); \ 1.180 + SET_EXPR; \ 1.181 + alcMakeContextCurrent(current); \ 1.182 + } 1.183 + 1.184 +<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>) \ 1.185 + _MAKE_SYNC(NAME, \ 1.186 + <span style="color: #dfdfbf; font-weight: bold;">TYPE</span> <span style="color: #f0dfaf;">value</span>, \ 1.187 + GET(sourceID1, param, &value), \ 1.188 + SET(sourceID2, param, value)) 1.189 + 1.190 +<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>) \ 1.191 + _MAKE_SYNC(NAME, \ 1.192 + <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>;, \ 1.193 + GET(sourceID1, param, &value1, &value2, &value3), \ 1.194 + SET(sourceID2, param, value1, value2, value3)) 1.195 + 1.196 +MAKE_SYNC( syncSourcei, ALint, alGetSourcei, alSourcei); 1.197 +MAKE_SYNC( syncSourcef, ALfloat, alGetSourcef, alSourcef); 1.198 +MAKE_SYNC3(syncSource3i, ALint, alGetSource3i, alSource3i); 1.199 +MAKE_SYNC3(syncSource3f, ALfloat, alGetSource3f, alSource3f); 1.200 + 1.201 +<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>, 1.202 + <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>){ 1.203 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">master</span> = masterSource->source; 1.204 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">slave</span> = slaveSource->source; 1.205 + <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); 1.206 + 1.207 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_PITCH); 1.208 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_GAIN); 1.209 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_MAX_DISTANCE); 1.210 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_ROLLOFF_FACTOR); 1.211 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_REFERENCE_DISTANCE); 1.212 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_MIN_GAIN); 1.213 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_MAX_GAIN); 1.214 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_CONE_OUTER_GAIN); 1.215 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_CONE_INNER_ANGLE); 1.216 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_CONE_OUTER_ANGLE); 1.217 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_SEC_OFFSET); 1.218 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_SAMPLE_OFFSET); 1.219 + syncSourcef(master,slave,masterCtx,slaveCtx,AL_BYTE_OFFSET); 1.220 + 1.221 + syncSource3f(master,slave,masterCtx,slaveCtx,AL_POSITION); 1.222 + syncSource3f(master,slave,masterCtx,slaveCtx,AL_VELOCITY); 1.223 + syncSource3f(master,slave,masterCtx,slaveCtx,AL_DIRECTION); 1.224 + 1.225 + syncSourcei(master,slave,masterCtx,slaveCtx,AL_SOURCE_RELATIVE); 1.226 + syncSourcei(master,slave,masterCtx,slaveCtx,AL_LOOPING); 1.227 + 1.228 + alcMakeContextCurrent(masterCtx); 1.229 + <span style="color: #dfdfbf; font-weight: bold;">ALint</span> <span style="color: #f0dfaf;">source_type</span>; 1.230 + alGetSourcei(master, AL_SOURCE_TYPE, &source_type); 1.231 + 1.232 + <span style="color: #708070;">// </span><span style="color: #7f9f7f;">Only static sources are currently synchronized! </span> 1.233 + <span style="color: #f0dfaf; font-weight: bold;">if</span> (AL_STATIC == source_type){ 1.234 + <span style="color: #dfdfbf; font-weight: bold;">ALint</span> <span style="color: #f0dfaf;">master_buffer</span>; 1.235 + <span style="color: #dfdfbf; font-weight: bold;">ALint</span> <span style="color: #f0dfaf;">slave_buffer</span>; 1.236 + alGetSourcei(master, AL_BUFFER, &master_buffer); 1.237 + alcMakeContextCurrent(slaveCtx); 1.238 + alGetSourcei(slave, AL_BUFFER, &slave_buffer); 1.239 + <span style="color: #f0dfaf; font-weight: bold;">if</span> (master_buffer != slave_buffer){ 1.240 + alSourcei(slave, AL_BUFFER, master_buffer); 1.241 + } 1.242 + } 1.243 + 1.244 + <span style="color: #708070;">// </span><span style="color: #7f9f7f;">Synchronize the state of the two sources.</span> 1.245 + alcMakeContextCurrent(masterCtx); 1.246 + <span style="color: #dfdfbf; font-weight: bold;">ALint</span> <span style="color: #f0dfaf;">masterState</span>; 1.247 + <span style="color: #dfdfbf; font-weight: bold;">ALint</span> <span style="color: #f0dfaf;">slaveState</span>; 1.248 + 1.249 + alGetSourcei(master, AL_SOURCE_STATE, &masterState); 1.250 + alcMakeContextCurrent(slaveCtx); 1.251 + alGetSourcei(slave, AL_SOURCE_STATE, &slaveState); 1.252 + 1.253 + <span style="color: #f0dfaf; font-weight: bold;">if</span> (masterState != slaveState){ 1.254 + <span style="color: #f0dfaf; font-weight: bold;">switch</span> (masterState){ 1.255 + <span style="color: #f0dfaf; font-weight: bold;">case</span> AL_INITIAL : alSourceRewind(slave); <span style="color: #f0dfaf; font-weight: bold;">break</span>; 1.256 + <span style="color: #f0dfaf; font-weight: bold;">case</span> AL_PLAYING : alSourcePlay(slave); <span style="color: #f0dfaf; font-weight: bold;">break</span>; 1.257 + <span style="color: #f0dfaf; font-weight: bold;">case</span> AL_PAUSED : alSourcePause(slave); <span style="color: #f0dfaf; font-weight: bold;">break</span>; 1.258 + <span style="color: #f0dfaf; font-weight: bold;">case</span> AL_STOPPED : alSourceStop(slave); <span style="color: #f0dfaf; font-weight: bold;">break</span>; 1.259 + } 1.260 + } 1.261 + <span style="color: #708070;">// </span><span style="color: #7f9f7f;">Restore whatever context was previously active.</span> 1.262 + alcMakeContextCurrent(current); 1.263 +} 1.264 + 1.265 + 1.266 +<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>){ 1.267 + <span style="color: #708070;">/* </span><span style="color: #7f9f7f;">If there aren't sufficient sources in slave to mirror </span> 1.268 +<span style="color: #7f9f7f;"> the sources in master, create them. </span><span style="color: #708070;">*/</span> 1.269 + <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); 1.270 + 1.271 + <span style="color: #dfdfbf; font-weight: bold;">UIntMap</span> *<span style="color: #f0dfaf;">masterSourceMap</span> = &(master->SourceMap); 1.272 + <span style="color: #dfdfbf; font-weight: bold;">UIntMap</span> *<span style="color: #f0dfaf;">slaveSourceMap</span> = &(slave->SourceMap); 1.273 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">numMasterSources</span> = masterSourceMap->size; 1.274 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">numSlaveSources</span> = slaveSourceMap->size; 1.275 + 1.276 + alcMakeContextCurrent(slave); 1.277 + <span style="color: #f0dfaf; font-weight: bold;">if</span> (numSlaveSources < numMasterSources){ 1.278 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">numMissingSources</span> = numMasterSources - numSlaveSources; 1.279 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">newSources</span>[numMissingSources]; 1.280 + alGenSources(numMissingSources, newSources); 1.281 + } 1.282 + 1.283 + <span style="color: #708070;">/* </span><span style="color: #7f9f7f;">Now, slave is gauranteed to have at least as many sources</span> 1.284 +<span style="color: #7f9f7f;"> as master. Sync each source from master to the corresponding</span> 1.285 +<span style="color: #7f9f7f;"> source in slave. </span><span style="color: #708070;">*/</span> 1.286 + <span style="color: #dfdfbf; font-weight: bold;">int</span> <span style="color: #f0dfaf;">i</span>; 1.287 + <span style="color: #f0dfaf; font-weight: bold;">for</span>(i = 0; i < masterSourceMap->size; i++){ 1.288 + syncSources((<span style="color: #dfdfbf; font-weight: bold;">ALsource</span>*)masterSourceMap->array[i].value, 1.289 + (<span style="color: #dfdfbf; font-weight: bold;">ALsource</span>*)slaveSourceMap->array[i].value, 1.290 + master, slave); 1.291 + } 1.292 + alcMakeContextCurrent(current); 1.293 +} 1.294 + 1.295 +<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>){ 1.296 + <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; 1.297 + <span style="color: #708070;">// </span><span style="color: #7f9f7f;">expand array if necessary</span> 1.298 + <span style="color: #f0dfaf; font-weight: bold;">if</span> (data->numContexts >= data->maxContexts){ 1.299 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">newMaxContexts</span> = data->maxContexts*2 + 1; 1.300 + data->contexts = realloc(data->contexts, newMaxContexts*<span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(context_data)); 1.301 + data->maxContexts = newMaxContexts; 1.302 + } 1.303 + <span style="color: #708070;">// </span><span style="color: #7f9f7f;">create context_data and add it to the main array</span> 1.304 + <span style="color: #dfdfbf; font-weight: bold;">context_data</span> *<span style="color: #f0dfaf;">ctxData</span>; 1.305 + ctxData = (<span style="color: #dfdfbf; font-weight: bold;">context_data</span>*)calloc(1, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(*ctxData)); 1.306 + ctxData->renderBuffer = malloc(data->size); 1.307 + ctxData->ctx = context; 1.308 + 1.309 + data->contexts[data->numContexts] = ctxData; 1.310 + data->numContexts++; 1.311 +} 1.312 + 1.313 + 1.314 +<span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">Context Switching </span> 1.315 + 1.316 +<span style="color: #708070;">/* </span><span style="color: #7f9f7f;">A device brings along with it two pieces of state</span> 1.317 +<span style="color: #7f9f7f;"> * which have to be swapped in and out with each context.</span> 1.318 +<span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> 1.319 +<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>){ 1.320 + memcpy(Device->ClickRemoval, ctxData->ClickRemoval, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(ALfloat)*MAXCHANNELS); 1.321 + memcpy(Device->PendingClicks, ctxData->PendingClicks, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(ALfloat)*MAXCHANNELS); 1.322 +} 1.323 + 1.324 +<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>){ 1.325 + memcpy(ctxData->ClickRemoval, Device->ClickRemoval, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(ALfloat)*MAXCHANNELS); 1.326 + memcpy(ctxData->PendingClicks, Device->PendingClicks, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(ALfloat)*MAXCHANNELS); 1.327 +} 1.328 + 1.329 +<span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> **<span style="color: #f0dfaf;">currentContext</span>; 1.330 +<span style="color: #f0dfaf; font-weight: bold;">static</span> <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">currentNumContext</span>; 1.331 + 1.332 +<span style="color: #708070;">/* </span><span style="color: #7f9f7f;">By default, all contexts are rendered at once for each call to aluMixData.</span> 1.333 +<span style="color: #7f9f7f;"> * This function uses the internals of the ALCdecice struct to temporarly </span> 1.334 +<span style="color: #7f9f7f;"> * cause aluMixData to only render the chosen context.</span> 1.335 +<span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> 1.336 +<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>){ 1.337 + currentContext = Device->Contexts; 1.338 + currentNumContext = Device->NumContexts; 1.339 + Device->Contexts = &ctx; 1.340 + Device->NumContexts = 1; 1.341 +} 1.342 + 1.343 +<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>){ 1.344 + Device->Contexts = currentContext; 1.345 + Device->NumContexts = currentNumContext; 1.346 +} 1.347 + 1.348 + 1.349 +<span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">Main Device Loop</span> 1.350 + 1.351 +<span style="color: #708070;">/* </span><span style="color: #7f9f7f;">Establish the LWJGL context as the main context, which will</span> 1.352 +<span style="color: #7f9f7f;"> * be synchronized to all the slave contexts</span> 1.353 +<span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> 1.354 +<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>){ 1.355 + <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">masterContext</span> = alcGetCurrentContext(); 1.356 + addContext(Device, masterContext); 1.357 +} 1.358 + 1.359 + 1.360 +<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>){ 1.361 + <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>;} 1.362 + <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; 1.363 + <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); 1.364 + 1.365 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">i</span>; 1.366 + <span style="color: #f0dfaf; font-weight: bold;">for</span> (i = 1; i < data->numContexts; i++){ 1.367 + syncContexts(data->contexts[0]->ctx , data->contexts[i]->ctx); 1.368 + } 1.369 + 1.370 + <span style="color: #f0dfaf; font-weight: bold;">if</span> ((<span style="color: #dfdfbf; font-weight: bold;">uint</span>) samples > Device->UpdateSize){ 1.371 + printf(<span style="color: #cc9393;">"exceeding internal buffer size; dropping samples\n"</span>); 1.372 + printf(<span style="color: #cc9393;">"requested %d; available %d\n"</span>, samples, Device->UpdateSize); 1.373 + samples = (<span style="color: #dfdfbf; font-weight: bold;">int</span>) Device->UpdateSize; 1.374 + } 1.375 + 1.376 + <span style="color: #f0dfaf; font-weight: bold;">for</span> (i = 0; i < data->numContexts; i++){ 1.377 + <span style="color: #dfdfbf; font-weight: bold;">context_data</span> *<span style="color: #f0dfaf;">ctxData</span> = data->contexts[i]; 1.378 + <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">ctx</span> = ctxData->ctx; 1.379 + alcMakeContextCurrent(ctx); 1.380 + limitContext(Device, ctx); 1.381 + swapInContext(Device, ctxData); 1.382 + aluMixData(Device, ctxData->renderBuffer, samples); 1.383 + saveContext(Device, ctxData); 1.384 + unLimitContext(Device); 1.385 + } 1.386 + alcMakeContextCurrent(current); 1.387 +} 1.388 + 1.389 + 1.390 +<span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">JNI Methods</span> 1.391 + 1.392 +<span style="color: #8cd0d3;">#include</span> <span style="color: #cc9393;">"com_jme3_capture_AudioSend.h"</span> 1.393 + 1.394 +<span style="color: #708070;">/*</span> 1.395 +<span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> 1.396 +<span style="color: #7f9f7f;"> * Method: nstep</span> 1.397 +<span style="color: #7f9f7f;"> * Signature: (JI)V</span> 1.398 +<span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> 1.399 +JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_nstep 1.400 +(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>){ 1.401 + UNUSED(env);UNUSED(clazz);UNUSED(device); 1.402 + renderData((<span style="color: #dfdfbf; font-weight: bold;">ALCdevice</span>*)((<span style="color: #dfdfbf; font-weight: bold;">intptr_t</span>)device), samples); 1.403 +} 1.404 + 1.405 +<span style="color: #708070;">/*</span> 1.406 +<span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> 1.407 +<span style="color: #7f9f7f;"> * Method: ngetSamples</span> 1.408 +<span style="color: #7f9f7f;"> * Signature: (JLjava/nio/ByteBuffer;III)V</span> 1.409 +<span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> 1.410 +JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_ngetSamples 1.411 +(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>, 1.412 + <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>){ 1.413 + UNUSED(clazz); 1.414 + 1.415 + <span style="color: #dfdfbf; font-weight: bold;">ALvoid</span> *<span style="color: #f0dfaf;">buffer_address</span> = 1.416 + ((<span style="color: #dfdfbf; font-weight: bold;">ALbyte</span> *)(((<span style="color: #dfdfbf; font-weight: bold;">char</span>*)(*env)->GetDirectBufferAddress(env, buffer)) + position)); 1.417 + <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); 1.418 + <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; 1.419 + <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>;} 1.420 + <span style="color: #f0dfaf; font-weight: bold;">if</span> ((<span style="color: #dfdfbf; font-weight: bold;">uint</span>) samples > data->size){ 1.421 + samples = (<span style="color: #dfdfbf; font-weight: bold;">int</span>) data->size; 1.422 + } 1.423 + memcpy(buffer_address, data->contexts[n]->renderBuffer, samples*<span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(ALfloat)); 1.424 +} 1.425 + 1.426 +<span style="color: #708070;">/*</span> 1.427 +<span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> 1.428 +<span style="color: #7f9f7f;"> * Method: naddListener</span> 1.429 +<span style="color: #7f9f7f;"> * Signature: (J)V</span> 1.430 +<span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> 1.431 +JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_naddListener 1.432 +(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>){ 1.433 + UNUSED(env); UNUSED(clazz); 1.434 + printf(<span style="color: #cc9393;">"creating new context via naddListener\n"</span>); 1.435 + <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); 1.436 + <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>); 1.437 + addContext(Device, new); 1.438 +} 1.439 + 1.440 +<span style="color: #708070;">/*</span> 1.441 +<span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> 1.442 +<span style="color: #7f9f7f;"> * Method: nsetNthListener3f</span> 1.443 +<span style="color: #7f9f7f;"> * Signature: (IFFFJI)V</span> 1.444 +<span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> 1.445 +JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_nsetNthListener3f 1.446 + (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>, 1.447 + <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>){ 1.448 + UNUSED(env);UNUSED(clazz); 1.449 + 1.450 + <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); 1.451 + <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; 1.452 + 1.453 + <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); 1.454 + <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>;} 1.455 + alcMakeContextCurrent(data->contexts[contextNum]->ctx); 1.456 + alListener3f(param, v1, v2, v3); 1.457 + alcMakeContextCurrent(current); 1.458 +} 1.459 + 1.460 +<span style="color: #708070;">/*</span> 1.461 +<span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> 1.462 +<span style="color: #7f9f7f;"> * Method: nsetNthListenerf</span> 1.463 +<span style="color: #7f9f7f;"> * Signature: (IFJI)V</span> 1.464 +<span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> 1.465 +JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_nsetNthListenerf 1.466 +(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>, 1.467 + <span style="color: #dfdfbf; font-weight: bold;">jint</span> <span style="color: #f0dfaf;">contextNum</span>){ 1.468 + 1.469 + UNUSED(env);UNUSED(clazz); 1.470 + 1.471 + <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); 1.472 + <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; 1.473 + 1.474 + <span style="color: #dfdfbf; font-weight: bold;">ALCcontext</span> *<span style="color: #f0dfaf;">current</span> = alcGetCurrentContext(); 1.475 + <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>;} 1.476 + alcMakeContextCurrent(data->contexts[contextNum]->ctx); 1.477 + alListenerf(param, v1); 1.478 + alcMakeContextCurrent(current); 1.479 +} 1.480 + 1.481 +<span style="color: #708070;">/*</span> 1.482 +<span style="color: #7f9f7f;"> * Class: com_jme3_capture_AudioSend</span> 1.483 +<span style="color: #7f9f7f;"> * Method: ninitDevice</span> 1.484 +<span style="color: #7f9f7f;"> * Signature: (J)V</span> 1.485 +<span style="color: #7f9f7f;"> </span><span style="color: #708070;">*/</span> 1.486 +JNIEXPORT <span style="color: #dfdfbf; font-weight: bold;">void</span> <span style="color: #f0dfaf;">JNICALL</span> Java_com_jme3_capture_AudioSend_ninitDevice 1.487 +(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>){ 1.488 + UNUSED(env);UNUSED(clazz); 1.489 + 1.490 + <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); 1.491 + init(Device); 1.492 + 1.493 +} 1.494 + 1.495 + 1.496 +<span style="color: #708070;">//////////////////// </span><span style="color: #7f9f7f;">Device Initilization / Management</span> 1.497 + 1.498 +<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>; 1.499 + 1.500 +<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>, 1.501 + <span style="color: #f0dfaf; font-weight: bold;">const</span> <span style="color: #dfdfbf; font-weight: bold;">ALCchar</span> *<span style="color: #f0dfaf;">deviceName</span>) 1.502 +{ 1.503 + <span style="color: #dfdfbf; font-weight: bold;">send_data</span> *<span style="color: #f0dfaf;">data</span>; 1.504 + <span style="color: #708070;">// </span><span style="color: #7f9f7f;">stop any buffering for stdout, so that I can </span> 1.505 + <span style="color: #708070;">// </span><span style="color: #7f9f7f;">see the printf statements in my terminal immediatley</span> 1.506 + setbuf(stdout, <span style="color: #dca3a3; font-weight: bold;">NULL</span>); 1.507 + 1.508 + <span style="color: #f0dfaf; font-weight: bold;">if</span>(<span style="color: #f0dfaf; font-weight: bold;">!</span>deviceName) 1.509 + deviceName = sendDevice; 1.510 + <span style="color: #f0dfaf; font-weight: bold;">else</span> <span style="color: #f0dfaf; font-weight: bold;">if</span>(strcmp(deviceName, sendDevice) != 0) 1.511 + <span style="color: #f0dfaf; font-weight: bold;">return</span> ALC_FALSE; 1.512 + data = (<span style="color: #dfdfbf; font-weight: bold;">send_data</span>*)calloc(1, <span style="color: #f0dfaf; font-weight: bold;">sizeof</span>(*data)); 1.513 + device->szDeviceName = strdup(deviceName); 1.514 + device->ExtraData = data; 1.515 + <span style="color: #f0dfaf; font-weight: bold;">return</span> ALC_TRUE; 1.516 +} 1.517 + 1.518 +<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>) 1.519 +{ 1.520 + <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; 1.521 + alcMakeContextCurrent(<span style="color: #dca3a3; font-weight: bold;">NULL</span>); 1.522 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">i</span>; 1.523 + <span style="color: #708070;">// </span><span style="color: #7f9f7f;">Destroy all slave contexts. LWJGL will take care of </span> 1.524 + <span style="color: #708070;">// </span><span style="color: #7f9f7f;">its own context.</span> 1.525 + <span style="color: #f0dfaf; font-weight: bold;">for</span> (i = 1; i < data->numContexts; i++){ 1.526 + <span style="color: #dfdfbf; font-weight: bold;">context_data</span> *<span style="color: #f0dfaf;">ctxData</span> = data->contexts[i]; 1.527 + alcDestroyContext(ctxData->ctx); 1.528 + free(ctxData->renderBuffer); 1.529 + free(ctxData); 1.530 + } 1.531 + free(data); 1.532 + device->ExtraData = <span style="color: #dca3a3; font-weight: bold;">NULL</span>; 1.533 +} 1.534 + 1.535 +<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>) 1.536 +{ 1.537 + <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; 1.538 + <span style="color: #dfdfbf; font-weight: bold;">ALuint</span> <span style="color: #f0dfaf;">channels</span>=0, <span style="color: #f0dfaf;">bits</span>=0; 1.539 + device->FmtType = DevFmtShort; 1.540 + bits = BytesFromDevFmt(device->FmtType) * 8; 1.541 + channels = ChannelsFromDevFmt(device->FmtChans); 1.542 + data->size = device->UpdateSize * channels * bits / 8; 1.543 + 1.544 + <span style="color: #f0dfaf; font-weight: bold;">return</span> ALC_TRUE; 1.545 +} 1.546 + 1.547 +<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>){ 1.548 + UNUSED(Device); 1.549 +} 1.550 + 1.551 +<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> = { 1.552 + send_open_playback, 1.553 + send_close_playback, 1.554 + send_reset_playback, 1.555 + send_stop_playback, 1.556 + <span style="color: #dca3a3; font-weight: bold;">NULL</span>, 1.557 + <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> 1.558 + <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> 1.559 + <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> 1.560 + <span style="color: #dca3a3; font-weight: bold;">NULL</span>, 1.561 + <span style="color: #dca3a3; font-weight: bold;">NULL</span> 1.562 +}; 1.563 + 1.564 +<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>){ 1.565 + *func_list = send_funcs; 1.566 + <span style="color: #f0dfaf; font-weight: bold;">return</span> ALC_TRUE; 1.567 +} 1.568 + 1.569 +<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>){} 1.570 + 1.571 +<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>) 1.572 +{ 1.573 + <span style="color: #f0dfaf; font-weight: bold;">switch</span>(type) 1.574 + { 1.575 + <span style="color: #f0dfaf; font-weight: bold;">case</span> DEVICE_PROBE: 1.576 + AppendDeviceList(sendDevice); 1.577 + <span style="color: #f0dfaf; font-weight: bold;">break</span>; 1.578 + <span style="color: #f0dfaf; font-weight: bold;">case</span> ALL_DEVICE_PROBE: 1.579 + AppendAllDeviceList(sendDevice); 1.580 + <span style="color: #f0dfaf; font-weight: bold;">break</span>; 1.581 + <span style="color: #f0dfaf; font-weight: bold;">case</span> CAPTURE_DEVICE_PROBE: 1.582 + <span style="color: #f0dfaf; font-weight: bold;">break</span>; 1.583 + } 1.584 +} 1.585 + 1.586 + 1.587 + 1.588 +</pre> 1.589 + 1.590 + 1.591 + 1.592 + 1.593 + 1.594 +<div id="postamble"> 1.595 +<p class="date">Date: 2011-10-20 15:48:47 MST</p> 1.596 +<p class="author">Author: Robert McIntyre</p> 1.597 +<p class="creator">Org version 7.6 with Emacs version 23</p> 1.598 +<a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a> 1.599 +</div> 1.600 +</div> 1.601 +</body> 1.602 +</html>