Guest User

Untitled

a guest
Oct 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. static OSStatus ca_capture_conversion_callback(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets,
  2. AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void* inUserData)
  3. {
  4. ALCdevice *device = (ALCdevice*)inUserData;
  5. ca_data *data = (ca_data*)device->ExtraData;
  6.  
  7. AL_PRINT("*ioNumberDataPackets: %d\n", *ioNumberDataPackets);
  8.  
  9. // Read from the ring buffer directly to the input data buffer
  10. ReadRingBuffer(data->ring, ioData->mBuffers[0].mData, (ALsizei)(*ioNumberDataPackets));
  11.  
  12. // Set the input data
  13. ioData->mNumberBuffers = 1;
  14. ioData->mBuffers[0].mNumberChannels = data->format.mChannelsPerFrame;
  15. ioData->mBuffers[0].mDataByteSize = (*ioNumberDataPackets) * data->format.mBytesPerFrame;
  16.  
  17. return noErr;
  18. }
  19.  
  20.  
  21. static void ca_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
  22. {
  23. ca_data *data = (ca_data*)device->ExtraData;
  24.  
  25. ALCuint ringBufferSize = (ALCuint)RingBufferSize(data->ring);
  26.  
  27. AL_PRINT("samples: %d\n", samples);
  28. AL_PRINT("ringBufferSize: %d\n", ringBufferSize);
  29.  
  30. if(samples <= ringBufferSize && samples != 0)
  31. {
  32. UInt32 resampledFrameCount = samples / data->sampleRateRatio;
  33. AL_PRINT("resampledFrameCount: %d\n", resampledFrameCount);
  34.  
  35. // Point the resampling buffer to the capture buffer
  36. data->resampledBufferList->mBuffers[0].mData = buffer;
  37.  
  38. // Resample into another AudioBufferList
  39. OSStatus err = AudioConverterFillComplexBuffer(data->audioConverter, ca_capture_conversion_callback, device,
  40. &resampledFrameCount, data->resampledBufferList, NULL);
  41. if (err)
  42. {
  43. AL_PRINT("AudioConverterFillComplexBuffer error: %d\n", err);
  44. alcSetError(device, ALC_INVALID_VALUE);
  45. return;
  46. }
  47. }
  48. else
  49. alcSetError(device, ALC_INVALID_VALUE);
  50. }
Add Comment
Please, Sign In to add comment