LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about sound files in an executable after build.

Solved!
Go to solution

So, I made a simple piano vi that plays a wave (.wav) file from a specified and local file path for each note pressed. It works as intended in the labview. After building the executable though,

no sound is heard (obviously).
So I have to manually just change the paths in the new computer for each note so that it works. As you can guess, this is counter-intuitive. So, how to include these sound files and automatically get called after building?
I tried putting these files in the data folder that contains the lvsound2.dll but it doesn't work. I also tried putting them as "source files and always included" at the build menu.

9.png7.png

0 Kudos
Message 1 of 9
(1,623 Views)

Here's how I handle finding the data I need for my Executable programs --

  1. I house the Project in a Project Folder, with the Project file (My Project.lvproj) "just inside" the folder.
  2. I create a sub-folder called "Data" inside the Project Folder.
  3. When I write code to save data, I save it in the Project's Data folder.  
  4. I write a sub-VI called "Data Folder" that builds a Path by combining the Folder holding the Application Directory (found in sub-Palette "File Constants" of the File I/O Palette) with the name "Data".  When used in Development Mode, this points to the Data Folder you just created in the Project File, and when used in Application Mode, it points to the Data sub-Folder that is in the LabVIEW Build folder you specify in the Build Specification, just what you want.  To play it safe, you can do a "Create Folder", but I think the Build will create it for you.

I vaguely recall reading that there is an extra layer of folder nesting between the Development and Executable modes, but using the Data Folder sub-VI that I just described, I can locate the Data folder in the same (relative) place in both Development and Executable modes, so if I can save files in Data (and any sub-folders I choose to create in Data) when developing, I can also do it when executing.

 

Bob Schor

Message 2 of 9
(1,586 Views)

And this works surely on different computers? Can you just please send a very simple example so that you dont waste your time so I can learn please?

0 Kudos
Message 3 of 9
(1,552 Views)

Have you tried using the "Application Directory" VI from the Fille I/O -> File Constants palette and use that to build a path to the sound files?  If your app is compiled into an EXE, this will return the directory where the EXE is saved.  If used in dev environment, VI will return the directory where the top-level VI or the project file is saved. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 4 of 9
(1,536 Views)
Solution
Accepted by Seiryuu90

Using the Application Directory constant to build a path to the folder containing the wav files would look something like this. In this example each wav file is loaded from a "notes" folder into a waveform array, so it's just a matter of indexing the waveform you need for playback. The notes folder would be a sub directory in either the lvproj path, or the built exe path.

Dataflow_G_0-1682516531034.png

 

An alternative to loading wav files at runtime is to embed the audio data directly into your VI as a constant. To do this, first load the audio data into an indicator (as above). Once the data is in the indicator, right-click it and change it to a constant. You'd then use that constant in place of any sound file loading. When you save the VI the audio data in the constant will be saved with it.

 

This method is less flexible, but for small resource files that don't change often it can be a handy way to package them with the code. It also means you can create LabVIEW snippets that play audio when run...

What Is Love (LV2013).png

Message 5 of 9
(1,528 Views)

@Seiryuu90 wrote:

And this works surely on different computers? Can you just please send a very simple example so that you dont waste your time so I can learn please?


It works on any "different" computer as long as you keep the "data" folder next to the executable. A better option would be to build an installer and specify to "always include" the sound files. Now you would just install it on any other computer and things will work.

 

Guessing from your original picture, your code seems overly complicated and limiting. Why not use an array of booleans? If you want to simulate a real keyboard with white and black keys, use a cluster of booleans with keys in the correct cluster order, but arranged like in a real piano. Even the sounds could be synthesized from first principles using plain math (given main frequency, harmonics, attack, decays, etc. parameters). No sound files needed and fully scalable even for a 88 keys the code would still fit on a postcard. Your code architecture would be unmanageable because it does not scale!

Message 6 of 9
(1,513 Views)

Thank you so much, guys!

0 Kudos
Message 7 of 9
(1,495 Views)

Thank you the first way just worked as intended. When I try the second and make it a constant, this happens. What am I doing wrong?9.png

0 Kudos
Message 8 of 9
(1,491 Views)

A constant is a data source, not a data sink.

 

Create an indicator instead and run the VI until it contains data. The turn that indicator into a constant and it will keep the data forever.

 

(I am not sure why you have a greedy while loop that spins as fast as the computer allows, reading the same files over and over again. Makes no sense. Once is sufficient! You don't need the while loop to create that constant ad described)

0 Kudos
Message 9 of 9
(1,479 Views)