LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sound generation to external speakers with cDAQ

Hello esteemed Labview connaisseurs


In short:

When I run the attached VI, I cannot change the produced sound frequency via the Basic Function Generator's input variable "Frequency", only the amplitude via its respective input variable. 


In long: 

I extracted the attached VI from a much larger, even uglier VI that would earn me the scorn of anyone reading this. The goal of this smaller VI is to create a sound with cDAQ-hardware and a NI9260 card. 

 

Currently I can create a sound that is to some degree dependent on the amplitude of the Basic Function Generator. The problem is that the frequency is for some unknown reason heavily dependent of the DAQ Sample Clock's sample rate. Sounds from frequencies between 10240 and just below 17000 sound the same while there is an audible change above that. 

I suspect that the way I cut the signal combines with the sample rate in some way to create the actual sound's frequency. The theoretically targeted sound's frequency that is input in the Basic Function Generator is completely ignored. 

 

I am aware that there are some workarounds like creating the whole sound at the beginning of the VI and then just play the whole thing. The issue is that in its final application, this little VI is run parallel to some read tasks that control the given amplitude to ensure that the hardware cannot be damaged by accidental misuse. Additionally there are some graphs and dynamic UI elements so depending on the requested sound resolution and duration it might lead to some delays within the display and loop execution. This is why I would prefer to just handle one period of the signal between states and loops and let the DAQ Write deal with filling in the rest. 

 

The sample rate input is also limited to certain values due to additional hardware requirements that apply to the final VI, but not to the attached one. This limitation is thus irrelevant to you, dear reader. 

 

Anyone who wishes to run this VI on their own machine can simply remove the inital "Initalize Output"-SubVI and replace it with a "Create Channel" with AO Voltage and 2 channels. 

 

Having read of my plight - an act for which I am already thankful - do you have any advice on what I am missing and what I have to change to ensure accurate sound production at a targeted amplitude and frequency? Any advice and explanation beyond that is always welcome as well. 


Kind regards

Jay-Al 

 

0 Kudos
Message 1 of 4
(853 Views)

Edit: maybe try this: 

snip.png

its from the examples 


______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
0 Kudos
Message 2 of 4
(837 Views)

Thanks for the advice!

 

I have looked through some example VIs that might fit as well, and your solution seems to be a viable method to create sound with DAQ in general, but it does not quite fit all the needs of the situation I am in.

Please correct me if I am wrong, but with your solution I would have to define the sound information at the beginning of the task. But in the end I would like to keep the VI where I have functionally inserted the previously attached VI running and change the sound frequency preferably by creating a different one period sound wave and handing that over to the Write function.

 

If that is not something that is possible in any way or shape, let me know.

0 Kudos
Message 3 of 4
(799 Views)

@JayAl wrote:

Thanks for the advice!

 

I have looked through some example VIs that might fit as well, and your solution seems to be a viable method to create sound with DAQ in general, but it does not quite fit all the needs of the situation I am in.

Please correct me if I am wrong, but with your solution I would have to define the sound information at the beginning of the task. But in the end I would like to keep the VI where I have functionally inserted the previously attached VI running and change the sound frequency preferably by creating a different one period sound wave and handing that over to the Write function.

 

If that is not something that is possible in any way or shape, let me know.



To focus only on the main issue of reading control values in a loop, you can try this slightly modified version of your code (with the disclaimer that there are other code issues here that will eventually need to be sorted out). Based on your issue, you want to update the waveform in the loop so you need to put your input (the controls) in the loop so they are read each time through the loop: 

snip.png

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
0 Kudos
Message 4 of 4
(785 Views)