diff record.c @ 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/record.c	Tue Oct 25 13:02:31 2011 -0700
     1.3 @@ -0,0 +1,1199 @@
     1.4 +/**
     1.5 + * OpenAL cross platform audio library
     1.6 + * Copyright (C) 2010 by Chris Robinson
     1.7 + * This library is free software; you can redistribute it and/or
     1.8 + *  modify it under the terms of the GNU Library General Public
     1.9 + *  License as published by the Free Software Foundation; either
    1.10 + *  version 2 of the License, or (at your option) any later version.
    1.11 + *
    1.12 + * This library is distributed in the hope that it will be useful,
    1.13 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.15 + *  Library General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU Library General Public
    1.18 + *  License along with this library; if not, write to the
    1.19 + *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    1.20 + *  Boston, MA  02111-1307, USA.
    1.21 + * Or go to http://www.gnu.org/copyleft/lgpl.html
    1.22 + */
    1.23 +
    1.24 +#include "config.h"
    1.25 +#include <stdlib.h>
    1.26 +#include "alMain.h"
    1.27 +#include "AL/al.h"
    1.28 +#include "AL/alc.h"
    1.29 +#include "alSource.h"
    1.30 +#include <jni.h>
    1.31 +
    1.32 +
    1.33 +typedef struct record_data {
    1.34 +  volatile int killNow;
    1.35 +  ALvoid *thread;
    1.36 +  ALuint robert;
    1.37 +  
    1.38 +  ALvoid *mainBuffer;
    1.39 +  ALvoid *auxBuffer;
    1.40 +  ALuint size;
    1.41 +  
    1.42 +  ALuint *unPauseIDs;
    1.43 +  int    unPauseCount;
    1.44 +  ALboolean mainFull;
    1.45 +  ALboolean auxFull;
    1.46 +  ALboolean auxReady;
    1.47 +  ALboolean mainReady;
    1.48 +
    1.49 +} record_data;
    1.50 +
    1.51 +
    1.52 +
    1.53 +
    1.54 +#define UNUSED(x)  (void)(x)
    1.55 +#define RUNONLY(n)				\
    1.56 +  {static int __runonce = n;			\
    1.57 +    if (__runonce-- <= 0){return;}}
    1.58 +
    1.59 +#define RUNAT(n)				\
    1.60 +  {static int __runat = n;			\
    1.61 +    if (0 != __runat--){return;}}
    1.62 +
    1.63 +/// al error handling code prototypes
    1.64 +
    1.65 +char* GetALErrorString(ALenum err);
    1.66 +char* GetALCErrorString(ALenum err);
    1.67 +void printError(void);
    1.68 +void init(ALCdevice *);
    1.69 +void init2(ALCdevice *);
    1.70 +void later(ALCdevice *);
    1.71 +void every(ALCdevice *);
    1.72 +void every2(ALCdevice *);
    1.73 +void step(ALCdevice *);
    1.74 +
    1.75 +
    1.76 +//synchronization
    1.77 +struct record_data;
    1.78 +void syncContexts(ALCcontext *, ALCcontext *);
    1.79 +void syncSources(ALsource *, ALsource *, ALCcontext *, ALCcontext *);
    1.80 +void pauseMainContext(struct record_data *);
    1.81 +void unPauseMainContext(struct record_data *);
    1.82 +void pauseAllSources(ALCcontext *);
    1.83 +static void saveAux(ALCdevice *);
    1.84 +static void swapInAux(ALCdevice *);
    1.85 +static void saveMain(ALCdevice *);
    1.86 +static void swapInMain(ALCdevice *);
    1.87 +void aux_alListenerf(ALenum param, ALfloat value);
    1.88 +void aux_alListener3f(ALenum param, ALfloat v1, ALfloat v2, ALfloat v3);
    1.89 +
    1.90 +
    1.91 +//////////////
    1.92 +
    1.93 +
    1.94 +
    1.95 +// remove all the sources from all the auxContexts
    1.96 +// take the mainContext and for each context, COPY
    1.97 +// the sources from the main context.
    1.98 +
    1.99 +// render each context and make their data available.
   1.100 +
   1.101 +// =alGenSources= (and =alGetError=)
   1.102 +// attach each source to the shared buffer using =alSourcei=
   1.103 +
   1.104 +
   1.105 +// need to make sure in the AudioRender class that we don't do
   1.106 +// anything to sources while the audio is being rendered, so make sure
   1.107 +// to maintain an "isDone" state as well.
   1.108 +
   1.109 +// Special device which allows simulation of multiple listeners 
   1.110 +// hearing the same set of sources.  Provides access to the rendered
   1.111 +// data for each listener.  Designed to work with LWJGL.
   1.112 +
   1.113 +// first, the mainContext is the only context that is controlled by
   1.114 +// LWJGL.
   1.115 +
   1.116 +// One context will be created for each listener that we want.
   1.117 +
   1.118 +// Then, at the start of each render loop, first PAUSE the sources on
   1.119 +// all other contexts except the mainContext (this takes care of
   1.120 +// sources in the mainContext being shut down.)
   1.121 +// we will iterate through all
   1.122 +// the active sources in our mainContext (the one which is controlled
   1.123 +// through LWJGL), and take their sourceIDs.  For each of these IDs
   1.124 +// and for each other context, we'll check some internal structure to
   1.125 +// see if we've already created a corresponding source.  If that
   1.126 +// source exits, we will SYNCH it with the source which belongs to the
   1.127 +// mainContext. If it DOESN'T exist, we will CLONE the source from the
   1.128 +// main context and establish it in the other context.
   1.129 +
   1.130 +// Each render loop consists of noting all of the active sources in
   1.131 +// the mainContext and storing their IDs.  Then, for each context,
   1.132 +// the correspondig sources to the active sources in the mainContext
   1.133 +// will be set to PLAY, and all sources in all other contexts will be
   1.134 +// set to PAUSE. aluMixData will be called for each context in this
   1.135 +// way.
   1.136 +
   1.137 +// approved by KittyCat
   1.138 +
   1.139 +
   1.140 +// CAN get id appropiate for us in the sorce-repated openal functions
   1.141 +// by quering *source->source
   1.142 +
   1.143 +// first, do it with only two listeners, two contexts, automatically
   1.144 +// created.
   1.145 +
   1.146 +static ALCcontext* mainContext = NULL;
   1.147 +static ALCcontext* auxContext  = NULL;
   1.148 +
   1.149 +
   1.150 +void aux_alListenerf(ALenum param, ALfloat value){
   1.151 +  ALCcontext *current = alcGetCurrentContext();
   1.152 +  alcMakeContextCurrent(auxContext);
   1.153 +  alListenerf(param, value);
   1.154 +  alcMakeContextCurrent(current);
   1.155 +}
   1.156 +
   1.157 +void aux_alListener3f(ALenum param, ALfloat v1, ALfloat v2, ALfloat v3){
   1.158 +  ALCcontext *current = alcGetCurrentContext();
   1.159 +  alcMakeContextCurrent(auxContext);
   1.160 +  alListener3f(param, v1, v2, v3);
   1.161 +  alcMakeContextCurrent(current);
   1.162 +}
   1.163 +
   1.164 +
   1.165 +
   1.166 +void pauseAllSources(ALCcontext *ctx){
   1.167 +  ALCcontext *current = alcGetCurrentContext();
   1.168 +  alcMakeContextCurrent(ctx);
   1.169 +  ALsource **src, **src_end;
   1.170 +  src     = ctx->ActiveSources;
   1.171 +  src_end = src + ctx->ActiveSourceCount;
   1.172 +  while(src != src_end){
   1.173 +    if (AL_PLAYING == (*src)->state){
   1.174 +    //if (AL_TRUE){
   1.175 +      ALuint source_id = (*src)->source;
   1.176 +      //printf("pausing ONE source\n");
   1.177 +      alSourcePause(source_id);
   1.178 +    }
   1.179 +    src++;
   1.180 +  }
   1.181 +  alcMakeContextCurrent(current);
   1.182 +}
   1.183 +
   1.184 +
   1.185 +void init2(ALCdevice *Device){
   1.186 +  UNUSED(Device);
   1.187 +  RUNONLY(1)
   1.188 +  // the mainContext only ever has a FIXED number of sources!
   1.189 +  // duplicate them ALL into auxContext!
   1.190 +  alcMakeContextCurrent(auxContext);{
   1.191 +    UIntMap source_map= mainContext->SourceMap;
   1.192 +    ALuint num_sources = source_map.size;
   1.193 +    ALuint newSources[num_sources];
   1.194 +    alGenSources(num_sources, newSources);}
   1.195 +  alcMakeContextCurrent(mainContext);
   1.196 +
   1.197 +
   1.198 +}
   1.199 +
   1.200 +
   1.201 +
   1.202 +  /*
   1.203 +void syncSourcei(ALuint sourceID1, ALuint sourceID2, 
   1.204 +		 ALCcontext *ctx1, ALCcontext *ctx2,
   1.205 +		 int numParams, ALenum *params){
   1.206 +  ALint values[numParams];
   1.207 +  ALCcontext current = alcGetCurrentContext();
   1.208 +  // get values
   1.209 +  printf("getting values from source1\n");
   1.210 +  alcMakeContextCurrent(ctx1);
   1.211 +  int i;
   1.212 +  for(i=0; i<numParams; i++){
   1.213 +    alGetSourcei(sourceID1, params[i], values+i);
   1.214 +    printf("value is %d\n", values[i]);
   1.215 +    printError();
   1.216 +  }
   1.217 +  // set values
   1.218 +  printf("setting values of source2\n");
   1.219 +  alcMakeContextCurrent(ctx2);
   1.220 +  for (i=0; i<numParams; i++){
   1.221 +    alSourcei(sourceID2, params[i], values[i]);
   1.222 +    printError();
   1.223 +  }
   1.224 +  alcMakeContextCurrent(current);
   1.225 +  printError();
   1.226 +}
   1.227 +  */
   1.228 +
   1.229 +
   1.230 +#define _MAKE_SYNC(NAME, INIT_EXPR, GET_EXPR, SET_EXPR)	\
   1.231 +  void NAME (ALuint sourceID1, ALuint sourceID2,	\
   1.232 +	     ALCcontext *ctx1, ALCcontext *ctx2,	\
   1.233 +	     ALenum param){				\
   1.234 +    INIT_EXPR;						\
   1.235 +    ALCcontext *current = alcGetCurrentContext();	\
   1.236 +    alcMakeContextCurrent(ctx1);			\
   1.237 +    GET_EXPR;						\
   1.238 +    /*printError();*/					\
   1.239 +    alcMakeContextCurrent(ctx2);			\
   1.240 +    SET_EXPR;						\
   1.241 +    /*printError();*/					\
   1.242 +    alcMakeContextCurrent(current);			\
   1.243 +  }
   1.244 +  
   1.245 +#define MAKE_SYNC(NAME, TYPE, GET, SET)			\
   1.246 +  _MAKE_SYNC(NAME,					\
   1.247 +	     TYPE value,				\
   1.248 +             GET(sourceID1, param, &value),		\
   1.249 +             SET(sourceID2, param, value))
   1.250 +  
   1.251 +#define MAKE_SYNC3(NAME, TYPE, GET, SET)				\
   1.252 +  _MAKE_SYNC(NAME,							\
   1.253 +	     TYPE value1; TYPE value2; TYPE value3;,			\
   1.254 +	     GET(sourceID1, param, &value1, &value2, &value3),		\
   1.255 +	     SET(sourceID2, param,  value1,  value2,  value3))
   1.256 +
   1.257 +MAKE_SYNC( syncSourcei,  ALint,   alGetSourcei,  alSourcei);
   1.258 +MAKE_SYNC( syncSourcef,  ALfloat, alGetSourcef,  alSourcef);
   1.259 +MAKE_SYNC3(syncSource3i, ALint,   alGetSource3i, alSource3i);
   1.260 +MAKE_SYNC3(syncSource3f, ALfloat, alGetSource3f, alSource3f);
   1.261 +  
   1.262 +
   1.263 +
   1.264 +
   1.265 +  
   1.266 +
   1.267 +#define DsyncSourcei(sourceID1, sourceID2, ctx1, ctx2, param)	\
   1.268 +  {/*printf("synci : " #param "\n");*/				\
   1.269 +    syncSourcei(sourceID1, sourceID2, ctx1, ctx2, param);}
   1.270 +
   1.271 +#define DsyncSourcef(sourceID1, sourceID2, ctx1, ctx2, param)	\
   1.272 +  {/*printf("syncf : " #param "\n");*/				\
   1.273 +    syncSourcef(sourceID1, sourceID2, ctx1, ctx2, param);}
   1.274 +
   1.275 +#define DsyncSource3i(sourceID1, sourceID2, ctx1, ctx2, param)	\
   1.276 +  {/*printf("sync3i : " #param "\n");*/				\
   1.277 +    syncSource3i(sourceID1, sourceID2, ctx1, ctx2, param);}
   1.278 +
   1.279 +#define DsyncSource3f(sourceID1, sourceID2, ctx1, ctx2, param)	\
   1.280 +  {/*printf("sync3f : " #param "\n");*/				\
   1.281 +    syncSource3f(sourceID1, sourceID2, ctx1, ctx2, param);}
   1.282 +
   1.283 +void printValid(ALuint sourceID){
   1.284 +  alcMakeContextCurrent(auxContext);
   1.285 +  printf("source%d : %s\n", sourceID, alIsSource(sourceID) ? "VALID" : "INVALID");
   1.286 +  alcMakeContextCurrent(mainContext);
   1.287 +}
   1.288 +
   1.289 +
   1.290 +
   1.291 +void syncSources(ALsource *source1, ALsource *source2, 
   1.292 +		 ALCcontext *ctx1, ALCcontext *ctx2){
   1.293 +
   1.294 +  ALuint ID1 = source1->source;
   1.295 +  ALuint ID2 = source2->source;
   1.296 +  ALCcontext *current = alcGetCurrentContext();
   1.297 +  //printf("***************\n");
   1.298 +  //printf("SYNCHING source %d with source %d\n", ID1, ID2);
   1.299 +  
   1.300 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_PITCH);
   1.301 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_GAIN);
   1.302 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_MAX_DISTANCE);
   1.303 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_ROLLOFF_FACTOR);
   1.304 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_REFERENCE_DISTANCE);
   1.305 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_MIN_GAIN);
   1.306 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_MAX_GAIN);
   1.307 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_CONE_OUTER_GAIN);
   1.308 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_CONE_INNER_ANGLE);
   1.309 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_CONE_OUTER_ANGLE);
   1.310 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_SEC_OFFSET);
   1.311 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_SAMPLE_OFFSET);
   1.312 +  DsyncSourcef(ID1,ID2,ctx1,ctx2,AL_BYTE_OFFSET);
   1.313 +    
   1.314 +  DsyncSource3f(ID1,ID2,ctx1,ctx2,AL_POSITION);
   1.315 +  DsyncSource3f(ID1,ID2,ctx1,ctx2,AL_VELOCITY);
   1.316 +  DsyncSource3f(ID1,ID2,ctx1,ctx2,AL_DIRECTION);
   1.317 +  
   1.318 +  DsyncSourcei(ID1,ID2,ctx1,ctx2,AL_SOURCE_RELATIVE);
   1.319 +  DsyncSourcei(ID1,ID2,ctx1,ctx2,AL_LOOPING);
   1.320 +
   1.321 +
   1.322 +
   1.323 +
   1.324 +
   1.325 +  // first, copy buffer patterns over.
   1.326 +
   1.327 +  //source2->lSourceType = source1->lSourceType;
   1.328 +  //source2->NumChannels = source1->NumChannels;
   1.329 +  //source2->SampleSize = source1->SampleSize;
   1.330 +  //source2->Buffer = source1->Buffer;
   1.331 +  // source2->queue  = source1->queue;
   1.332 +  // source2->BuffersInQueue = source1-> BuffersInQueue;
   1.333 +  // source2->BuffersPlayed = source1 -> BuffersPlayed;
   1.334 +
   1.335 +  // then, duplicate the state.
   1.336 +
   1.337 +  // handle static sources
   1.338 +  //printf("handling Buffers\n");
   1.339 +  alcMakeContextCurrent(ctx1);
   1.340 +  ALint source_type;
   1.341 +  alGetSourcei(ID1, AL_SOURCE_TYPE, &source_type);
   1.342 +  //printError();
   1.343 +  
   1.344 +  if (AL_STATIC == source_type){
   1.345 +    //printf("setting STATIC source\n");
   1.346 +    ALint buffer_id1;
   1.347 +    ALint buffer_id2;
   1.348 +    alGetSourcei(ID1, AL_BUFFER, &buffer_id1);
   1.349 +    alcMakeContextCurrent(ctx2);
   1.350 +    alGetSourcei(ID2, AL_BUFFER, &buffer_id2);
   1.351 +    if (buffer_id1 != buffer_id2){
   1.352 +      //printf("setting source2's buffer from %d to %d\n", buffer_id2, buffer_id1);
   1.353 +      alSourcei(ID2, AL_BUFFER, buffer_id1);
   1.354 +      //printError();
   1.355 +    }
   1.356 +    else {
   1.357 +      //printf("Buffers are already the same, doing nothing.\n");
   1.358 +    }
   1.359 +  }
   1.360 +  else {
   1.361 +    // printf("not a static source!\n");
   1.362 +  }
   1.363 +    
   1.364 +
   1.365 +
   1.366 +
   1.367 +
   1.368 +
   1.369 +  alcMakeContextCurrent(ctx2);
   1.370 +  
   1.371 +  
   1.372 +
   1.373 +
   1.374 +  //printf("setting STATE\n");
   1.375 +  alcMakeContextCurrent(ctx1);
   1.376 +  ALint state1;
   1.377 +  alGetSourcei(ID1, AL_SOURCE_STATE, &state1);
   1.378 +  //printError();
   1.379 +
   1.380 +  alcMakeContextCurrent(ctx2);
   1.381 +  ALint state2;
   1.382 +  alGetSourcei(ID2, AL_SOURCE_STATE, &state2);
   1.383 +  //printError();
   1.384 +  if (state1 != state2){
   1.385 +    switch (state1){
   1.386 +    case AL_INITIAL : /*printf("INITIAL\n")*/;alSourceRewind(ID2);break;
   1.387 +    case AL_PLAYING : /*printf("PLAYING\n")*/;alSourcePlay(ID2);break;
   1.388 +    case AL_PAUSED  : /*printf("PAUSED\n")*/;alSourcePause(ID2);break;
   1.389 +    case AL_STOPPED : /*printf("STOPPED\n")*/;alSourceStop(ID2);break;
   1.390 +    }
   1.391 +  }
   1.392 +  //printError();
   1.393 +  
   1.394 +  
   1.395 +
   1.396 +  alcMakeContextCurrent(current);
   1.397 +
   1.398 +}
   1.399 +
   1.400 +
   1.401 +void syncContexts(ALCcontext *ctx1, ALCcontext *ctx2){
   1.402 +  // if there aren't sufficient sources in ctx2 to mirror the sources
   1.403 +  // in ctx1, create them.
   1.404 +  ALCcontext *current = alcGetCurrentContext();
   1.405 +
   1.406 +  UIntMap *sourceMap1 = &(ctx1->SourceMap);
   1.407 +  UIntMap *sourceMap2 = &(ctx2->SourceMap);
   1.408 +
   1.409 +
   1.410 +  ALuint sources1 = sourceMap1->size;
   1.411 +  ALuint sources2 = sourceMap2->size;
   1.412 +
   1.413 +  //printf("ctx1 has %d sources; ctx2 has %d sources\n", sources1, sources2);
   1.414 +  
   1.415 +  alcMakeContextCurrent(ctx2);
   1.416 +  if (sources2 < sources1){
   1.417 +    ALuint numSources = sources1 - sources2;
   1.418 +    ALuint newSources[numSources];
   1.419 +    alGenSources(numSources, newSources);
   1.420 +    printf("adjusting...\n");
   1.421 +    printf("now ctx1 has %d sources; ctx2 has %d sources\n", 
   1.422 +	   sourceMap1->size, sourceMap2->size);
   1.423 +  }
   1.424 +  //printError();
   1.425 +  
   1.426 +
   1.427 +  alcMakeContextCurrent(current);
   1.428 +  
   1.429 +  
   1.430 +  // after this, ctx2 is gauranteed to have at least as many sources
   1.431 +  // as ctx1.  Now, sync each source from ctx1 to the corresponding
   1.432 +  // source in ctx2.
   1.433 +
   1.434 +  int i;
   1.435 +
   1.436 +
   1.437 +  
   1.438 +  for(i = 0; i < sourceMap1->size; i++){
   1.439 +    syncSources((ALsource*)sourceMap1->array[i].value,
   1.440 +		(ALsource*)sourceMap2->array[i].value,
   1.441 +		ctx1, ctx2);
   1.442 +  }
   1.443 +  
   1.444 +
   1.445 +  
   1.446 + 
   1.447 +
   1.448 +}
   1.449 +
   1.450 +
   1.451 +
   1.452 +void pauseMainContext(record_data *data){
   1.453 +  //printf("pausing MainContext\n");
   1.454 +  data->unPauseCount = 0;
   1.455 +  data->unPauseIDs = 
   1.456 +    (ALuint*)realloc(data->unPauseIDs, 
   1.457 +		     sizeof(ALuint) * mainContext->ActiveSourceCount);
   1.458 +
   1.459 +  ALsource **src, **src_end;
   1.460 +  src     = mainContext->ActiveSources;
   1.461 +  src_end = src + mainContext->ActiveSourceCount;
   1.462 +  
   1.463 +  while(src != src_end){
   1.464 +    
   1.465 +    if (AL_PLAYING == (*src)->state){
   1.466 +      ALuint source_id = (*src)->source;
   1.467 +      data->unPauseIDs[data->unPauseCount++] = source_id;
   1.468 +      alSourcePause(source_id);
   1.469 +    }
   1.470 +    src++; 
   1.471 +  }
   1.472 +}
   1.473 +
   1.474 +
   1.475 +
   1.476 +
   1.477 +void unPauseMainContext(record_data *data){
   1.478 +  int i;
   1.479 +  for(i=0;i<data->unPauseCount;i++){
   1.480 +    alSourcePlay(data->unPauseIDs[i]);
   1.481 +  }
   1.482 +}
   1.483 +
   1.484 +
   1.485 +// a device brings along with it multiple pieces of state
   1.486 +// which have to be swapped in and out with each context.
   1.487 +
   1.488 +//static ALfloat DryBufferMain[BUFFERSIZE][MAXCHANNELS];
   1.489 +//static ALfloat DryBufferAux[BUFFERSIZE][MAXCHANNELS];
   1.490 +//static ALfloat PanningLUTMain[LUT_NUM][MAXCHANNELS];
   1.491 +//static ALfloat PanningLUTAux[LUT_NUM][MAXCHANNELS];
   1.492 +static ALfloat ClickRemovalMain[MAXCHANNELS];
   1.493 +static ALfloat ClickRemovalAux[MAXCHANNELS];
   1.494 +static ALfloat PendingClicksMain[MAXCHANNELS];
   1.495 +static ALfloat PendingClicksAux[MAXCHANNELS];
   1.496 +
   1.497 +
   1.498 +
   1.499 +static void saveAux(ALCdevice *Device){
   1.500 +  //memcpy(DryBufferAux, Device->DryBuffer, sizeof(ALfloat)*BUFFERSIZE*MAXCHANNELS);
   1.501 +  //memcpy(PanningLUTAux, Device->PanningLUT, sizeof(ALfloat)*LUT_NUM*MAXCHANNELS);
   1.502 +  memcpy(ClickRemovalAux, Device->ClickRemoval, sizeof(ALfloat)*MAXCHANNELS);
   1.503 +  memcpy(PendingClicksAux, Device->PendingClicks, sizeof(ALfloat)*MAXCHANNELS);
   1.504 +}
   1.505 +static void swapInAux(ALCdevice *Device){
   1.506 +  //memcpy(Device->DryBuffer, DryBufferAux, sizeof(ALfloat)*BUFFERSIZE*MAXCHANNELS);
   1.507 +  //memcpy(Device->PanningLUT, PanningLUTAux, sizeof(ALfloat)*LUT_NUM*MAXCHANNELS);
   1.508 +  memcpy(Device->ClickRemoval, ClickRemovalAux, sizeof(ALfloat)*MAXCHANNELS);
   1.509 +  memcpy(Device->PendingClicks, PendingClicksAux, sizeof(ALfloat)*MAXCHANNELS);
   1.510 +}
   1.511 +
   1.512 +
   1.513 +static void saveMain(ALCdevice *Device){
   1.514 +  //memcpy(DryBufferMain, Device->DryBuffer, sizeof(ALfloat)*BUFFERSIZE*MAXCHANNELS);
   1.515 +  //memcpy(PanningLUTMain, Device->PanningLUT, sizeof(ALfloat)*LUT_NUM*MAXCHANNELS);
   1.516 +  memcpy(ClickRemovalMain, Device->ClickRemoval, sizeof(ALfloat)*MAXCHANNELS);
   1.517 +  memcpy(PendingClicksMain, Device->PendingClicks, sizeof(ALfloat)*MAXCHANNELS);
   1.518 +}
   1.519 +static void swapInMain(ALCdevice *Device){
   1.520 +  //memcpy(Device->DryBuffer, DryBufferMain, sizeof(ALfloat)*BUFFERSIZE*MAXCHANNELS);
   1.521 +  //memcpy(Device->PanningLUT, PanningLUTMain, sizeof(ALfloat)*LUT_NUM*MAXCHANNELS);
   1.522 +  memcpy(Device->ClickRemoval, ClickRemovalMain, sizeof(ALfloat)*MAXCHANNELS);
   1.523 +  memcpy(Device->PendingClicks, PendingClicksMain, sizeof(ALfloat)*MAXCHANNELS);
   1.524 +}
   1.525 +
   1.526 +
   1.527 +static ALCcontext **currentContext;
   1.528 +static ALuint currentNumContext;
   1.529 +static void unLimitContext(ALCdevice *Device){
   1.530 +  Device->Contexts = currentContext;
   1.531 +  Device->NumContexts = currentNumContext;
   1.532 +}
   1.533 +
   1.534 +static void limitContext(ALCdevice *Device, ALCcontext *ctx){
   1.535 +  currentContext  = Device->Contexts;
   1.536 +  currentNumContext  = Device->NumContexts;
   1.537 +  Device->Contexts = &ctx;
   1.538 +  Device->NumContexts = 1;
   1.539 +}
   1.540 +
   1.541 +
   1.542 +void every2(ALCdevice *Device){
   1.543 +
   1.544 +  record_data *data = (record_data*)Device->ExtraData;
   1.545 +
   1.546 +  if (data->mainFull){
   1.547 +    printf("data has not yet been extracted!\n");
   1.548 +    return;
   1.549 +  }
   1.550 +
   1.551 +  
   1.552 +  syncContexts(mainContext , auxContext);
   1.553 +
   1.554 +  alcMakeContextCurrent(auxContext);
   1.555 +  limitContext(Device, auxContext);
   1.556 +  swapInAux(Device);
   1.557 +  aluMixData(Device, data->auxBuffer, Device->UpdateSize);
   1.558 +  saveAux(Device);
   1.559 +  unLimitContext(Device);
   1.560 +  
   1.561 +
   1.562 +  alcMakeContextCurrent(mainContext);
   1.563 +  limitContext(Device, mainContext);
   1.564 +  swapInMain(Device);
   1.565 +  aluMixData(Device, data->mainBuffer, Device->UpdateSize);
   1.566 +  saveMain(Device);
   1.567 +  unLimitContext(Device);
   1.568 +    
   1.569 +  data->mainFull = AL_TRUE;
   1.570 +  data->auxFull = AL_TRUE;
   1.571 +
   1.572 +}
   1.573 +
   1.574 +
   1.575 +
   1.576 +
   1.577 +
   1.578 +
   1.579 +void every(ALCdevice *Device){
   1.580 +  UNUSED(Device);
   1.581 +  // by the time every() is called, mainContext and auxContext will
   1.582 +  // have been initiliazed.
   1.583 +  printf("+++++++\nevery is called\n");
   1.584 +  // print sourceid for all sources.
   1.585 +  ALsource **src, **src_end;
   1.586 +  //  LockDevice(Device);
   1.587 +  //  pauseAllSources(auxContext);
   1.588 +  src     = mainContext->ActiveSources;
   1.589 +  src_end = src + mainContext->ActiveSourceCount;
   1.590 +  UIntMap source_map ;
   1.591 +  int i;
   1.592 +
   1.593 +  source_map= mainContext->SourceMap;
   1.594 +  printf("max sources in the mainContext is %d\n", source_map.maxsize);
   1.595 +  printf("current sources: %d\n", source_map.size);
   1.596 +
   1.597 +  printf("their ID's are:\n");
   1.598 +  for(i = 0; i < source_map.size; i++){
   1.599 +    printf("%d, ",source_map.array[i].key);
   1.600 +  }
   1.601 +  printf("\n");
   1.602 +  source_map= auxContext->SourceMap;
   1.603 +  printf("max sources in the auxContext is %d\n", source_map.maxsize);
   1.604 +  printf("current sources: %d\n", source_map.size);
   1.605 + 
   1.606 +  printf("their ID's are:\n");
   1.607 +  for(i = 0; i < source_map.size; i++){
   1.608 +    printf("%d, ",source_map.array[i].key);
   1.609 +  }
   1.610 +  printf("\n");
   1.611 +
   1.612 +  while(src != src_end){
   1.613 +    
   1.614 +    if (AL_PLAYING == (*src)->state){
   1.615 +      ALuint source_id = (*src)->source;
   1.616 +      printf("source %d is AL_PLAYING\n",source_id);      
   1.617 +    }
   1.618 +    src++;
   1.619 +
   1.620 +  }
   1.621 +
   1.622 +
   1.623 +  //  UnlockDevice(Device);
   1.624 +}
   1.625 +
   1.626 +
   1.627 +
   1.628 +
   1.629 +
   1.630 +
   1.631 +
   1.632 +// debug printing
   1.633 +
   1.634 +#define DEBUG 0
   1.635 +
   1.636 +#define dprintf(expr) {if (DEBUG) {printf(expr);}}
   1.637 +
   1.638 +
   1.639 +
   1.640 +
   1.641 +static const ALCchar recordDevice[] = "Aurellem";
   1.642 +
   1.643 +
   1.644 +
   1.645 +
   1.646 +
   1.647 +
   1.648 +struct ALsource * cloneSource(struct ALsource *source);
   1.649 +
   1.650 +//struct ALsource * cloneSource(struct ALsource *source){
   1.651 +//  ALuint[1] sourceID;
   1.652 +  
   1.653 +
   1.654 +//}
   1.655 +
   1.656 +int lock = 0;
   1.657 +
   1.658 +/*
   1.659 +static ALuint RecordProc()
   1.660 +{
   1.661 +  if (0 == lock){return 0;}
   1.662 +  ALCdevice *Device = deviceInstance;
   1.663 +  dprintf("RLM: recordProc is begun!!\n");
   1.664 +  printError();
   1.665 +  static int MixCount = 0 ;
   1.666 +  if (Device->Connected)
   1.667 +    {
   1.668 +      // the device does not seem to be "ready" until this point.
   1.669 +      init(Device);
   1.670 +      //init2(Device);
   1.671 +      printf("\nMix Cycle %d\n", MixCount++);
   1.672 +      every(Device);
   1.673 +      every2(Device);
   1.674 +      //aluMixData(Device, NULL, Device->UpdateSize);
   1.675 +    }
   1.676 +  lock = 1;
   1.677 +  return 0;
   1.678 +}
   1.679 +*/
   1.680 +
   1.681 +
   1.682 + /*
   1.683 +static ALuint RecordProc(ALvoid *ptr)
   1.684 +{
   1.685 +  
   1.686 +  printf("RLM: recordProc is begun!!\n");
   1.687 +  ALCdevice *Device = (ALCdevice*)ptr;
   1.688 +  //printError();
   1.689 +  record_data *data = (record_data*)Device->ExtraData;
   1.690 +  ALuint now, start;
   1.691 +  ALuint64 avail, done;
   1.692 +  const ALuint restTime = (ALuint64)Device->UpdateSize * 1000 /
   1.693 +    Device->Frequency / 2;
   1.694 +
   1.695 +  done = 0;
   1.696 +  start = timeGetTime();
   1.697 +  //static int MixCount = 0 ;
   1.698 +
   1.699 +
   1.700 +  if(!data->killNow && Device->Connected)
   1.701 +    {
   1.702 +      printf("sext level breakfast manuever!\n");
   1.703 +      now = timeGetTime();
   1.704 +	
   1.705 +      avail = (ALuint64)(now-start) * Device->Frequency / 1000;
   1.706 +      if(avail < done)
   1.707 +        {
   1.708 +	 
   1.709 +	  avail += (ALuint64)0xFFFFFFFFu*Device->Frequency/1000 - done;
   1.710 +	  done = 0;
   1.711 +        }
   1.712 +      if(avail-done < Device->UpdateSize)
   1.713 +        {
   1.714 +	  //Sleep(restTime); 
   1.715 +	  //continue;
   1.716 +        }
   1.717 +
   1.718 +      while(avail-done >= Device->UpdateSize)
   1.719 +        {
   1.720 +	  // the device does not seem to be "ready" until this point.
   1.721 +	  init(Device);
   1.722 +	  //init2(Device);
   1.723 +	  //printf("\nMix Cycle %d\n", MixCount++);
   1.724 +	  //every(Device);
   1.725 +	  every2(Device);
   1.726 +	  //later(Device);
   1.727 +	  //printError();
   1.728 +	  //aluMixData(Device, NULL, Device->UpdateSize);
   1.729 +	  //Sleep(3000);
   1.730 +	  done += Device->UpdateSize;
   1.731 +        }
   1.732 +    }
   1.733 +  else {
   1.734 +    printf("WARNGING\n");
   1.735 +  }
   1.736 +
   1.737 +  return 0;
   1.738 +}
   1.739 +*/
   1.740 +
   1.741 +
   1.742 +
   1.743 +static ALuint RecordProc(ALCdevice *Device)
   1.744 +{
   1.745 +  
   1.746 +  //printf("RLM: recordProc is begun!!\n");
   1.747 +  //  ALCdevice *Device = (ALCdevice*)ptr;
   1.748 +
   1.749 +  record_data *data = (record_data*)Device->ExtraData;
   1.750 +
   1.751 +  if(!data->killNow && Device->Connected)
   1.752 +    {
   1.753 +      
   1.754 +      if (AL_TRUE)
   1.755 +        {
   1.756 +	  // the device does not seem to be "ready" until this point.
   1.757 +	  init(Device);
   1.758 +	  //init2(Device);
   1.759 +	  //printf("\nMix Cycle %d\n", MixCount++);
   1.760 +	  //every(Device);
   1.761 +	  every2(Device);
   1.762 +	  //later(Device);
   1.763 +	  //printError();
   1.764 +	  //aluMixData(Device, NULL, Device->UpdateSize);
   1.765 +	  //Sleep(3000);
   1.766 +        }
   1.767 +    }
   1.768 +  else {
   1.769 +    printf("WARNGING\n");
   1.770 +  }
   1.771 +  
   1.772 +  return 0;
   1.773 +}
   1.774 +
   1.775 +
   1.776 +void init(ALCdevice *Device){
   1.777 +  RUNONLY(1);
   1.778 +  printf("one time init\n");
   1.779 +  printError();
   1.780 +  printf("auxContext  : %p\n", auxContext);
   1.781 +  auxContext = alcCreateContext(Device,NULL);
   1.782 +  printf("auxContext  : %p\n", auxContext);
   1.783 +  printError();
   1.784 +  printf("mainContext : %p\n", mainContext);
   1.785 +  mainContext = alcGetCurrentContext();
   1.786 +  printf("mainContext : %p\n", mainContext);
   1.787 +  printError();
   1.788 +  printf("setting listener properties\n");
   1.789 +  alcMakeContextCurrent(auxContext);
   1.790 +  ALfloat val1;
   1.791 +  ALfloat val2;
   1.792 +  ALfloat val3;
   1.793 +  alGetListener3f(AL_POSITION, &val1, &val2, &val3);
   1.794 +  printf("location is [%f,%f,%f]\n", val1,val2,val3);
   1.795 +  alGetListener3f(AL_VELOCITY, &val1, &val2, &val3);
   1.796 +  printf("velocity is [%f,%f,%f]\n", val1,val2,val3);
   1.797 +  saveAux(Device);
   1.798 +  saveMain(Device);
   1.799 +}
   1.800 +
   1.801 +void later(ALCdevice *Device){
   1.802 +  // run only the third time it is called
   1.803 +  UNUSED(Device);
   1.804 +  RUNAT(3);
   1.805 +  printf("Suspending main Context....\n");
   1.806 +  alcSuspendContext(mainContext);
   1.807 +  printError();
   1.808 +  printf("Switching to aux Context...\n");
   1.809 +  alcMakeContextCurrent(auxContext);
   1.810 +  printError();
   1.811 +}
   1.812 +
   1.813 +
   1.814 +
   1.815 +static ALCboolean record_open_playback(ALCdevice *device, const ALCchar *deviceName)
   1.816 +{
   1.817 +  record_data *data;
   1.818 +  // stop any buffering for stdout, so that I can 
   1.819 +  // see the damm printf statements in my terminal immediatley
   1.820 +  setbuf(stdout, NULL);
   1.821 +
   1.822 +  dprintf("open_playback is called.\n");
   1.823 +  if(!deviceName)
   1.824 +    deviceName = recordDevice;
   1.825 +  else if(strcmp(deviceName, recordDevice) != 0)
   1.826 +    return ALC_FALSE;
   1.827 +
   1.828 +  data = (record_data*)calloc(1, sizeof(*data));
   1.829 +    
   1.830 +  device->szDeviceName = strdup(deviceName);
   1.831 +  data->robert = 5;
   1.832 +  device->ExtraData = data;
   1.833 +    
   1.834 +  return ALC_TRUE;
   1.835 +}
   1.836 +
   1.837 +static void record_close_playback(ALCdevice *device)
   1.838 +{
   1.839 +  record_data *data = (record_data*)device->ExtraData;
   1.840 +  dprintf("RLM: close playback called\n");
   1.841 +  free(data);
   1.842 +  device->ExtraData = NULL;
   1.843 +}
   1.844 +
   1.845 +
   1.846 +
   1.847 +
   1.848 +
   1.849 +static ALCboolean record_reset_playback(ALCdevice *device)
   1.850 +{
   1.851 +  record_data *data = (record_data*)device->ExtraData;
   1.852 +  dprintf("RLM: reset playback called\n");
   1.853 +
   1.854 +  ALuint channels=0, bits=0;
   1.855 +
   1.856 +  
   1.857 +
   1.858 +  switch(device->FmtType)
   1.859 +    {
   1.860 +    case DevFmtByte:
   1.861 +      device->FmtType = DevFmtUByte;
   1.862 +      break;
   1.863 +    case DevFmtUShort:
   1.864 +      device->FmtType = DevFmtShort;
   1.865 +      break;
   1.866 +    case DevFmtUByte:
   1.867 +    case DevFmtShort:
   1.868 +    case DevFmtFloat:
   1.869 +      break;
   1.870 +    }
   1.871 +  bits = BytesFromDevFmt(device->FmtType) * 8;
   1.872 +  channels = ChannelsFromDevFmt(device->FmtChans);
   1.873 +  data->size = device->UpdateSize * channels * bits / 8;
   1.874 +  data->auxBuffer = malloc(data->size);
   1.875 +  data->mainBuffer = malloc(data->size);
   1.876 +  data->mainFull = AL_FALSE;
   1.877 +  data->auxFull = AL_FALSE;
   1.878 +  data->mainReady = AL_TRUE;
   1.879 +  data->auxReady = AL_TRUE;
   1.880 +    
   1.881 +  if(!data->mainBuffer || !data->auxBuffer)
   1.882 +    {
   1.883 +      ERR("Buffer malloc failed\n");
   1.884 +      return ALC_FALSE;
   1.885 +    }
   1.886 +
   1.887 +  //data->thread = StartThread(RecordProc, device);
   1.888 +  //data->thread = StartThread(noop, device);
   1.889 +  
   1.890 +  //TODO: shoudl free everything somewhere else!
   1.891 +
   1.892 +  /*
   1.893 +  if(data->thread == NULL)
   1.894 +    {
   1.895 +      free(data->mainBuffer);
   1.896 +      free(data->auxBuffer);
   1.897 +      free(data->unPauseIDs);
   1.898 +      data->auxBuffer = NULL;
   1.899 +      data->mainBuffer = NULL;
   1.900 +
   1.901 +      return ALC_FALSE;
   1.902 +    }
   1.903 +  */
   1.904 +  return ALC_TRUE;
   1.905 +}
   1.906 +
   1.907 +
   1.908 +
   1.909 +static void record_stop_playback(ALCdevice *device)
   1.910 +{
   1.911 +  record_data *data = (record_data*)device->ExtraData;
   1.912 +  dprintf("RLM: stop playback called\n");
   1.913 +  printf("szName is %s \n", device->szDeviceName);
   1.914 +  printf("robert is %d \n", data->robert);
   1.915 +
   1.916 +
   1.917 +  if(!data->thread)
   1.918 +    return;
   1.919 +
   1.920 +  data->killNow = 1;
   1.921 +  StopThread(data->thread);
   1.922 +  data->thread = NULL;
   1.923 +
   1.924 +  data->killNow = 0;
   1.925 +}
   1.926 +
   1.927 +
   1.928 +static const BackendFuncs record_funcs = {
   1.929 +  record_open_playback,
   1.930 +  record_close_playback,
   1.931 +  record_reset_playback,
   1.932 +  record_stop_playback,
   1.933 +  NULL,
   1.934 +  NULL,  /* These would be filled with functions to */
   1.935 +  NULL,  /* handle capturing audio if we did that. */
   1.936 +  NULL,
   1.937 +  NULL,
   1.938 +  NULL
   1.939 +};
   1.940 +
   1.941 +ALCboolean alc_record_init(BackendFuncs *func_list)
   1.942 +{
   1.943 +  dprintf("RECORD: I'm InIT111\n");
   1.944 +  *func_list = record_funcs;
   1.945 +  return ALC_TRUE;
   1.946 +}
   1.947 +
   1.948 +void alc_record_deinit(void)
   1.949 +{
   1.950 +}
   1.951 +
   1.952 +void alc_record_probe(enum DevProbe type)
   1.953 +{
   1.954 +  dprintf("RECORD: I'm being probed! :/\n");
   1.955 +
   1.956 +  switch(type)
   1.957 +    {
   1.958 +    case DEVICE_PROBE:
   1.959 +      AppendDeviceList(recordDevice);
   1.960 +      break;
   1.961 +    case ALL_DEVICE_PROBE:
   1.962 +      AppendAllDeviceList(recordDevice);
   1.963 +      break;
   1.964 +    case CAPTURE_DEVICE_PROBE:
   1.965 +      break;
   1.966 +    }
   1.967 +}
   1.968 +
   1.969 +
   1.970 +
   1.971 +
   1.972 +void printError(void){
   1.973 +  ALenum error = alGetError();
   1.974 +  printf("%s\n", GetALCErrorString(error));
   1.975 +  printf("%s\n", GetALErrorString(error));
   1.976 +}
   1.977 +
   1.978 +
   1.979 +
   1.980 +char* GetALCErrorString(ALenum err)
   1.981 +{
   1.982 +  switch(err)
   1.983 +    {
   1.984 +    case ALC_NO_ERROR:
   1.985 +      return "AL_NO_ERROR";
   1.986 +      break;
   1.987 +
   1.988 +    case ALC_INVALID_DEVICE:
   1.989 +      return "ALC_INVALID_DEVICE";
   1.990 +      break;
   1.991 +
   1.992 +    case ALC_INVALID_CONTEXT:
   1.993 +      return "ALC_INVALID_CONTEXT";
   1.994 +      break;
   1.995 +
   1.996 +    case ALC_INVALID_ENUM:
   1.997 +      return "ALC_INVALID_ENUM";
   1.998 +      break;
   1.999 +
  1.1000 +    case ALC_INVALID_VALUE:
  1.1001 +      return "ALC_INVALID_VALUE";
  1.1002 +      break;
  1.1003 +
  1.1004 +    case ALC_OUT_OF_MEMORY:
  1.1005 +      return "ALC_OUT_OF_MEMORY";
  1.1006 +      break;
  1.1007 +    };
  1.1008 +  return "UNknown error.";
  1.1009 +}
  1.1010 +
  1.1011 +
  1.1012 +
  1.1013 +
  1.1014 +
  1.1015 +
  1.1016 +
  1.1017 +char* GetALErrorString(ALenum err)
  1.1018 +{
  1.1019 +  switch(err)
  1.1020 +    {
  1.1021 +    case AL_NO_ERROR:
  1.1022 +      return "AL_NO_ERROR";
  1.1023 +      break;
  1.1024 +
  1.1025 +    case AL_INVALID_NAME:
  1.1026 +      return "AL_INVALID_NAME";
  1.1027 +      break;
  1.1028 +
  1.1029 +    case AL_INVALID_ENUM:
  1.1030 +      return "AL_INVALID_ENUM";
  1.1031 +      break;
  1.1032 +
  1.1033 +    case AL_INVALID_VALUE:
  1.1034 +      return "AL_INVALID_VALUE";
  1.1035 +      break;
  1.1036 +
  1.1037 +    case AL_INVALID_OPERATION:
  1.1038 +      return "AL_INVALID_OPERATION";
  1.1039 +      break;
  1.1040 +
  1.1041 +    case AL_OUT_OF_MEMORY:
  1.1042 +      return "AL_OUT_OF_MEMORY";
  1.1043 +      break;
  1.1044 +    };
  1.1045 +  return "UNknown error.";
  1.1046 +}
  1.1047 +
  1.1048 +
  1.1049 +
  1.1050 +
  1.1051 +
  1.1052 +
  1.1053 +
  1.1054 +#include "com_aurellem_audioPlay_TestCall.h"
  1.1055 +
  1.1056 +JNIEXPORT void JNICALL Java_com_aurellem_audioPlay_TestCall_nprintGarbage
  1.1057 +(JNIEnv *env, jclass clazz){
  1.1058 +  UNUSED(env);UNUSED(clazz);
  1.1059 +  printf("Native! method* zzz\n");
  1.1060 +  return;
  1.1061 +}
  1.1062 +
  1.1063 +#include "com_aurellem_audioPlay_WavCaptureMaybe.h"
  1.1064 +
  1.1065 +JNIEXPORT void JNICALL Java_com_aurellem_audioPlay_WavCaptureMaybe_nrecord_1whatever
  1.1066 +(JNIEnv *env, jclass clazz){
  1.1067 +  UNUSED(env);UNUSED(clazz);
  1.1068 +  printf("record_aurellem_whatever!");
  1.1069 +}
  1.1070 +
  1.1071 +
  1.1072 +
  1.1073 +
  1.1074 +
  1.1075 +
  1.1076 +
  1.1077 +
  1.1078 +
  1.1079 +
  1.1080 +
  1.1081 +
  1.1082 +
  1.1083 +
  1.1084 +
  1.1085 +
  1.1086 +//////////////////////////// Real JNI stuff ////////////////////////////////
  1.1087 +void getMainSamples(ALCvoid *buffer){
  1.1088 +  UNUSED(buffer);
  1.1089 +  //  memcpy(mainBuffer, (ALubyte*) buffer, samples);
  1.1090 +}
  1.1091 +
  1.1092 +void getAuxSamples(ALCvoid *buffer){
  1.1093 +  UNUSED(buffer);
  1.1094 +  //  memcpy(auxBuffer, (ALubyte*) buffer, samples);
  1.1095 +}
  1.1096 +
  1.1097 +#include "com_jme3_capture_RecordAudioRenderer.h"
  1.1098 +
  1.1099 +/*
  1.1100 + * Class:     com_jme3_capture_RecordAudioRenderer
  1.1101 + * Method:    helloEveryone
  1.1102 + * Signature: ()V
  1.1103 + */
  1.1104 +JNIEXPORT void JNICALL Java_com_jme3_capture_RecordAudioRenderer_helloEveryone
  1.1105 +(JNIEnv *env, jclass clazz){
  1.1106 +  UNUSED(env);UNUSED(clazz);
  1.1107 +  printf("\n**************\nC from Java: I'm audioRecorder :)\n***********\n");
  1.1108 +}
  1.1109 +
  1.1110 +
  1.1111 +/*
  1.1112 + * Class:     com_jme3_capture_RecordAudioRenderer
  1.1113 + * Method:    nstep
  1.1114 + * Signature: ()V
  1.1115 + */
  1.1116 +JNIEXPORT void JNICALL Java_com_jme3_capture_RecordAudioRenderer_nstep
  1.1117 +(JNIEnv *env, jclass clazz, jlong device){
  1.1118 +  UNUSED(env);UNUSED(clazz);UNUSED(device);
  1.1119 +  //printf("C from Java: I'm audioRecorder -- nstep :)\n");
  1.1120 +  RecordProc((ALCdevice*)((intptr_t)device));
  1.1121 +}
  1.1122 +
  1.1123 +/*
  1.1124 + * Class:     com_jme3_capture_RecordAudioRenderer
  1.1125 + * Method:    ngetMainSamples
  1.1126 + * Signature: (JLjava/nio/ByteBuffer;I)V
  1.1127 + */
  1.1128 +JNIEXPORT void JNICALL Java_com_jme3_capture_RecordAudioRenderer_ngetMainSamples
  1.1129 +(JNIEnv *env, jclass clazz, jlong device, jobject buffer, jint position){
  1.1130 +  UNUSED(clazz);
  1.1131 +  
  1.1132 +  ALvoid *buffer_address = 
  1.1133 +    ((ALbyte *)(((char*)(*env)->GetDirectBufferAddress(env, buffer)) + position));
  1.1134 +  ALCdevice *recorder = (ALCdevice*) ((intptr_t)device);
  1.1135 +  //printf("getMainSamples: device is %p\n", recorder);
  1.1136 +  record_data *data = (record_data*)recorder->ExtraData;
  1.1137 +  if (!data->mainFull){
  1.1138 +    printf("data is not ready!\n"); 
  1.1139 +    return;
  1.1140 +  }
  1.1141 +  memcpy(buffer_address, data->mainBuffer, data->size);
  1.1142 +  data->mainFull = AL_FALSE;
  1.1143 +}
  1.1144 +
  1.1145 +/*
  1.1146 + * Class:     com_jme3_capture_RecordAudioRenderer
  1.1147 + * Method:    ngetAuxSamples
  1.1148 + * Signature: (JLjava/nio/ByteBuffer;I)V
  1.1149 + */
  1.1150 +JNIEXPORT void JNICALL Java_com_jme3_capture_RecordAudioRenderer_ngetAuxSamples
  1.1151 +  (JNIEnv *env, jclass clazz, jlong device, jobject buffer, jint position){
  1.1152 +  UNUSED(clazz);
  1.1153 +  
  1.1154 +  ALvoid *buffer_address = 
  1.1155 +    ((ALbyte *)(((char*)(*env)->GetDirectBufferAddress(env, buffer)) + position));
  1.1156 +  ALCdevice *recorder = (ALCdevice*) ((intptr_t)device);
  1.1157 +  //printf("getMainSamples: device is %p\n", recorder);
  1.1158 +  record_data *data = (record_data*)recorder->ExtraData;
  1.1159 +  
  1.1160 +  memcpy(buffer_address, data->auxBuffer, data->size);
  1.1161 +  
  1.1162 +}
  1.1163 +
  1.1164 +
  1.1165 +/*
  1.1166 + * Class:     com_jme3_capture_RecordAudioRenderer
  1.1167 + * Method:    nsetAuxListener3f
  1.1168 + * Signature: (IFFF)V
  1.1169 + */
  1.1170 +JNIEXPORT void JNICALL Java_com_jme3_capture_RecordAudioRenderer_nsetAuxListener3f
  1.1171 +(JNIEnv *env, jclass clazz, jint pname, jfloat v1, jfloat v2, jfloat v3){
  1.1172 +  UNUSED(env);UNUSED(clazz);
  1.1173 +  aux_alListener3f(pname, v1, v2, v3);
  1.1174 +}
  1.1175 +
  1.1176 +/*
  1.1177 + * Class:     com_jme3_capture_RecordAudioRenderer
  1.1178 + * Method:    nsetAuxListenerf
  1.1179 + * Signature: (IF)V
  1.1180 + */
  1.1181 +JNIEXPORT void JNICALL Java_com_jme3_capture_RecordAudioRenderer_nsetAuxListenerf
  1.1182 +(JNIEnv *env, jclass clazz, jint pname, jfloat v1){
  1.1183 +  UNUSED(env);UNUSED(clazz);
  1.1184 +  aux_alListenerf(pname, v1);
  1.1185 +}
  1.1186 +
  1.1187 +
  1.1188 +
  1.1189 +/*
  1.1190 +static void JNICALL Java_org_lwjgl_openal_ALC11_nalcCaptureSamples
  1.1191 +(JNIEnv *env, jclass clazz, jlong device, jobject buffer, jint position, jint samples) {
  1.1192 +  ALvoid *buffer_address = 
  1.1193 +    ((ALbyte *)(((char*)(*env)->GetDirectBufferAddress(env, buffer)) + position));
  1.1194 +  alcCaptureSamples((ALCdevice*) ((intptr_t)device), buffer_address, samples);
  1.1195 +}
  1.1196 +*/
  1.1197 +
  1.1198 +
  1.1199 +
  1.1200 +
  1.1201 +
  1.1202 +