mirror of https://github.com/encounter/SDL.git
coreaudio: capture devices should let the system allocate the render buffer.
This commit is contained in:
parent
fda7a3d158
commit
3b53304a94
|
@ -354,16 +354,19 @@ inputCallback(void *inRefCon,
|
||||||
UInt32 inBusNumber, UInt32 inNumberFrames,
|
UInt32 inBusNumber, UInt32 inNumberFrames,
|
||||||
AudioBufferList *ioData)
|
AudioBufferList *ioData)
|
||||||
{
|
{
|
||||||
|
AudioBufferList bufferList;
|
||||||
SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon;
|
SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon;
|
||||||
if (!SDL_AtomicGet(&this->enabled) || SDL_AtomicGet(&this->paused)) {
|
if (!SDL_AtomicGet(&this->enabled) || SDL_AtomicGet(&this->paused)) {
|
||||||
return noErr; /* just drop this if we're not accepting input. */
|
return noErr; /* just drop this if we're not accepting input. */
|
||||||
}
|
}
|
||||||
|
|
||||||
const OSStatus err = AudioUnitRender(this->hidden->audioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, &this->hidden->captureBufferList);
|
bufferList.mNumberBuffers = 1;
|
||||||
SDL_assert(this->hidden->captureBufferList.mNumberBuffers == 1);
|
bufferList.mBuffers[0].mData = NULL;
|
||||||
|
|
||||||
|
const OSStatus err = AudioUnitRender(this->hidden->audioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, &bufferList);
|
||||||
|
|
||||||
if (err == noErr) {
|
if (err == noErr) {
|
||||||
const AudioBuffer *abuf = &this->hidden->captureBufferList.mBuffers[0];
|
const AudioBuffer *abuf = &bufferList.mBuffers[0];
|
||||||
UInt32 remaining = abuf->mDataByteSize;
|
UInt32 remaining = abuf->mDataByteSize;
|
||||||
const Uint8 *ptr = (const Uint8 *) abuf->mData;
|
const Uint8 *ptr = (const Uint8 *) abuf->mData;
|
||||||
|
|
||||||
|
@ -460,7 +463,6 @@ COREAUDIO_CloseDevice(_THIS)
|
||||||
AudioComponentInstanceDispose(this->hidden->audioUnit);
|
AudioComponentInstanceDispose(this->hidden->audioUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_free(this->hidden->captureBufferList.mBuffers[0].mData);
|
|
||||||
SDL_free(this->hidden->buffer);
|
SDL_free(this->hidden->buffer);
|
||||||
SDL_free(this->hidden);
|
SDL_free(this->hidden);
|
||||||
|
|
||||||
|
@ -604,27 +606,12 @@ prepare_audiounit(_THIS, void *handle, int iscapture,
|
||||||
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)");
|
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)");
|
||||||
|
|
||||||
if (iscapture) { /* only need to do this for capture devices. */
|
if (iscapture) { /* only need to do this for capture devices. */
|
||||||
void *ptr;
|
const UInt32 yes = 1;
|
||||||
UInt32 framesize = 0;
|
result = AudioUnitSetProperty(this->hidden->audioUnit,
|
||||||
UInt32 propsize = sizeof (UInt32);
|
kAudioUnitProperty_ShouldAllocateBuffer,
|
||||||
|
kAudioUnitScope_Output,
|
||||||
result = AudioUnitGetProperty(this->hidden->audioUnit,
|
input_bus, &yes, sizeof (yes));
|
||||||
kAudioUnitProperty_MaximumFramesPerSlice,
|
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_ShouldAllocateBuffer)");
|
||||||
kAudioUnitScope_Global, output_bus,
|
|
||||||
&framesize, &propsize);
|
|
||||||
CHECK_RESULT
|
|
||||||
("AudioUnitGetProperty (kAudioDevicePropertyBufferFrameSize)");
|
|
||||||
|
|
||||||
framesize *= SDL_AUDIO_BITSIZE(this->spec.format) / 8;
|
|
||||||
ptr = SDL_calloc(1, framesize);
|
|
||||||
if (ptr == NULL) {
|
|
||||||
SDL_OutOfMemory();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
this->hidden->captureBufferList.mNumberBuffers = 1;
|
|
||||||
this->hidden->captureBufferList.mBuffers[0].mNumberChannels = this->spec.channels;
|
|
||||||
this->hidden->captureBufferList.mBuffers[0].mDataByteSize = framesize;
|
|
||||||
this->hidden->captureBufferList.mBuffers[0].mData = ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the audio callback */
|
/* Set the audio callback */
|
||||||
|
|
|
@ -48,7 +48,6 @@ struct SDL_PrivateAudioData
|
||||||
void *buffer;
|
void *buffer;
|
||||||
UInt32 bufferOffset;
|
UInt32 bufferOffset;
|
||||||
UInt32 bufferSize;
|
UInt32 bufferSize;
|
||||||
AudioBufferList captureBufferList;
|
|
||||||
#if MACOSX_COREAUDIO
|
#if MACOSX_COREAUDIO
|
||||||
AudioDeviceID deviceID;
|
AudioDeviceID deviceID;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue