# Example of loading wav resource?

**URL:** <https://iplug2.discourse.group/t/example-of-loading-wav-resource/381>\
**Category:** Uncategorized\
**Created:** [13 April 2021 23:19 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381 "2021-04-13T23:19:07Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlanglois](https://avatars.discourse-cdn.com/v4/letter/t/a88e57/32.png) [@tlanglois](https://iplug2.discourse.group/u/tlanglois)\
**Post date:** [13 April 2021 23:19 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/1 "2021-04-13T23:19:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ric](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@Ric](https://iplug2.discourse.group/u/Ric)\
**Post date:** [14 April 2021 01:58 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/2 "2021-04-14T01:58:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AlexHarker](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@AlexHarker](https://iplug2.discourse.group/u/AlexHarker)\
**Post date:** [15 April 2021 18:22 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/4 "2021-04-15T18:22:13Z")

</div>

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).

> **[AlexHarker/HISSTools\_Library](https://github.com/AlexHarker/HISSTools_Library/tree/59b343edc1101c0f4308851a2b1e4247d287a4fe/AudioFile)**
>
> 59b343edc1101c0f4308851a2b1e4247d287a4fe/AudioFile

---

<div class="post-metadata">

**Author:** ![ValeGen](https://avatars.discourse-cdn.com/v4/letter/v/8e7dd6/32.png) [@ValeGen](https://iplug2.discourse.group/u/ValeGen)\
**Post date:** [3 May 2024 07:59 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/5 "2024-05-03T07:59:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ric](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@Ric](https://iplug2.discourse.group/u/Ric)\
**Post date:** [3 May 2024 14:17 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/6 "2024-05-03T14:17:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [4 May 2024 15:15 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/7 "2024-05-04T15:15:32Z")

</div>

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](https://github.com/iPlug2/iPlug2/wiki/06_Load_a_resource)

---

<div class="post-metadata">

**Author:** ![ValeGen](https://avatars.discourse-cdn.com/v4/letter/v/8e7dd6/32.png) [@ValeGen](https://iplug2.discourse.group/u/ValeGen)\
**Post date:** [4 May 2024 16:25 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/8 "2024-05-04T16:25:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [4 May 2024 16:25 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/9 "2024-05-04T16:25:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ValeGen](https://avatars.discourse-cdn.com/v4/letter/v/8e7dd6/32.png) [@ValeGen](https://iplug2.discourse.group/u/ValeGen)\
**Post date:** [4 May 2024 16:36 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/10 "2024-05-04T16:36:24Z")

</div>

tried with something like this:  
std::ifstream file(MYAMP\_FN);

```auto
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.

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [4 May 2024 16:44 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/11 "2024-05-04T16:44:38Z")

</div>

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

> <https://github.com/olilarkin/NeuralAmpModelerCore/commit/7ea2631e8d401a3146968cf5d53ddd477a3f8f2c>

---

<div class="post-metadata">

**Author:** ![ValeGen](https://avatars.discourse-cdn.com/v4/letter/v/8e7dd6/32.png) [@ValeGen](https://iplug2.discourse.group/u/ValeGen)\
**Post date:** [4 May 2024 16:46 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/12 "2024-05-04T16:46:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ValeGen](https://avatars.discourse-cdn.com/v4/letter/v/8e7dd6/32.png) [@ValeGen](https://iplug2.discourse.group/u/ValeGen)\
**Post date:** [5 May 2024 15:15 UTC](https://iplug2.discourse.group/t/example-of-loading-wav-resource/381/13 "2024-05-05T15:15:29Z")

</div>

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:

```auto
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.
