Xtensa Audio Framework (Hostless) Programmer's Guide Hi Fi AF Hostless Programmers
User Manual:
Open the PDF directly: View PDF
.
Page Count: 54
| Download | |
| Open PDF In Browser | View PDF |
® Xtensa Audio Framework (Hostless) Programmer’s Guide For HiFi DSPs Cadence Design Systems, Inc. 2655 Seely Ave. San Jose, CA 95134 www.cadence.com Xtensa Audio Framework (Hostless) Programmer's Guide © 2019 Cadence Design Systems, Inc. All Rights Reserved This publication is provided “AS IS.” Cadence Design Systems, Inc. (hereafter “Cadence") does not make any warranty of any ki nd, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. Information in this document is provided solely to enable system and software developers to use our processors. Unless specifically set fort h herein, there are no express or implied patent, copyright or any other intellectual property rights or licenses granted hereunder to design or fabricate Cadence integrated circuits or integrated circuits based on the information in this document. Cadence does not warrant that t he contents of this publication, whether individually or as one or more groups, meets your requirements or that the publication is error-free. This publication could include technical inaccuracies or typographical errors. Changes may be made to the information herein, and these changes may be incorporated in new editions of this publication. © 2019 Cadence, the Cadence logo, Allegro, Assura, Broadband Spice, CDNLIVE!, Celtic, Chipestimate.com, Conformal, Connections, Dena li, Diva, Dracula, Encounter, Flashpoint, FLIX, First Encounter, Incisive, Incyte, InstallScape, NanoRoute, NC -Verilog, OrCAD, OSKit, Palladium, PowerForward, PowerSI, PSpice, Purespec, Puresuite, Quickcycles, SignalStorm, Sigrity, SKILL, SoC Encounter, SourceLink, Spectre, Specman, Specman-Elite, SpeedBridge, Stars & Strikes, Tensilica, TripleCheck, TurboXim, Vectra, Virtuoso, VoltageStorm, Xplorer, Xtensa, and Xtreme are either trademarks or registered trademarks of Cadence Design Systems, Inc. in the United States and/or other j urisdictions. OSCI, SystemC, Open SystemC, Open SystemC Initiative, and SystemC Initiative are registered trademarks of Open SystemC Initiative, Inc. in the United States and other countries and are used with permission. All other trademarks are the property of their respective holders. Version 1.5 March 2019 ii CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Contents 1. Introduction to Xtensa Audio Framework ....................................................................... 1 1.1 Document Overview .................................................................................................. 1 1.2 Xtensa Audio Framework Specifications ................................................................... 2 1.2.1 1.2.2 Terminology ........................................................................................................... 2 Feature Set ............................................................................................................ 4 1.3 Xtensa Audio Framework Performance .................................................................... 5 1.3.1 Memory .................................................................................................................. 6 1.3.2 Timings .................................................................................................................. 7 2. Xtensa Audio Framework Architecture Overview .......................................................... 8 2.1 Xtensa Audio Framework Building Blocks ................................................................. 8 2.1.1 2.1.2 2.1.3 2.1.4 3. Applications ........................................................................................................... 8 Xtensa Audio Framework ...................................................................................... 9 XOS (RTOS) .......................................................................................................... 9 Audio Components ................................................................................................ 9 Xtensa Audio Framework Developer APIs .................................................................... 10 3.1 Files Specific to Developer APIs ............................................................................. 12 3.2 Developer API-Specific Error Codes ....................................................................... 12 3.2.1 3.2.2 3.3 4. Common API Errors............................................................................................. 13 Specific Errors ..................................................................................................... 13 Developer APIs ........................................................................................................ 14 Xtensa Audio Framework Sample Applications ........................................................... 31 4.1 Build and Execute using makefile............................................................................ 35 4.1.1 4.1.2 4.2 5. Making the Executable ........................................................................................ 35 Usage .................................................................................................................. 37 Build and Execute using Xplorer ............................................................................. 37 Integration of New Audio Components with XAF .......................................................... 39 5.1 Component Modification .......................................................................................... 39 5.2 Component Integration ............................................................................................ 39 5.3 Component Integration – Examples ........................................................................ 42 6. Known Issues ................................................................................................................ 43 7. Appendix: Memory Guidelines ...................................................................................... 44 8. References .................................................................................................................... 48 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL iii Xtensa Audio Framework (Hostless) Programmer's Guide Figures Figure 1-1 Terminology ............................................................................................................. 3 Figure 2-1 Software Stack Diagram ......................................................................................... 8 Figure 3-1 Flowgraph Sequence for API Calls ........................................................................ 11 Figure 4-1 Testbench 1 (pcm-gain) Block Diagram ................................................................ 31 Figure 4-2 Testbench 2 (dec) Block Diagram .......................................................................... 31 Figure 4-3 Testbench 3 (dec-mix) Block Diagram ................................................................... 32 Figure 4-4 Testbench 4 (full-duplex) Block Diagram ............................................................... 32 Figure 4-5 Testbench 5 (amr-wb-dec) Block Diagram ............................................................ 32 Figure 4-6 Testbench 6 (src) Block Diagram ........................................................................... 33 Figure 4-7 Testbench 7 (aac-dec) Block Diagram................................................................... 33 Figure 4-8 Testbench 8 (mp3-dec-rend) Block Diagram ......................................................... 33 Figure 4-9 Testbench 9 (gain-renderer) Block Diagram .......................................................... 33 Figure 4-10 Testbench 10 (capturer-pcm-gain) Block Diagram .............................................. 34 Figure 4-11 Testbench 11 (capturer-mp3-enc-test) Block Diagram ........................................ 34 Tables Table 1-1 Table 1-2 Table 1-3 Table 1-4 Component types ..................................................................................................... 4 Library Memory ........................................................................................................ 6 Runtime Memory ...................................................................................................... 6 MCPS ....................................................................................................................... 7 Table 3-1 xaf_adev_open API ............................................................................................ 14 Table 3-2 xaf_adev_close API .......................................................................................... 16 Table 3-3 xaf_comp_create API ........................................................................................ 17 Table 3-4 xaf_comp_delete API ........................................................................................ 20 Table 3-5 xaf_comp_set_config API ............................................................................... 21 Table 3-6 xaf_comp_get_config API ............................................................................... 22 Table 3-7 xaf_connect API ................................................................................................. 23 Table 3-8 xaf_comp_process API ...................................................................................... 24 Table 3-9 xaf_comp_get_status API ............................................................................... 27 Table 3-10 xaf_get_verinfo API ...................................................................................... 29 Table 5-1 Example components ............................................................................................. 42 iv CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Document Change History Version Changes 1.0 Initial release 1.1 Known issues (Section 6) in Release 1.0 fixed. Minor changes in API (Section 3). Mixer, audio encoder and speech decoder components with the corresponding testbenches added (Section 4). Added support for the ALC5677 EVM. Real-time capturer and renderer components added. Xtensa tool chain v6.0.3 (RF-2015.3) supported only. Removed references to a specific target (ALC5677 EVM). Updated Software Stack Diagram (Figure 2.1). Modified library inclusion step in Xtensa-Xplorer (section 4.2). Updated Memory Guidelines (Section 7, Appendix) and added examples. Updated Feature Set (Section 1.2.2) and Known Issues (Section 6) about fast functional “TurboSim” ISS mode restriction with XAF. Sample Rate Convertor component wrapper is updated to work with Sample Rate Convertor v1.9 library. Added support for Ogg-Vorbis component sample application. Added xaf_get_mem_info API support. Updated Memory and Timings tables for pcm_gain application on 7.0.5 tools. 1.2 1.3 1.4 1.5 v CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide 1. Introduction to Xtensa Audio Framework Xtensa Audio Framework (XAF) is a framework designed to accelerate the development of audio processing applications for the HiFi family of DSP cores. Application developers may choose components from the rich portfolio of audio and speech libraries already developed by Cadence and its ecosystem partners. In addition, customers may also package their proprietary algorithms and components and integrate them into the framework. Towards this goal, a simplified “Developer API” is defined, which enables application developers to rapidly create an end application and focus more on using the available components. XAF is designed to work on both the instruction set simulator as well as actual hardware. The version of XAF described in this guide is designed to work on a single DSP (that is, a “hostless” solution). XAF is part of the “HiFi Integrator Studio” suite of tools. 1.1 Document Overview This guide covers all the information required to create, configure, and run audio processing chains using XAF developer APIs. Section 2 briefly describes the XAF architecture, and Section 3 provides details about developer APIs available for the application developer. Section 4 provides details about building and running a sample application, which illustrates usage of the developer APIs. Section 5 provides a “How To” guide for adding support for a new component in XAF. 1 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide 1.2 Xtensa Audio Framework Specifications This section provides XAF specifications, including the operating system. 1.2.1 Terminology The following terms are used within this guide. Audio Device: The software abstraction of a digital signal processor (DSP) core. Component: A software module that conforms to a specified interface and runs on the audio device. It would implement some audio processing functionality. Port: An interface through which a component can connect to other components and exchange data. Each port may be connected to only one port of another component. A component must have at least one port. Input Port: A port through which a component can receive data from another component. A component may have 0 or more input ports. Output Port: A port through which a component can send data to another component. A component may have 0 or more output ports. Link: The connection between the output port of one component and the input port of another component. Buffer: Memory block containing data that is transferred over a link between two ports. Chain: A graph formed by connecting different components by links. Framework: A software entity that enable the creation of an audio processing chain. It manages the transfer of buffers between ports as well as the scheduling of the different components in the chain. Application: A software entity that uses the framework to create a chain. It is the responsibility of the application to provide input data to the chain and consume the output data generated by the chain. CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 2 Xtensa Audio Framework (Hostless) Programmer's Guide Figure 1-1 shows the terms above in a diagrammatic form, with an example chain. Audio Device Application Framework Scheduler Buffer management etc... Chain Input port A1 Component A Output port Input port Component C Input port Component B Output port Output port Input port Legend Buffers Component Link Port Figure 1-1 Terminology 3 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide 1.2.2 Feature Set API features: Ability to create components and connect them in a chain. Ability to read and write component configuration parameters. Ability to read component status and trigger component processing. XAF features: Manages the scheduling of components in the chain. No explicit restriction on the complexity of the component chain, i.e., the number of components/links is restricted by the memory/MHz resources available and not by XAF. Manages the allocation of memory for data buffers. Number of data buffers is 0, 1, or 2 for input ports and 0 or 1 for output ports. The number of buffers on a link between two ports can be increased at component connection stage. Manages the allocation of memory for itself and created components. Dynamic memory allocation within XAF is done through an allocation function registered by the application. This allows the application to control the memory type/region for the allocation. Manages the data transfer between components. The buffering of data to match the different block sizes between two connected components is also managed by XAF. As XAF merely transfers the data between components, there is no restriction on the actual format of the data. Component types supported (See Table 1-1), depending on the number of ports and the type of data transferred across the ports (PCM or non-PCM). Table 1-1 Component types Component Type Decoder Input Ports PCM 1 N Output Ports PCM 1 Y Encoder 1 Y 1 N Mixer 4 Y 1 Y Preprocessing Post processing Renderer 1 Y 1 Y 1 Y 1 Y 1 Y 0 NA Capturer 0 NA 1 Y Component Description Decodes input compressed data to generate output PCM data. Encodes input PCM data to generate output compressed data. Combines input PCM data from multiple ports to generate one output PCM data. Pre-processes input PCM data to generate output PCM data. Post-processes input PCM data to generate output PCM data. Plays input PCM data to a speaker/headphone. Captures output PCM data from a microphone. CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 4 Xtensa Audio Framework (Hostless) Programmer's Guide Package features: Twelve example test applications provided to demonstrate various use-cases. Example code to demonstrate the integration of five Cadence audio libraries (MP3 decoder, MP3 encoder, AMR-WB decoder, Sample Rate Convertor, AAC decoder, Ogg-Vorbis decoder) into XAF is included in this package. Note that the actual libraries need to be licensed separately and are not part of this package. Compile time flags provided to support detailed analysis and debugging Tracing: Enables printing of detailed component scheduling information (Set TRACE = 1 while building, disabled by default). Debugging: Disables optimization and enables debugger information (Set DEBUG = 1 while building, disabled by default). Profiling: Measurement of component and XAF MHz. (Set XAF_PROFILE = 1 while building, enabled by default). RTOS: XAF requires a real-time operating system (RTOS) for multithreaded execution, message queue interface, mutual exclusion for accessing shared resources, etc. This version of XAF supports Cadence XOS [1] (only) as the RTOS. Support for other RTOS variants will be added in future versions. Limitations: Code for the components needs to be linked into the application. Dynamic loading of code is not supported. API enhancements to disconnect components from a graph and to pause/resume the graph are planned in future releases. Only one instance of XAF can run at a time. XAF does not support fast functional “TurboSim” mode of Instruction Set Simulator (ISS). ISS must be used in cycle accurate mode with XAF. 1.3 Xtensa Audio Framework Performance The performance was characterized on the 5-stage HiFi DSP processor cores. The memory usage and performance figures are provided for design reference. 5 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide 1.3.1 Memory Table 1-2 Library Memory HiFi Mini 20.0 Note Text (Kbytes) HiFi 2 HiFi 3 20.6 21.7 HiFi 4 22.7 Data (Kbytes) 0.6 Other than for Text and Data, XAF uses 8 bytes for bss. The measurements exclude the memory required by XOS and the standard C library. The measurements were done with Version 7.0.5 of the Xtensa tool chain. The size of the total runtime memory allocated by XAF depends mainly on the two parameters audio_frmwk_buf_size and audio_comp_buf_size passed to the xaf_adev_open() function. Refer to Section 7 for guidelines on setting these parameters. The total runtime memory allocated can be divided into two categories: 1. Memory used by XAF: This memory is allocated by XAF for its internal data structures. 2. Memory allocated by XAF for use by Audio Components: This is the memory that is allocated by XAF for usage by audio components. Table 1-3 shows the runtime memory allocated by XAF for a simple processing chain. Table 1-3 Runtime Memory No 1 2 3 Memory breakup Local Memory used by DSP Components Shared Memory used by Audio Components and Framework Local Memory used by Framework memory Total Note Note HiFi Mini RAM (Kbytes) HiFi 2 HiFi 3 HiFi 4 76.4 76.4 76.4 76.4 28 28 28 28 15.2 15.1 15.2 15.2 119.6 119.5 119.6 119.6 The measurements were done with Version 7.0.5 of the Xtensa tool chain. For this example, audio_frmwk_buf_size = 64 KB and _ _ _ audio comp buf size = 128 KB, during xaf_adev_open()call. Note that some of the memory allocated during xaf_adev_open is for internal XAF structures and the remainder is allocated by XAF for use by the components. Refer to Section 7 for details. CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 6 Xtensa Audio Framework (Hostless) Programmer's Guide 1.3.2 Timings Table 1-4 contains details for the MCPS usage for the processing function. The “Total” MCPS are the MHz consumed by the entire system. The “XAF” MCPS are the MCPS consumed by XAF. This is measured by subtracting the MCPS consumed by the application and the audio components from the total MCPS. Note that the XAF MCPS would depend on the complexity of the audio processing chain — this measurement was done on a simple chain consisting of a single PCM gain component. Table 1-4 MCPS Use Case Simple PCM Gain (Mono, 48KHz, Buffer size = 4096 samples) Note 7 XAF Total HiFi Mini 0.38 4.06 Average CPU Load (MHz) HiFi 2 HiFi 3 0.40 0.37 4.13 4.10 HiFi 4 0.32 3.04 Performance specification measurements are carried out on a cycle-accurate simulator assuming an ideal memory system (that is, one with zero memory wait states) for HiFiMini/HiFi2/HiFi3/HiFi4 cores. This is equivalent to running with all code and data in local memories or using an infinite-size, pre-filled cache model. The measurements were done with Version 7.0.5 of the Xtensa tool chain. CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide 2. Xtensa Audio Framework Architecture Overview 2.1 Xtensa Audio Framework Building Blocks The following figure shows various building blocks of applications based on XAF. Note that in this figure the gray blocks are not part of XAF. Figure 2-1 Software Stack Diagram 2.1.1 Applications In this application space, an application developer will leverage the developer API to create a processing chain and XOS APIs to handle multiple threads. As such, XAF enables chains to be set up and configured. The developer API is the interface between the Application space and XAF. Note that XAF allows an unlimited number of components in the audio processing chain — the limitation is only from the system hardware. The system developer must ensure that there is enough memory and CPU bandwidth available on the hardware. CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 8 Xtensa Audio Framework (Hostless) Programmer's Guide 2.1.2 Xtensa Audio Framework This block interfaces between the application framework and the audio processing components. It also performs all memory management for audio processing chains. It receives commands from applications and sends the responses back. It also manages the data buffers between each individual audio component. Note that each audio component running in the audio processing chain may consume and produce a different amount of data. The decoder component from Cadence consumes one encoded frame and produces one output PCM frame in one execution call. For example, the MP3 decoder [4] from Cadence may consume 2048 bytes (largest encoded frame size) and produce one output PCM frame of 4608 bytes (1152 samples, stereo channel, 16-bit data). Post process components from Cadence generally consume and produce a variable block size (from a pre-defined set) in one execution call. 2.1.3 XOS (RTOS) The applications use the XOS RTOS to create process threads for audio component chains. Also, XOS facilitates communication between the control and processing framework modules within XAF using message queues. Note 2.1.4 XOS is released with the Xtensa tools SDK, and is not a part of the XAF release package. Audio Components Audio components, used by the Application Framework, can be connected to form chains with a cascade or parallel interface. Except for the mixer, each audio component type can have one input and one output stream. The Mixer Component type can have up to four input streams and one output stream. Section 5 contains details on how to add a new component. 9 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide 3. Xtensa Audio Framework Developer APIs This section discusses XAF developer APIs that are available for the application programmer to create, configure and run audio processing chains. Figure 3-1 shows the flow graph for a typical application. CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 10 Xtensa Audio Framework (Hostless) Programmer's Guide Figure 3-1 Flowgraph Sequence for API Calls 11 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Following is a brief description of the flowgraph sequence: Initialize XAF: The XAF is initialized by calling xaf_adev_open. The framework memory allocation is performed at this stage. Create Processing Chain: The various components in the chain are instantiated by calling xaf_comp_create for each component. Then, the component configuration parameters (if any) are set using xaf_comp_set_config. Finally, the components are connected together using xaf_connect. Process data: Input and output data is passed to the components using xaf_comp_process. This must be performed only for components that need to be supplied with input/output data (typically the edge components of the chain). The component status should be queried using xaf_comp_status. This stage continues until all the data has been processed. Delete Processing Chain: The various components of the chain are deleted by calling xaf_comp_delete. Terminate XAF: The XAF is terminated by calling xaf_adev_close. The memory allocated by the framework is freed at this stage. 3.1 Files Specific to Developer APIs Developer API Header File (/include/) 3.2 xaf-api.h Developer API-Specific Error Codes The errors in this section can result from the developer API layer of the Xtensa Audio Framework. All errors are fatal (unrecoverable) errors. In response to an error, the function xaf_adev_close(p_adev, XAF_ADEV_FORCE_CLOSE) may be called to close the device and release resources used by XAF. CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 12 Xtensa Audio Framework (Hostless) Programmer's Guide 3.2.1 Common API Errors XAF_PTR_ERROR This error indicates that a null pointer was passed to the developer API where a valid pointer was expected. XAF_INVALID_VALUE This error code indicates that an invalid value (out of valid range) was passed to the developer API. XAF_XOS_ERROR This error code indicates an internal error, typically caused when one of the XOS calls made within XAF returns an error. XAF_API_ERR This error code indicates a developer API call sequence error, for example, xaf_comp_create() is called before xaf_adev_open(). 3.2.2 Specific Errors The following error is specific to some APIs. XAF_ROUTING_ERROR This error code indicates that the developer API was unable to connect (xaf_connect() call) the two requested components. 13 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide 3.3 Developer APIs This section contains tables describing the developer APIs. Table 3-1 xaf_adev_open API API XAF_ERR_CODE xaf_adev_open(pVOID *p_adev, WORD32 audio_frmwk_buf_size, WORD32 audio_comp_buf_size, xaf_mem_malloc_fxn_t mem_malloc, xaf_mem_free_fxn_t mem_free) Description This API opens and initializes the audio device structure. It starts the processing thread that performs all audio processing. It also allocates persistent memory for Audio components and shared memory for the framework. Actual Parameters p_adev Pointer to audio device audio_frmwk_buf_size Size of memory allocated for the framework and for component data buffers. audio_comp_buf_size Size of memory allocated for the framework and for persistent/scratch/input/output memory allocated for audio components mem_malloc Function pointer to testbench implementation of memory allocation. The ‘id’ indicates whether the memory is allocated for device (DEV_ID) or for component (COMP_ID). pVOID mem_malloc(WORD32 size, WORD32 id); Note: XAF expects that mem_malloc should return a 4-byte aligned address (this is required by XOS). mem_free Function Pointer to testbench implementation of memory free VOID mem_free(pVOID ptr, WORD32 id); CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 14 Xtensa Audio Framework (Hostless) Programmer's Guide Restrictions Prerequisite: The XOS startup procedure needs to be invoked before calling this function. This involves calling the following XOS functions. 1. xos_set_clock_freq() to set the core clock frequency. 2. xos_start_main() to start the scheduler. 3. xos_start_system_timer() to start the timer for scheduling. Refer to the function start_xos() in the file test/src/xafutils-test.c for an example. Only one instance of XAF can run at a time. Example ret = xaf_adev_open(&p_adev, XAF_DSP_SHARED_POOL_SIZE, XAF_DSP_SCR_PER_SIZE, &mem_malloc, &mem_free); Errors 15 Common API Errors CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Table 3-2 xaf_adev_close API API XAF_ERR_CODE xaf_adev_close(pVOID p_adev, xaf_comp_flag flag) Description This API closes the Audio Device and frees up allocated memory. It also stops DSP thread execution. p_adev Actual Parameters Pointer to the audio device flag XAF_ADEV_FORCE_CLOSE: Closes the audio device, even when there are existing components. This option can be used to close the device following a fatal error. XAF_ADEV_NORMAL_CLOSE: Returns an error if there are active components in the chain. This option can be used to close the device in the normal sequence of operation. Restrictions Should not be called before xaf_adev_open API. All components must be deleted before closing the audio device. Only for a fatal error condition, the device should be force closed (i.e., with the XAF_ADEV_FORCE_CLOSE flag, even when all components are not deleted). Example ret = xaf_adev_close(p_adev, XAF_ADEV_NORMAL_CLOSE); Errors Common API Errors CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 16 Xtensa Audio Framework (Hostless) Programmer's Guide Table 3-3 xaf_comp_create API API XAF_ERR_CODE xaf_comp_create(pVOID p_adev, pVOID *p_comp, xf_id_t comp_id, UWORD32 ninbuf, UWORD32 noutbuf, pVOID pp_inbuf[], xaf_comp_type comp_type) Description This API creates the Audio Component. The component is identified by comp_id and comp_type. You can specify the number of input and output buffers for the component. The IO buffer requirement is dependent upon the position of the component in the audio processing chain – see the parameter description below for details. 17 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Actual Parameters p_adev Pointer to the audio device structure p_comp Pointer to the audio component structure (should be one of the available audio components) comp_id Component Identifier string. e.g. “mixer”, “audio-decoder/mp3”, etc. It should match with class_id’s defined under the constant definition of xf_component_id in xa-factory.c file. (Refer to Section 5.2, Step 6) ninbuf Unsigned integer containing the number of input buffers. This is the number of buffers that the testbench needs to pass to the component. For components connected in the chain where it receives input from other components, this must be configured as zero (0). Valid values: 0, 1, 2. noutbuf Unsigned integer containing the number of output buffers. This is the number of buffers that the component passes to the testbench as output. For components connected in the chain where the output is passed to another component, this must be configured as zero (0). Valid values: 0, 1. pp_inbuf Pointer to the array to hold ninbuf input buffer addresses that have been allocated within XAF. If the pointer is NULL, the input buffer addresses will not be returned. type Type of audio component Following are valid values: Restrictions Type XAF_DECODER: Description Decoder component XAF_ENCODER: XAF_MIXER: Encoder component XAF_PRE_PROC: Preprocessing component XAF_POST_PROC: Post component XAF_RENDERER: XAF_CAPTURER: Renderer component Mixer component processing Capturer component Should not be called before xaf_adev_open CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 18 Xtensa Audio Framework (Hostless) Programmer's Guide Example ret = xaf_comp_create(p_adev, &p_audioComp, "comp_id", N_INP_BUFF, N_OUT_BUFF, & inbuf[0], XAF_POST_PROC); Errors 19 Common API Errors CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Table 3-4 xaf_comp_delete API API XAF_ERR_CODE xaf_comp_delete(pVOID p_comp) Description This API deletes the Audio Component and frees the memory associated with it. Actual Parameters p_comp Pointer to the audio component structure Should not be called before xaf_comp_create. Should be used once all the threads have exited under normal execution conditions (after xos_thread_join). To force close the device, xaf_dev_close API with XAF_ADEV_FORCE_CLOSE flag should be used. Restrictions Example ret = xaf_comp_delete(p_audioComp); Errors Common API Errors CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 20 Xtensa Audio Framework (Hostless) Programmer's Guide Table 3-5 xaf_comp_set_config API API XAF_ERR_CODE xaf_comp_set_config( pVOID p_comp, WORD32 num_param, pWORD32 p_param) Description This API sets (writes) configuration parameters to the Audio Component. num_param provides the number of configuration parameters to be set. p_param points to an array containing ID/value pairs for all num_param parameters. For example, for two parameters, p_param will contain ID1, VAL1, ID2, VAL2. Actual Parameters p_comp Pointer to the audio component structure num_param Integer containing the The maximum limit is 16. number of parameters to be set. p_param Pointer to an integer array containing ID/Value pairs – i.e., parameter ID followed by parameter value. Restrictions Should not be called before xaf_comp_create Example ret = xaf_comp_set_config(p_comp, N_PARAMS, ¶m[0]); Errors 21 Common API Errors CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Table 3-6 xaf_comp_get_config API API XAF_ERR_CODE xaf_comp_get_config( pVOID p_comp, WORD32 num_param, pWORD32 p_param) Description This API gets (reads) configuration parameters from the Audio Component. num_param provides the number of configuration parameters to get. p_param points to an array containing ID/value pairs for all num_param parameters. For example, for two parameters, p_param will contain ID1, VAL1, ID2, VAL2. VAL1 and VAL2 can contain any arbitrary value, as they will be overwritten when the function returns. Actual Parameters Upon successful execution of this API, the value field of the ID/value pair will be set to the correct value. p_comp Pointer to the audio component structure num_param Integer containing the The maximum limit is 16. number of parameters to get. p_param Pointer to an integer array containing ID/Value pairs – i.e., parameter ID followed by parameter value. Restrictions Should not be called before xaf_comp_create Example ret = xaf_comp_get_config(p_comp, N_PARAMS, ¶m[0]); Errors Common API Errors CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 22 Xtensa Audio Framework (Hostless) Programmer's Guide Table 3-7 xaf_connect API API XAF_ERR_CODE xaf_connect(pVOID p_src, pVOID p_dest, WORD32 num_buf) Description This API connects the output port of audio component p_src to the input port of audio component p_dest with num_buf buffers between them. The size of these buffers will be equal to the size of the output buffer of p_src . This API will fail if there are no free input or output ports on Audio Components. Audio Components have input and output ports as follows: Component Type XAF_DECODER XAF_ENCODER XAF_PRE_PROC XAF_POST_PROC XAF_MIXER XAF_RENDERER XAF_CAPTURER Actual Parameters or or or Input Ports 1 Output Ports 1 4 1 0 1 0 1 p_src Pointer to the source audio component structure p_dest Pointer to the destination audio component structure num_buf Number of buffers to be added between components Valid values: 2, 3, 4 Restrictions Should not be called before at least two audio components are created using xaf_comp_create. Example ret = xaf_connect(p_audioComp1, p_audioComp2, N_BUFFS); Errors Common API Errors XAF_ROUTING_ERROR 23 Indicates that the API was unable to connect the two requested components CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Table 3-8 xaf_comp_process API API XAF_ERR_CODE xaf_comp_process(pVOID p_adev, pVOID p_comp, pVOID p_buf, UWORD32 length, xaf_comp_flag flag) Description This API is the main process function for the audio component; it will do Audio Component start, initialization, execution, and wrap-up based on the process flag provided to it. This API needs to be called only for components that need to be supplied with input/output data, typically the edge components of the chain. After processing has started, this API should be called until end of stream, alternatively along with xaf_comp_get_status API. The value to be set for the parameter ‘flag’ depends on the status returned by the xaf_comp_get_status API. Note: This API is asynchronous, i.e., it delivers the process command to the audio component and returns. The audio component will process this request when all required resources (IO buffers, CPU, etc.) from the processing chain are available. The status of this process command can be probed by the API described in Table 3-9. Note: The pointer to an audio device (p_adev) is not required and can be passed as NULL during the execution phase of the audio component (after the component is initialized). CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 24 Xtensa Audio Framework (Hostless) Programmer's Guide Actual Parameters p_adev Pointer to the audio device structure p_comp Pointer to the audio component structure p_buf Pointer to the input buffer with the input data or output buffer to be filled length Unsigned integer containing the length of buffer in bytes process_flag – Process flag Following are valid values: Restrictions 25 Flag _ _ XAF START FLAG Description Initiates processing, to be called only once for each component, during initialization. XAF_EXEC_FLAG Executes, to be called only once for each component to start processing. XAF_INPUT_OVER_FLAG Indicates input is complete, when xaf_comp_get_status returns XAF_NEED_INPUT, and input stream is exhausted. XAF_INPUT_READY_FLAG Indicates input buffer availability, when xaf_comp_get_status returns XAF_NEED_INPUT, and input data is available. XAF_NEED_OUTPUT_FLAG Request for output, when xaf_comp_get_status returns XAF_OUTPUT_READY, and size returned in p_info[1] is non-zero. Should not be called before xaf_comp_create CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Example ret = xaf_comp_process( p_adev, p_audioComp, &Buff, length, compFlag); Errors Common API Errors CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 26 Xtensa Audio Framework (Hostless) Programmer's Guide Table 3-9 xaf_comp_get_status API API XAF_ERR_CODE xaf_comp_get_status( pVOID p_adev, pVOID p_comp, xaf_comp_status *p_status, pVOID p_info) Description This API returns the status of the audio component and associated information. p_adev and p_comp should point to the valid audio device and audio component structures respectively. This API will return one of following status and associated information. Note: This API is a blocking API, i.e., it may block for status from the DSP thread for a previously issued process command. p_adev Pointer to the audio device structure Actual Parameters p_comp Pointer to the audio component structure p_status Pointer to get the audio component status Valid values are: Flag XAF_STARTING XAF_INIT_DONE XAF_NEED_INPUT XAF_OUTPUT_READY XAF_EXEC_DONE Restrictions 27 Description p_status Started Initialization complete Component needs data Component has generated output Execution done Buffer pointer, size in bytes Buffer pointer, size in bytes p_info Pointer to array of size 2 (pointer, size) to get information from the audio component associated with its status. When the p_status returned is XAF_STARTING or XAF_INIT_DONE, this buffer is not updated. Should not be called before xaf_comp_create CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Example ret = xaf_comp_get_status(p_adev, p_audioComp, &compStatus, &Info[0]); Errors Common API Errors CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 28 Xtensa Audio Framework (Hostless) Programmer's Guide Table 3-10 xaf_get_verinfo API API XAF_ERR_CODE xaf_get_verinfo (pUWORD8 ver_info[3]) Description This API gets the version information from the XAF library. It returns an array of the following three strings. ver_info[0] ver_info[1] ver_info[2] Actual Parameters ver_info Pointer to array of three strings Restrictions None Library name Library version API version Example ret = xaf_get_verinfo(&versionInfo[0]); Errors Common API Errors Table 3-11 xaf_get_mem_stats API API XAF_ERR_CODE xaf_get_mem_stats(pVOID p_adev, WORD32 *p_mem_stats) Description This API returns the information about the memory usage statistics of the audio components, framework and XAF. p_adev should point to the valid audio device structure. This API will update the pointer contents with memory usage statistics. 29 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Actual Parameters p_adev Pointer to the audio device structure p_mem_stats Pointer to an array of three WORD32 data types to get information from the API about the memory usage statistics in bytes. 1. Local Memory used by DSP Components (p_mem_stats[0]), 2. Shared Memory used by Components and Framework (p_mem_stats[1]) and 3. Local Memory used by Framework (p_mem_stats[2]) Restrictions The API is recommended to be used at the very end of application execution and before closing the device (using xaf_dev_close API call) for the memory statistics to be reliable. Example WORD32 mem_stats[3]; ret = xaf_get_mem_stats(p_adev, &mem_stats[0]); Errors Common API Errors CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 30 Xtensa Audio Framework (Hostless) Programmer's Guide 4. Xtensa Audio Framework Sample Applications Eleven sample applications (testbenches) are provided, which implement eleven different audio processing chains as described below. Audio components and links are shown in blue in the diagrams below. Note All of the audio component libraries used in this document’s example testbenches are not included in the XAF release package. They need to be separately licensed. Testbench 1 (xa_af_hostless_test) applies gain to PCM streams. Input PCM File PCM gain Output PCM File Figure 4-1 Testbench 1 (pcm-gain) Block Diagram Testbench 2 (xaf-dec-test) decodes MP3 streams. Input MP3 File MP3 Decoder Output PCM File Figure 4-2 Testbench 2 (dec) Block Diagram Testbench 3 (xaf-dec-mix-test) decodes two MP3 streams and mixes the output. 31 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Input MP3 File 1 MP3 Decoder 1 Output PCM File Mixer Input MP3 File 2 MP3 Decoder 2 Figure 4-3 Testbench 3 (dec-mix) Block Diagram Testbench 4 (xaf-full-duplex-test) decodes an MP3 stream and simultaneously encodes an MP3 stream. Input MP3 File 1 MP3 Decoder Output PCM File 1 Input PCM File 2 MP3 Encoder Output MP3 File 2 Figure 4-4 Testbench 4 (full-duplex) Block Diagram Testbench 5 (xaf-amr-wb-dec-test) decodes AMR-WB streams. Input AMR File AMR-WB Decoder Output PCM File Figure 4-5 Testbench 5 (amr-wb-dec) Block Diagram Testbench 6 (xaf-src-test) does a sample rate conversion. CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 32 Xtensa Audio Framework (Hostless) Programmer's Guide Input PCM File Sample Rate Convertor Output PCM File Figure 4-6 Testbench 6 (src) Block Diagram Testbench 7 (xaf-aac-dec-test) decodes AAC streams. Input AAC File AAC Decoder Output PCM File Figure 4-7 Testbench 7 (aac-dec) Block Diagram Testbench 8 (xaf-mp3-dec-rend-test) decodes MP3 streams and renders it on the audio output device (hardware case). For the simulator case, the output is written to a file. Input MP3 File MP3 decoder Renderer Figure 4-8 Testbench 8 (mp3-dec-rend) Block Diagram Testbench 9 (xaf-gain-renderer-test) applies gain to PCM streams and renders it on the audio output device (hardware case). For the simulator case, the output is written to a file. Input PCM File PCM gain Renderer Figure 4-9 Testbench 9 (gain-renderer) Block Diagram Testbench 10 (xaf-capturer-pcm-gain-test) captures a PCM stream from the audio input device (hardware case) and applies a gain to it. For the simulator case, the input is read from a file. 33 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide Capturer PCM gain Output PCM File Figure 4-10 Testbench 10 (capturer-pcm-gain) Block Diagram Testbench 11 (xaf-capturer-mp3-enc-test) captures data from the audio input device (hardware case) and encodes it to an MP3 stream. For the simulator case, the input is read from a file. MP3 encoder Capturer Output MP3 File Figure 4-11 Testbench 11 (capturer-mp3-enc-test) Block Diagram Testbench 12 (xaf-vorbis-dec-test) decodes Ogg streams. OggVorbisDeco der Input Ogg File Output PCM File Figure 4-12 Testbench 12 (vorbis-dec) Block Diagram Testbench specific source files (/test/src/) xaf-pcm-gain-test.c xaf-dec-test.c xaf-dec-mix-test.c xaf-full-duplex-test.c xaf- amr-wb-dec-test.c xaf-src-test.c xaf-aac-dec-test.c xaf-mp3-dec-rend-test.c CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 34 Xtensa Audio Framework (Hostless) Programmer's Guide xaf-gain-renderer-test.c xaf-capturer-pcm-gain-test.c xaf-capturer-mp3-enc-test.c xaf-vorbis-dec-test.c Note: For the testbench xaf-src-test.c, execution is repeated 32 times with the same parameters, demonstrating consistency of the framework. Common testbench source files (/test/src/) xaf-clk-test.c – Clock functions used for MCPS measurements. xaf-mem-test.c – Memory allocation functions. xaf-utils-test.c – Other shared utility functions. xaf-fio-test.c – File read and write support Other directories (in /test/) plugins/ – Wrappers for the different audio components. test_inp/ – Input data for the test execution. test_out/ – Output data from test execution will be written here. test_ref/– Reference data against which the generated output can be compared. The XAF library and all testbenches can be built and executed using either of two ways, described in the following sections. 1. Using makefile 2. Using Xplorer workspace 4.1 4.1.1 Build and Execute using makefile Making the Executable Before building the executable, ensure the environment variable $XTENSA_CORE is set correctly. Testbench 1 Only: To build the pcm-gain testbench application, follow these steps: 35 CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL Xtensa Audio Framework (Hostless) Programmer's Guide 3. Go to /test/build. 4. At the prompt type: $ xt-make –f makefile_testbench_sample clean all This will build the example test application xa_af_hostless_test. All Testbenches: To build the other testbenches, the Cadence MP3 decoder [4], MP3 encoder [5], AMR-WB decoder [6,[7], Sample rate convertor [8] , AAC decoder [9] and Ogg-Vorbis[10] libraries are required. Copy these libraries to the following directories. /test/plugins/cadence/mp3_dec/lib/xa_mp3_dec.a /test/plugins/cadence/mp3_enc/lib/ xa_mp3_enc.a /test/plugins/cadence/amr_wb/lib/xa_amr_wb_codec.a /test/plugins/cadence/src-pp/lib/xa_src_pp.a /test/plugins/cadence/aac_dec/lib/xa_aac_dec.a /test/plugins/cadence/vorbis_dec/lib/xa_vorbis_dec.a 5. Go to /test/build. 6. At the prompt, type: $ xt-make –f makefile_testbench_sample clean all-dec This will build all the testbench applications. Note: If source code distribution is available, the library needs to be built before building the testbench application. To build the XAF library, follow these steps: 1. Go to /build/. 2. At the prompt, type $ xt-make clean all install This command will build the XAF library and copy it to the /lib/ folder. Special Build Settings To build in the debug mode, add “DEBUG=1” to the command lines described above. To build with trace prints, add “TRACE=1” to the command lines described above. CADENCE DESIGN SYSTEMS , INC. / CONFIDENTIAL 36 Xtensa Audio Framework (Hostless) Programmer's Guide 4.1.2 Usage The sample application executables can be run as described below using the cycle-accurate mode of the Instruction Set Simulator (ISS). The input files for the applications are stored in the test/test_inp folder. The generated output files are available in the test/test_out folder. These can be compared against the reference output files in the test/test_ref folder. Testbench 1 only: To run only the pcm-gain test application, at the prompt (in test/build), type: $ xt-make –f makefile_testbench_sample run All Testbenches: To run all the five testbenches, at the prompt (in test/build), type: $ xt-make –f makefile_testbench_sample run-dec Note 4.2 Note In Instruction Set Simulator (ISS) mode, the renderer testbench output is stored to the output file in the test/test_out/ path. Similarly, the input for capturer testbench is read from the input file stored in test/test_inp/ path. Build and Execute using Xplorer The above testbenches require Xtensa Xplorer version 6.0.3 or greater. Following are the steps for importing to Xplorer and building testbenches: 1. To import the HiFi Audio Framework Xtensa Workspace file (extension xws) into Xplorer, click on “File” and select “Import…”. The “Import” wizard opens. Select “Import Xtensa Xplorer Workspace”. Click “Next >”. Browse for the Xtensa workspace file, and click “Next >”. Select the available project checkboxes and click “Finish”. 2. Select “testxa_af_hostless” as the active project and any of the compatible HiFi core as the configuration. 3. Build by clicking on the “Build Active” button. 4. To run Testbench 1 (PCM gain), from the “Run configurations” menu, under “Arguments” tab in “Program Arguments” text box add the following text and click on “Run” button. -infile: -outfile:
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.7 Linearized : No Page Count : 54 Language : en-US Tagged PDF : Yes XMP Toolkit : 3.1-701 Producer : Microsoft® Word 2016 Title : Xtensa Audio Framework (Hostless) Programmer's Guide Creator : Tensilica, Inc. Creator Tool : Microsoft® Word 2016 Create Date : 2019:03:07 10:38:32-08:00 Modify Date : 2019:03:07 10:38:32-08:00 Document ID : uuid:ED0358E2-1DA2-4CAA-A115-97DF61E09E63 Instance ID : uuid:ED0358E2-1DA2-4CAA-A115-97DF61E09E63 Author : Tensilica, Inc. Keywords : AMR-WB, Codec, APIEXIF Metadata provided by EXIF.tools