LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Record to wav.

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?

 

0 Kudos
Message 1 of 8
(1,220 Views)

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(1,214 Views)

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?

0 Kudos
Message 3 of 8
(1,172 Views)

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.  😉

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 4 of 8
(1,163 Views)

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

0 Kudos
Message 5 of 8
(1,136 Views)

@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.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 6 of 8
(1,110 Views)

@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

0 Kudos
Message 7 of 8
(1,101 Views)

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:
audacity_wasapi_loopback.png

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).

Spoiler

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.

 

Spoiler

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.

 

Message 8 of 8
(1,085 Views)