A Jetson Device For All Your Audio Applications

By Luke Abela

AIoT Engineer

SmartCow

February 17, 2022

Blog

A Jetson Device For All Your Audio Applications

Over the years Nvidia have released a line-up of Jetson Developer Kits, small, power-efficient AI computers.

With models including the Jetson Nano, Xavier NX, and the AGX Xavier, NVIDIA has produced a line of compact computers capable of efficiently deploying AI solutions in various environments to meet diverging needs and expectations.

The Jetson Nano Developer kit is a small, powerful computer which allows users to run multiple neural networks simultaneously for applications such as image classification, object detection, segmentation, and speech processing — all in a compact device consuming as little as 5 watts. The Jetson Nano development kit comes equipped with various peripheral devices including USB, Ethernet, and HDMI connections. One missing but common peripheral is some form of audio input or output. Numerous devices these days come equipped with audio jacks, and some even carry on-board microphones.

 

Jetson Nano Development Kit (Photo: NVIDIA)

There are many ways to go about adding audio capabilities to a Jetson device. USB speakers and USB microphones are an easy solution, but they do take up valuable USB slots which may be better served for keyboards, adding Bluetooth capability, Internet Keys, and other accessories.

On the Jetson devices, NVIDIA provides access to a range of peripherals such as I2C, SPI, and I2S via a 40-pin GPIO expansion header. For the sake of working with audio, we are most interested in the I2S peripheral, an electrical serial bus interface used to connect digital audio devices. We do not need to create an I2S functionality from scratch, but knowing the ins and outs of common communication protocols is always useful, so for more information on the I2S check out this great article.

The Jetson’s 40-pin expansion header allows us to access the I2S peripheral easily, and with the appropriate additional electronics — we can quickly take advantage of the I2S functionality.

I2S Timing Diagram from Philips Semiconductor, the developers of the protocol. (Photo: SmartCow)

Our Hardware of Choice

The Adafruit I2S MEMS Microphone breakout board (SPH0645LM4H) is a compact audio recording solution with an input frequency range of 50 Hz to 15 kHz. The board does not feature an analog output but rather a purely digital one.

Many micro-controllers typically come equipped with an analog input, making the addition of an analog audio signal a straightforward task. For larger and more complex micro-controllers and micro-computers, an analog input is not guaranteed. To compound the issue, analog microphone systems are known to have noise seep into them. In place of an analog input, an I2S peripheral may commonly be found.

The microphone is a single mono element — you can opt to make use of the left or right channel. For those who would prefer/require stereo, a simple configuration using two microphones can be easily implemented with one microphone set to the left channel, and a second microphone set to the right channel. It is also worth nothing that this device is a slave device, and must be fully driven using an external logic.

Adafruit I2S MEMS Microphone Breakout — SPH0645LM4H (Photo: Adafruit)

The Adafruit MAX98357 I2S Class-D Mono Amp is suited to micro-controllers and microcomputers which have digital audio capability. It can receive a standard I2S digital audio input, and decode it into analog signal before amplifying directly into a speaker. This compact breakout board solves two common tasks for digital audio outputs: I2S digital to audio conversion (DAC) and amplification. The amplification gain can also be modified with the addition of well chosen resistors or variable resistors.

The output is an approximate 300kHz square wave PWM which is averaged out by the speaker coil — high frequencies are not heard. It is in fact capable of driving a generic speaker directly without any intermediate steps.

This small mono amplifier punches above its weight — able to deliver up to 3.2 Watts of power into a 4 ohm impedance speaker (5V power @ 10% THD). The amp is incredibly efficient, given its class D architecture, making it easy run from 2.7V to 5.5V DC supplies — perfect for portable and battery-powered projects.

Adafruit MAX98357 I2S Class-D Mono Amp (Photo: Adafruit)

Setting up the Jetson Nano

The Jetson Nano is the heart and center piece of this project. Setting up the Jetson Nano is a well-documented process. You can find various resources as to how to accomplish this task. One such guide would be the following: https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit

For our task, the Jetson Nano will need a USB to UART cable for power and programming, a keyboard, mouse, and HDMI monitor. Furthermore, we need to wire up our breakout boards to the Jetson Nano:

Make sure to also connect your MAX98357A outputs to a speaker. We used an 8 Ohm, 15 Watt speaker with a 3.3V supplied from the Jetson Nano.

Configuring the I2S

Jetson Nano with SPH0645 and MAX98375A + Speaker (Photo: SmartCow)

Once you have Jetson Nano booted up, it is a very straightforward process to configure your I2S pins in the Jetson 40-pin GPIO expansion header:

1. On the developer kit, open a command line terminal and run the following:

2. Jetson will launch and its main display shown. In our case we want to Configure the Jetson 40pin Header and Configure header pins manually.

3. On the "Select desired functions (for pins):" page, select the i2s4 option.

4. Afterwards, you will be taken back to the main page and asked to reboot and save the re-configurations you have made, so go ahead and reboot.

Configure Jetson 40pin Header (Photo: SmartCow)

Configure Headers Pins Manually (Photo: SmartCow)

Select i2s4 Peripheral (Photo: SmartCow)

Save Pin Changes (Photo: SmartCow)

Save and Reboot! (Photo: SmartCow)

Should you require further guidance on configuring your Jetson pins, please check out this link.

After you have rebooted and logged back into your Jetson Nano, you’ll want to install to install any updates, and download a couple of libraries.

Let’s initialize our microphone settings: all we have to do is reset our sound card, set our volume, and specify the path we would like our audio signal to use.

After setting the sampling rate (48kHz), and specifying the desired length of recording (in this case 30 seconds), we can finally begin recording!

After recording you’ll notice that we now have a file called “test.wav”, this is the recorded audio. We’re not quite done yet though, we can also play the recorded audio back. Let’s reset the sound card and set our volume.

All that’s left to do now is input the command to play the generated audio file.

Be sure to take a moment to sit back and enjoy listening to the speaker. Please feel free to check out our-mini demo. We recorded a song via the SPH0645 microphone and played it back using the MAX98357.

Conclusion

Mission accomplished! We’ve successfully built an end-to-end audio system for the Jetson Nano development kit, powered by nothing but a USB cable. You could possibly include a machine learning model next and playback an altered version of the recording. Consider translating from one language to another, adding audio effects such as filtering and compression, or creating a voice mapping (who wouldn’t want to sound like Darth Vader or Morgan Freeman?)

References

  1. https://developer.nvidia.com/embedded/jetson-developer-kits
  2. https://hackaday.com/2019/04/18/all-you-need-to-know-about-i2s/
  3. https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp
  4. https://www.adafruit.com/product/3421
  5. https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit
  6. https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/hw_setup_jetson_io.html

Luke Abela is an AIoT Engineer working with SmartCow AI Technologies Ltd. at their Malta office. He obtained his Bachelor of Engineering from the University of Malta before pursing a Master of Science in Artificial Intelligence at Queen Mary, University of London.

Luke Abela is an AIoT Engineer working with SmartCow AI Technologies Ltd. at their Malta office. He obtained his Bachelor of Engineering from the University of Malta before pursing a Master of Science in Artificial Intelligence at Queen Mary, University of London.

More from Luke

Tech News Roundup
MORE