LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

play sine wave with soundcard on CVI

Does anybody know how to generate sine waves with the soundcard ?
Thank you for your help.
0 Kudos
Message 1 of 12
(6,909 Views)
Diver,

The way to go here is the Windows SDK. First make sure that you have the Windows SDK installer; go to the help menu and you should be able to select Windows SDK . If you don't have that option then you need to run the installer again and change the installation to include the Windows SDK.

Once you have this running there are a couple of ways you can do this:

  • Play a WAV file: this is the easy and fast way of doing it; record or generate the WAV file with any simple sound editor and use the function PlaySound() from the Windows SDK to play strait from the file (you can find more info about the function in the Windows SKD help file).
  • Play generated data using lower level soundcard functions: this is not as easy, but gives
    you the most flexibility; you basically open a session with the sound card and write data to it. I'm attaching a very basic example that can get you started.
  • Use Media Player to play a file: you can use ActiveX to embed Media Player in your UI and use it's capabilities to play wav files. CVI has a good shipping example about this, you can find it here.


You can request this feature for future version of CVI; go to http://www.ni.com/contact and select product feedback to submit your request.

In the mean time I hope this helps you get started.

Regards,

Juan Carlos
N.I.
Message 2 of 12
(6,909 Views)
Hello Juan Carlos,
thank you very much for your help.
With your sample programm I was able to solve my problem.

regards
Diver
0 Kudos
Message 3 of 12
(6,909 Views)
Dear Juan Carlos,

I just found your example code for generating sine waves through a sound card in Windows; thanks very much, it looks like exactly what I've been looking for for the last couple of weeks!

I'm currently designing a kind of digital theramin, using ultrasonic sensors, a PIC USB microcontroller, and LabWindows. For this, I need to generate tones of different frequencies and amplitudes, which I can switch on and off depending on input from the sensing hardware.

My questions are:

    1. Is it possible to generate a tone indefintely, and then switch it off as desired

    2. I've managed to change the frequency by altering NumberofCycles (or NumberofElements) in the SinePattern function, but would appreciate any suggestions you have on the best             way to produce different frequencies

    3. Any ideas on a good way to produces tones with some harmonics would be brilliant. I'm thinking one way would be to generate a square wave, but it would be nice to be able to             control how many harmonics were there...

           [ e.g. sin(x) + .5sin(2x) + .25sin(4x) ]

This is for a short project,  which we need to complete by Thurs, 5th June, so would be very grateful if you were able to get back in the next day or so.

Many thanks,

Richard.
0 Kudos
Message 4 of 12
(6,518 Views)

Hi Richard,

I'm glad to hear that you found Juan Carlos' example useful.

In order to play the tone indefinitely, you could call the waveOutWrite function multiple times in a loop until you are done.
Alternatively, if you know how long you want to play the tone, you can set the dwLoops attribute of the WAVEHDR.

In order to create the exact signal you want (ie, with harmonics), you might want to create the datapoints manually.
All the SinePattern function does is use a mathematical formula to generate datapoints of the wave. If you know what you want the wave to look like you could write a function that does just that.

Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 5 of 12
(6,478 Views)

Does anybody know how to creat a *.wav file ( out of sound datas ) in CVI. This file could then be played with a media player without my program.

 

Many thanks for any assitance.

 

 

Johann

0 Kudos
Message 6 of 12
(5,935 Views)
0 Kudos
Message 7 of 12
(5,930 Views)

Hello, many thanks this helps. You spoke of more hints in the forum. Please be so kind and send me some more

links to the subject: creating a *.wav file. Or send me the search items. I had no glue what to write into the search line.

 

 

thanks Johann

0 Kudos
Message 8 of 12
(5,895 Views)

Hi,

 

nothing spectacular, I simply used 'wav file' and got 64 entries... 🙂

0 Kudos
Message 9 of 12
(5,892 Views)

Hello Justin,

 

I like to use the WaveOut1.c file to play my accelerometer datas measured in a noisy environment again in the office.

 

To play a continous tone ( fix sine ) e.g. you described to use the waveOutWrite function multiple times in a loop.

Disatvantage: the sounds overlap or with delay you get brakes. Can I get a message from the soundcard

when its ready playing?

 

Then I tried to use the dwLoops attribute of the WAVEHDR...my program ignores  a higher loop number.

 

Can you please assist a second time.

 

Thanks for your patience

 

Johann Schuster

 


0 Kudos
Message 10 of 12
(5,272 Views)