加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xcode – iOS LoadPresetDemo示例代码中的AU Preset(.aupreset)

发布时间:2020-12-14 17:45:48 所属栏目:百科 来源:网络整理
导读:我一直在使用iOS LoadPresetDemo示例代码 – 如果加载AUPreset文件来配置不同类型的采样器(非常酷) – 并且遇到了问题/问题. 演示代码运行正常,但是当我尝试在从头开始构建的测试项目中重用.aupreset文件时,Trombone.aupreset不起作用.深入研究.我发现.aupre
我一直在使用iOS LoadPresetDemo示例代码 – 如果加载AUPreset文件来配置不同类型的采样器(非常酷) – 并且遇到了问题/问题.

演示代码运行正常,但是当我尝试在从头开始构建的测试项目中重用.aupreset文件时,Trombone.aupreset不起作用.深入研究.我发现.aupreset文件中的音频样本路径看起来很奇怪.

plist中的路径(下图)指向:

file://localhost//Library/Audio/Sounds/Tbone/1a%23.caf

但这不是正确的路径 – 根据项目目录结构.没有“库/音频”目录 – 虚拟或真实.所以我很困惑. Apple演示工作正常,但我从头开始项目没有(尝试加载示例时得到错误-43).加载样本的代码(在底部)没有做任何事情来在运行时重新激活路径.

有谁看到我在这里误解了什么? – 谢谢!

// Load a synthesizer preset file and apply it to the Sampler unit
- (OSStatus) loadSynthFromPresetURL: (NSURL *) presetURL {

CFDataRef propertyResourceData = 0;
Boolean status;
SInt32 errorCode = 0;
OSStatus result = noErr;

// Read from the URL and convert into a CFData chunk
status = CFURLCreateDataAndPropertiesFromResource (
            kCFAllocatorDefault,(__bridge CFURLRef) presetURL,&propertyResourceData,NULL,&errorCode
         );

NSAssert (status == YES && propertyResourceData != 0,@"Unable to create data and properties from a preset. Error code: %d '%.4s'",(int) errorCode,(const char *)&errorCode);

// Convert the data object into a property list
CFPropertyListRef presetPropertyList = 0;
CFPropertyListFormat dataFormat = 0;
CFErrorRef errorRef = 0;
presetPropertyList = CFPropertyListCreateWithData (
                        kCFAllocatorDefault,propertyResourceData,kCFPropertyListImmutable,&dataFormat,&errorRef
                    );

// Set the class info property for the Sampler unit using the property list as the value.
if (presetPropertyList != 0) {

    result = AudioUnitSetProperty(
                self.samplerUnit,kAudioUnitProperty_ClassInfo,kAudioUnitScope_Global,&presetPropertyList,sizeof(CFPropertyListRef)
            );

    CFRelease(presetPropertyList);
}

if (errorRef) CFRelease(errorRef);
CFRelease (propertyResourceData);

return result;
}

解决方法

我遇到了同样的问题,经过2个小时的比较“加载预设”-Demo和我的代码后,我找到了解决方案:

添加声音文件夹时检查选项:

>复制项目>为任何添加的文件夹创建文件夹引用 – 添加的文件夹将为蓝色,如“加载预设”-demo-project!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读