From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Hobbyist Toolkit

cancel
Showing results for 
Search instead for 
Did you mean: 

G-Audio sound library on Raspberry Pi (beta testing)

Hi everyone,

 

I'm in the process of bringing G-Audio to Raspberry Pi / LINX, and am pleased to report audio playback is working with a Raspberry Pi 3B+.

 

This means it's now possible to decode and playback MP3, FLAC, WAV, and Ogg Vorbis files directly from LabVIEW running on a LINX target. No chroot ssh trick, system exec calls, or Python code necessary 🎉

 

 

Spoiler

Those tact switches make for terrible sample trigger buttons - here's a more musical demo video of the same example VI running on Windows, demonstrating the multi-channel mixer.

If you're unfamiliar with G-Audio, it's an open source LabVIEW library designed as a replacement for LabVIEW's sound library (lvsound2), while bringing a number of new features and improvements.

 

Now a humble request to fellow hobbyists - I only have access to RPi 3B+ hardware, so would greatly appreciate if anyone could help test the library with other Raspberry Pi variants, BeagleBone Black, or other LINX capable boards (RockPi etc). If you have an audio hat / cape for your board or USB soundcard, I'd be interested to know if the library works with those too.

 

If you're interested in testing, or just want to try out the library, installation and (optional) build instructions are below.

 

Installation

Before beginning, ensure your board has the LINX toolkit installed and SSH is enabled.

 

1. Install G-Audio
Download and install the VIPM package from the github project dev branch:

https://github.com/dataflowg/g-audio/raw/dev/src/LabVIEW/VIPM/dataflow_g_lib_g_audio-0.3.0.2-dev.vip

 

2. Install ALSA to chroot
SSH into the LINX target (using PuTTy or similar) and run the commands:

 

 

sudo schroot -r -c lv
opkg update
opkg install alsa-lib
exit

 

 

 

3. Copy g_audio_32.so to the target
(Note: This library has been compiled for armv7a processors. Other architectures may need to build the library using the build instructions below.)

 

SCP / SFTP to the LINX target (using WinSCP or similar) and copy the library file located in <vi.lib>\Dataflow_G\G-Audio\lib\LINX\g_audio_32.so to the /srv/chroot/labview/usr/lib folder.

 

Alternatively, SSH to the LINX target and download the library direct from github:

 

 

cd /srv/chroot/labview/usr/lib
wget https://github.com/dataflowg/g-audio/raw/dev/src/LabVIEW/G-Audio/lib/LINX/g_audio_32.so

 

 


4. Make some noise!
Copy some audio files to your device using SCP or SFTP and place them in /home/pi or your preferred location. Create a LabVIEW project, add your LINX target, then try running the playback example VI from the Add-ons >> G-Audio >> Examples >> LINX palette.

 

If you need to adjust the volume output, SSH into the LINX target and run alsamixer. Press F6, then select the physical audio device (not Default). Use the up and down arrow keys to adjust the volume, or use numbers 1-9 to set the volume in 10% increments. Press Esc to save and exit the mixer.


Building

If you don't trust random libraries from the internet (and why would you?) or the pre-built library doesn't work on your hardware, the library can also be built from source. The following commands will install the build environment to chroot, clone the git repo, build the library, and copy the built library to chroot's /usr/lib.

 

 

 

sudo schroot -r -c lv
opkg update
opkg install packagegroup-core-buildessential
opkg install --force-depends libc6-dev
opkg install --force-depends libgcc-s-dev
opkg install libstdc++-staticdev
opkg install git
opkg install alsa-lib-dev
git clone https://github.com/dataflowg/g-audio
cd g-audio/src/C++
git checkout dev
g++ -shared -fPIC -o g_audio_32.so *.cpp -lm -lpthread -ldl -std=c++11
cp g_audio_32.so /usr/lib
exit

 

 


Known Issues

  • Calling Configure Audio Device.vi with an audio device other than the default (unwired) device will either hang during playback, or return an error. This includes what should be the default headphone device returned by Query Audio Devices.vi.
  • HDMI audio on Raspberry Pi doesn't work, even if it works in the host and is the default device in /etc/asound.conf in both host and chroot.
  • CPU usage when decoding and playing files in chroot is roughly double that of the same decoding and playback functions compiled in the host. Possibly softfp / fpu related - need to test compiler options.

 

If you do get a chance to test the library, please mention the hardware board, OS version, and the audio device you tested with. There are a few known issues (see above), but playback should work with the default headphone audio device. Thank you!

Message 1 of 7
(3,360 Views)

