2013-06-27 136 views
0

我一直在關注由Adamson和Avila學習Core Audio書中的音頻單元示例。出於某種原因,我收到了上述錯誤。 I #include <CoreAudio/CoreAudio.h>甚至只是爲了確保我正在導入可能的音頻庫,並確保在目標的「構建階段」部分下配置「鏈接二進制文件庫」。我甚至將Base SDK更改爲OSX 10.7(而不是默認的10.8),以查看會發生什麼,但沒有雪茄。根據文檔,語音合成API並沒有被完全棄用 - 然而,一些功能是。我的MacBook正在運行10.7.5。 Xcode是4.6版(4H127。使用未聲明的標識符'kAudioUnitSubType_SpeechSynthesis ...

下面我把在那裏我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; 
} 

回答

1

kAudioUnitSubType_SpeechSynthesis在SpeechSynthesis.framework,其中生活在ApplicationServices.framework內宣佈傘架,所以你應該#import < ApplicationServices.framework>

+0

謝謝!這有助於......編譯器現在很開心 – edderic

+0

太好了!接受已解決你提出的問題的答案的禮儀很好 – bdash

+0

對不起,我忘了:) – edderic