10-06-2010 11:04 AM
We share a VI that allows the user to easily switch between real-time audio acquisition and reading from a static WAV file. The output of the VI is a waveform that may be used for graphing or signal processing.
This VI is written like an express VI: references and tasks are opened on first call, data is acquired on every call (unless an acquisition fails or the end-of-file is reached), and the stop input closes all tasks. Use the stopped output to wire into the conditional terminal of a loop. On first call, a reference is opened to an audio acquisition task, or an audio input file, and hence the Input Mode control is only read once. The mode cannot be changed at runtime.
The Input Mode input is the only required terminal. In Real-Time Audio mode, data is acquired from audio input device at sample rate (S/s) and output as a waveform of duration segment length (s) (or less if acquisition is stopped). In Audio File mode, data is acquired from WAV Input File at the input file's native sampling rate and output as a waveform of duration segment length (s) (or less if acquisition is stopped or end-of-file is reached); if play audio file is true, then the acquisition is synchronized to real-time and passed to audio output device for audio playback.
Note that real-time audio input tends to require segment lengths of 250ms or longer; the same applies for audio output. Shorter segment lengths may introduce clicks, aliasing, or artifacts due to operating system jitter.
If placed in a loop for continuous acquisition, and the mode is Real-Time Audio (or Audio File with play audio file set to true), then the duration of each loop iteration will be at least segment length (s).
Audio is continuously acquired from a user-selected source. Returned waveforms are plotted in both time and frequency domains.
The first screenshot shows the real-time audio acquisition case; the second shows acquisition from a file.
1.0 (2010-10-06): Initial release.
1.1 (2011-09-16): Added screenshots, fixed broken images.
08-31-2011 02:03 PM
Could you update the images so they would show up on the article? Also can you down convert the code to LN 2009? Thanks!
08-31-2011 09:30 PM
Hi, I'll look into why the images aren't showing. I generally post in the version of LabVIEW that I am using and don't down convert.
09-01-2011 09:51 AM
Have you tested this on Mac? I'd like to record sound on Macbook Pro; however as you might know there is no Microphone In on Macs, only Line In that requires high quality mics with pre-amps. What is your experience with it?
09-01-2011 10:58 AM
I have not tested this on Mac - if the audio functions in LabVIEW work on Mac (as I suspect they do), I think this VI should work.
09-16-2011 02:20 PM
Thanks for fixing the images! I've been testing sound capabilities on a Mac and found they differ from the PC. I've not tested your code on Macs but I assume the result will be different. I posted some comments on NI Mac OS forums however I do not tihnk NI will fix the issues anytime soon since it's PC oriented right now.