A multi-channel PCM data real-time acquisition and output system and method based on the ALSA framework

By establishing a direct PCM data link between memory and audio devices in the ALSA framework, simplifying DMA configuration and adopting audio routing mechanism, the delay and jitter problems of the ALSA framework in multi-channel audio data processing are solved, and efficient multi-channel PCM data synchronization and acquisition output are achieved.

CN119621622BActive Publication Date: 2025-08-01TRONLONG
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411608950.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-12
Publication Date
2025-08-01
Estimated Expiration
2044-11-12

AI Technical Summary

Technical Problem

When the ALSA framework processes multi-frequency, multi-sampling points and high-real-time audio data, there are problems with PCM data delay and jitter. The DMA controller configuration is complex, multi-channel data synchronization is difficult, and resource competition is serious.

Method used

A multi-channel PCM data real-time acquisition and output system based on the ALSA framework is adopted, including a multi-channel analog input unit, a multi-channel analog output unit, a system configuration unit, a memory resource unit, an AD acquisition and conversion unit, a DA output conversion unit and an ALSA DMA buffer allocation unit. By establishing a direct PCM data link between memory and audio equipment, DMA configuration is simplified, and an audio routing mechanism is used to process multi-channel audio data.

Benefits of technology

It improves the synchronization efficiency of multi-channel audio data, reduces delay and jitter, reduces system resource usage, and realizes efficient multi-channel PCM data acquisition and output.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621622B_ABST
    Figure CN119621622B_ABST
Patent Text Reader

Abstract

The present invention relates to a multi-channel PCM data real-time acquisition and output system and method based on the ALSA framework. The system includes a multi-channel analog input unit and a multi-channel analog output unit, and further includes a system configuration unit, a memory resource unit, an AD acquisition and conversion unit, an audio routing unit, a DA output conversion unit, and an ALSA DMA buffer allocation unit. The ALSA DMA buffer allocation unit is used to build a PCM data path between the user space and the kernel space and provide a circular buffer queue to store DMA device resource descriptors. The audio routing unit allocates the DMA device resource descriptors obtained and returned from the ALSA DMA buffer allocation unit to the output end to complete synchronous multi-channel input and output of PCM data. The system provided by the present invention adopts an ALSA DMA buffer allocation unit, which simplifies the DMA configuration process and improves the data transmission efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of audio signal processing, and particularly to a multi-channel PCM data real-time acquisition and output system and method based on the ALSA framework. Background Art

[0002] ALSA (Advanced Linux Sound Architecture) is an audio subsystem of Linux, which provides device management functions for lower-layer driver programs in the system kernel space and provides a standardized audio acquisition and output interface for upper-layer application programs in the system user space, enabling application programs to conveniently acquire and output PCM data. However, when processing AD / DA acquisition and output tasks of audio devices, due to the separation of the system user space and the kernel space in using memory resources, frequent allocation and release operations of memory resources, and the complexity of audio data frame processing, when the system processes the multi-frequency, multi-sampling point, and high real-time requirements of audio data, the ALSA framework may face problems such as PCM data delay and jitter. These problems may be caused by various factors, including improper system scheduling strategies, interrupt processing delays, memory access conflicts, and differences in the specific implementation of driver programs.

[0003] In addition, when the program processes PCM data of multiple channels, it is inevitable to consider the connection relationship of 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 different memory areas, and the DMA parameters need to be reconfigured when switching multi-channel audio, which increases the complexity of DMA controller configuration, makes it difficult to synchronize data between channels, and may cause 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 solution: A multi-channel PCM data real-time acquisition and output system based on the ALSA framework, the system includes a multi-channel analog input unit and a multi-channel analog output unit, and the system further includes a system configuration unit, a memory resource unit, an AD acquisition and 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 and output sound card device, DMA device resource control parameters, and generate a DMA device resource descriptor through memory resources;

[0006] The ALSA DMA buffer allocation unit is used to build a PCM data path between the user space and the kernel space, provide a circular buffer queue to store DMA device resource descriptors, and adjust the allocation and feedback of DMA resources according to the audio routing unit;

[0007] The AD acquisition and conversion unit is used to convert multi-channel analog quantities into corresponding multi-channel PCM data respectively;

[0008] And the DMA device resource descriptor collected and generated from the system configuration unit is sent back to the ALSA DMA buffer allocation unit;

[0009] The audio routing unit is used to configure the link between the multi-channel audio input data and the output data, and complete the synchronous multi-channel input and output PCM data by obtaining the sent-back DMA device 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 device resource descriptor sent back from the acquisition end from the audio routing unit, and convert the multi-channel PCM data into analog quantities for output according to the link rules.

