AudioUnit Render callback issue (callback not called)

I have a simple requirement at the moment - an iOS app that reads from an audio file and outputs to the speaker using AudioUnits. The reason for not using the high-level APIs is that at some point I need to process the samples coming out of the audio file and eventually send them over the network.

I have some code that works, reads an audio file and plays it back. The only problem here is the render callback doesn't work. The callback is never called and I don't get any errors on registration. Help is greatly appreciated (I'm new to Core Audio and this is my first stackoverflow question, so please apologize for any major mistakes / shortcomings). The piece of code I am using to initialize the graph is attached.

void createMyAUGraph (MyAUGraphPlayerST *player) {
    // Create a new AUGraph

    CheckError(NewAUGraph(&player->graph), "New AUGraph failed");

    // Generate description for output

    AudioComponentDescription outputcd = {0};
    outputcd.componentType = kAudioUnitType_Output;
    outputcd.componentSubType = kAudioUnitSubType_RemoteIO;
    outputcd.componentManufacturer = kAudioUnitManufacturer_Apple;
    outputcd.componentFlags = 0;
    outputcd.componentFlagsMask = 0;

    // Add new node

    AUNode outputNode;
    CheckError(AUGraphAddNode(player->graph, &outputcd, &outputNode), "Add output node failed");

    // Node for file player

    AudioComponentDescription fileplayercd = {0};
    fileplayercd.componentType = kAudioUnitType_Generator;
    fileplayercd.componentSubType = kAudioUnitSubType_AudioFilePlayer;
    fileplayercd.componentManufacturer = kAudioUnitManufacturer_Apple;

    // Add new node

    AUNode fileNode;
    CheckError(AUGraphAddNode(player->graph, &fileplayercd, &fileNode), "Add file node failed");

    // Open graph

    CheckError(AUGraphOpen(player->graph), "Graph open failed");

    // Retrive AudioUnit

    CheckError(AUGraphNodeInfo(player->graph, outputNode, NULL, &player->outputAU), "file unit retrive failed");
    CheckError(AUGraphNodeInfo(player->graph, fileNode, NULL, &player->fileAU), "file unit retrive failed");

    // connect nodes

    CheckError(AUGraphConnectNodeInput(player->graph, fileNode, 0, outputNode, 0), "failed to connect nodes");

    // some other setup

    UInt32 flag = 1;
    CheckError(AudioUnitSetProperty(player->outputAU,
                                      kAudioOutputUnitProperty_EnableIO,
                                      kAudioUnitScope_Output,
                                      0,
                                      &flag,
                                      sizeof (flag)), "Set io property failed");

    // Register render callback

    AURenderCallbackStruct output_cb;
    output_cb.inputProc = recording_cb;
    output_cb.inputProcRefCon = player;
    CheckError(AudioUnitSetProperty(player->outputAU, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, 0, &output_cb, sizeof (output_cb)), "callback register failed");

    // initialize graph

    CheckError(AUGraphInitialize(player->graph), "graph initialization failed");
}

      

+3


source to share


1 answer


You told the graphic to connect your RemoteIO input to the file player node and not to the render callback. Then you initialized the graph, which overloads the render property.



If you want to pull samples from a file for processing, your processing or render callback will have to do so, not a player connection to the RemoteIO input. So don't let the schedule make this connection.

0


source







All Articles