How to get array of float audio data from AudioQueueRef in iOS?

前端 未结 2 1844
梦毁少年i
梦毁少年i 2020-12-14 04:09

I\'m working on getting audio into the iPhone in a form where I can pass it to a (C++) analysis algorithm. There are, of course, many options: the AudioQueue tutorial at tra

2条回答
  •  眼角桃花
    2020-12-14 04:22

      // so you don't have to hunt them all down when you decide to switch to float: 
      #define AUDIO_DATA_TYPE_FORMAT SInt16
    
      // the actual sample-grabbing code:
      int sampleCount = inBuffer->mAudioDataBytesCapacity / sizeof(AUDIO_DATA_TYPE_FORMAT);
      AUDIO_DATA_TYPE_FORMAT *samples = (AUDIO_DATA_TYPE_FORMAT*)inBuffer->mAudioData;
    

    Then you have your (in this case SInt16) array samples which you can access from samples[0] to samples[sampleCount-1].

提交回复
热议问题