Sound and Vibration

cancel
Showing results for 
Search instead for 
Did you mean: 

Real-Time Audio Acquisition and Audio File Playback on Desktop Targets

Introduction

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.

Supported Targets

  • LabVIEW (Windows / MAC)

Requirements

  • LabVIEW 2010

Implementation

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.

context help.jpg

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

Sample Code

Audio is continuously acquired from a user-selected source. Returned waveforms are plotted in both time and frequency domains.

snippet.JPG

Under the Hood

The first screenshot shows the real-time audio acquisition case; the second shows acquisition from a file.

snippet3.JPG

snippet2.JPG

Versions

1.0 (2010-10-06): Initial release.

1.1 (2011-09-16): Added screenshots, fixed broken images.

0 Kudos
Message 1 of 6
(19,577 Views)

Could you update the images so they would show up on the article? Also can you down convert the code to LN 2009? Thanks!

0 Kudos
Message 2 of 6
(11,824 Views)

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.

0 Kudos
Message 3 of 6
(11,825 Views)

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?

0 Kudos
Message 4 of 6
(11,825 Views)

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.

0 Kudos
Message 5 of 6
(11,825 Views)

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. 

0 Kudos
Message 6 of 6
(11,825 Views)