LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Playing short Wavs and resources

Hi,
 
I am using the Windows SDK function PlaySound() to play a short click sound from a wav file when a user clicks a switch on the UIR. It works fine when I provide a full pathname to the wav file, but I have a few questions:
 
a) Wouldn't it be better to have this wav file loaded into memory so the disk need not be accessed each time the click is needed? How can I do this?
 
b) Can I do it by specifying it and loading it as a resource using LoadResource()?
 
c) Can I embed the wav into my exe at build time (perhaps as a named resource) using the CVI environment, or would I have to use a resource editor such as the freeware Resource Hacker?
 
Any help appreciated.
 
Thanks
 
Jamie Fraser
 
 
0 Kudos
Message 1 of 10
(5,369 Views)

What OS are you using? XP is particularly good at caching such file operations, so that although it appears to be reloading from disc each time as far as your program is concerned, it is in reality only being reloaded from an internal Windows memory area.

JR

0 Kudos
Message 2 of 10
(5,364 Views)
Hi,
 
Thanks for the reply. I use W2k or XP depending on machine. It certainly seems much quicker after the first click is played (only tested on the W2k machine so far), so it probably is caching. Do you know where I can find out more about when Windows caches data? It would still be nice to avoid any delay at all. Can you help with my other questions re. embedded resources?
 
Thanks
 
Jamie
0 Kudos
Message 3 of 10
(5,361 Views)

With regard to internal Windows operations, you would probably have better luck on the Microsoft Forums. Don't know of a way for CVI to embed a resource as you suggest - NI should be able to tell you.

JR

0 Kudos
Message 4 of 10
(5,359 Views)

Hi Jamie

 

There is no direct way to embed resources into an exe so the only way to do it would be to define the bit stream as an array constant.

 

What you could do to embed the wav file is to work out the bit stream, embed the array and load it in as constant. You could do this directly in your code or crate a dll and have the bit stream data as an array constant and use a function to call the data this would allow you to change the dll at a later date without rebuilding the exe.

 

This isn’t the neatest way of doing it and I would still recommend reading it from a file.

 

Hope this help

 

Tim

 

NI UK and Ireland AE

0 Kudos
Message 5 of 10
(5,337 Views)
I've just started looking to do the same thing, and am glad to see there's a question already here.  However, I'm starting from a slightly more basic knowledge of LabWindows - can someone point me in the direction of help on including SDK functions within LabWindows.
 
On the other hand, is there an easier method for playing WAV files from a control?
__________________________________________
The world is full of exciting challenges,
brilliantly disguised as insoluble problems.
0 Kudos
Message 6 of 10
(5,268 Views)

 I don't know if there is an easier way; however, it was pretty easy to do using this.

Look in your CVI executable directory (I use 8.0 -- so ...CVI80\samples\sdk\audio ) for the

files playsnd.c and playsnd.h.  I took them and incorporated them into my project and then made

calls to CVI_PlaySoundEx() straight from my code.  I also have the WINMM.LIB as part of my project.

I don't remember whether I had to add it or whether I was prompted.  either way......

That should do it.

0 Kudos
Message 7 of 10
(5,264 Views)
Yep, that is a nice easy way of playing .wav files.

More important question for me, though - is there any way of producing a tone through the sound card - i.e. not a PC speaker "beep", but using the sound card to produce a 2500 Hz signal for 1.25 s repeated every 5 s, for example.

Yes, creating a wav with those properties isn't hard, but I need to have full control over pitch / repetition rate / length in my program.

Cheers.

Message Edited by Pythonist on 04-21-2006 10:36 AM

__________________________________________
The world is full of exciting challenges,
brilliantly disguised as insoluble problems.
0 Kudos
Message 8 of 10
(5,190 Views)
Anyone?

__________________________________________
The world is full of exciting challenges,
brilliantly disguised as insoluble problems.
0 Kudos
Message 9 of 10
(5,085 Views)
The Microsoft solution for this would be to go through the DirectX SDK audio interface.  That would be extreme overkill for something as simple as this.  If you are using a specific sound card adapter, the vendor may have their own simple API that works with their device driver to allow you access to basic sound functions.  
0 Kudos
Message 10 of 10
(5,080 Views)