Some updates on the library progress. The latest VIPM dev build can be found here:

https://github.com/dataflowg/g-audio/raw/dev/src/LabVIEW/VIPM/dataflow_g_lib_g_audio-0.3.0.3-dev.vip

 

Installation instructions remain the same, though the build command has been updated (see below) if you're building from source.

 

CPU usage has been significantly reduced. Decoding and playing an mp3 previously used ~30% CPU on the RPi 3B+, but is now down to around 7% CPU. FLAC playback has dropped from ~20% to ~7%, and WAV playback is down from ~15% to ~6%. The updated build command is:

g++ -shared -fPIC -o g_audio_32.so *.cpp -lm -lpthread -ldl -std=c++11 -mfpu=neon -mfloat-abi=softfp

 

The ALSA backend now performs a verbose query on all available devices and their subdevices. Previously all of the hardware devices were abstracted into a single high level device. In reality a single device (like the headphone jack) can have many subdevices with different capabilities, of which only a subset are available in the chroot environment.

 

Unless there's any serious issues that appear during testing in the next week or two, I'll include Raspberry Pi / LINX support in the next library release.

0 Kudos
Message 2 of 7
(3,078 Views)

Hi,

I have tested G-Audio in my Raspberry Pi 3B+ with Raspbian 11 (bullseye) OS.

I'm getting the following error while playback and capture audio.

 

Capture Audio

Error code : 559239
G-Audio.lvlib:Configure Audio Device.vi:1020001<ERR>
G-Audio: Undefined error code -301 (see miniaudio.h).


Playback Audio
Error code : 559239
G-Audio.lvlib:Configure Audio Device.vi:1020001<ERR>
G-Audio: Undefined error code -2 (see miniaudio.h).

 

 

0 Kudos
Message 3 of 7
(2,493 Views)

@shijin_mathew wrote:

Hi,

I have tested G-Audio in my Raspberry Pi 3B+ with Raspbian 11 (bullseye) OS.

I'm getting the following error while playback and capture audio.

 

Capture Audio

Error code : 559239
G-Audio.lvlib:Configure Audio Device.vi:1020001<ERR>
G-Audio: Undefined error code -301 (see miniaudio.h).


Playback Audio
Error code : 559239
G-Audio.lvlib:Configure Audio Device.vi:1020001<ERR>
G-Audio: Undefined error code -2 (see miniaudio.h).

 

 


Hi shijin_mathew,

 

Thanks for the error report. Error -301 means the minaudio library failed to open the backend device, while error -2 is indicates invalid args in some internal function (likely that the audio device pointer is null).

 

There is a newer version of the VIPM package (dataflow_g_lib_g_audio-0.3.1.3-dev.vip). Please try installing it, and recopying / rebuilding the g_audio_32.so library file on the Pi.

 

  • Did you use the precompiled version of g_audio_32.so, or a manually compiled version?
  • What audio backends does Query Audio Backends.vi return?
  • What audio devices does Query Audio Devices.vi return?

I'll setup my Pi 3B+ with the latest Raspberry Pi OS and see if I can reproduce the errors.

0 Kudos
Message 4 of 7
(2,440 Views)

I've tested a clean install of Raspberry Pi OS 11 (32-bit with desktop, April 4th 2022), with version 0.3.1.3 and a manually compiled g_audio_32.so file. After copying an mp3 to /home/pi, I ran the example Audio Playback Example (LINX).vi and playback works via the headphone output.

 

There's no corresponding LINX audio capture example, as the Pi doesn't have an audio input device (no mic or line in). I can generate error -301 trying to capture audio, but that's expected as there is no input device.

 

If you've tried version 0.3.1.3 and are still seeing the playback error, could you share your LabVIEW code?

0 Kudos
Message 5 of 7
(2,419 Views)

Hi @Dataflow_G,

After updating with the link provided, all the errors are gone. Now it's working! 

  • I have used the precompiled so file. I was not able to figure out the cause for the previous errors. 
  • While having the error, on running Query Audio Backends.vi returns 'ALSA' .
  • While running Query Audio Devices.vi, disconnect the connection to RPI and after than i need to restart the device for establishing the connection.

Thanks for this amazing project.

0 Kudos
Message 6 of 7
(2,406 Views)

I think what might have happened was a mismatch between the VIPM package, and the g_audio_32.so library on the RPi. There were some API changes in the latest version to include additional device info. I'd updated the .so library file on github but hadn't posted a link to the new package here. Good to hear it's all working now 👍

0 Kudos
Message 7 of 7
(2,392 Views)