06-02-2020 10:37 AM
Hello,
I'm wondering how I would be able to control the amount of instances of a subVI in a single VI. For example, having a main VI which contains a numeric control that changes the amount of the tone generator subVIs to play harmonics. I could do a case statement that has a case for each harmonic, but if I have 5 harmonics I would have cases for 5, 4, 3, and 2 harmonics with corresponding amount of subVI instances in each case. This seems really inefficient, though. Any ideas?
Solved! Go to Solution.
06-02-2020 10:51 AM
What tone generator VI are you using?
I'd just use a For loop to generate each subharmonic, then combine them into a single waveform to play.
06-02-2020 11:04 AM
I made a tone generator subVI on my own as that's going to be used as the base of a larger project.
06-02-2020 11:07 AM
@danthecoffeecan wrote:
I'm wondering how I would be able to control the amount of instances of a subVI in a single VI.
Define what you mean by "control the amount". Is the subVI reentrant or not? How is it used? Does it generate the tone or just create the waveforms to be added?
Please show us some simple code example so we understand what you are doing.
06-02-2020 11:26 AM
The subVI is reentrant, and generates a tone (sine wave, triangle wave, etc) at a defined frequency to the computer audio output device. Essentially, it's just the Sound Output VIs with a wave type selection, and a duration control.
As for controlling the amount of VIs, I like to think about it in terms of text based programming: you would have a for loop (controlled by user input) that calls a function for each instance of the for loop. In this example, if you input "3," the loop will call the function three times with the frequency as an argument which correlates to the base frequency and iterations of the loop.
I just don't know how I could "call" the reentrant subVI at different amounts set by the user.
06-02-2020 11:52 AM
Your post is a bit ambiguous, so maybe I misunderstand.
You need to separate the waveform generation from the audio output. The sound output is a shared device and there is no need to hammer it from multiple code locations.
06-02-2020 12:19 PM
@danthecoffeecan wrote:
I just don't know how I could "call" the reentrant subVI at different amounts set by the user.
I don't understand this. If you call the subVI inside a For loop with your "user input" set to the Count terminal then would this not give you what you want? It seems to me to be analogous to your text based programming description. Just make sure that you don't have any autoindexing inputs.
06-02-2020 12:21 PM
Good to know, thanks, I'll turn the harmonics VI into the sound output VI itself. But then the fundamental issue still exists. I attached a couple images to visualize it.
In this case the instances would be how many harmonics the user wants to generate, which directly corresponds to how many waveforms (tones from above) are generated. I'm not sure how else to describe it.
06-02-2020 12:25 PM
@danthecoffeecan wrote:
Good to know, thanks, I'll turn the harmonics VI into the sound output VI itself. But then the fundamental issue still exists. I attached a couple images to visualize it.
In this case the instances would be how many harmonics the user wants to generate, which directly corresponds to how many waveforms (tones from above) are generated. I'm not sure how else to describe it.
Have you looked at the For loop as previously suggested? You should be able to easily do this with the For loop.
06-02-2020 12:32 PM
Waveform generation is nearly instantaneous compared to sound output, which is an extremely slow for a computer. Yes, use a FOR loop, autoindexing on an array of frequencies and sum the outputs for the combined sound.