示例#1
0
void  auAudioOutputCallback(void *SELF, AudioQueueRef queue, AudioQueueBufferRef buffer)
{
  Audio* self = (Audio*) SELF;
  int resultFrames = self->audioCallback(SELF, (auSample_t*)buffer->mAudioData, (buffer->mAudioDataBytesCapacity / self->dataFormat.mBytesPerFrame), self->dataFormat.mChannelsPerFrame);
  buffer->mAudioDataByteSize = resultFrames * self->dataFormat.mBytesPerFrame;//buffer->mAudioDataBytesCapacity;
  AudioQueueEnqueueBuffer(queue, buffer, 0, NULL);
}
示例#2
0
void* auAudioCallback(void* SELF)
{
  Audio* self = (Audio*)SELF;
  self->threadIsRunning = self->threadShouldContinueRunning = YES;
  signal(SIGPIPE, SIG_IGN);
  int success = YES;
  
  while(self->threadShouldContinueRunning)
    {
      if(!self->isOutput) 
        success = auTransferData(self, snd_pcm_readi);
        
      if(success)
        self->audioCallback(SELF, self->sampleBuffer, self->bufferNumFrames, self->numChannels);
      
      if(self->isOutput) 
        success = auTransferData(self, (snd_pcm_sframes_t (*)(snd_pcm_t*, void*, snd_pcm_uframes_t)) snd_pcm_writei);

      if(!success) break;
    }
  self->threadIsRunning = NO;
  return NULL;
}