title: Custom AVAudioUnit with AVAudioEngine crashes on set provider block
body: <p>I have the follow code block that <em>should</em> create an AVAudioNode that produces a sine wave, however it crashes on the line marked with a -[AUAudioUnitV2Bridge setOutputProvider:]: unrecognized selector sent to instance.</p>
  
  <p>Any ideas what might be wrong?</p>
  
  <pre><code>// TEST  
  AudioComponentDescription mixerDesc;  
  mixerDesc.componentType = kAudioUnitType_Generator;  
  mixerDesc.componentSubType = kAudioUnitSubType_ScheduledSoundPlayer;  
  mixerDesc.componentManufacturer = kAudioUnitManufacturer_Apple;  
  mixerDesc.componentFlags = 0;  
  mixerDesc.componentFlagsMask = 0;  
  
  [AVAudioUnit instantiateWithComponentDescription:mixerDesc options:kAudioComponentInstantiation_LoadInProcess completionHandler:^(__kindof AVAudioUnit * _Nullable audioUnit, NSError * _Nullable error) {  
      NSLog(@"here");  
  
      // Crashes here  
      audioUnit.AUAudioUnit.outputProvider = ^AUAudioUnitStatus(AudioUnitRenderActionFlags *actionFlags, const AudioTimeStamp *timestamp, AUAudioFrameCount frameCount, NSInteger inputBusNumber, AudioBufferList *inputData)  
      {  
          const double amplitude = 0.2;  
          static double theta = 0.0;  
          double theta_increment = 2.0 * M_PI * 880.0 / 44100.0;  
          const int channel = 0;  
          Float32 *buffer = (Float32 *)inputData-&gt;mBuffers[channel].mData;  
  
          memset(inputData-&gt;mBuffers[channel].mData, 0, inputData-&gt;mBuffers[channel].mDataByteSize);  
          memset(inputData-&gt;mBuffers[1].mData, 0, inputData-&gt;mBuffers[1].mDataByteSize);  
  
          // Generate the samples  
          for (UInt32 frame = 0; frame &lt; inputBusNumber; frame++)  
          {  
              buffer[frame] = sin(theta) * amplitude;  
  
              theta += theta_increment;  
              if (theta &gt;= 2.0 * M_PI)  
              {  
                  theta -= 2.0 * M_PI;  
              }  
          }  
  
          return noErr;  
      };  
  
  }]; 
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>It feels like something like this would be the right approach, but alas, status throws errors, callback never called.:</p>
  
  <pre><code>    AVAudioUnitGenerator *unit = [[AVAudioUnitGenerator alloc] init];
  
  // TEST
  AudioComponentDescription desc;
  desc.componentType = kAudioUnitType_Generator;
  desc.componentSubType = kAudioUnitSubType_ScheduledSoundPlayer;
  desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  desc.componentFlags = 0;
  desc.componentFlagsMask = 0;
  
  [AVAudioUnit instantiateWithComponentDescription:desc options:kAudioComponentInstantiation_LoadInProcess completionHandler:^(__kindof AVAudioUnit * _Nullable audioUnit, NSError * _Nullable error) {
      NSLog(@"here");
  
      self.audioNode = audioUnit;
  
      OSStatus status;
       AudioUnit *unit = audioUnit.audioUnit;
  
      UInt32 numBuses = 1;
      status = AudioUnitSetProperty(unit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Output, 0, &amp;numBuses, sizeof(UInt32));
      NSLog(@"status: %d", status);
  
  
      AURenderCallbackStruct rcbs;
      rcbs.inputProc = callback2;
      rcbs.inputProcRefCon = (__bridge void * _Nullable)(self);
  
  
      status = AudioUnitSetProperty(unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Output, 0, &amp;rcbs, sizeof(rcbs));
      NSLog(@"status: %d", status);
  
  }];
  </code></pre>