Resource task in a predefined task (.aupreset) in the IOS application code loading example LoadPresetDemo

I worked with iOS. LoadPresetDemo sample code - if it loads AUPreset files to configure various types of samplers (pretty cool) - and ran into a question / question.

The demo code works fine, but when I try to reuse .aupreset files in a test project created from scratch, Trombone.aupreset does not work. Delving into this, I noticed that it seems like weirdness with the ways of fetching audio in a .aupreset file.

The paths in the plist (images below) indicate:

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

but this is not the right way - according to the structure of the project directory. There are no Library / Audio directories - virtual or real. Therefore, I am confused. The demo version of Apple is working fine, but my project does not receive it from scratch (when loading samples), a -43 error occurs. The code that downloads the samples (below) does nothing to relativize paths at runtime.

Does anyone see me misunderstanding here? - Thanks!

directory structure

.aupreset plist

 // 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, 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, 0, &presetPropertyList, sizeof(CFPropertyListRef) ); CFRelease(presetPropertyList); } if (errorRef) CFRelease(errorRef); CFRelease (propertyResourceData); return result; } 
+4
source share
3 answers

I had the same problem, and after 2 hours comparing the โ€œpre-loadingโ€ -Demo with my code, I found a solution:

When adding a sound folder, check the options:

  • Copy elements
  • Create folder links for any added folders - and the added folders will be blue, as in the "pre-load task" -demo-project!
+5
source

Below is Apple's TN2283 technical note and discusses the issue with the paths that were originally asked. You will obviously need the Sounds folder, your assets and the pre-installed file part of your package.

Technical Note TN2283 AUSampler - Unloading Tools

When AUSampler tries to download audio files along the paths indicated on the outside of the refs file of the .aupreset file or a set of separate file URLs, it will use the following rules to resolve each path:

If the audio file is in the original path, it is downloaded. If the sound file is NOT found, AUSampler looks for whether the path will contain the part matching "/ Sounds /", "/ Sampler Files /" or "/ Apple Loops /" in that order.

If the path does NOT include one of the listed subpaths, an error is returned. If the DOES path includes one of the listed subpaths, part of the path preceding the subpath is deleted, and the following directory location constants are replaced in the following order:

NSLibraryDirectory Package Directory NSDocumentDirectory NSDownloadsDirectory

For example, in an iOS application, if the source path was "/Users/geddy/Library/Audio/Sounds/MyFavoriteHeadacheSound.caf" and this path was not found, AUSampler will then search for the sound file in the following four places:

 <Bundle_Directory>/Sounds/MyFavoriteHeadacheSound.caf <NSLibraryDirectory>/Sounds/MyFavoriteHeadacheSound.caf <NSDocumentDirectory>/Sounds/MyFavoriteHeadacheSound.caf <NSDownloadsDirectory>/Sounds/MyFavoriteHeadacheSound.caf 

Therefore, using the above example, if you moved the preset created on the desktop to the iOS application, you can simply put the MyFavoriteHeadacheSound.caf file in the Sounds folder in your application suite, and AUSampler will find the audio file referenced by the preset.

+3
source

You need to add both presets to your goal so that they are part of the package:

Show Package Contents of the Device Built executable

What is the line:

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

He speaks.

You can also see the Link to external audio files at the bottom of the page.

0
source

Source: https://habr.com/ru/post/1394694/


All Articles