[0011] Preferably, the multi-channel PCM data is audio with 8-channel input and 8-channel output.

[0012] The AD acquisition and 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.

[0013] The present invention also provides a method for real-time acquisition and output of multi-channel PCM data based on the ALSA framework. The method includes the following steps:

[0014] Step 1: Initialize the ALSA DMA buffer allocation unit. The initialization 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 the DMA device resource descriptor; uses the Linux IO operation function to open the DMA device resource descriptor, obtains the DMA device resource control parameters, and can directly map the DMA memory resources to the user layer for use, which is convenient for expanding the 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 achieve synchronous acquisition and output of the corresponding frames of the PCM data;

[0016] Step 3: Loop and execute Step 2 to achieve the acquisition and output of multi-channel PCM data;

[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 device resource descriptor to the buffer allocation unit. Correspondingly, the PCM data output sub-thread is generated;

[0019] Sub-step 22: The PCM data acquisition main thread configures the audio multi-channel link. Correspondingly, the PCM data output sub-thread configures the synchronization acquisition end link;

[0020] Sub-step 23: The PCM data acquisition main thread obtains an idle DMA device resource descriptor from the allocation unit. Correspondingly, the PCM data output sub-thread obtains the returned DMA device resource descriptor from the allocation unit;

[0021] Sub-step 24: The PCM data acquisition main thread acquires PCM data and passes the DMA device resource descriptor back to the allocation unit to complete the acquisition of the PCM data frame. Correspondingly, the PCM data output sub-thread outputs the data of the corresponding frame.

[0022] Preferably, before step 1, there is also a system configuration step, and the system configuration step includes the following sub-steps:

[0023] Sub-step 01: The Linux kernel enables the support modes of ALSA and DMA, and the system starts to load 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 descriptors, and provide directly usable physical memory resources for 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: Apply for a ring-shaped circular buffer queue in the user layer space to manage and control the use of DMA device resource descriptors;

[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 steps of the audio multi-channel link configuration include the following sub-steps:

[0031] Sub-step 221: Initialize the PCM data output audio routing unit to configure the link relationship of the acquisition output end according to requirements;

[0032] Sub-step 222: Obtain an idle and available DMA device resource descriptor from the ALSA DMA buffer allocation unit;

[0033] Sub-step 223: The link configuration of the system default acquisition output channel is to acquire and output once. To obtain or output PCM data of multiple channels simultaneously, a sub-thread needs to be separated. The main thread is responsible for the acquisition task, and the sub-thread is responsible for the output task. The sub-thread needs to synchronize the configuration of the main thread to ensure that the acquired and output data is correct under multi-threaded collaborative processing;

[0034] Sub-step 224: The PCM data is transferred end-to-end through the DMA device resource descriptor.

[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, improves the data transmission efficiency, enables the system to transfer data without passing 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] This system also adopts an audio routing mechanism to process the flow direction of the audio data that needs to be adjusted at the acquisition output end to ensure the correct transmission of the audio data, can more flexibly process multi-channel audio data, and improves the data synchronization efficiency between multiple channels.

[0038] Since the data is directly transmitted between the memory and the audio device, reducing the intermediate links, it is possible to more precisely control the timing and synchronization of the PCM data, greatly reducing the delay and jitter phenomena that occur when the system acquires and outputs PCM data.

[0039] At the same time, the method provided by the present invention can conveniently connect the data at the acquisition output end, enabling the embedded system to efficiently respond to and process the acquisition and output of 8-channel PCM data. Description of the Drawings

[0040] Figure 1 It is 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 It is a flowchart of normal playback of a new call between terminals provided by the present invention;

[0042] Figure 3Flow chart of PCM data synchronous acquisition and output provided by the present invention;

[0043] Figure 4 Flow chart of system resource configuration provided by the present invention;

[0044] Figure 5 Flow chart of allocation of the ALSA DMA buffer allocation unit provided by the present invention;

[0045] Figure 6 Flow chart of audio multi-channel link configuration provided by the present invention; Detailed implementation manners

[0046] Next, the technical solutions in an embodiment of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention.

[0047] Please refer to Figures 1-6 :

[0048] A multi-channel PCM data real-time acquisition and output system based on the ALSA framework. This 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 further includes a system configuration unit, a memory resource unit, an AD acquisition and 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 and output sound card device, DMA device resource control parameters, and generate a DMA device resource descriptor through the memory resource;

[0050] The ALSA DMA buffer allocation unit is used to build a PCM data path between the user space and the kernel space, provide a circular buffer queue to store the DMA device resource descriptor, and adjust the allocation and return of DMA resources according to the audio routing unit;

[0051] The AD acquisition and conversion unit is used to convert multi-channel analog quantities into corresponding multi-channel PCM data respectively;

[0052] And the DMA device resource descriptor collected and generated from the system configuration unit is returned to the ALSA DMA buffer allocation unit;

[0053] The audio routing unit is used to configure the link between multi-channel audio input data and output data, and complete synchronous multi-channel input and output PCM data by obtaining the returned DMA device resource descriptor from the ALSA DMA buffer allocation unit and allocating it to the output end;

[0054] The DA output conversion unit is used to obtain the DMA device 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 adopts an ALSA DMA buffer allocation unit to establish a direct transmission PCM data link between the system memory and the audio device. This simplifies the DMA configuration process, improves the data transmission efficiency, enables the system to transfer data without passing through the CPU cache mechanism during the acquisition and output processes, reduces the CPU intervention, and thus reduces the use of system resources.

[0056] This system also adopts an audio routing mechanism to process the flow direction of the audio data that needs to be adjusted at the acquisition and output ends, ensuring the correct transmission of the audio data, enabling more flexible processing of multi-channel audio data, and improving the data synchronization efficiency between multiple channels.

[0057] Since the data is directly transmitted between the memory and the audio device, reducing the intermediate links, it is possible to more precisely control the timing and synchronization of the PCM data, greatly reducing the delay and jitter phenomena that occur when the system acquires 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 analog-to-digital 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 as high as 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 digital-to-analog converter at the system output end can provide 8 hardware audio DA digital-to-analog conversion channels, accepting 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. Adopting the Delta Sigma framework eliminates the distortion problems caused by capacitor mismatch.

[0061] Supports adjusting the sampling frequency and sampling points of AD / DA through system configuration, enabling the system to achieve low distortion of data and no loss of points and breakpoints in the PCM data waveform under load conditions.

[0062] Supporting the Zero-Copy technology for audio data further reduces the usage burden of embedded hardware resources. The Zero-Copy technology avoids multiple copies of data between the CPU cache and memory, reduces the overhead and latency of data transmission, and enhances the real-time performance of system AD / DA acquisition and output.

[0063] The present invention also provides a method for real-time acquisition and output of multi-channel PCM data based on the ALSA framework. The method includes the following steps:

[0064] Step 1: Initialize the ALSA DMA buffer allocation unit, and its initialization includes: The ALSA DMA buffer allocation unit applies for a circular buffer queue in the user space to manage and control the use of DMA device resource descriptors; uses the Linux IO operation function to open the DMA device resource descriptor, obtains the DMA device resource control parameters, and can directly map the DMA memory resources to the user space for convenient expansion of 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 achieve synchronous acquisition and output of corresponding frames of PCM data;

[0066] Step 3: Loop to execute 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 device resource descriptor to the buffer allocation unit. Correspondingly, the PCM data output sub-thread is generated;

[0069] Sub-step 22: The PCM data acquisition main thread configures the audio multi-channel link. Correspondingly, the PCM data output sub-thread configures the synchronous acquisition end link;

[0070] Sub-step 23: The PCM data acquisition main thread obtains an idle DMA device resource descriptor from the allocation unit. Correspondingly, the PCM data output sub-thread obtains the returned DMA device resource descriptor from the allocation unit;

[0071] Sub-step 24: The PCM data acquisition main thread acquires PCM data and returns the DMA device resource descriptor 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] Among them, before step 1, there is also a system configuration step, and the system configuration step includes the following sub-steps:

[0073] Sub-step 01: The Linux kernel enables the support modes of ALSA and DMA, and the system starts to load 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 a DMA device resource descriptor, and provide directly usable physical memory resources for the Linux system user layer and driver layer.

[0077] The above method can conveniently connect the data at the acquisition output end, enabling the embedded system to efficiently respond to and process the acquisition and output of 8-channel PCM data.

[0078] Among them, in step 1, the allocation steps of the ALSA DMA buffer allocation unit include the following sub-steps:

[0079] Sub-step 11: Apply for a ring-shaped circular buffer queue in the user layer space to manage and control the use of the DMA device resource descriptor;

[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 steps of audio multi-channel link configuration include the following sub-steps:

[0082] Sub-step 221: Initialize the PCM data output audio routing unit to configure the link relationship at the acquisition output end according to requirements;

[0083] Sub-step 222: Obtain an idle and available DMA device resource descriptor from the ALSA DMA buffer allocation unit;

[0084] Sub-step 223: Configure the link of the acquisition output channel to acquire and output once. To obtain or output PCM data of multiple channels simultaneously, a sub-thread needs to be separated. The main thread is responsible for the acquisition task, and the sub-thread is 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 the coordinated processing of multiple threads;

[0085] Sub-step 224: The PCM data is transmitted end-to-end through the DMA device resource descriptor. For example, the descriptor file mem_fd is used in the AD1->DA1 link, and the acquisition and output devices share the same piece of physically contiguous memory resource.

[0086] The above are only embodiments of the present invention, and thus do not limit the patent scope of the present invention. Any equivalent structural or equivalent process transformations made using the contents of the specification and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.

Claims

1. A multi-channel PCM data real-time acquisition and output system based on the ALSA framework. The system includes a multi-channel analog input unit and a multi-channel analog output unit, and is characterized in that: The system further includes a system configuration unit, a memory resource unit, an AD acquisition and 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, the DMA device resource control parameters, and generate a DMA device resource descriptor through the memory resource; The ALSA DMA buffer allocation unit is used to build the PCM data path between the user space and the kernel space, provide a circular buffer queue to store the DMA device resource descriptor, and adjust the allocation and return of the DMA resource according to the audio routing unit; The AD acquisition and conversion unit is used to convert the multi-channel analog quantities into corresponding multi-channel PCM data respectively; and transmit the DMA device resource descriptor collected and generated from the system configuration unit back 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 complete the synchronous multi-channel input and output PCM data by obtaining the DMA device resource descriptor returned from the ALSA DMA buffer allocation unit and allocating it to the output end; The DA output conversion unit is used to obtain the DMA device resource descriptor returned from the acquisition end from the audio routing unit, and convert the multi-channel PCM data into analog quantities 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, wherein: The multi-channel PCM data is audio with 8-channel input and 8-channel output.

3. A multi-channel PCM data real-time acquisition and output system based on the ALSA framework according to claim 2, characterized in that: The AD acquisition and 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.

4. A real-time acquisition and output method for multi-channel PCM data based on the ALSA framework, characterized in that: The method is based on a multi-channel PCM data real-time acquisition and output system based on the ALSA framework according to any one of claims 1-3, and the method includes 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 to execute Step 2 to realize the acquisition and output of multi-channel PCM data; 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 device resource descriptor into the buffer allocation unit. Correspondingly, the PCM data output sub-thread is generated; Sub-step 22: The PCM data acquisition main thread configures the audio multi-channel link. Correspondingly, the PCM data output sub-thread configures the synchronous acquisition end link; Sub-step 23: The PCM data acquisition main thread obtains the idle DMA device resource descriptor from the allocation unit. Correspondingly, the PCM data output sub-thread obtains the DMA device resource descriptor returned from the allocation unit; Sub-step 24: The PCM data acquisition main thread performs PCM data acquisition and passes the DMA device resource descriptor back to the allocation unit to complete the acquisition of the PCM data frame. Correspondingly, the PCM data output sub-thread performs the data output of the corresponding frame.

5. A real-time multi-channel PCM data acquisition and output method based on the ALSA framework according to claim 4, characterized in that: Before step 1, there is also a system configuration step, which includes the following sub-steps: Sub-step 01: The Linux kernel enables the support modes of ALSA and DMA, and the system starts to load 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 continuously physically addressed memory resources, generate the DMA device resource descriptor, and provide directly usable physical memory resources for the Linux system user layer and driver layer.

6. A real-time acquisition and output method for multi-channel PCM data based on the ALSA framework according to claim 4, characterized in that: In step 1, the allocation steps of the ALSA DMA buffer allocation unit include the following sub-steps: Sub-step 11: Apply for a ring-shaped circular buffer queue in the user layer space to manage and control the use of the DMA device resource descriptor. 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. A real-time multi-channel PCM data acquisition and output method based on the ALSA framework according to claim 4, characterized in that: In step 2, the steps of the audio multi-channel link configuration include the following sub-steps: Sub-step 221: Initialize the PCM data output audio routing unit to configure the link relationship of the acquisition output end according to requirements. Sub-step 222: Obtain the idle and available DMA device resource descriptor from the ALSA DMA buffer allocation unit. Sub-step 223: Configure the link of the acquisition output channel to perform one acquisition output. To obtain or output PCM data of multiple channels simultaneously, a sub-thread needs to be separated. The main thread is responsible for the acquisition task, and the sub-thread is responsible for the output task. The sub-thread needs to synchronize the configuration of the main thread to ensure that the acquisition output data is correct under the coordinated processing of multiple threads. Sub-step 224: The PCM data is transmitted end-to-end through the DMA device resource descriptor.

Citation Information

Patent Citations

  • Heterogeneous system audio data interaction processing method and device and storage medium

    CN114528244A

  • Data sharing method and device

    CN117795485A