Audio Unidirectional

Description

The Audio Unidirectional application uses the SPARK Wireless Core to transmit a stereo audio stream with 48kHz/24-bit depth from the Coordinator to the Node. When the link quality degrades, it will automatically switch into fallback mode which involves an audio stream with 48kHz/16-bit depth instead. The audio stream will revert to 24-bit depth once the link quality returns to normal.

The application can either use the analog audio codec or the USB audio interface to receive and transmit audio data. Different compilation flags are required to select the desired audio interface. A USB audio Coordinator can communicate with an analog audio Node and vice versa.

To compile the application for USB audio, set the “USB_AUDIO_ENABLED”: “ON” flag in the application’s CMake preset cacheVariables section.

     {
         "name": "audio-unidirectional-sr11xx-quasar-usb_audio",
         "inherits": ["base","quasar"],
         "description": "Audio unidirectional example for SR11xx with Quasar USB AUDIO",
         "cacheVariables": {
             "APP": "Audio-Unidirectional",
             "TRANSCEIVER": "SR1100",
             "USB_AUDIO_ENABLED": "ON"
         }
     },

Behavior

Audio Configuration

The application can be configured using the sac_cfg.h file located in the config folder.

/* **** Main Channel Settings. **** */

#define MAIN_CHANNEL_SAMPLE_RATE_HZ 48000
#define MAIN_CHANNEL_SAMPLE_COUNT   13
#define MAIN_CHANNEL_CHANNEL_COUNT  2
#define MAIN_CHANNEL_BIT_DEPTH      24
#define MAIN_CHANNEL_LATENCY_MS     5

/* Calculated values. */
#define MAIN_CHANNEL_SWC_PAYLOAD_SIZE \
    SAC_CALCULATE_PAYLOAD_SIZE(MAIN_CHANNEL_SAMPLE_COUNT, MAIN_CHANNEL_CHANNEL_COUNT, MAIN_CHANNEL_BIT_DEPTH)
#define MAIN_CHANNEL_I2S_PAYLOAD_SIZE \
    SAC_CALCULATE_PAYLOAD_SIZE(MAIN_CHANNEL_SAMPLE_COUNT, MAIN_CHANNEL_CHANNEL_COUNT, I2S_DMA_BIT_DEPTH)
/* Size of the latency queue used by the Audio Core for the main channel. */
#define MAIN_CHANNEL_LATENCY_QUEUE_SIZE                                                                    \
    SAC_CALCULATE_LATENCY_QUEUE_SIZE(MAIN_CHANNEL_LATENCY_MS, CODEC_LATENCY_MS, MAIN_CHANNEL_SAMPLE_COUNT, \
                                     MAIN_CHANNEL_SAMPLE_RATE_HZ)

Audio Interface

The application receives audio from the line in of the Coordinator, utilizes the audio codec to transmit and receives over the I2S line using DMA transfers, and outputs the audio to the headphone out of the Node.

The audio core pipeline processes audio samples coming from the I2S to format them to be sent over the air using the SWC. The I2S end of transfer callback and the SWC transmission success callback will trigger the audio processing to synchronize the I2S production rate and the SWC consumption rate.

Audio application timings in normal operation

Figure 12: Audio application timings in normal operation.

The Audio Task row shows when swc_connection_send() actually enqueues the packet. The event that decides which slot the packet catches is the connection’s frame preparation (prepare_frame), which selects and latches the payload for the next assigned slot. Frame preparation runs in the SPI DMA ISR context (see the prepare_frame step in the Wireless Core timing diagram).

Each transmit slot first dequeues the previously acknowledged packet, then pulls the next one from the SWC queue to prepare it, so the queue must be able to hold at least two entries to track both the in-flight and the next packet.

If the Audio Task enqueues after that preparation point, the packet misses the slot, which ships empty, and it must wait for the following preparation, adding one inter-opportunity gap to its wireless latency; see Wireless Latency for the corresponding formulas.

When a packet transmission fails, the audio packets will accumulate in the audio consumer queue until the wireless core can transmit its payloads and free a space in its queue.

Audio application timings when a packet transmission fails

Figure 13: Audio application timings when a packet transmission fails.

