07-06-2023 08:35 AM
I have made a piano that is just buttons that when pressed read from a specific path the .wav and play it. I just wanna "record" what I'm playing. How to do that?
07-06-2023 08:52 AM
Hi Seiryuu,
@Seiryuu90 wrote:
II just wanna "record" what I'm playing. How to do that?
Record the information which button was pressed at which timestamp…
07-06-2023 10:32 AM
I dont know that way that you're describing. Isn't there a simpler way to just record the audio output while the program is running?
07-06-2023 10:44 AM
Not really. You are already using whatever sound card driver you have to play the notes. Setting it up to concurrently record its own output might be trivial with a dedicated audio program, but LabVIEW is a programming language mainly used for test and measurement. It's not designed for music production. You will probably need the API of whatever audio driver you are using and then call those functions in LabVIEW through a DLL. Even then, you would never come close to the performance of an audio program that has fast, low latency ASIO drivers.
Is there some specific reason you want to use LabVIEW for this? BTW, most people will not see your code at version 2023. Do a Save for Previous Version... and pick 2018 or so. 😉
07-06-2023 01:27 PM
Have you checked out LabVIEW's "Sound" Palette? It contains a bunch of VIs that "know" (a little bit) about Sound, including Sound Input, Sound Output, and handling Sound Files.
Bob Schor
07-07-2023 08:37 AM
@Bob_Schor wrote:
Have you checked out LabVIEW's "Sound" Palette? It contains a bunch of VIs that "know" (a little bit) about Sound, including Sound Input, Sound Output, and handling Sound Files.
Bob Schor
I assumed that OP was using those VIs to read and play his sound files. Can't be sure since I'm using LabVIEW 2019 and his VIs are the latest 2023, so I can't look at the code.
07-07-2023 08:56 PM
@NIquist wrote:
I assumed that OP was using those VIs to read and play his sound files. Can't be sure since I'm using LabVIEW 2019 and his VIs are the latest 2023, so I can't look at the code.
I partly agree with you -- if the OP was using the LabVIEW "Sound" VIs (which I also can't tell because I'm also using LabVIEW 2019), then I also can't understand why there is a problem recording sounds to a .WAV file. Maybe we'll see some code posted with the "Save for Previous Version" option ... We can't suggest fixes for code we can't see (and we aren't being paid to do someone else's work for them ...) (Oops, I didn't mean to say that ...)
Bob Schor
07-08-2023 11:34 AM
Hi Seiryuu90,
There are a number of approaches you can take depending on your requirements.
The quickest is to use another app like Audacity to do loopback audio recording while playing audio in LabVIEW. Ensure the WASAPI driver is selected, then select the loopback version of your audio output device. Hit record and it will capture whatever is being played on that device:
If the recording needs to be done within LabVIEW, there are a few options. LabVIEW's sound library doesn't have WASAPI + loopback audio support, but I've written a library called G-Audio (on github and vipm) which can do loopback audio recording. It includes a VI called Audio Loopback Example.vi which can run in parallel to your piano VI and save any playing audio to a wav file. Here's a quick demo showing playback being triggered in the piano VI, and the resulting audio being captured, displayed, and saved as wav via the WASAPI loopback audio device (sorry I didn't have any piano note samples handy).
Another option (also using G-Audio) is to use its mixer component for playing the piano note samples. In addition to mixing + playback, the mixer provides a copy of the output audio data in a queue which can be used in other parts of a LabVIEW application. The example video below demonstrates the included Sample Pad Example.vi and shows multiple audio clips being triggered, mixed, and the resulting audio written to both the output device and the queue. The audio in the queue is then read and displayed in a simple music visualizer. In your case the mixer would contain the piano note samples, and instead of the music visualizer the audio would be read from the queue and saved to a wav file in a separate loop.
If using base LabVIEW is your only option, a similar approach can be taken to the mixer mentioned above. You would need to configure the audio output device for continuous playback, then manage playback of each individual audio clip, mixing each clip's audio samples. The resulting audio would then be written to the audio output device and a copy written to a wav file. A combination of the bundled LabVIEW examples Sound File to Sound Output.vi and Sound Input to File.vi would probably be a good starting point, but isn't trivial. If you go down this path I'd recommend getting note playback and wav recording working for a single note / button first, then look at adding more notes.
For those without LV2023, I've attached the original VI saved in LV2018.