Multi-channel PCM data real-time acquisition and output system and method based on ALSA framework
By designing a multi-channel PCM data real-time acquisition and output system in the ALSA framework, using the ALSA DMA cache area allocation unit and audio routing mechanism, the delay and jitter problems of the ALSA framework when processing audio data are solved, and efficient multi-channel data synchronization and processing are achieved.
Patent Information
- Application Number
- CN202411608950.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-12
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-11-12
AI Technical Summary
The ALSA framework may face delay and jitter problems of PCM data when processing audio data, and the multi-channel audio data processing is complex and the DMA controller configuration is complex, resulting in difficulty in data synchronization between channels and resource competition.
A multi-channel PCM data real-time acquisition and output system based on the ALSA framework is designed, and the ALSA DMA cache area allocation unit is used to establish a direct transmission PCM data link between the system memory and the audio equipment, simplifying DMA configuration, improving data transmission efficiency, and realizing multi-channel data synchronization through the audio routing mechanism.
By directly transmitting PCM data, CPU intervention is reduced, system resource use is reduced, PCM data timing and synchronization is accurately controlled, delay and jitter phenomenon is greatly reduced, and multi-channel data processing efficiency is improved.
Smart Images

Figure CN119621622A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of audio signal processing, and in particular to a multi-channel PCM data real-time acquisition and output system and method based on an ALSA framework. Background Art
[0002] ALSA (Advanced Linux Sound Architecture) is an audio subsystem of Linux. It provides device management functions for lower-level drivers in the system kernel space and provides standardized audio acquisition and output interfaces for upper-level applications in the system user space, allowing applications to easily collect and output PCM data. However, when processing the AD / DA acquisition and output tasks of audio devices, due to the separation of system user space and kernel space in the use of memory resources, frequent allocation and release of memory resources, and the complexity of audio data frame processing, the ALSA framework may face delay and jitter problems of PCM data when the system processes multi-frequency, multi-sampling points and high real-time requirements of audio data. These problems may be caused by a variety of factors, including improper system scheduling strategies, interrupt processing delays, memory access conflicts, and differences in the specific implementation of drivers.
[0003] In addition, when the program processes PCM data of multiple channels, it is inevitable to consider the link relationship between multiple input and output channels. However, the configuration of the DMA controller is relatively complex. The PCM data of each channel is usually stored in a different memory area. When switching multi-channel audio, the DMA parameters need to be reconfigured, which increases the complexity of the DMA controller configuration, making data synchronization between channels difficult and possible resource competition problems in multi-channel data processing. Summary of the invention
[0004] To achieve the above object, the present invention provides the following technical solutions: a multi-channel PCM data real-time acquisition and output system based on the ALSA framework, the system comprising a multi-channel analog input unit and a multi-channel analog output unit, the system also comprising a system configuration unit, a memory resource unit, an AD acquisition conversion unit, an audio routing unit, a DA output conversion unit and an ALSA DMA buffer allocation unit;
[0005] The system configuration unit is used to configure the acquisition output sound card device, DMA device resource control parameters and generate DMA device resource file descriptors through memory resources;
[0006] The ALSA DMA buffer allocation unit is used to build the PCM data path between the user space and the kernel space and provide a circular buffer queue to store DMA resource descriptors, and adjust the allocation and return of DMA resources according to the audio routing unit;
[0007] The AD acquisition conversion unit is used to convert the analog quantities of multiple channels into corresponding PCM data of multiple channels respectively;
[0008] And return the converted DMA resource descriptors collected from the system configuration unit to the ALSA DMA buffer allocation unit;
[0009] The audio routing unit is used to configure the link between the audio multi-channel input data and the output data, and completes the synchronization of the multi-channel input and output PCM data by obtaining the returned DMA resource descriptor from the ALSA DMA buffer allocation unit and allocating it to the output end;
[0010] The DA output conversion unit is used to obtain the DMA resource descriptor returned by the acquisition end from the audio routing unit, and convert the multi-channel PCM data into analog quantity for output according to the link rule.
[0011] Preferably, the multi-channel PCM data is audio with 8-channel input and 8-channel output.
[0012] The AD acquisition conversion unit uses CS5368 as an AD analog-to-digital converter, and the DA output conversion unit uses CS4385 as a DA digital-to-analog converter at the system output end.
[0013] The present invention also provides a multi-channel PCM data real-time acquisition and output method based on the ALSA framework, the method comprising the following steps:
[0014] Step 1: Initialize the ALSA DMA buffer allocation unit, which includes: the ALSA DMA buffer allocation unit applies for a circular buffer queue in the user layer space to manage and control the use of DMA resource descriptors; use the LinuxIO operation function to open the DMA device resource descriptor, obtain the DMA device resource control parameters, and directly map the DMA memory resources to the user layer for use, which is convenient for expanding PCM data to the network link;
[0015] Step 2: The PCM data acquisition main thread executes the PCM data acquisition task and generates a PCM data output sub-thread for executing the PCM output task to realize the synchronous acquisition and output of the corresponding frames of the PCM data;
[0016] Step 3: Loop through step 2 to achieve multi-channel PCM data acquisition and output;
[0017] Among them, the sub-steps of the PCM data acquisition main thread and the sub-steps of the PCM data output sub-thread in step 2 are as follows:
[0018] Sub-step: 21: The PCM data acquisition main thread passes the DMA resource descriptor to the buffer allocation unit, and correspondingly, the PCM data output sub-thread is generated;
[0019] Sub-step 22: The PCM data acquisition main thread performs audio multi-channel link configuration, and correspondingly, the PCM data output sub-thread performs synchronous acquisition end link configuration;
[0020] Sub-step 23: the PCM data acquisition main thread obtains the idle DMA resource descriptor from the allocation unit, and correspondingly, the PCM data output sub-thread obtains the returned DMA resource descriptor from the allocation unit;
[0021] Sub-step 24: The PCM data acquisition main thread performs PCM data acquisition and returns the DMA resource description to the allocation unit to complete the acquisition of the PCM data frame. Correspondingly, the PCM data output sub-thread performs data output of the corresponding frame.
[0022] Preferably, a system configuration step is further included before step 1, and the system configuration step includes the following sub-steps:
[0023] Sub-step 01: The Linux kernel enables ALSA and DMA support mode, and the system starts loading the DMA controller driver;
[0024] Sub-step 02: Use the i2cset command tool to configure the acquisition output register and initialize the acquisition output controller;
[0025] Sub-step 03: Use the interface provided by alsa lib to open and configure the acquisition output sound card device;
[0026] Sub-step 04: Apply for memory resources with continuous physical addresses, generate DMA device resource file description, and provide physical memory resources that can be directly used by the Linux system user layer and driver layer.
[0027] Preferably, in step 1, the allocation step of the ALSA DMA buffer allocation unit includes the following sub-steps:
[0028] Sub-step 11: The user layer space applies for a ring body circular buffer queue for managing and controlling the use of DM resource description;
[0029] Sub-step 12: Use the Linux IO operation function to open the DMA device resource descriptor, and map the memory resources to the user layer space according to the DMA device resource descriptor.
[0030] Preferably, in step 2, the step of configuring the audio multi-channel link includes the following sub-steps:
[0031] Sub-step 221: initializing the PCM data output audio routing unit to configure the link relationship of the acquisition output end according to the requirements;
[0032] Sub-step 222: Obtain an idle and available DMA resource descriptor from the ALSA DMA buffer allocation unit;
[0033] Sub-step 223: The system defaults to the link configuration of the acquisition output channel as acquisition and output once. In order to simultaneously acquire or output PCM data of multiple channels, a sub-thread needs to be separated. The main thread will be responsible for the acquisition task, and the sub-thread will be responsible for the output task. The sub-thread needs to synchronize the configuration of the main thread to ensure that the acquisition and output data are correct under multi-thread collaborative processing;
[0034] Sub-step 224: PCM data is transmitted end-to-end via the DMA resource descriptor file.
[0035] The present invention has the following beneficial effects:
[0036] The system provided by the present invention adopts an ALSA DMA buffer allocation unit to establish a direct transmission PCM data link between the system memory and the audio device, which simplifies the DMA configuration process and improves the efficiency of data transmission. The system does not need to transfer data through the CPU cache mechanism during the acquisition and output process, reduces the intervention of the CPU, and thus reduces the use of system resources.
[0037] The system also adopts an audio routing mechanism to process the audio data according to the flow direction that needs to be adjusted at the acquisition output end to ensure that the audio data can be transmitted correctly. It can process multi-channel audio data more flexibly and improve the efficiency of data synchronization between multiple channels.
[0038] Since data is transmitted directly between the memory and the audio device, the intermediate links are reduced, so the timing and synchronization of PCM data can be controlled more accurately, greatly reducing the delay and jitter that occurs when the system collects and outputs PCM data.
[0039] At the same time, the method provided by the present invention can conveniently connect the data of the acquisition output end, so that the embedded system can efficiently respond to and process the acquisition and output of 8-channel PCM data. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 A block diagram of a multi-channel PCM data real-time acquisition and output system based on the ALSA framework provided by the present invention;
[0041] Figure 2 A flow chart of normally playing a new call between terminals provided by the present invention;
[0042] Figure 3A flowchart of PCM data synchronous acquisition and output provided by the present invention;
[0043] Figure 4 A flow chart of system resource configuration provided by the present invention;
[0044] Figure 5 An allocation flow chart of the ALSA DMA buffer allocation unit provided by the present invention;
[0045] Figure 6 A flowchart of the audio multi-channel link configuration provided by the present invention; DETAILED DESCRIPTION
[0046] The technical solution in one embodiment of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0047] See also Figure 1-6 :
[0048] A multi-channel PCM data real-time acquisition and output system based on ALSA framework, the system is an 8-channel PCM data real-time acquisition and output system, the system includes a multi-channel analog input unit and a multi-channel analog output unit, the system also includes a system configuration unit, a memory resource unit, an AD acquisition conversion unit, an audio routing unit, a DA output conversion unit and an ALSA DMA buffer allocation unit;
[0049] The system configuration unit is used to configure the acquisition output sound card device, DMA device resource control parameters and generate DMA device resource file descriptors through memory resources;
[0050] The ALSA DMA buffer allocation unit is used to build the PCM data path between user space and kernel space and provide a circular buffer queue to store DMA resource descriptors, as well as adjust the allocation and return of DMA resources according to the audio routing unit;
[0051] The AD acquisition conversion unit is used to convert the analog quantities of multiple channels into corresponding PCM data of multiple channels respectively;
[0052] And return the converted DMA resource descriptors collected from the system configuration unit to the ALSA DMA buffer allocation unit;
[0053] The audio routing unit is used to configure the link between the audio multi-channel input data and the output data, and completes the synchronization of multi-channel input and output PCM data by obtaining the returned DMA resource descriptor from the ALSADMA buffer allocation unit and allocating it to the output end;
[0054] The DA output conversion unit is used to obtain the DMA resource descriptor returned by the acquisition end from the audio routing unit, and convert the multi-channel PCM data into analog quantity for output according to the link rules.
[0055] This system uses an ALSA DMA buffer allocation unit to establish a direct transmission PCM data link between the system memory and the audio device, which simplifies the DMA configuration process and improves the efficiency of data transmission. It makes the system no longer need to transfer data through the CPU cache mechanism during the acquisition and output process, reduces CPU intervention, and thus reduces the use of system resources.
[0056] The system also adopts an audio routing mechanism to process the audio data according to the flow direction that needs to be adjusted at the acquisition output end to ensure that the audio data can be transmitted correctly. It can process multi-channel audio data more flexibly and improve the efficiency of data synchronization between multiple channels.
[0057] Since data is transmitted directly between the memory and the audio device, the intermediate links are reduced, so the timing and synchronization of PCM data can be controlled more accurately, greatly reducing the delay and jitter that occurs when the system collects and outputs PCM data.
[0058] The AD acquisition conversion unit uses CS5368 as the AD analog-to-digital converter, and the DA output conversion unit uses CS4385 as the DA digital-to-analog converter at the system output end.
[0059] Using CS5368 as the AD converter at the system acquisition end can provide 8 hardware audio AD analog-to-digital conversion channels, and the sampling rate of a single data stream is up to 192KHz. The oversampling multi-bit Delta Sigma modulator using mismatch shaping technology has an outstanding 114dB dynamic range and low distortion.
[0060] Using CS4385 as the DA converter at the system output, it can provide 8 hardware audio DA DA conversion channels and accept sampling rates from 4KHz to 216KHz. It is equipped with digital de-emphasis, half-dB step volume control, ATAPI channel mixing, and selectable fast and slow digital interpolation filters. It adopts the Delta Sigma framework to eliminate distortion problems caused by capacitor mismatch.
[0061] It supports adjusting the sampling frequency and number of sampling points of AD / DA through system configuration, so that the system can achieve low data distortion and no missing or breakpoints in the PCM data waveform under load environment.
[0062] Supports Zero-Copy technology for audio data, further reducing the burden of embedded hardware resources. Zero-Copy technology avoids multiple copies of data between CPU cache and memory, reduces data transmission overhead and delay, and enhances the real-time performance of system AD / DA acquisition output.
[0063] The present invention also provides a multi-channel PCM data real-time acquisition and output method based on the ALSA framework, the method comprising the following steps:
[0064] Step 1: Initialize the ALSA DMA buffer allocation unit, which includes: the ALSA DMA buffer allocation unit applies for a circular buffer queue in the user layer space to manage and control the use of DMA resource descriptors; use the LinuxIO operation function to open the DMA device resource descriptor, obtain the DMA device resource control parameters, and directly map the DMA memory resources to the user layer for use, which is convenient for expanding PCM data to the network link;
[0065] Step 2: The PCM data acquisition main thread executes the PCM data acquisition task and generates a PCM data output sub-thread for executing the PCM output task to realize the synchronous acquisition and output of the corresponding frames of the PCM data;
[0066] Step 3: Loop through step 2 to achieve multi-channel PCM data acquisition and output;
[0067] Among them, the sub-steps of the PCM data acquisition main thread and the sub-steps of the PCM data output sub-thread in step 2 are as follows:
[0068] Sub-step: 21: The PCM data acquisition main thread passes the DMA resource descriptor to the buffer allocation unit, and correspondingly, the PCM data output sub-thread is generated;
[0069] Sub-step 22: The PCM data acquisition main thread performs audio multi-channel link configuration, and correspondingly, the PCM data output sub-thread performs synchronous acquisition end link configuration;
[0070] Sub-step 23: the PCM data acquisition main thread obtains the idle DMA resource descriptor from the allocation unit, and correspondingly, the PCM data output sub-thread obtains the returned DMA resource descriptor from the allocation unit;
[0071] Sub-step 24: The PCM data acquisition main thread performs PCM data acquisition and returns the DMA resource description to the allocation unit to complete the acquisition of the PCM data frame. Correspondingly, the PCM data output sub-thread performs data output of the corresponding frame.
[0072] Wherein, before step 1, a system configuration step is also included, and the system configuration step includes the following sub-steps:
[0073] Sub-step 01: The Linux kernel enables ALSA and DMA support mode, and the system starts loading the DMA controller driver;
[0074] Sub-step 02: Use the i2cset command tool to configure the acquisition output register and initialize the acquisition output controller;
[0075] Sub-step 03: Use the interface provided by alsa lib to open and configure the acquisition output sound card device;
[0076] Sub-step 04: Apply for memory resources with continuous physical addresses, generate DMA device resource file description, and provide physical memory resources that can be directly used by the Linux system user layer and driver layer.
[0077] The above method can conveniently connect the data of the acquisition output end, so that the embedded system can efficiently respond to and process the acquisition and output of 8-channel PCM data.
[0078] Wherein, in step 1, the allocation step of the ALSA DMA buffer allocation unit includes the following sub-steps:
[0079] Sub-step 11: The user layer space applies for a ring body circular buffer queue for managing and controlling the use of DM resource description;
[0080] Sub-step 12: Use the Linux IO operation function to open the DMA device resource descriptor, and map the memory resources to the user layer space according to the DMA device resource descriptor.
[0081] In step 2, the step of configuring the audio multi-channel link includes the following sub-steps:
[0082] Sub-step 221: initializing the PCM data output audio routing unit to configure the link relationship of the acquisition output end according to the requirements;
[0083] Sub-step 222: Obtain an idle and available DMA resource descriptor from the ALSA DMA buffer allocation unit;
[0084] Sub-step 223: The link configuration of the acquisition output channel is to acquire and output once. In order to simultaneously acquire or output PCM data of multiple channels, a sub-thread needs to be separated. The main thread will be responsible for the acquisition task, and the sub-thread will be responsible for the output task. The sub-thread needs to synchronize the configuration of the main thread to ensure that the acquisition and output data are correct under multi-thread collaborative processing;
[0085] Sub-step 224: PCM data is transmitted end-to-end through the DMA resource descriptor file. For example, the descriptor file mem fd is used in the AD1->DA1 link, and the acquisition and output devices share the same memory resource with continuous physical addresses.
[0086] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A multi-channel PCM data real-time acquisition and output system based on ALSA framework, the system comprises a multi-channel analog input unit and a multi-channel analog output unit, characterized in that: The system also includes a system configuration unit, a memory resource unit, an AD acquisition conversion unit, an audio routing unit, a DA output conversion unit and an ALSA DMA buffer allocation unit; The system configuration unit is used to configure the acquisition output sound card device, DMA device resource control parameters and generate DMA device resource file descriptors through memory resources; The ALSA DMA buffer allocation unit is used to build the PCM data path between the user space and the kernel space and provide a circular buffer queue to store DMA resource descriptors, and adjust the allocation and return of DMA resources according to the audio routing unit; The AD acquisition conversion unit is used to convert the analog quantities of the multiple channels into the corresponding PCM data of the multiple channels respectively; and return the DMA resource descriptors acquired and converted from the system configuration unit to the ALSA DMA buffer allocation unit; The audio routing unit is used to configure the link between the audio multi-channel input data and the output data, and completes the synchronization of multi-channel input and output PCM data by obtaining the returned DMA resource descriptor from the ALSADMA buffer allocation unit and allocating it to the output end; The DA output conversion unit is used to obtain the DMA resource descriptor returned by the acquisition end from the audio routing unit, and convert the multi-channel PCM data into analog quantity for output according to the link rule.
2. The multi-channel PCM data real-time acquisition and output system based on the ALSA framework according to claim 1, characterized in that: The multi-channel PCM data is 8-channel input and 8-channel output audio.
3. A multi-channel PCM data real-time acquisition and output system based on ALSA framework according to claim 2, characterized in that: The AD acquisition conversion unit uses CS5368 as an AD analog-to-digital converter, and the DA output conversion unit uses CS4385 as a DA digital-to-analog converter at the system output end.
4. A multi-channel PCM data real-time acquisition and output method based on ALSA framework, characterized by: The method is based on a multi-channel PCM data real-time acquisition and output system based on an ALSA framework as described in any one of claims 1 to 3, and the method comprises the following steps: Step 1: Initialize the ALSA DMA buffer allocation unit; Step 2: The PCM data acquisition main thread executes the PCM data acquisition task and generates a PCM data output sub-thread for executing the PCM output task to realize the synchronous acquisition and output of the corresponding frames of the PCM data; Step 3: Loop through step 2 to achieve multi-channel PCM data acquisition and output; Among them, the sub-steps of the PCM data acquisition main thread and the sub-steps of the PCM data output sub-thread in step 2 are as follows: Sub-step: 21: The PCM data acquisition main thread passes the DMA resource descriptor to the buffer allocation unit, and correspondingly, the PCM data output sub-thread is generated; Sub-step 22: The PCM data acquisition main thread performs audio multi-channel link configuration, and correspondingly, the PCM data output sub-thread performs synchronous acquisition end link configuration; Sub-step 23: the PCM data acquisition main thread obtains the idle DMA resource descriptor from the allocation unit, and correspondingly, the PCM data output sub-thread obtains the returned DMA resource descriptor from the allocation unit; Sub-step 24: The PCM data acquisition main thread performs PCM data acquisition and returns the DMA resource description to the allocation unit to complete the acquisition of the PCM data frame. Correspondingly, the PCM data output sub-thread performs data output of the corresponding frame.
5. A multi-channel PCM data real-time acquisition and output method based on ALSA framework according to claim 4, characterized in that: Before step 1, a system configuration step is also included, and the system configuration step includes the following sub-steps: Sub-step 01: The Linux kernel enables ALSA and DMA support mode, and the system starts loading the DMA controller driver; Sub-step 02: Use the i2cset command tool to configure the acquisition output register and initialize the acquisition output controller; Sub-step 03: Use the interface provided by alsa lib to open and configure the acquisition output sound card device; Sub-step 04: Apply for memory resources with continuous physical addresses, generate DMA device resource file description, and provide physical memory resources that can be directly used by the Linux system user layer and driver layer.
6. The multi-channel PCM data real-time acquisition and output method based on the ALSA framework according to claim 4 is characterized in that: In step 1, the allocation step of the ALSA DMA buffer allocation unit includes the following sub-steps: Sub-step 11: The user layer space applies for a ring body circular buffer queue for managing and controlling the use of DM resource description; Sub-step 12: Use the Linux IO operation function to open the DMA device resource descriptor, and map the memory resources to the user layer space according to the DMA device resource descriptor.
7. The multi-channel PCM data real-time acquisition and output method based on the ALSA framework according to claim 4 is characterized in that: In step 2, the step of configuring the audio multi-channel link includes the following sub-steps: Sub-step 221: initializing the PCM data output audio routing unit to configure the link relationship of the acquisition output end according to the requirements; Sub-step 222: Obtain an idle and available DMA resource descriptor from the ALSA DMA buffer allocation unit; Sub-step 223: The link configuration of the acquisition output channel is to acquire and output once. In order to simultaneously acquire or output PCM data of multiple channels, a sub-thread needs to be separated. The main thread will be responsible for the acquisition task, and the sub-thread will be responsible for the output task. The sub-thread needs to synchronize the configuration of the main thread to ensure that the acquisition and output data are correct under multi-thread collaborative processing; Sub-step 224: PCM data is transmitted end-to-end via the DMA resource descriptor file.
Citation Information
Patent Citations
Heterogeneous system audio data interaction processing method and device and storage medium
CN114528244A
Data sharing method and device
CN117795485A
Cross-domain audio processing method and device, electronic equipment and storage medium
CN118132028A
Method for reducing latency of accessing data stored in a file system on a computer storage device by caching file system permission information in the computer storage device
US20130254477A1
Audio processing method and device, and computer storage medium
WO2017005010A1
Cited By
Zero-copy data transmission method and device, medium and product
CN120803987A
A zero-copy data transmission method, device, medium and product
CN120803987B