Audio Player¶
1. Overview¶
SDK built-in components The lightweight audio player is a very important component. CI130X is a voice recognition chip, and voice broadcast is an indispensable part of voice interaction. The component is lightweight, easy to use, and extensible. The playback component can support decoder registration extensions. Users can register audio decoders, such as MP3, ACC, and FLAC. After completing the registration of related decoders, they can use the universal player interface for audio playback. Player data source acquisition has supported spiflash, sd card, http network download and extended writing interface. If you use spiflash, sd card, http network download, you can directly use the relevant api interface to directly start the playback. While using the data write interface, you can freely call the write function to write data into the buffer, and you can complete the playback task without caring about decoding and hardware playback.
2. Instructions for use¶
2.1. Code structure¶
Source File | illustrate |
---|---|
audio_ play_ api.c audio_ play_ api. h |
Player interface function |
audio_ play_ decoder.c audio_ play_ decoder. h |
decoder interface |
audio_ play_ device.c audio_ play_ device. h |
sound card hardware |
audio_ play_ os_ port.c audio_ play_ os_ port.h |
os abstraction layer |
audio_ play_ process.c audio_ play_ process. h |
The player schedules the main task |
get_ play_ data.c get_ play_ data. h |
Audio data source acquisition |
2.2. Decoder registration¶
The player provides the audio playing format, which requires the decoder. The decoder structure is defined in audio_ play_ In the decoder, when the system is initialized, the corresponding decoder of the used audio format needs to be registered_ decoder_ The ops function is registered to the player component.
registe_ decoder_ ops(&prompt_decoder); // Register prompt decoder
registe_ decoder_ ops(&mp3_decoder); // Register MP3 decoder
registe_ decoder_ ops(&aac_decoder); // Register aac decoder
registe_ decoder_ ops(&ms_wav_decoder); // Register ms_ Wav decoder
registe_ decoder_ ops(&flac_decoder); // Register flac decoder
Prompt
Relevant audio playback formats need to be provided by the decoder. Here, only the registered ops interface is provided.
2.3. Preset Data Source Playback API¶
2.3.1. Play audio¶
play_ The audio function provides the function of playing audio files from SD cards and network urls. Examples are as follows:
//Play from the file system/test128.mp3. 0 represents the start offset of play. "mp3" is a standard mp3 file with a decoder type and ID3V2 header. You can fill in NULL. The player can automatically identify the file type. NULL is the callback function registration when play is completed
play_ audio("/", "test128.mp3", 0, "mp3",NULL);
//Playback is from the network 192.168.31.1/test128.mp3, the second parameter is filled with NULL, "mp3" is the decoder type, 0 represents the start offset of playback, and NULL is the callback function registration when playback is completed
play_ audio("192.168.31.1/test128.mp3", NULL, 0, "mp3",NULL);
2.3.2. Play voice command words¶
play_ The prompt function provides the function of playing adpcm broadcast words from the splash. The use example is as follows:
//0x4000 is the audio address of adpcm broadcast words in flash, 1 is the number of audio played, and NULL is the callback when playing is completed
play_ prompt(0x4000,1,NULL);
Prompt
Please use cmd to obtain the address of the broadcast speech audio in flash_ The player interface in info is basically used for internal playback.
2.4. Use of External User defined Data Source¶
In audio_ play_ The API also provides a set of outside_* The purpose of the interface is to create an external data stream. By writing the original audio data to the data stream, the player can play through the player’s decoder.
Interface name | Function description |
---|---|
play_ with_ Outside | Request to play external data |
outside_ init_ Stream | To create an external data stream service, you need to pass the data stream descriptor and data end descriptor |
outside_ destroy_ Stream | Destroy the data stream |
set_ curr_ outside_ Handle | Set the data stream descriptor used by the current player |
outside_ send_ end_ Sem | End signal of sending data |
outside_ write_ Stream | Write data to the data stream |
outside_ clear_ Stream | Clean up the data stream |
Outside in this group of interfaces_ init_ The stream function can create an external data stream service_ curr_ outside_ The handle sets the data stream used by the current player through the outside_ write_ The stream function writes data to the data stream. At this time, calling the player interface will automatically obtain audio data from the data stream, and decode and play. When the data ends, use the outside_ send_ end_ The sem function sends a signal, so that when all data is played, the playback end callback function will end normally. Using the external data stream mode page can also use the player’s start pause query progress interface. As shown in the figure:
- Start the playback process:
- Users actively pause/stop playing:
- The user actively continues to play:
- The end of user audio data sends the end of data signal to stop:
Note
The data management of this group of interfaces requires users to manage themselves, and the player will not be responsible for the data progress information.