Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static OSStatus ca_capture_conversion_callback(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets,
- AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void* inUserData)
- {
- ALCdevice *device = (ALCdevice*)inUserData;
- ca_data *data = (ca_data*)device->ExtraData;
- AL_PRINT("*ioNumberDataPackets: %d\n", *ioNumberDataPackets);
- // Read from the ring buffer directly to the input data buffer
- ReadRingBuffer(data->ring, ioData->mBuffers[0].mData, (ALsizei)(*ioNumberDataPackets));
- // Set the input data
- ioData->mNumberBuffers = 1;
- ioData->mBuffers[0].mNumberChannels = data->format.mChannelsPerFrame;
- ioData->mBuffers[0].mDataByteSize = (*ioNumberDataPackets) * data->format.mBytesPerFrame;
- return noErr;
- }
- static void ca_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
- {
- ca_data *data = (ca_data*)device->ExtraData;
- ALCuint ringBufferSize = (ALCuint)RingBufferSize(data->ring);
- AL_PRINT("samples: %d\n", samples);
- AL_PRINT("ringBufferSize: %d\n", ringBufferSize);
- if(samples <= ringBufferSize && samples != 0)
- {
- UInt32 resampledFrameCount = samples / data->sampleRateRatio;
- AL_PRINT("resampledFrameCount: %d\n", resampledFrameCount);
- // Point the resampling buffer to the capture buffer
- data->resampledBufferList->mBuffers[0].mData = buffer;
- // Resample into another AudioBufferList
- OSStatus err = AudioConverterFillComplexBuffer(data->audioConverter, ca_capture_conversion_callback, device,
- &resampledFrameCount, data->resampledBufferList, NULL);
- if (err)
- {
- AL_PRINT("AudioConverterFillComplexBuffer error: %d\n", err);
- alcSetError(device, ALC_INVALID_VALUE);
- return;
- }
- }
- else
- alcSetError(device, ALC_INVALID_VALUE);
- }
Add Comment
Please, Sign In to add comment