gpt4 book ai didi

cocoa - 音频单元 : getting generated audio into a render callback

转载 作者:行者123 更新时间:2023-12-03 16:20:22 25 4
gpt4 key购买 nike

我一直在尝试通过将 AURenderCallbackStruct 附加到音频单元的输入来操作 kAudioUnitType_Generator 音频单元生成的样本,但没有成功。我设法使用以下简单图表在 OS X 上实现此功能:

(input callback) -> multichannel mixer -> (intput callback) -> default output

但是我失败了以下(甚至更简单)以发电机组开头的图表:

speech synthesis -> (intput callback) -> default output           | fails in render callback with kAudioUnitErr_Uninitialized
audiofile player -> (intput callback) -> default output | fails when scheduling file region with kAudioUnitErr_Uninitialized

我已经尝试了几乎所有我能想到的方法,从设置 ASBD 格式到采样率,但我总是遇到这些错误。有谁知道如何设置一个图表,我们可以在其中操作来自这些漂亮的生成器单元的样本?

下面是尝试使用语音合成时失败的渲染回调函数和图形实例化方法。当然,除了设置文件播放之外,音频文件播放器几乎是相同的。如果我删除回调并在其位置添加 AUGraphConnectNodeInput,这两种设置都可以工作...

static OSStatus RenderCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {

AppDelegate *app = (AppDelegate *)inRefCon;
AudioUnit inputUnit = app->_speechUnit;
OSStatus status = noErr;

status = AudioUnitRender(inputUnit, ioActionFlags, inTimeStamp, 0, inNumberFrames, ioData);
// *** ERROR *** kAudioUnitErr_Uninitialized, code: -10867

// ... insert processing code here...

return status;
}

- (int)createSynthGraph {
AUGRAPH_CHECK( NewAUGraph( &_graph ) );

AUNode speechNode, outputNode;

// speech synthesizer
AudioComponentDescription speechCD = {0};
speechCD.componentType = kAudioUnitType_Generator;
speechCD.componentSubType = kAudioUnitSubType_SpeechSynthesis;
speechCD.componentManufacturer = kAudioUnitManufacturer_Apple;

// output device (speakers)
AudioComponentDescription outputCD = {0};
outputCD.componentType = kAudioUnitType_Output;
outputCD.componentSubType = kAudioUnitSubType_DefaultOutput;
outputCD.componentManufacturer = kAudioUnitManufacturer_Apple;

AUGRAPH_CHECK( AUGraphAddNode( _graph, &outputCD, &outputNode ) );
AUGRAPH_CHECK( AUGraphAddNode( _graph, &speechCD, &speechNode ) );

AUGRAPH_CHECK( AUGraphOpen( _graph ) );
AUGRAPH_CHECK( AUGraphNodeInfo( _graph, outputNode, NULL, &_outputUnit ) );
AUGRAPH_CHECK( AUGraphNodeInfo( _graph, speechNode, NULL, &_speechUnit ) );

// setup stream formats:
AudioStreamBasicDescription streamFormat = [self streamFormat];
AU_CHECK( AudioUnitSetProperty( _speechUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &streamFormat, sizeof(streamFormat) ) );

// setup callback:
AURenderCallbackStruct callback;
callback.inputProc = RenderCallback;
callback.inputProcRefCon = self;
AUGRAPH_CHECK( AUGraphSetNodeInputCallback ( _graph, outputNode, 0, &callback ) );

// init and start
AUGRAPH_CHECK( AUGraphInitialize( _graph ) );
AUGRAPH_CHECK( AUGraphStart( _graph ) );
return 0;
}

最佳答案

您必须使用 AUGraphConnectNodeInput 将这些节点连接在一起。 AUGraph 不会初始化其中的 AudioUnit,除非它们已连接。图中未连接到其他单元的单元将不会被初始化。

您还可以尝试在启动图表之前手动初始化它们。

关于cocoa - 音频单元 : getting generated audio into a render callback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14190884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com