I'm just replying to say THANK YOU for the detailed explanation of how you got it to work. You definitely saved me many, many hours of headaches figuring all that out by myself!
To other people who possibly find this thread and find that AUHostMusicalContextBlock is always nil: (I hope Leonardo and jfjs already got it, since it's been 3 years...)
since AUHostMusicalContextBlock is apparently only invoked during render time, it seems it's always nil unless you poll it from the render block. Mine ended up looking like this:
Code Block Objective-C- (AUInternalRenderBlock)internalRenderBlock { |
//return _kernelAdapter.internalRenderBlock; |
|
return ^AUAudioUnitStatus(AudioUnitRenderActionFlags *actionFlags, |
const AudioTimeStamp *timestamp, |
AVAudioFrameCount frameCount, |
NSInteger outputBusNumber, |
AudioBufferList *outputData, |
const AURenderEvent *realtimeEventListHead, |
AURenderPullInputBlock __unsafe_unretained pullInputBlock) { |
// get tempo from host |
double currentTempo; |
if ( _musicalContext ) { // only use this if the host supports it... |
if (_musicalContext( ¤tTempo, NULL, NULL, NULL, NULL, NULL ) ) { |
[self->_kernelAdapter setTempo: currentTempo]; |
} |
} |
|
return self->_kernelAdapter.internalRenderBlock(actionFlags, timestamp, frameCount, outputBusNumber, outputData, realtimeEventListHead, pullInputBlock); |
}; |
} |
(I hope I'm doing this right, I don't really understand exactly how Objective C blocks work, as you can very possibly tell...)