Example of loading wav resource?

Hi,

If I want to package some wav files (e.g., some impulse responses, or a set of HRTFs) with an iPlug effect, what’s the best way? I’m assuming there is some way to put them in the resources folder, then load them, but I only see examples doing that with bitmaps and fonts. Are there functions to do it with audio data?

Thanks, Tim

Hi. Yes, I copy the files into the project folder (and drag them into the IDE folder). Then I use the function:

WDL_String path;
LocateResource (filename, filetype, path, GetBundleID (), nullptr , nullptr);
FILE *fin = fopen(path.Get(), "rb");

where filename and filetype are both const char* parameters with the file name (including path) and the file extension respectively. I don’t know if this is the best approach but at least it works for me.

As mentioned above you can use LocateResource for finding the file but there’s nothing in plug itself for loading audio.

I use IAudioFile here, which should be pretty portable and which is in a library I maintain with a liberal licenses (allowing inclusion in commercial products).

2 Likes

Hi Ric, I’m trying to use LocateResource to load a file but it seems that it works on Mac but when I try that in windows it just compiles and build fine but then the .exe crashes because it doesn’t find the file itself, did you have the same problem?

Yes l remember that for Windows some additional steps were required where you have to modify some files inside the solution’s file manager. l think all of that is explained somewhere in the IPlug2 FAQ or tutorials under “including external files” or something like that.

Not sure what is going on there, but you might try converting the resource to a cpp file using the included bin2c.py. info is here: 06_Load_a_resource · iPlug2/iPlug2 Wiki · GitHub

I’m actually trying to include a .nam file inside the plugin itself, it works for mac but not for windows, even if I included it in the config.h #define MYAMP_FN “myamp.nam” and also in the main.rc “MYAMP_FN NAM MYAMP_FN”. Still not working, Idk what I’m doing wrong.

Nam files are just json files. You could also include it as a string literal in your C++ source code file

tried with something like this:
std::ifstream file(MYAMP_FN);

std::unique_ptr<nam::DSP> mymodel = nam::get_dsp(file);

mModel = std::make_unique<ResamplingNAM>(std::move(mymodel), GetSampleRate());

mModel->Reset(GetSampleRate(), GetBlockSize());

mStagedModel = std::move(mModel);

But i get an error with the get_dsp, it says that no overload function can convert all argument types.

I’m a bit busy to help you through this but here is a clue:

I absolutely don’t wanna bother anyone, especially you Oli, thank you for the help!

1 Like

Sorry to bother again, I had no luck by doing this, but I was also thinking (before going even further) that I don’t really want to edit the NAMCore because if there’s an update I should redo every edit previously did, so I might want to find a solution to use the nam file and embed it in the .exe and .vst3. But currently having trouble with this on windows. I’ve included the file in the main.rc but the code:

WDL_String path;
        LocateResource("myamp.nam", "nam", path, GetBundleID(), nullptr, nullptr);
        std::unique_ptr<nam::DSP> mymodel = nam::get_dsp(path.Get());
        mModel = std::make_unique<ResamplingNAM>(std::move(mymodel), GetSampleRate());
        mModel->Reset(GetSampleRate(), GetBlockSize());
        mStagedModel = std::move(mModel);

Looks for the file outside of the exe.