coreaudio: capture devices should let the system allocate the render buffer.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 03 Sep 2016 00:13:41 -0400
changeset 103089c5833cbeb8f
parent 10307 d8d0569ec151
child 10309 38583cb96c1a
coreaudio: capture devices should let the system allocate the render buffer.
src/audio/coreaudio/SDL_coreaudio.c
src/audio/coreaudio/SDL_coreaudio.h
     1.1 --- a/src/audio/coreaudio/SDL_coreaudio.c	Fri Sep 02 13:12:21 2016 -0400
     1.2 +++ b/src/audio/coreaudio/SDL_coreaudio.c	Sat Sep 03 00:13:41 2016 -0400
     1.3 @@ -354,16 +354,19 @@
     1.4                UInt32 inBusNumber, UInt32 inNumberFrames,
     1.5                AudioBufferList *ioData)
     1.6  {
     1.7 +    AudioBufferList bufferList;
     1.8      SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon;
     1.9      if (!SDL_AtomicGet(&this->enabled) || SDL_AtomicGet(&this->paused)) {
    1.10          return noErr;  /* just drop this if we're not accepting input. */
    1.11      }
    1.12  
    1.13 -    const OSStatus err = AudioUnitRender(this->hidden->audioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, &this->hidden->captureBufferList);
    1.14 -    SDL_assert(this->hidden->captureBufferList.mNumberBuffers == 1);
    1.15 +    bufferList.mNumberBuffers = 1;
    1.16 +    bufferList.mBuffers[0].mData = NULL;
    1.17 +
    1.18 +    const OSStatus err = AudioUnitRender(this->hidden->audioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, &bufferList);
    1.19  
    1.20      if (err == noErr) {
    1.21 -        const AudioBuffer *abuf = &this->hidden->captureBufferList.mBuffers[0];
    1.22 +        const AudioBuffer *abuf = &bufferList.mBuffers[0];
    1.23          UInt32 remaining = abuf->mDataByteSize;
    1.24          const Uint8 *ptr = (const Uint8 *) abuf->mData;
    1.25  
    1.26 @@ -460,7 +463,6 @@
    1.27          AudioComponentInstanceDispose(this->hidden->audioUnit);
    1.28      }
    1.29  
    1.30 -    SDL_free(this->hidden->captureBufferList.mBuffers[0].mData);
    1.31      SDL_free(this->hidden->buffer);
    1.32      SDL_free(this->hidden);
    1.33  
    1.34 @@ -604,27 +606,12 @@
    1.35      CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)");
    1.36  
    1.37      if (iscapture) {  /* only need to do this for capture devices. */
    1.38 -        void *ptr;
    1.39 -        UInt32 framesize = 0;
    1.40 -        UInt32 propsize = sizeof (UInt32);
    1.41 -
    1.42 -        result = AudioUnitGetProperty(this->hidden->audioUnit,
    1.43 -                                      kAudioUnitProperty_MaximumFramesPerSlice,
    1.44 -                                      kAudioUnitScope_Global, output_bus,
    1.45 -                                      &framesize, &propsize);
    1.46 -        CHECK_RESULT
    1.47 -            ("AudioUnitGetProperty (kAudioDevicePropertyBufferFrameSize)");
    1.48 -
    1.49 -        framesize *= SDL_AUDIO_BITSIZE(this->spec.format) / 8;
    1.50 -        ptr = SDL_calloc(1, framesize);
    1.51 -        if (ptr == NULL) {
    1.52 -            SDL_OutOfMemory();
    1.53 -            return 0;
    1.54 -        }
    1.55 -        this->hidden->captureBufferList.mNumberBuffers = 1;
    1.56 -        this->hidden->captureBufferList.mBuffers[0].mNumberChannels = this->spec.channels;
    1.57 -        this->hidden->captureBufferList.mBuffers[0].mDataByteSize = framesize;
    1.58 -        this->hidden->captureBufferList.mBuffers[0].mData = ptr;
    1.59 +        const UInt32 yes = 1;
    1.60 +        result = AudioUnitSetProperty(this->hidden->audioUnit,
    1.61 +                                      kAudioUnitProperty_ShouldAllocateBuffer,
    1.62 +                                      kAudioUnitScope_Output,
    1.63 +                                      input_bus, &yes, sizeof (yes));
    1.64 +        CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_ShouldAllocateBuffer)");
    1.65      }
    1.66  
    1.67      /* Set the audio callback */
     2.1 --- a/src/audio/coreaudio/SDL_coreaudio.h	Fri Sep 02 13:12:21 2016 -0400
     2.2 +++ b/src/audio/coreaudio/SDL_coreaudio.h	Sat Sep 03 00:13:41 2016 -0400
     2.3 @@ -48,7 +48,6 @@
     2.4      void *buffer;
     2.5      UInt32 bufferOffset;
     2.6      UInt32 bufferSize;
     2.7 -    AudioBufferList captureBufferList;
     2.8  #if MACOSX_COREAUDIO
     2.9      AudioDeviceID deviceID;
    2.10  #endif