The application receives audio from the USB audio interface at either 1 kHz (USB Full-Speed) or 8 kHz (USB High-Speed) depending on the capabilities of the device.

Note

When using USB audio, the host computer controls the playback. If audio playback stops on the host computer, no audio samples are receives on the device. This means that the audio connection will not send any packets.

These frames are then accumulated and splitted into audio packets to be sent to the audio pipeline for processing before being sent OTA using the SWC. When using The USB interface, the audio samples are already formatted to packed 24-bit.

On the receiving side, the audio packets received OTA are processed and sent to the USB audio interface where a FIFO will accumulate the samples.

Note

When using USB audio, the host computer controls the recording. If the audio recording stops on the host computer, no audio samples are read from the device. This means that the USB audio transmission FIFO will not be depleted and will eventually overflow. Once the recording resumes, the FIFO will be consumed again and will stabilize to the correct level to match the expected latency.

In addition to transmitting a unidirectional audio link, the application allows for the transmission of various data such as the status of a button and the link margin. The link margin makes it possible for the Coordinator to track the quality of the connection, thereby switching between fallback and normal modes as needed.

Note

The Coordinator’s data connection is part of the synchronization design of this application. With USB audio, the audio connection stops transmitting entirely while the host is not streaming, and the Coordinator’s periodic data transmission becomes the Node’s only synchronization source, acting as the network beacon. Its period must not exceed 10 ms so that two data frames fit within the Node’s synchronization-loss timeout, tolerating one lost frame (see Sync Timeslot (Beacon)). Removing this data connection or increasing its period would cause the Node to repeatedly lose synchronization while the audio stream is idle.

The wireless schedule allocates 49 timeslots for the audio transmissions and 1 timeslot for the data transmissions. The schedule is designed to reserve more bandwidth for transmitting audio stream instead of data. When the Node acknowleges the data transmissions, the reply also includes the data to be transmitted from the Node to the Coordinator.

In the UWB frequency range, the wireless core alternates between 5 different frequency bands at each transmission.

Application Schedule

The following diagram illustrates the general structure of the schedule used in this application.

Audio Unidirectional schedule

Figure 14: Audio Unidirectional Application’s Schedule.

Pairing

On boot, devices attempt to pair automatically. If unsuccessful, manual pairing can be performed afterward to use the application.

Auto Pairing:
  • On boot, devices automatically start the pairing process. RGB blinks blue twice to indicate that pairing is in progress.

  • If the pairing procedure is unsuccessful, RGB blinks red twice after 10 seconds.

  • Once successfully paired, RGB turns magenta, and the devices begin exchanging application data.

Manual Pairing:
  • Press the SW1 button on both devices to start the pairing procedure; RGB blinks blue twice when doing so.

  • If the pairing procedure is unsuccessful, RGB blinks red twice after 10 seconds.

  • Once successfully paired, RGB turns magenta, and the devices begin exchanging application data.

Unpairing:
  • When paired, pressing the SW1 button again unpairs the device; RGB blinks red twice to indicate that unpairing has been completed.

  • Unpairing causes the devices to forget their learned addresses. The devices are no longer able to exchange application data.

  • To start a new pairing procedure, both devices must be unpaired first.

Fallback

The Coordinator continuously monitors the link quality. If the link quality degrades, the system will enter fallback mode. If the signal quality remains strong for 5 seconds and the CCA try count stays below a defined threshold, the system will revert to normal mode. The thresholds for entering and exiting fallback mode differ, creating hysteresis to prevent the system from toggling frequently in conditions of marginal signal quality.

Clock Drift Compensation (CDC)

Clock Drift Compensation (CDC) is used to adjust the timing difference between the two devices. The Coordinator is the reference clock. Therefore, for the stereo audio stream, the Node can use its internal PLL (when hardware allows) to adjust its clock frequency to the Coordinator’s. For more information regarding CDC, refer to Clock Drift Compensation.

Coordinator User Interface

The Coordinator user interfaces includes LEDs, RGB and button switches.

Table 7: Quasar Coordinator User Interface Description

Interface

Name

Description

SW1

Pairing process

Pair, unpair, or abort the pairing process depending on the current state.

SW2

Button activity

Turn on the LED state of the remote device.

