Skip to content

Feature Guides Audio Development

Alex J Lennon edited this page Oct 10, 2025 · 3 revisions

Audio Development Guide

Board Support: Edge AI (imx8mm-jaguar-sentai) - TAS2563 Audio Codec
⏱️ Time Required: 15-45 minutes depending on complexity
Prerequisites: Board booted and validated from Quick-Start-01-Board-Setup-Checklist

🎵 Audio System Overview

Hardware Configuration

# Audio Codec: TAS2563 (I2C address 0x4C)
# Audio Interface: SAI3 (Serial Audio Interface)
# Microphones: Dual PDM microphones via MICFIL
# Format: I2S, TDM support
# Sample Rates: 8kHz - 192kHz
# Bit Depth: 16/24/32-bit

ALSA Device Names

# Check available audio devices
aplay -l                           # Playback devices
arecord -l                         # Capture devices

# Expected devices:
# Card 0: tas2563audio (TAS2563 playback)
# Card 1: micfilaudio (PDM microphone capture)  
# Card 2: Loopback (software loopback)
# USB Audio Gadget: Appears when enabled for debugging

🔧 Basic Audio Setup

1. Audio System Validation (2 minutes)

# Check audio cards are detected
cat /proc/asound/cards

# Expected output:
# 0 [tas2563audio   ]: tas2563-audio - tas2563-audio
# 1 [micfilaudio   ]: micfil-audio - micfil-audio
# 2 [Loopback      ]: Loopback - Loopback

# Test basic playback capability
speaker-test -D hw:0,0 -t sine -f 1000 -c 1 -s 1
# Should generate 1kHz tone for 1 second

2. Volume Control Setup (3 minutes)

# Check available mixer controls
amixer -c 0 scontrols              # TAS2563 controls
amixer -c 1 scontrols              # MICFIL controls

# Set playback volume (TAS2563)
amixer -c 0 sset 'Master' 80%      # Set to 80% volume
amixer -c 0 sget 'Master'          # Check current volume

# Set capture volume (Microphones)
amixer -c 1 sset 'Capture' 70%     # Set mic gain

3. Audio File Playback Test (2 minutes)

# Play WAV file (if available)
aplay -D hw:0,0 /usr/share/sounds/alsa/Front_Left.wav

# Generate and play test tone
sox -n -t wav - synth 3 sine 440 | aplay -D hw:0,0

# Play MP3 (if gstreamer available)
gst-launch-1.0 filesrc location=test.mp3 ! decodebin ! audioconvert ! alsasink device=hw:0,0

🎤 Microphone Configuration

1. PDM Microphone Setup

# Check microphone capture
arecord -D hw:1,0 -f S16_LE -r 48000 -c 2 -d 5 test-recording.wav
# Records 5 seconds of stereo audio at 48kHz

# Play back recording
aplay -D hw:0,0 test-recording.wav

# Check recording levels
arecord -D hw:1,0 -f S16_LE -r 48000 -c 2 -V mono /dev/null
# Shows VU meter for input levels

2. Microphone Gain Adjustment

# List microphone controls
amixer -c 1 controls

# Adjust microphone gain
amixer -c 1 sset 'Capture' 60%     # Lower gain (reduce noise)
amixer -c 1 sset 'Capture' 90%     # Higher gain (increase sensitivity)

# Check for AGC (Automatic Gain Control)
amixer -c 1 sget 'AGC'             # If available

🔊 Advanced Audio Configuration

1. TAS2563 Codec Programming

# Check codec I2C communication
i2cget -y 1 0x4C 0x00              # Read Page Select register
# Expected: 0x00 (Page 0 selected)

# Read codec status
i2cget -y 1 0x4C 0x01              # Read Software Reset register
i2cget -y 1 0x4C 0x02              # Read Power Control register

# Advanced: Load custom codec configuration
# (Requires TAS2563 firmware binary)
echo "tas2563" > /sys/class/firmware/tas2563_uCDSP.bin/loading
cat /path/to/tas2563_uCDSP.bin > /sys/class/firmware/tas2563_uCDSP.bin/data
echo 0 > /sys/class/firmware/tas2563_uCDSP.bin/loading

2. Audio Routing Configuration

# Check current audio routing
cat /proc/asound/card0/pcm0p/info   # Playback info
cat /proc/asound/card1/pcm0c/info   # Capture info

# Advanced routing with ALSA PCM plugins
# Create ~/.asoundrc for custom routing:
cat > ~/.asoundrc << 'EOF'
pcm.!default {
    type asym
    playback.pcm "hw:0,0"
    capture.pcm "hw:1,0"
}

ctl.!default {
    type hw
    card 0
}
EOF

3. Real-Time Audio Processing

# Check audio latency
aplay -D hw:0,0 --period-size=64 --buffer-size=128 test.wav

# Low-latency audio setup (requires RT kernel)
# Add to /etc/security/limits.conf:
# @audio - rtprio 95
# @audio - memlock unlimited

# Test real-time audio
jackd -d alsa -d hw:0,0 -r 48000 -p 64 -n 2

🎛️ Audio Application Development

