Playing From Resource (Visual Studio)

C++. If needed to play audio files from resource in Visual Studio (not to directly provide audio files), process would be a little bit different.  When upload files to resource, firstly you create .rc file, and then import files into it.  After uploading as binary file, a resource ID would be given in resource.h file. You can rename or modify them:

Then, by a piece of code block, you can search the file and use in the play function. FindResource(NULL, MAKEINTRESOURCE(resourceId), resourceType) plays an important role here. Here, play function for FMOD coud be like that:

Although it is enough for a steady single play, it is not good enough for interactive music play because it needs quickly search for short segments. It creates approximately 40-50 milliseconds delay for quick loads. That’s why, for optimisation, it would be good to insert sound objects for each file to relevant map container so that play function could call them from there. In my Closed Single State post, it would be easily placed there, and would perfectly work without a delay. You can download an example .exe file and run it. So, loading function, setting file names and load them into the container would be like that:

References:

[1] Using Resources – MSDN – Microsoft

[2] FMOD API Documentation

[3] Katy’s Code