External Audio Files for AUSampler

I have an app that uses .aupreset files along with .wav samples to define instruments that are loaded into an AUSampler audio unit.

The .aupreset files reference the .wav files with absolute paths. As described in Technical Note 2283, if the audio files cannot be found at the original path, then the system searches in the Bundle Directory, NSLibraryDirectory, NSDocumentsDirectory, and NSDownloadsDirectory, in that order.


I can get the instruments working in the app bundle, but now I'm trying to support downloaded instruments. If I put the content in <NSLibraryDirectory>/Sounds/, the AUSampler can't find the .wav samples, but if I put it in <NSDocumentsDirectory>/Sounds/, it works. I don't want to clutter the Documents directory with the instruments though, as that folder shows up in iTunes.


Also, I can't even create a directory at the NSDownloadsDirectory location - I just get an Operation not permitted error.


Has anyone successfully loaded samples from the Library before?


Note: This is on iOS 8 on an iPad Air.

Answered by in 20643022

It turns out the documentation for this is incorrect for iOS: AUSampler will only look in NSDocumentDirectory and the NSDownloadsDirectory in addition to the bundle. These are the recommended locations for storing application-specific data, if you aren't going to store it in the bundle, or you wish to enable users to add additional content to the app.


For OSX, the NSLibraryDirectory is also available.


-DS

>Note: This is on iOS 8.

Which device?

iPad Air

I ended up discussing this with the AUSampler engineer and if you can you submit a bug report with a test app. we can run some debug logging to figure out where things break and go from there. There have been some changes in access behavior for apps under iOS — but none that we could think of off the top under 8.0.


You can post the bug number here if you'd like or submit it via a Technical Support request and I can route it for you.

I've created a bug report and attached a sample project (a slightly modified version of LoadPresetDemo)

The number is: 21658533

Accepted Answer

It turns out the documentation for this is incorrect for iOS: AUSampler will only look in NSDocumentDirectory and the NSDownloadsDirectory in addition to the bundle. These are the recommended locations for storing application-specific data, if you aren't going to store it in the bundle, or you wish to enable users to add additional content to the app.


For OSX, the NSLibraryDirectory is also available.


-DS

Thanks for clearing that up!


I'd also just like to mention, it doesn't seem we can use the NSDownloadsDirectory either, as trying to create the directory returns an error ("The operation couldn’t be completed. Operation not permitted"). So it would appear that the only options on iOS are loading from the bundle or from the Documents directory. Not ideal when you also want to enable iTunes File Sharing for other content.


That being said, I did think of a workaround: put the content in an arbitrary location, and when loading the .aupreset file, rewrite all the file references to refer to that location before setting it on the Audio Unit. For now I'm just going to use the documents directory but if I ever need to enable iTunes File Sharing I may have to resort to the workaround.

External Audio Files for AUSampler
 
 
Q