1. GStreamer Audio Pipeline

# Basic playback pipeline
gst-launch-1.0 filesrc location=audio.wav ! wavparse ! audioconvert ! alsasink device=hw:0,0

# Capture pipeline
gst-launch-1.0 alsasrc device=hw:1,0 ! audioconvert ! wavenc ! filesink location=recorded.wav

# Real-time processing pipeline
gst-launch-1.0 alsasrc device=hw:1,0 ! audioconvert ! audioresample ! \
    ladspa-amp gain=2.0 ! audioconvert ! alsasink device=hw:0,0

2. ALSA Programming Example

// Simple ALSA playback example
#include <alsa/asoundlib.h>

int main() {
    snd_pcm_t *handle;
    int err;
    
    // Open PCM device for playback
    err = snd_pcm_open(&handle, "hw:0,0", SND_PCM_STREAM_PLAYBACK, 0);
    if (err < 0) {
        printf("Playback open error: %s\n", snd_strerror(err));
        return -1;
    }
    
    // Configure PCM parameters
    snd_pcm_set_params(handle,
                       SND_PCM_FORMAT_S16_LE,  // 16-bit signed little endian
                       SND_PCM_ACCESS_RW_INTERLEAVED,
                       1,                       // channels (mono)
                       48000,                   // sample rate
                       1,                       // allow resampling
                       500000);                 // 0.5 second latency
    
    // Write audio data...
    // snd_pcm_writei(handle, buffer, frames);
    
    snd_pcm_close(handle);
    return 0;
}

3. Python Audio Development

#!/usr/bin/env python3
import pyaudio
import numpy as np

# Audio parameters
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 48000

# Initialize PyAudio
p = pyaudio.PyAudio()

# Open audio stream
stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,
                input_device_index=1,    # MICFIL device
                output=True,
                output_device_index=0,   # TAS2563 device
                frames_per_buffer=CHUNK)

# Real-time audio processing loop
try:
    while True:
        # Read audio data
        data = stream.read(CHUNK)
        audio_array = np.frombuffer(data, dtype=np.int16)
        
        # Process audio (example: simple gain)
        processed = (audio_array * 0.5).astype(np.int16)
        
        # Write processed audio
        stream.write(processed.tobytes())
        
except KeyboardInterrupt:
    pass

# Cleanup
stream.stop_stream()
stream.close()
p.terminate()

🔍 Audio Debugging

Common Audio Issues

# No audio output
# 1. Check volume levels
amixer -c 0 sget Master
# 2. Check device not muted
amixer -c 0 sget Master | grep -o '\[on\]'
# 3. Check codec power
i2cget -y 1 0x4C 0x02

# Distorted audio
# 1. Check for clipping (reduce volume)
# 2. Check sample rate mismatch
# 3. Check for ground loops (power supply)

# No microphone input
# 1. Check capture device
arecord -l
# 2. Check microphone power/bias
# 3. Check PDM clock configuration

Audio Performance Monitoring

# Check audio dropouts/underruns
cat /proc/asound/card0/pcm0p/sub0/status
cat /proc/asound/card1/pcm0c/sub0/status

# Monitor CPU usage during audio
htop                               # Look for high CPU processes
cat /proc/interrupts | grep audio # Check interrupt load

📋 Audio Development Checklist

Basic Setup:

  • Audio devices detected - aplay -l shows tas2563audio
  • Microphones working - arecord captures audio
  • Volume control - amixer controls work
  • Playback test - speaker-test produces sound

Advanced Features:

  • Codec communication - I2C reads/writes successful
  • Custom routing - ALSA configuration working
  • Low latency - Real-time audio processing
  • Application integration - GStreamer/ALSA APIs working

🔧 USB Audio Gadget (Debugging)

Overview

The USB Audio Gadget feature allows the board to appear as a USB audio device to a host computer. This is useful for debugging audio issues and testing audio routing.

Configuration

  • Purpose: Debugging only - disabled by default
  • Audio Format: 48kHz, 16-bit, stereo
  • Functions: Separate playback and capture

Usage

# Enable USB audio gadget for debugging session
sudo systemctl start usb-audio-gadget.service

# Check status
setup-usb-audio-gadget status

# Manual control
sudo setup-usb-audio-gadget setup    # Enable
sudo setup-usb-audio-gadget stop     # Disable

# Disable after debugging
sudo systemctl stop usb-audio-gadget.service

Host Computer Detection

When enabled, the board will appear as "Jaguar Sentai USB Audio" on the host computer:

  • Linux: Shows in aplay -l and PulseAudio
  • Windows: Appears in Sound control panel
  • macOS: Shows in Audio MIDI Setup

🔄 Next Steps

Basic audio working? → Try Feature-Guides-Wireless-Configuration for Bluetooth audio

Need custom processing? → See Advanced-Topics-Cm33-Firmware-Guide for DSP development

Performance issues? → Check Development-Workflows-Debugging-and-Troubleshooting


💡 Pro Tip: Use alsamixer (ncurses interface) for interactive audio control - much easier than command-line amixer for testing!

Clone this wiki locally