Alios things 3.3.0: a2sa component introduction


A2SA is the abbreviation of advanced AliOS Things sound architecture. It is the service framework of AliOS Things audio system, including audio driver layer, audio service interface layer and audio plug-in management. Some design concepts draw lessons from the design ideas of Linux ALSA, such as supporting VFS device driver mount access in the device driver layer, supporting multi sound card management, PCM/Control audio device model, friendly abstraction to audio Codec, etc. The audio service interface layer is compatible with the API interface specification of Linux ALSA lib, which is convenient for porting the application components developed based on alsa lib to AliOS Things. At the same time, the footprint of A2SA is small enough (23KB), which is suitable for transplantation on embedded IoT devices.
The component supports the following functions:

  • It is compatible with Linux alsa lib API specification to the greatest extent to facilitate the transplantation of Linux application ecology to AliOS Things.
  • Support multi sound card mode (Bluetooth sound card, I2S sound card, etc.)
  • Drive and mount VFS, and support open/ read/ write and other operation interfaces.
  • The simplified Audio Codec driver interface abstraction (11 API s in total) can facilitate the docking of different Codec HAL drivers.
  • An adaptation compatible with Linux ALSA audio driver is under development.

Copyright information

Apache license v2.0

directory structure

│   ├── driver               # Audio drive frame
│   │   ├── core             # Audio driver frame Core
│   │   └── platform         # Hardware abstraction layer of audio driver on different platforms
│   │       ├── Linux        # Linux platform audio driver hardware abstraction layer, under development, subsequent release.
│   │       └── RTOS         # RTOS platform audio driver hardware abstraction layer, a total of 11 API abstractions, supporting low-power management.
│   └── framework            # Audio service interface API
│       ├── sound_mixer.c    # Implementation of sound card mixer device driver
│       └── sound_pcm.c      # Implementation of sound card pcm device driver
├── include
│   ├── sound_mixer.h        # Sound card mixer device driver, such as setting codec parameters, volume, etc.
│   └── sound_pcm.h          # Sound card pcm device driver, such as recording, playing, etc.
├── internal                 # Internal header file
├── package.yaml             # Compile configuration file
└── example
    ├── sound_example.c      # a2sa sample code
    ├── sound_example_lb.c   # loopback test code
    ├── sound_example_vol.c  # volume test code
    └── sound_example_wav.c  # wav player test code

Dependent component

  • rhino
  • vfs
  • ulog
  • posix

Common configuration

There are default values for relevant configurations in the system. If you need to modify the configuration, it is unified in the package of this component Def in yaml_ The config node is modified as follows:

Maximum number of sound cards supported: 5 by default. If you need to modify it, it can be found in package Modify AOS in yaml_ SNDCARD_ NUM_ Max configuration


The maximum number of audio device nodes supported by each sound card is 5 by default, and the package can be modified according to actual needs Yaml configuration is as follows:


API description

Use example

The code download, compilation and firmware burning related to the component use examples all rely on Alios studio, the supporting development tool of AliOS Things, so you need to refer to it first AOS studio instructions for building a development environment Download and install Alios studio.
After the development environment is built, you can test the example according to the following steps.

Step 1 create or open a project

Open existing project

If the case project for testing already exists, you can refer to it AOS studio operating instructions opening project Open an existing project.

Create a new project

The sample code of the component can be run by compiling any solution linked to AliOS Things. Here, choose helloworld_demo case. helloworld_ The source code related to the demo case can be downloaded for reference AOS studio instruction creation project.

Step 2 add components

After downloading the case, you need to download it in HelloWorld_ Package. Of demo component Add dependency on components in yaml:

  - a2sa: dev_aos          # helloworld_ Introducing a2sa component into demo
  - littlefs: dev_aos      # The a2sa wav player example relies on the littlefs file system component

    CONFIG_A7_DSP_ENABLE: 1    # Must: enable HaaS100 audio drive switch
    CLI_IOBOX_ENABLE: 1        # Optional: enable file system test commands, such as ls, ll, mkdir, touch, echo, etc

Step 3 download components

In the development environment toolbar with Alios studio installed, select terminal - > new terminal to start the terminal, and the default working path is the workspace of the current project. At this time, enter in the command line of the terminal:

aos install a2sa

After the above command is executed successfully, the component source code is downloaded to/ components/a2sa path.

Step 4 add example

In the package of a2sa component Add in yaml Example example code:

  - "src/*.c"
  - example/sound_example.c
  - example/sound_example_lb.c
  - example/sound_example_vol.c
  - example/sound_example_wav.c

Where sound_example_wav.c is to play / data / 7 in the local file system Example of wav audio file. If you want to demonstrate the example of playing wav file, you need to package according to the following 2 steps Wav audio files into the file system.

cp ./6.wav ./hardware/chip/haas1000/prebuild/data/  # Copy 6.0 in the current directory WAV files to the file system packaging directory/ hardware/chip/haas1000/prebuild/data /. Note: 6 WAV files need to be prepared by yourself.
# Confirm/ hardware/chip/haas1000/package. Lines 177 to 179 in the yaml file are open. As follows,
   - filename: release/write_flash_tool/ota_bin/littlefs.bin
     address: 0xB32000

Step 5 compile firmware

After the sample code has been added to the configuration file of the component, and HelloWorld_ After the demo has added a dependency on this component, you can compile helloworld_demo case to generate firmware. Please refer to the specific compilation method AOS studio instructions for compiling firmware.

Step 6 burn firmware

helloworld_ After the firmware of demo case is generated, you can refer to AOS studio instructions for burning firmware To burn firmware.

Step 7 open the serial port

After the firmware is burned, you can view the operation results of the example through the serial port. For the specific method of opening the serial port, please refer to Viewing the log of AOS studio.

After the serial port terminal is opened successfully, you can enter help in the serial port to view the added test commands.

Step 8 test example

CLI command line input:

sound_install_driver # Install default sound card

Key logs:

sound install driver test begin ...
sound install driver test end !!!

CLI command line input:

sound_loopback start # Start sound card recording and playback loopback test

Key logs:

sound loopback test begin ...

CLI command line input:

sound_loopback stop # Stop sound card recording and playback loopback test

Key logs:

sound loopback test end !!!

CLI command line input:

sound_setvol 80 # Set the playback volume to 80

CLI critical logs:

alsa_volume_set percent 80

CLI command line input:

sound_getvol # Set the playback volume to 80

Key logs:

get volume 80

CLI command line input:

sound_wav /data/7.wav 1 # Play / data / 7 wav audio once (modifiable), limited to wav format audio

Key logs:

open /data/7.wav successfully


Q1: must pass sound_ install_ Does driver install the sound card manually?

A: due to different hardware environments and different sound card types, the number of capture & playback channels supported by the sound card is different. Developers can call audio at the appropriate position of the code according to the actual board hardware_ native_ card_ Register() function to install the sound card. It is recommended to refer to audio_ install_ codec_ Implementation of driver().

Keywords: Embedded system IoT

Added by drawmack on Fri, 18 Feb 2022 07:49:22 +0200