0

我一直在关注 Adamson 和 Avila 的 Learning Core Audio book 中的 Audio Units 示例。由于某种原因,我收到了上述错误。我#include <CoreAudio/CoreAudio.h>什至只是为了确保我正在为音频导入可能的库,并确保在目标的“构建阶段”部分下配置“使用库链接二进制文件”。我什至将 Base SDK 更改为 OSX 10.7(而不是默认的 10.8)以查看会发生什么,但没有雪茄。根据文档,语音合成 API 无论如何都没有完全弃用——但是,有些功能是。我的 MacBook 运行的是 10.7.5。XCode 是 4.6 版 (4H127.

下面我对我在 CAPS 中出现错误的位置发表评论。有任何想法吗?

//
//  main.c
//  CAsamplerSynthesisGraph
//
//  Created by Edderic Ugaddan on 6/25/13.
//  Copyright (c) 2013 Edderic Ugaddan. All rights reserved.
//

//#include <CoreFoundation/CoreFoundation.h>
#include <AudioUnit/AudioUnit.h>
#include <AudioToolbox/AudioToolbox.h>
#include <CoreAudio/CoreAudio.h>

// #define PART_II

#pragma mark user-data struct
// Insert Listing 7.19 here

typedef struct MyAUGraphPlayer {
    AUGraph graph;
    AudioUnit samplerAU;
} MyAUGraphPlayer;

#pragma mark utility functions
// Insert Listing 4.2 here

static void CheckError(OSStatus error, const char *operation) {
    if (error == noErr) return;

    char errorString[20];

    // See if it appears to be a 4-char-code.

    *(UInt32 *)*(errorString + 1) = CFSwapInt32HostToBig(error);
    if (isprint(errorString[1]) && isprint(errorString[2]) &&
        isprint(errorString[3]) && isprint(errorString[4])) {
        errorString[0] = errorString[5] = '\'';
        errorString[6] = '\0';
    }
    else {

        // No, format it as an integer.

        sprintf(errorString, "%d", (int) error);
        fprintf(stderr, "Error: %s (%s)\n", operation, errorString);
        exit(1);
    }
}


void CreateMyAUGraph(MyAUGraphPlayer *player) {
    // Insert Listing 7.21 here
    // Create a new graph
    CheckError(NewAUGraph(&player->graph),
               "NewAUGraph failed");

    // Generates a description that matches our output device (speakers)
    AudioComponentDescription outputcd = {0};
    outputcd.componentType = kAudioUnitType_Output;
    outputcd.componentSubType = kAudioUnitSubType_DefaultOutput;
    outputcd.componentManufacturer = kAudioUnitManufacturer_Apple;

    // Adds a node with above description to the graph
    AUNode outputNode;
    CheckError(AUGraphAddNode(player->graph,
                              &outputcd,
                              &outputNode),
               "AUGraphAddNode[kAudioUnitSubType_DefaultOutput] failed");

    // Generates a description that will match a generator AU
    // of type: sampler synthesizer
    AudioComponentDescription samplercd = {0};
    samplercd.componentType = kAudioUnitType_Generator;
    samplercd.componentSubType = kAudioUnitSubType_SpeechSynthesis; // I GET ERROR HERE
    samplercd.componentManufacturer = kAudioUnitManufacturer_Apple;

    // Adds a node with above description to the graph
    AUNode samplerNode;
    CheckError(AUGraphAddNode(player->graph,
                              &samplercd,
                              &samplerNode),
               "AUGraphAddNode[kAudioUnitSubType_samplerSynthesis] failed");

    // Opening the graph opens all contained audio units, but
    // does not allocate any resources yet
    CheckError(AUGraphOpen(player->graph),
               "AUGraphOpen failed");


    // Gets the reference to the AudioUnit object for the
    // sampler graph node
    CheckError(AUGraphNodeInfo(player->graph,
                               samplerNode,
                               NULL,
                               &player->samplerAU),
               "AUGraphNodeInfo failed");

#ifdef PART_II
    // Insert Listing 7.24 - 7.26 here
#else
    // Insert Listing 7.22 here
    // Connect the output source of the sampler synthesis AU
    // to the input source of the output node
    CheckError(AUGraphConnectNodeInput(player->graph,
                                       samplerNode,
                                       0,
                                       outputNode,
                                       0),
               "AUGraphConnectNodeInput failed");
#endif
}

// Replace with listing 7.23
void PrepareSamplerAU(MyAUGraphPlayer *player) {
//    Sampler

}

#pragma mark main function
// Replace with listing 7.20

int main(int argc, const char * argv[])
{

    MyAUGraphPlayer player = {0};

    // Build a basic sampler->speakers graph
    CreateMyAUGraph(&player);

    // Configure the sampler synthesizer
    PrepareSamplerAU(&player);

    // Start playing
    CheckError(AUGraphStart(player.graph),
               "AUGraphStart failed");

    // Sleep a while so the sampler can play out
    usleep ((int)(10 * 1000. * 1000.));

    // Cleanup
    AUGraphStop(player.graph);
    AUGraphUninitialize(player.graph);
    AUGraphClose(player.graph);

    return 0;
}
4

1 回答 1

1

kAudioUnitSubType_SpeechSynthesis在 SpeechSynthesis.framework 中声明,它位于 ApplicationServices.framework 伞形框架中,因此您应该#import < ApplicationServices.framework>.

于 2013-06-27T06:50:57.463 回答