Example #1
0
// open the android audio device for input 
OPENSL_STREAM *android_OpenRecDevice(char *name, int sr, int inchannels,
		int bufferframes, int bits_per_sample)
{
  
  OPENSL_STREAM *p;
  p = (OPENSL_STREAM *) calloc(sizeof(OPENSL_STREAM),1);
	memset(p, 0, sizeof(OPENSL_STREAM));

  p->inchannels = inchannels;
  p->sr = sr;
	p->queue = Queue_New(TRUE, -1, -1);
	p->buffersize = bufferframes;
	p->bits_per_sample = bits_per_sample;

	if ((p->bits_per_sample != 8) && (p->bits_per_sample != 16))
	{
    android_CloseRecDevice(p);
		return NULL;
	}
	
  if(openSLCreateEngine(p) != SL_RESULT_SUCCESS)
	{
    android_CloseRecDevice(p);
    return NULL;
  }

  if(openSLRecOpen(p) != SL_RESULT_SUCCESS)
	{
    android_CloseRecDevice(p);
    return NULL;
  } 

  return p;
}
Example #2
0
// open the android audio device for input and/or output
OPENSL_STREAM *android_OpenAudioDevice(int sr, int outchannels, int bufferframes){
  
  OPENSL_STREAM *p;
  p = (OPENSL_STREAM *) malloc(sizeof(OPENSL_STREAM));
  memset(p, 0, sizeof(OPENSL_STREAM));
  p->outchannels = outchannels;
  p->sr = sr;
 
  if((p->outBufSamples  =  bufferframes*outchannels) != 0) {
    if((p->outputBuffer = (short *) calloc(p->outBufSamples, sizeof(short))) == NULL) {
      android_CloseAudioDevice(p);
      return NULL;
    }
  }

  if((p->outrb = create_circular_buffer(p->outBufSamples*sizeof(short)*4)) == NULL) {
      android_CloseAudioDevice(p);
      return NULL; 
  }

  if(openSLCreateEngine(p) != SL_RESULT_SUCCESS) {
    android_CloseAudioDevice(p);
    return NULL;
  }

  if(openSLPlayOpen(p) != SL_RESULT_SUCCESS) {
    android_CloseAudioDevice(p);
    return NULL;
  }  

  return p;
}
Example #3
0
// open the android audio device for and/or output
OPENSL_STREAM* android_OpenAudioDevice(int sr, int outchannels,
                                       int bufferframes)
{
	OPENSL_STREAM* p;
	p = (OPENSL_STREAM*) calloc(sizeof(OPENSL_STREAM), 1);

	if (!p)
		return NULL;

	p->queuesize = bufferframes;
	p->outchannels = outchannels;
	p->sr = sr;

	if (openSLCreateEngine(p) != SL_RESULT_SUCCESS)
	{
		android_CloseAudioDevice(p);
		return NULL;
	}

	if (openSLPlayOpen(p) != SL_RESULT_SUCCESS)
	{
		android_CloseAudioDevice(p);
		return NULL;
	}

	p->queue = Queue_New(TRUE, -1, -1);

	if (!p->queue)
	{
		android_CloseAudioDevice(p);
		return NULL;
	}

	return p;
}
Example #4
0
// open the android audio device for input and/or output
OPENSL_STREAM *android_OpenAudioDevice(int sr, int inchannels, int outchannels, int bufferframes) {

  OPENSL_STREAM *p;
  p = (OPENSL_STREAM *) calloc(sizeof(OPENSL_STREAM), 1);

  p->inchannels = inchannels;
  p->outchannels = outchannels;
  p->sr = sr;
  p->inlock = createThreadLock();
  p->outlock = createThreadLock();

  if ((p->outBufSamples  =  bufferframes * outchannels) != 0) {
    if ((p->outputBuffer[0] = (short *) calloc(p->outBufSamples, sizeof(short))) == NULL ||
        (p->outputBuffer[1] = (short *) calloc(p->outBufSamples, sizeof(short))) == NULL) {
      android_CloseAudioDevice(p);
      return NULL;
    }
  }

  if ((p->inBufSamples  =  bufferframes * inchannels) != 0) {
    if ((p->inputBuffer[0] = (short *) calloc(p->inBufSamples, sizeof(short))) == NULL ||
        (p->inputBuffer[1] = (short *) calloc(p->inBufSamples, sizeof(short))) == NULL) {
      android_CloseAudioDevice(p);
      return NULL;
    }
  }

  p->currentInputIndex = 0;
  p->currentOutputBuffer  = 0;
  p->currentInputIndex = p->inBufSamples;
  p->currentInputBuffer = 0;

  if (openSLCreateEngine(p) != SL_RESULT_SUCCESS) {
    android_CloseAudioDevice(p);
    return NULL;
  }

  if (openSLRecOpen(p) != SL_RESULT_SUCCESS) {
    android_CloseAudioDevice(p);
    return NULL;
  }

  if (openSLPlayOpen(p) != SL_RESULT_SUCCESS) {
    android_CloseAudioDevice(p);
    return NULL;
  }

  notifyThreadLock(p->outlock);
  notifyThreadLock(p->inlock);

  p->time = 0.;
  return p;
}
Example #5
0
// open the android audio device for input and/or output
OPENSL_STREAM *android_OpenAudioDevice(int sr, int outchannels, int bufferframes, int nrbuffers){
	
	OPENSL_STREAM *p;
	p = (OPENSL_STREAM *) malloc(sizeof(OPENSL_STREAM));
	if(p == NULL) return NULL;
	
	memset(p, 0, sizeof(OPENSL_STREAM));
	p->outchannels = outchannels;
	p->sr = sr;
	
	p->outBufSamples = bufferframes * outchannels;
	p->nrbuffers = nrbuffers;
	p->outBufBytes = p->outBufSamples * sizeof(short);

	short *bfr = (short *)calloc(p->outBufSamples * p->nrbuffers, sizeof(short));	
	if(bfr == NULL) {
		free(p);
		return NULL;
	}

	p->buffer = (short **)malloc(sizeof(short *) * p->nrbuffers);
	if(p->buffer == NULL) {
		free(p);
		free(bfr);
	}
	
	int k;
	for(k = 0; k < p->nrbuffers; k++) {
		p->buffer[k] = &bfr[k * p->outBufSamples];
	}

	if(openSLCreateEngine(p) != SL_RESULT_SUCCESS) {
		android_CloseAudioDevice(p);
		return NULL;
	}

	if(openSLPlayOpen(p) != SL_RESULT_SUCCESS) {
		android_CloseAudioDevice(p);
		return NULL;
	}  

	return p;
}