示例#1
0
文件: opensl_io.c 项目: Andux/jack2
// puts a buffer of size samples to the device
int android_AudioOut(OPENSL_STREAM *p, float *buffer,int size){

  short *outBuffer;
  int i, bufsamps, index;
  if(p == NULL) return 0;
  bufsamps = p->outBufSamples;
  if(bufsamps ==  0) return 0;
  index = p->currentOutputIndex;
  outBuffer = p->outputBuffer[p->currentOutputBuffer];

  for(i=0; i < size; i++){
    outBuffer[index++] = (short) (buffer[i]*CONV16BIT);
    if (index >= p->outBufSamples) {
      waitThreadLock(p->outlock);
      (*p->bqPlayerBufferQueue)->Enqueue(p->bqPlayerBufferQueue, 
					 outBuffer,bufsamps*sizeof(short));
      p->currentOutputBuffer = (p->currentOutputBuffer ?  0 : 1);
      index = 0;
      outBuffer = p->outputBuffer[p->currentOutputBuffer];
    }
  }
  p->currentOutputIndex = index;
  p->time += (double) size/(p->sr*p->outchannels);
  return i;
}
示例#2
0
// puts a buffer of size samples to the device
int android_AudioOut(OPENSL_STREAM *p, float *buffer,int size, int millibel){
  short *outBuffer;
  int i, bufsamps = p->outBufSamples, index = p->currentOutputIndex;
  SLresult result;
  SLVolumeItf volumeItf = p->bqPlayerVolume;
  if(p == NULL  || bufsamps ==  0)  return 0;
  outBuffer = p->outputBuffer[p->currentOutputBuffer];
  if (NULL != volumeItf) {
    result = (*volumeItf)->SetVolumeLevel(volumeItf, millibel);
    if(SL_RESULT_SUCCESS != result) return 0;
  }

  for(i=0; i < size; i++){
    outBuffer[index++] = (short) (buffer[i]*CONV16BIT);
    if (index >= p->outBufSamples) {
      waitThreadLock(p->outlock);
      (*p->bqPlayerBufferQueue)->Enqueue(p->bqPlayerBufferQueue,
					 outBuffer,bufsamps*sizeof(short));
      p->currentOutputBuffer = (p->currentOutputBuffer ?  0 : 1);
      index = 0;
      outBuffer = p->outputBuffer[p->currentOutputBuffer];
    }
  }
  p->currentOutputIndex = index;
  p->time += (double) size/(p->sr*p->outchannels);
  return i;
}
示例#3
0
// gets a buffer of size samples from the device
int android_AudioIn(OPENSL_STREAM *p, float *buffer, int size) {
  short *inBuffer;
  int i, bufsamps = p->inBufSamples, index = p->currentInputIndex;
  if (p == NULL || bufsamps ==  0) return 0;

  inBuffer = p->inputBuffer[p->currentInputBuffer];
  for (i = 0; i < size; i++) {
    if (index >= bufsamps) {
      waitThreadLock(p->inlock);
      (*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,
                                         inBuffer, bufsamps * sizeof(short));
      p->currentInputBuffer = (p->currentInputBuffer ? 0 : 1);
      index = 0;
      inBuffer = p->inputBuffer[p->currentInputBuffer];
    }
    buffer[i] = (float) inBuffer[index++] * CONVMYFLT;
  }
  p->currentInputIndex = index;
  if (p->outchannels == 0) p->time += (double) size / (p->sr * p->inchannels);
  return i;
}