An audio processing method and device for an Android system
By registering the sound card device in the Android system and setting up the interface and cache, the problem of data asynchrony when the audio algorithm service outputs to different paths is solved, realizing efficient forwarding and standardization of audio streams and improving portability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU LANGO ELECTRONICS TECH CO LTD
- Filing Date
- 2022-09-19
- Publication Date
- 2026-05-29
AI Technical Summary
In Android-based conference all-in-one machines, existing technologies suffer from inter-process communication data synchronization issues when outputting audio algorithm services to Android applications and USBGadget UAC sound cards. Furthermore, these technologies do not conform to the ALSA standard structure design, resulting in poor portability.
The sound card device is registered through the Linux ALSA sound card driver function, and the first and second interfaces are set up. A buffer is requested, and the audio stream is forwarded using a ring buffer and kernel work queue to ensure data synchronization and compliance with the ALSA standard.
It simplifies the data forwarding process, reduces the processing difficulty of audio algorithm services, and improves portability and communication efficiency.
Smart Images

Figure CN115373627B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of audio processing technology, and more particularly to an audio processing method and apparatus for the Android system. Background Technology
[0002] In the context of Android-based all-in-one conferencing systems, when using noise reduction and echo cancellation algorithms, the algorithm service, after processing the raw data, typically needs to output to an Android application or to an external device via a USBGadget's UAC (USB Audio Class specification) sound card. In this scenario, due to the existence of two different paths—the Android application and the USBGadget UAC sound card—when the algorithm service outputs to the USBGadget UAC sound card, it can be implemented using the standard ALSA (Advanced Linux Sound Architecture) interface. However, when the algorithm service outputs to an Android application, the use of a standard inter-process communication mechanism for forwarding leads to data synchronization issues and does not conform to the ALSA standard architecture. This increases the design complexity of the algorithm service and reduces its portability. Summary of the Invention
[0003] This invention provides an audio processing method and apparatus for the Android system to address the technical problem of improving portability.
[0004] To address the aforementioned technical problems, embodiments of the present invention provide an audio processing method for an Android system, comprising:
[0005] Register a sound card device using Linux ALSA sound card driver functions;
[0006] Configure the first and second interfaces of the sound card device, and request a buffer from the kernel through the driver of the sound card device; wherein, the first interface is used to receive audio streams, and the second interface is used to send audio streams;
[0007] When audio stream data is detected being written by the audio algorithm service through the second interface, the written audio stream data is forwarded and made available for Android applications to read through the first interface; wherein, the cache is used for forwarding the written audio stream data.
[0008] As a preferred embodiment, after setting the first and second interfaces of the sound card device, the method further includes setting a standard ALSA driver interface.
[0009] As a preferred embodiment, the standard ALSA driver interface includes a prepare interface, a trigger interface, and a set_sysclk interface.
[0010] As a preferred embodiment, the cache is a FIFO-type circular cache.
[0011] As a preferred embodiment, after setting the first and second interfaces of the sound card device, the method further includes: initializing a kernel work queue, wherein the kernel work queue is used for forwarding the written audio stream data.
[0012] This invention also provides an audio processing device for an Android system, the audio processing device including a registration module, a first setting module, and a forwarding module, wherein...
[0013] The registration module is used to register a sound card device through the Linux ALSA sound card driver function;
[0014] The first setting module is used to set the first interface and the second interface of the sound card device, and to request a buffer from the kernel through the driver of the sound card device; wherein, the first interface is used to receive audio streams, and the second interface is used to send audio streams;
[0015] The forwarding module is used to forward the written audio stream data when it detects that the audio algorithm service has written audio stream data through the second interface, and to allow the Android application to read the written data through the first interface; wherein, the cache is used for forwarding the written audio stream data.
[0016] As a preferred embodiment, the audio processing device further includes a second setting module, which is used to set the standard ALSA driver interface after the first setting module sets the first interface and the second interface of the sound card device.
[0017] As a preferred embodiment, the standard ALSA driver interface includes a prepare interface, a trigger interface, and a set_sysclk interface.
[0018] As a preferred embodiment, the cache is a FIFO-type circular cache.
[0019] As a preferred embodiment, the audio processing device further includes a third setting module. After setting the first and second interfaces of the sound card device, the third setting module is used to initialize a kernel work queue, and the kernel work queue is used for forwarding the written audio stream data.
[0020] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0021] This invention provides an audio processing method and apparatus for an Android system. The audio processing method includes: registering a sound card device through a Linux ALSA sound card driver function; setting a first interface and a second interface of the sound card device, and requesting a buffer from the kernel through the sound card device driver; wherein the first interface is used to receive audio streams, and the second interface is used to send audio streams; when audio stream data written by an audio algorithm service through the second interface is detected, the written audio stream data is forwarded, and the data is read by an Android application through the first interface; wherein the buffer is used for forwarding the written audio stream data. Compared with the prior art, by registering a sound card device, the audio stream processed by the audio algorithm service is written to the sound card device through the second interface. The sound card device also serves as the sound input device for the Android application, realizing the purpose of the Android application reading the audio stream of the audio algorithm service. This simplifies the data forwarding process, reduces the processing difficulty of the audio stream output by the algorithm service, and improves the portability of the algorithm service. Attached Figure Description
[0022] Figure 1 : A flowchart illustrating an embodiment of the audio processing method for the Android system provided by the present invention.
[0023] Figure 2 : A schematic diagram of an embodiment of the audio processing device for the Android system provided by the present invention. Detailed Implementation
[0024] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0025] Example 1:
[0026] According to relevant technical records, in the application scenario of Android-based conference all-in-one machines, after processing the raw data, the algorithm service typically needs to output to an Android application or to an external device via a USBGadget's UAC (USB Audio Class Specification) sound card. For these two different paths, when the algorithm service's output target is a USBGadget UAC sound card, it can be implemented using the standard ALSA (Advanced Linux Sound Architecture) interface. When the algorithm service's output target is an Android application, a common inter-process communication mechanism is used for forwarding. For example, existing methods typically involve simple communication between two user-space processes using sockets, shared memory, and other mechanisms. Because these communication mechanisms lack standard constraints, they are difficult to make universally applicable, leading to data synchronization issues during inter-process communication. Furthermore, they do not conform to the ALSA standard structure design, significantly increasing the design complexity of the algorithm service and resulting in poor portability.
[0027] For one or more of the above technical issues, please refer to Figure 1 , Figure 1 An audio processing method for an Android system provided by an embodiment of the present invention includes steps S1 to S3, wherein,
[0028] Step S1: Register a sound card device using the Linux ALSA sound card driver function.
[0029] Step S2: Configure the first and second interfaces of the sound card device, and request a buffer from the kernel through the driver of the sound card device; wherein, the first interface is used to receive audio streams, and the second interface is used to send audio streams.
[0030] Step S3: When audio stream data written by the audio algorithm service through the second interface is detected, the written audio stream data is forwarded and the data is read by the Android application through the first interface; wherein, the cache is used for forwarding the written audio stream data.
[0031] In step S1 of this embodiment, a sound card device is registered with the Linux platform at the driver layer through the Linux ALSA sound card driver function.
[0032] Furthermore, in step S2 above, a first interface and a second interface of the sound card device are configured. The first interface is `capture`, which is an input channel used by the sound card device to receive audio streams. The second interface is `playback`, which is an output channel used by the sound card device to send audio streams. Both the first interface (`capture`) and the second interface (`playback`) are standard ALSA driver interfaces. In addition, this embodiment may also configure standard ALSA sound card driver interfaces including, but not limited to, `prepare`, `trigger`, and `set_sysclk` interfaces.
[0033] In a preferred implementation, a memory buffer is requested from the kernel within the sound card device driver using kzalloc. This buffer is used for caching during audio data processing (including forwarding in step S3). The requested buffer is a circular buffer in FIFO form. During audio data processing and forwarding, the audio data written by the audio service through the second interface is continuously refreshed and replaced within the circular buffer. Implementing this implementation can effectively improve the efficiency of audio data processing and forwarding.
[0034] In step S2 above, after setting the first and second interfaces of the sound card device, the audio processing method further includes: initializing a kernel work queue, which is used for forwarding written audio stream data. Therefore, in step S3, when audio stream data written by the audio algorithm service through the second interface is detected, the work queue is woken up, and the audio stream data is forwarded using a circular buffer through the work queue, which can further improve forwarding efficiency. The written audio data is then available for reading by the Android application through the first interface. Implementing this embodiment of the application, synchronizing data in the Linux kernel driver, and implementing it according to the standard Linux kernel driver framework, allows the technical solution of this application to be universal across all Linux-running platforms, improving communication efficiency.
[0035] Accordingly, refer to Figure 2 This invention also provides an audio processing device for an Android system, including a registration module 101, a first setting module 102, and a forwarding module 103, wherein...
[0036] The registration module 101 is used to register a sound card device through the Linux ALSA sound card driver function;
[0037] The first setting module 102 is used to set the first interface and the second interface of the sound card device, and to request a cache from the kernel through the driver of the sound card device; wherein, the first interface is used to receive audio streams, and the second interface is used to send audio streams;
[0038] The forwarding module 103 is used to forward the written audio stream data when it detects that the audio algorithm service has written audio stream data through the second interface, and to allow the Android application to read the written data through the first interface; wherein, the cache is used for forwarding the written audio stream data.
[0039] In this embodiment, the audio processing device further includes a second setting module. After the first setting module sets the first interface and the second interface of the sound card device, the second setting module is used to set the standard ALSA driver interface.
[0040] In this embodiment, the standard ALSA driver interface includes a prepare interface, a trigger interface, and a set_sysclk interface.
[0041] In this embodiment, the cache is a FIFO-type circular cache.
[0042] In this embodiment, the audio processing device further includes a third setting module. After setting the first and second interfaces of the sound card device, the third setting module is used to initialize a kernel work queue, and the kernel work queue is used for forwarding the written audio stream data.
[0043] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0044] This invention provides an audio processing method and apparatus for an Android system. The audio processing method includes: registering a sound card device through a Linux ALSA sound card driver function; setting a first interface and a second interface of the sound card device, and requesting a buffer from the kernel through the sound card device driver; wherein the first interface is used to receive audio streams, and the second interface is used to send audio streams; when audio stream data written by an audio algorithm service through the second interface is detected, the written audio stream data is forwarded, and the data is read by an Android application through the first interface; wherein the buffer is used for forwarding the written audio stream data. Compared with the prior art, by registering a sound card device, the audio stream processed by the audio algorithm service is written to the sound card device through the second interface. The sound card device also serves as the sound input device for the Android application, realizing the purpose of the Android application reading the audio stream of the audio algorithm service. This simplifies the data forwarding process, reduces the processing difficulty of the audio stream output by the algorithm service, and improves the portability of the algorithm service.
[0045] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. In particular, it should be noted that any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention for those skilled in the art.
Claims
1. An audio processing method for an Android system, characterized in that, include: Register a sound card device using Linux ALSA sound card driver functions; Configure the first and second interfaces of the sound card device, and request a buffer from the kernel through the driver of the sound card device; wherein, the first interface is used to receive audio streams, and the second interface is used to send audio streams; the buffer is a FIFO circular buffer; When audio stream data is detected being written by the audio algorithm service through the second interface, the written audio stream data is forwarded and made available for Android applications to read through the first interface; wherein, the cache is used for forwarding the written audio stream data. After setting the first and second interfaces of the sound card device, the method further includes: initializing a kernel work queue, wherein the kernel work queue is used for forwarding written audio stream data.
2. The audio processing method for an Android system as described in claim 1, characterized in that, After setting the first and second interfaces of the sound card device, the method further includes setting the standard ALSA driver interface.
3. The audio processing method for an Android system as described in claim 2, characterized in that, The standard ALSA driver interface includes the prepare interface, the trigger interface, and the set_sysclk interface.
4. An audio processing device for an Android system, characterized in that, It includes a registration module, a first settings module, and a forwarding module, among which, The registration module is used to register a sound card device through the Linux ALSA sound card driver function; The first setting module is used to set the first and second interfaces of the sound card device, and to request a buffer from the kernel through the driver of the sound card device; wherein, the first interface is used to receive audio streams, and the second interface is used to send audio streams; the buffer is a FIFO circular buffer; The forwarding module is used to forward the written audio stream data when it detects that the audio algorithm service has written audio stream data through the second interface, and to allow the Android application to read the written data through the first interface; wherein, the cache is used for forwarding the written audio stream data; The audio processing device further includes a third setting module. After setting the first and second interfaces of the sound card device, the third setting module is used to initialize a kernel work queue, and the kernel work queue is used for forwarding the written audio stream data.
5. An audio processing device for an Android system as described in claim 4, characterized in that, The audio processing device further includes a second setting module, which is used to set the standard ALSA driver interface after the first setting module sets the first interface and the second interface of the sound card device.
6. An audio processing device for an Android system as described in claim 5, characterized in that, The standard ALSA driver interface includes the prepare interface, the trigger interface, and the set_sysclk interface.