SW3

N/A

N/A

SW4

N/A

N/A

LED1

Transmission success

Toggles every time an audio packet is successfully transmitted.

LED2

N/A

N/A

LED3

Fallback status

LED is OFF in Normal mode and ON in Fallback mode.

LED4

Button state

Turn on upon receiving button state.

RGB

Pairing Event

Indicate pairing event as described in the pairing section.

Note

  • LEDs assigned to transmission or reception status are almost always on because of the high packet rate.

  • Audio volume can be adjusted by the Node, allowing to decrease or increase the sound it receives. This control is managed through the SW3 and SW4 buttons.

Node User Interface

The Node user interfaces includes LEDs, RGB and button switches.

Table 8: Quasar Node User Interface Description

Interface

Name

Description

SW1

Pairing process

Pair, unpair, or abort the pairing process depending on the current state.

SW2

Button activity

Turn on the LED state of the remote device.

SW3

Volume up

Raises the received audio volume (default at 100%).

SW4

Volume down

Lowers the received audio volume.

LED1

N/A

N/A

LED2

Reception success

Toggles every time an audio packet is successfully received.

LED3

Fallback status

LED is OFF in Normal mode and ON in Fallback mode.

LED4

Button state

Turn on upon receiving button state.

RGB

Pairing Event

Indicate pairing event as described in the pairing section.

Note

  • LEDs assigned to transmission or reception status are almost always on because of the high packet rate.

Certification

This application has the ability to run in Certification Mode.

When certification mode is active, a dedicated LED is activated to indicate that the mode is enabled. All activity status LEDs (transmission, reception, fallback, and payload) are suppressed so that only the certification indicator is visible.

Table 9: Certification Mode Indicator

Board

Indicator

Quasar

RGB LED steady yellow.

EVK1.4

Steady LED2.

Different levels of certification are required to test the fallback modes and data connection.

  • Depending of which mode is requested, the max_payload_size of the audio connection will be changed.

  • The order in which connection are initialized and their priority will be swapped if the data connection needs to be tested.

Activating the Certification Mode

Table 10: Certification Mode Activation for the Coordinator

Certification Mode

Activation Process

24-bit Audio

Hold SW2 at startup until the LED 1 blinks once, then release.

16-bit Audio

Hold SW2 at startup until the LED 1 blinks twice, then release.

Control Data

Hold SW2 at startup until the LED 1 blinks three times, then release.

Table 11: Certification Mode Activation for the Node

Certification Mode

Activation Process

Control Data

Press and hold SW2 at startup. LED 1 will blink once to confirm the selected certification mode.

Terminal

The following figure shows the terminal output of this application.

See Viewing the Terminal for details on how to view the terminal output.

Audio Unidirectional Serial Interface Output

Figure 15: Audio Unidirectional Serial Interface Output (from left: Coordinator & Node).

See Audio Core API - Statistics and Wireless Core API - Statistics for more details.

Latency Breakdown

The following diagram shows the typical end-to-end audio latency breakdown for this application (I2S interface, normal mode). Block widths are proportional to their contribution.

Audio Unidirectional Latency Breakdown

Figure 16: Audio Unidirectional Latency Breakdown.

Table 12: Latency Components

Component

Duration

Notes

TX Codec (ADC)

0.8 ms

MAX98091 ADC path delay at 48 kHz

Capture (DMA)

0.27 ms

1 packet = 13 samples at 48 kHz

Wireless transit (typical)

0.22 ms

CCA + airtime + post-RX + processing + E[wait]

RX Queue

2.98 ms

11 packets buffered for jitter absorption

RX Codec (DAC)

0.76 ms

MAX98091 DAC path delay at 48 kHz

Total (typical)

~5.0 ms

Target: 5 ms

Schedule: 48 TX slots (shared audio + data via priority), 200 us each, 9.8 ms frame period. Gap pattern: 47 x 200 us + 1 x 400 us (Node RX slot break). Max gap: 400 us.

Wireless budget: E[wait] = 104 us, CCA = 3.1 us, airtime = 55.0 us, post-RX = 2.6 us, RX processing = 59.0 us.

See Wireless Latency and Audio Latency for the formulas used in this breakdown.