在iOS6中加载带有CoreAudio AUSampler的EXS24乐器

时间:2012-10-25 01:29:35

标签: ipad ios6 core-audio coremidi

从AUSampler API看,它似乎应该支持Garage Band EXS24乐器。 AudioUnitProperties.h文件说明如下:

typedef struct AUSamplerInstrumentData {
    CFURLRef                fileURL;
    UInt8                   instrumentType;
    UInt8                   bankMSB;
    UInt8                   bankLSB;
    UInt8                   presetID;
} AUSamplerInstrumentData;

仪器类型可以具有以下类型:

enum
{
    kInstrumentType_DLSPreset   = 1,
    kInstrumentType_SF2Preset   = kInstrumentType_DLSPreset,
    kInstrumentType_AUPreset    = 2,
    kInstrumentType_Audiofile   = 3,
    kInstrumentType_EXS24       = 4
};

我尝试使用以下功能加载仪器:

-(OSStatus) loadFromEXS: (NSString *) path withSampler: (AudioUnit) sampler {
    OSStatus result = noErr;

    NSURL *presetURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:path ofType:@"exs"]];

    AUSamplerInstrumentData bpdata = {0};

    bpdata.fileURL = (__bridge CFURLRef)(presetURL);
    bpdata.instrumentType = kInstrumentType_EXS24;

    result = AudioUnitSetProperty(sampler,
                              kAUSamplerProperty_LoadInstrument,
                              kAudioUnitScope_Global,
                              0,
                              &bpdata,
                              sizeof(bpdata));
    return result;
}

在我的资源中,我有一个包含.exs文件和许多.wav示例的组。此函数会产生以下错误:

GlobalState::LoadEXS24Instrument: Load failed

这是否意味着EXS文件不正确?这是否意味着我没有正确加载它?或者,iOS6不支持此功能?

1 个答案:

答案 0 :(得分:0)

是的,它似乎支持EXS文件格式。但是有一个问题:EXS使用绝对文件路径。它不支持相对路径。这意味着你不能移动.wav样本,否则会破坏EXS乐器。这是我的猜测,为什么它不起作用。

请参阅:https://developer.apple.com/library/mac/#technotes/tn2283/_index.html