Android system USB and host audio dual-channel MIC mixing synchronization output method
By constructing a multi-threaded concurrent acquisition architecture and a dynamic synchronization mechanism, the problems of audio data misalignment and deadlock caused by external audio devices on Android terminals were solved, achieving synchronized output between onboard and external audio devices and system stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI INNOVATECH INFORMATION TECH
- Filing Date
- 2025-12-17
- Publication Date
- 2026-06-12
AI Technical Summary
When an external Universal Serial Bus (USB) audio device is connected to an Android terminal, the onboard audio device is disabled, causing audio data to become misaligned on the timeline, resulting in intermittent sounds, pops, or silence gaps. Furthermore, the failure of the external device's logic causes the audio service to deadlock, affecting the stability of the terminal.
By monitoring external devices through the audio hardware abstraction layer's listening thread, a multi-threaded concurrent acquisition architecture and dynamic synchronization mechanism are constructed to isolate the blockage of external audio input channels. A time synchronization strategy and physical connection monitoring are adopted, and a logical exception circuit breaker mechanism is introduced to ensure the continuity of audio data and system stability.
It enables synchronized output between onboard and external audio devices, preventing data loss or interruption, ensuring synchronization between the user interface and audio playback, enhancing the system robustness of the Android terminal, and preventing deadlock.
Smart Images

Figure CN121349401B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of audio signal processing technology, specifically to a method for synchronous output of dual microphones (USB and host AUDIO) in an Android system. Background Technology
[0002] With the development of mobile internet multimedia applications, Android terminal users' needs for audio interaction scenarios are gradually evolving towards multi-device collaboration. When conducting mobile live streaming, karaoke recording, or game voice chat, users need to simultaneously use external Universal Serial Bus (USB) audio devices and the Android terminal's built-in onboard audio devices. For example, users might want to use an external professional microphone to record vocals while simultaneously using the onboard microphone to capture ambient background noise, or they might want the audio stream to be played through both external headphones and the onboard speakers. However, the native audio framework of the Android operating system follows a single-routing strategy, automatically disabling the onboard audio device upon detecting an external audio device connection.
[0003] If dual-channel audio concurrency is forced by modifying the underlying driver, a slight deviation in sampling frequency and phase asynchrony will objectively exist between the onboard audio hardware and the external SATA audio device, since they are driven by physically independent crystal clock sources. In conventional serial data processing logic, the main processing thread is prone to blocking while waiting for data transmission from the external SATA audio device. This clock domain asynchrony will cause the two acquired audio data streams to be out of sync on the time axis, resulting in discontinuous audio signals, pops, or silent gaps due to insufficient data accumulation in the final synthesized audio signal.
[0004] Furthermore, in concurrent audio output scenarios, external SATA audio devices are limited by bus bandwidth and transmission protocols, resulting in unpredictable delays in write feedback. If the audio system relies on the write progress of external SATA audio devices to update the system timestamp, it can lead to a desynchronization between the application-level UI animations, lyrics scrolling, and the actual sound heard on the Android terminal. Simultaneously, SATA devices are prone to logical deadlocks in complex electromagnetic environments or frequent hot-plugging operations. Existing audio drivers lack dynamic monitoring and circuit breaker mechanisms for logical transmission errors. When an external SATA audio device maintains a physical connection but its internal logic stops responding, the Android terminal's audio service process often falls into a system-level freeze due to indefinitely waiting for a response from the external SATA audio device, impacting the operational stability of the Android terminal.
[0005] Therefore, this invention proposes a method for simultaneous output of dual-channel microphones (USB and AUDIO) in an Android system to address the shortcomings of existing technologies. Summary of the Invention
[0006] To address the shortcomings of existing technologies, this invention provides a method for simultaneous output of dual-channel microphones (USB and host AUDIO) in an Android system, which solves the stability problem of Android terminal audio service deadlock caused by logic failure of external universal serial bus audio devices.
[0007] To achieve the above objectives, the present invention provides the following technical solution:
[0008] This invention provides a method for synchronous hybrid output of dual microphones (USB and host AUDIO) in an Android system, comprising the following steps:
[0009] S1. Establish a listening thread for the Universal Serial Bus (USB) interface status through the audio hardware abstraction layer. When an external USB audio device is detected to be connected, update the connection status variable, parse the device descriptor of the external USB audio device, and construct a device capability set. The device capability set includes input capability identifiers and output capability identifiers.
[0010] S2. Based on the connection state variables and device capability set, the concurrent input process execution flag and concurrent output process execution flag are determined by a logical decision algorithm. The logical decision algorithm instructs the central processing unit to enter the dual-channel audio concurrent recording process or the dual-channel audio concurrent playback process according to the binary logic state of the input capability flag and the output capability flag.
[0011] S3. When the concurrent input process execution flag is set to 1, a multi-threaded concurrent acquisition architecture is started to mix the onboard audio data sequence and the external audio data sequence to generate the final output audio signal. The multi-threaded concurrent acquisition architecture maintains a set of acquisition threads in the audio hardware abstraction layer, which includes a main acquisition thread and sub-acquisition threads. The main acquisition thread is responsible for reading data from the onboard audio input channel. The sub-acquisition threads are responsible for reading data from the external audio input channel. The sub-acquisition threads run independently, isolating the blocking read operation of the external audio input channel in the sub-acquisition threads to prevent the main acquisition thread from being blocked. A data buffer set is allocated in the memory space, which includes an onboard circular buffer and an external circular buffer. Dynamic synchronization and threshold judgment are performed based on the effective data volume in the external circular buffer. When the effective data volume is greater than or equal to the synchronization trigger threshold, the mixing mode is entered, and a signal processing model combining linear superposition and amplitude clamping is used to generate the final output audio signal. When the effective data volume is less than the synchronization trigger threshold, the pass-through mode is entered, and the onboard audio data sequence is directly used as the final output audio signal.
[0012] When the concurrent output process execution flag is set to 1, the dual-channel concurrent establishment logic is executed, and concurrent writing is performed on the onboard audio output channel and the external audio output channel; a first physical output channel is established for the onboard audio interaction system and an onboard output handle is constructed; a second physical output channel is established for the external audio interaction system and an external output handle is constructed; audio source data blocks are received and the active output set is traversed; audio source data blocks are directly written to the onboard output handle; for the external output handle, when the target sampling rate is inconsistent with the source sampling rate, resampling processing is performed and then an adaptation data block is written; the final return write length is calculated based on the write result of the onboard output handle to ensure the benchmark of system timing;
[0013] During system operation, the physical connection status and logical transmission status are continuously monitored. When a device removal event or error counter exceeds the maximum tolerance threshold, the resource reclamation logic is triggered. The resource reclamation logic includes terminating the sub-acquisition thread, releasing the external ring buffer, and forcibly locking the synchronization state selection function to pass-through mode to ensure that the system can safely roll back to the single-path onboard operation mode.
[0014] This invention provides a method for simultaneous output of dual microphones (USB and host AUDIO) in an Android system. It offers the following advantages:
[0015] 1. This invention solves the problem of clock domain asynchrony between onboard audio devices and external universal serial bus audio devices by constructing a multi-threaded concurrent acquisition architecture including a main acquisition thread and sub-acquisition threads, combined with a circular buffer and dynamic threshold decision mechanism. The sub-acquisition threads isolate blocking read operations on external audio input channels, preventing the main acquisition thread from being blocked. The Android terminal calculates the effective data volume in the external circular buffer and compares it with the synchronization trigger threshold, enabling switching between mixing mode and pass-through mode. This ensures automatic fallback to single-channel mode during data jitter, guaranteeing the continuity of the final output audio signal.
[0016] 2. This invention employs a time synchronization strategy anchored to the onboard device in the concurrent output process. When concurrently writing data to the onboard audio output channel and the external audio output channel, the audio hardware abstraction layer determines the write result of the onboard output handle as the final return write length and feeds it back to the application framework layer. Since the clock source of the onboard audio interaction system is stable, this strategy shields the transmission delay present in external universal serial bus audio devices. The application framework layer updates the playback timestamp based on the write result of the onboard output handle, ensuring that the user interface animation and audio playback progress remain synchronized.
[0017] 3. This invention introduces a security protection mechanism that combines physical connection monitoring with logical exception circuit breaking. The Android terminal maintains an error counter for the external audio interaction system to count the number of failed read / write operations of the underlying driver. When the error counter exceeds the maximum tolerance threshold, the Android terminal determines that the external Universal Serial Bus audio device is in a logically unavailable state and triggers resource reclamation logic. This mechanism covers physical disconnection and device crashes, preventing the audio hardware abstraction layer from getting stuck in a deadlock while waiting for a response from a failed device, thus enhancing the system robustness of the Android terminal. Attached Figure Description
[0018] Figure 1 This is a diagram illustrating the method architecture of the present invention;
[0019] Figure 2 This is a schematic diagram of the method flow of the present invention;
[0020] Figure 3 This is a schematic diagram of the system structure of the present invention. Detailed Implementation
[0021] The technical solutions in 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.
[0022] See attached document Figure 1 To implement the method of simultaneous hybrid output of dual microphones (USB and host AUDIO) in an Android system, this invention provides a multi-audio device concurrent control terminal and system based on the Android system. The Android terminal, as the hardware execution entity, can achieve concurrent acquisition and output of dual-channel audio data when external audio devices are connected. The hardware architecture of the Android terminal mainly includes a central processing unit, memory, a first audio codec, and a universal serial bus host interface.
[0023] The central processing unit (CPU) and memory in an Android terminal establish a data communication connection via the system bus. Memory stores computer program instructions and temporary data generated during program execution. The CPU reads and executes the computer program instructions stored in memory. The CPU runs the Android operating system by executing these instructions. The Android operating system comprises a Linux kernel layer, an audio hardware abstraction layer (HHBL), and an application framework layer. The CPU primarily executes the logic control code in the HHBL, implementing calls to underlying hardware drivers and managing the routing of audio data streams.
[0024] An Android terminal integrates a first audio codec. This first audio codec is an onboard audio signal processing unit used to handle the conversion between analog and digital audio signals within the Android terminal itself. The first audio codec is connected to the central processing unit (CPU) via an integrated circuit bus. The first audio codec is physically connected to a first microphone and a first speaker. The first microphone is located on the Android terminal's casing and is used to collect ambient sound and convert it into analog electrical signals for transmission to the first audio codec. The first speaker is located inside or on the surface of the Android terminal's casing and is used to convert the analog electrical signals output by the first audio codec into sound waves for playback.
[0025] Android devices are equipped with a Universal Serial Bus (USB) host interface. The USB host interface is used for physical connection to external devices and provides power and data transmission channels for them. The USB host interface supports the USB Audio Protocol Class standard, allowing Android devices to recognize and drive external audio devices that conform to this standard.
[0026] In order to provide a precise mathematical description and state definition of the hardware entities in subsequent logic control, the onboard audio hardware resources within the Android terminal are defined as the onboard audio interaction system. Onboard audio interaction system From the onboard audio input channel and onboard audio output channels composition.
[0027] Onboard audio interaction system The set relation is represented as:
[0028] ;
[0029] in, Defined as the onboard audio input channel acquired through the first microphone and converted by the first audio codec. Defined as an onboard audio output channel that is converted by a first audio codec and played through a first speaker.
[0030] The central processing unit (CPU) manages the onboard audio interaction system through the audio hardware abstraction layer. Control is performed. The central processing unit can independently enable or disable the onboard audio input channels. The central processing unit can independently enable or disable the onboard audio output channel. The central processing unit can read the onboard audio input channels. The pulse code modulation data is stored in the CPU. The central processing unit can output data to the onboard audio output channel. Write pulse code modulation data.
[0031] See attached document Figure 1 The system in this embodiment of the invention also includes an external Universal Serial Bus (USB) audio device. The external USB audio device is physically connected to the USB host interface of the Android terminal via a USB cable. As an independent hardware entity, the external USB audio device has audio signal acquisition and playback functions.
[0032] External Serial Bus (USB) audio devices integrate a USB device interface controller. This controller handles the data communication protocol with the Android terminal. The USB device interface controller enumerates external USB audio devices as standard audio peripherals recognizable by the Android terminal operating system.
[0033] An external SATA audio device integrates a second audio codec. This second audio codec handles the conversion between analog and digital audio signals from the external SATA audio device. It interacts with the SATA device interface controller. A second microphone is connected to the second audio codec. The second microphone captures external sound and converts it into an analog electrical signal, which is then input to the second audio codec. A second speaker is connected to the second audio codec. The second speaker receives the analog electrical signal output from the second audio codec and converts it into sound waves.
[0034] When an external Unicode audio device is connected to an Android terminal, the Android terminal's audio hardware abstraction layer establishes a communication link with the external Unicode audio device through an identification program. To distinguish between onboard and external devices in the logic control, this specific implementation defines the hardware resources of the external Unicode audio device as an external audio interaction system. External audio interaction system From external audio input channel and external audio output channel composition.
[0035] External audio interaction system The set relation is represented as:
[0036] ;
[0037] in, Defined as a digital audio input data stream channel acquired through a second microphone and converted by a second audio codec. Defined as a digital audio output data stream channel that is converted by a second audio codec and played through a second speaker.
[0038] The central processing unit (CPU) of an Android device can send control commands to external SATA audio devices via the Universal Serial Bus (USB) protocol. The CPU can also read external audio input channels. The pulse code modulation data in the output. The central processing unit can output to an external audio output channel. Write pulse code modulation data. External audio input channel. Sampling rate and onboard audio input channels The sampling rate of each is determined by its own hardware clock source, and the two are physically independent of each other.
[0039] See attached document Figure 1 The Android terminal and the external SATA audio device establish a data communication connection via the SATA protocol. The Android terminal acts as the SATA host, controlling the timing and data transmission on the SATA. The external SATA audio device acts as the SATA device, responding to control commands and data read / write requests issued by the Android terminal.
[0040] The central processing unit (CPU) within an Android device runs a Linux kernel. The Linux kernel contains Universal Serial Bus (USB) drivers and audio drivers. The Audio Hardware Abstraction Layer (AHDL) runs in user space, situated between the Android application framework layer and the Linux kernel. The AHDL interacts with the underlying hardware drivers by calling application programming interfaces (APIs) provided by the Linux kernel. The AHDL accesses the onboard audio interaction system by opening device nodes generated by the Linux kernel. The audio hardware abstraction layer accesses external audio interaction systems by opening audio device nodes on the Universal Serial Bus (USB) generated by the Linux kernel. .
[0041] During system operation, the connection between the Android terminal and the external Universal Serial Bus audio device is dynamically changing. To accurately represent this dynamic connection in the control algorithm, a connection state variable is defined. Connection state variables Used to indicate whether an external Universal Serial Bus audio device is available at the current moment.
[0042] Connection state variables The mathematical definition of is as follows:
[0043] ;
[0044] In the formula, Defined as the condition when the audio hardware abstraction layer detects that an external Universal Serial Bus audio device has been connected to the Universal Serial Bus host interface and completes device enumeration. Defined as a condition where the audio hardware abstraction layer does not detect the access of an external Unicode audio device or detects that the external Unicode audio device has been disconnected from the Unicode host interface.
[0045] When connection state variable The value is At that time, the Android terminal's operating system kernel also contained a pointer to the onboard audio interaction system. Device handle and pointer to external audio interaction system The device handle. The audio hardware abstraction layer can use connection state variables. The value determines whether to initiate the concurrent control logic. At the physical level, the onboard audio interaction system... The clock signal is generated by the clock oscillator inside the Android terminal. External audio interaction system. The clock signal is generated by the internal clock oscillator of the external Universal Serial Bus audio device. Therefore, the onboard audio interaction system... External audio interaction system Located in two independent clock domains, the data transmission rates of the two domains exhibit a slight, uncorrelated deviation.
[0046] See attached document Figure 2 The control method provided in this embodiment of the invention begins with the continuous monitoring of system events by the audio hardware abstraction layer. After startup, the audio hardware abstraction layer enters its main loop logic. Within this main loop logic, the audio hardware abstraction layer establishes a listening thread for the Universal Serial Bus (USB) interface status. This listening thread reads device node status change events reported by the operating system kernel to determine in real time whether external hardware is connected to the USB host interface.
[0047] When an external Unicode audio device is physically connected to an Android terminal, the operating system kernel identifies the device descriptor of the external Unicode audio device. The operating system kernel generates a device access notification and sends it to the Audio Hardware Abstraction Layer (HAL). The HAL receives the device access notification and updates the aforementioned connection state variables. The value is updated to Meanwhile, the audio hardware abstraction layer parses the interface descriptor of the external Unicode audio device to determine the audio transmission direction supported by the external Unicode audio device.
[0048] To transform the functional attributes of external Universal Serial Bus audio devices into mathematical parameters that can be used for logical decision-making, a set of device capabilities is defined. Equipment capability set Includes input capability identifier Output capability identifier .
[0049] Equipment Capability Set The mathematical definition of is as follows:
[0050] ;
[0051] In the formula, Defined as an input capability identifier. When the audio hardware abstraction layer determines that an external universal serial bus audio device has an audio data acquisition interface... The value is set to 1. This occurs when the audio hardware abstraction layer determines that the external universal serial bus audio device does not have an audio data acquisition interface. The value is set to 0. Defined as an output capability identifier. When the audio hardware abstraction layer determines that an external universal serial bus audio device has an audio data playback interface... The value is set to 1. This occurs when the audio hardware abstraction layer determines that the external universal serial bus audio device does not have an audio data playback interface. The value is set to 0.
[0052] The audio hardware abstraction layer will obtain the connection state variables and equipment capability set Stored in memory, it serves as the state input for subsequent concurrent control logic. If the audio hardware abstraction layer does not receive a device access notification during monitoring, or receives a device removal notification, the audio hardware abstraction layer will connect the state variables. The value remains or is updated to 0.
[0053] See attached document Figure 2 The audio hardware abstraction layer is based on connection state variables. and equipment capability set The parameter values are used to determine the current system operating mode through a logical decision algorithm. This algorithm divides the system operating mode into a default audio processing flow, a concurrent audio input flow, and a concurrent audio output flow. Based on the output of the logical decision algorithm, the audio hardware abstraction layer dynamically schedules the execution logic of the main thread and child threads.
[0054] To provide a formal description of logical branches, this specific implementation defines three execution flag variables: default process execution flag. Concurrent input process execution identifier and concurrent output process execution flags These three execution flag variables are all binary logical variables. A value of 1 indicates that the corresponding process is activated and executed, and a value of 0 indicates that the corresponding process is suspended or skipped.
[0055] Default process execution flag The logical operations are defined as follows:
[0056] ;
[0057] In the formula, Defined as the logical NOT operator. When connecting state variables... When the value is 0, the result of the logical NOT operation is 1, at which point the default process execution flag is activated. Set to 1. The audio hardware abstraction layer responds to the default process execution flag. A state of 1 indicates that the central processing unit (CPU) should only enable the onboard audio interaction system in the main thread of the audio hardware abstraction layer. Onboard audio input channel and onboard audio output channels The central processing unit does not create a sub-thread for acquiring audio data from the Universal Serial Bus in the default audio processing flow.
[0058] Concurrent input process execution flag The logical operations are defined as follows:
[0059] ;
[0060] In the formula, Defined as the logical AND operator. When connecting state variables... The value is 1 and the input capability identifier When the value is 1, the result of the logical AND operation is 1, and the concurrent input process execution flag is activated. Set to 1. The audio hardware abstraction layer responds to the concurrent input process execution flag. A state of 1 indicates that the CPU has entered the dual-channel concurrent audio recording process. During the dual-channel concurrent audio recording process, the CPU, in addition to maintaining the onboard audio input channels in the main thread, also... In addition, a separate acquisition sub-thread was created to enable and maintain the external audio input channel. .
[0061] Concurrent output process execution flag The logical operations are defined as follows:
[0062] ;
[0063] In the formula, The logical AND operator as defined above. When connecting state variables... The value is 1 and the output capability identifier When the value is 1, the result of the logical AND operation is 1, and the concurrent output process execution flag is then executed. Set to 1. The audio hardware abstraction layer responds to the concurrent output process execution flag. A state of 1 indicates that the CPU has entered a dual-channel audio concurrent playback process. During this process, the CPU simultaneously activates the onboard audio output channels within the main thread. External audio output channel .
[0064] The audio hardware abstraction layer executes the above logical decision algorithm at each system clock cycle or event trigger point. If the external universal serial bus audio device only has microphone functionality and not speaker functionality, the concurrent input process execution flag is used. The value is 1, while the concurrent output process execution flag is 1. The value is 0. If the external Universal Serial Bus audio device has both microphone and speaker functions, then the concurrent input process execution flag is 0. With concurrent output process execution flags Simultaneously, the central processing unit executes dual-channel control logic for recording and playback concurrently. The logic decision algorithm ensures that the system can adaptively select the optimal data channel configuration strategy based on the actual physical state of the hardware connections.
[0065] See attached document Figure 2 When concurrent input process execution flag When the value is 1, the Audio Hardware Abstraction Layer (HHI) initiates a multi-threaded concurrent acquisition architecture. During operation, the HHI maintains a main acquisition thread. This main acquisition thread is the core process for processing audio data streams. To ensure compatibility with external asynchronous clock domain devices, the HHI creates an independent sub-acquisition thread via a system call when entering a concurrent input process.
[0066] To mathematically define the execution entities in a concurrent acquisition architecture, a set of acquisition threads is defined. Collection of data collection threads Includes the main collection thread Harmony Collection Thread .
[0067] Collection of threads The set relation is represented as:
[0068] ;
[0069] In the formula, Defined as the program execution flow responsible for data interaction of the onboard audio interaction system. Defined as the program execution flow responsible for data interaction with an external audio interaction system.
[0070] Main collection thread Responsible for calling the driver interface of the first audio codec. Main acquisition thread. Open the onboard audio input channel Main data collection thread Configure onboard audio input channel The sampling parameters. Main acquisition thread. The audio is periodically fed from the onboard audio input channel according to a preset frame length. Read the onboard pulse code modulation data.
[0071] Sub-collection thread This thread is responsible for calling the driver interface of the second audio codec. Open the external audio input channel Sub-collection thread Set external audio input channel The sampling parameters. Sub-sampling thread According to the preset frame length, the external audio input channel is periodically accessed. Read external pulse code modulation data.
[0072] Onboard audio input channel Data sampling is driven by the crystal oscillator clock source inside the Android terminal. External audio input channel. Data sampling is driven by the internal crystal clock source of the external Universal Serial Bus audio device. Since the two crystal clock sources are physically independent, the onboard audio input channels... The actual sampling frequency and the external audio input channel The actual sampling frequency has phase deviation and frequency drift.
[0073] If in the main collection thread Serial execution of onboard audio input channels Reading operations and external audio input channels The read operation, the data transmission delay of the external universal serial bus audio device will cause the main acquisition thread to... A blockage has occurred. Main data collection thread. The blockage will cause the onboard audio input channel Data loss or discontinuity occurs. This can be addressed by introducing sub-acquisition threads. The audio hardware abstraction layer will handle external audio input channels. Blocking read operations are isolated in the sub-acquisition thread In the middle. Main data collection thread. With sub-collection thread They run in parallel under the scheduling of the operating system kernel, without interfering with each other.
[0074] To describe the data stream generation process of parallel acquisition, this specific implementation defines an onboard audio data sequence. and external audio data sequence .
[0075] Onboard audio data sequence The generating function is represented as:
[0076] ;
[0077] External audio data sequence The generating function is represented as:
[0078] ;
[0079] In the formula, Defined as a pulse code modulation data reading operation performed on a specified channel by a specified thread. Defined as the main data collection thread Time-discrete index. Defined as a sub-collection thread The time-discrete index. Due to the asynchronous nature of the sampling clocks, the time-discrete index... With time discrete index There is no strict linear correspondence. (Main collection thread) The acquired onboard audio data sequence With sub-collection thread Acquired external audio data sequence It is asynchronous on the timeline.
[0080] See attached document Figure 2 In order to solve the main collection thread With sub-collection thread To address data processing conflicts caused by asynchronous data generation rates, the audio hardware abstraction layer allocates a circular buffer in memory to temporarily store pulse code modulation data. This circular buffer employs a first-in, first-out (FIFO) data queue structure, which smoothly handles onboard audio data sequences. With external audio data sequence The time-domain jitter between them.
[0081] This specific implementation defines a data cache set. Data cache collection Includes onboard circular cache and external circular cache .
[0082] Data cache collection The set relation is represented as:
[0083] ;
[0084] In the formula, Defined as a dedicated storage space for data collected by the main acquisition thread. The memory block that collects onboard audio data, i.e., the onboard circular buffer. Defined as a dedicated storage space for sub-collection threads The memory block containing the acquired external audio data, i.e., the external circular buffer.
[0085] Onboard circular cache With external ring cache They have the same preset storage capacity. The preset storage capacity is defined as... Its unit is bytes. The audio hardware abstraction layer is an external circular buffer. Maintain two address pointers: external write pointer and external read pointer External write pointer Indicate external ring cache The memory address offset of the next writable memory location. External read pointer. Indicate external ring cache The memory address offset of the next piece of data to be read.
[0086] Sub-collection thread As an external ring cache Data producers, performing the task of Write operations. When the sub-collection thread Get the length is external audio data sequence of bytes At that time, sub-collection thread Will Write to external write pointer The memory location it points to.
[0087] External write pointer The update logic follows the modular arithmetic rules, and its mathematical expression is as follows:
[0088] ;
[0089] In the formula, This indicates an assignment operation. This represents the modulo operator. This indicates the length of the data bytes currently being written. Modulo operation is used when the external write pointer... The value increases to exceed the preset storage capacity. At that time, external write pointer Automatic wraparound to external circular buffer The starting address is used to form a closed-loop storage structure.
[0090] Similarly, the main collection thread As an on-board circular cache Data producers, performing the task of Write operations. The audio hardware abstraction layer is an onboard circular buffer. Maintain onboard write pointer Main data collection thread The collected onboard audio data sequence Write to onboard write pointer The pointer points to the memory location and updates the onboard write pointer according to the same modulo operation rules. The value of .
[0091] In order to accurately determine the external circular cache in the subsequent synchronous decision logic The current accumulated data volume is defined in this specific implementation as an effective data volume function. Effective data volume function Used to calculate at time 1 External ring cache The number of bytes of data that have not yet been read.
[0092] Effective data volume function The calculation formula is as follows:
[0093] ;
[0094] In the formula, Defined as time The value of the external write pointer at that time. Defined as time The value of the external read pointer at that time. Using this formula, regardless of the external write pointer... Whether address wraparound has occurred, the audio hardware abstraction layer can calculate the external circular buffer. The actual usable data length. This effective data volume. This will serve as a key physical parameter for subsequently determining whether the external audio data stream is stable.
[0095] See attached document Figure 2 The audio hardware abstraction layer performs synchronization control of onboard and external audio data within the main acquisition thread. The audio hardware abstraction layer utilizes the effective data volume calculated above. As the basis for judgment, it determines whether to incorporate external audio data into the final audio stream at the current moment. To prevent discontinuous mixing results caused by data transmission jitter or clock drift from external Universal Serial Bus audio devices, the audio hardware abstraction layer presets a synchronization trigger threshold.
[0096] In this specific implementation, the synchronization triggering threshold is defined as follows: Synchronization trigger threshold The physical unit is a byte. In this embodiment, the synchronization trigger threshold... The value is set to 1024. Synchronization trigger threshold. The value corresponds to the amount of audio data buffered for a certain duration. The audio hardware abstraction layer only has an external circular buffer. The amount of data accumulated in the middle reaches the synchronization trigger threshold Only then can the data reading and mixing logic be initiated.
[0097] The audio hardware abstraction layer defines the synchronization state selection function. Synchronization state selection function Used to characterize time The mixing decision state at that time.
[0098] Synchronization state selection function The mathematical expression is as follows:
[0099] ;
[0100] In the formula, For a moment External ring cache The effective amount of data within. The synchronization trigger threshold. When the effective data volume... Greater than or equal to the synchronization trigger threshold Synchronization state selection function The value is When the effective data volume Less than the synchronization trigger threshold Synchronization state selection function The value is .
[0101] When the synchronization state selects the function The value is At this point, the audio hardware abstraction layer determines that the external audio data stream is in a stable state. The audio hardware abstraction layer then enters mixing mode. In mixing mode, the main acquisition thread retrieves data from the onboard circular buffer. A frame of onboard audio data is read. Simultaneously, the main acquisition thread reads data from an external circular buffer. Read a frame of external audio data of equal length.
[0102] After reading the external audio data, the main acquisition thread updates the external circular buffer. external read pointer External read pointer The update logic follows the modulo operation rules.
[0103] External read pointer The update formula is as follows:
[0104] ;
[0105] In the formula, Defined as the length of an audio data frame read in a single session. For external circular cache The preset storage capacity. This is achieved by updating the external read pointer. The audio hardware abstraction layer releases the external circular buffer. The storage space occupied by the data that has already been read.
[0106] When the synchronization state selects the function When the value is 0, the audio hardware abstraction layer determines that the external audio data stream is unstable or has insufficient data accumulation. The audio hardware abstraction layer enters pass-through mode. In pass-through mode, the audio hardware abstraction layer only draws data from the onboard circular buffer. The audio hardware abstraction layer reads onboard audio data. It does not perform operations from the external circular buffer. Data reading operations. The audio hardware abstraction layer maintains the external read pointer. Its current value remains unchanged.
[0107] This threshold-based dynamic decision mechanism constitutes the dynamic backoff logic. When the data output rate of the external Universal Serial Bus (USB) audio device is lower than the consumption rate of the main acquisition thread due to USB busyness or clock skew, the effective data volume... It will gradually decrease to the synchronization trigger threshold. The system automatically switches from mixing mode to pass-through mode. Pass-through mode ensures the continuity of onboard audio data, preventing the entire audio service from being blocked or experiencing silence gaps due to forced waiting for external audio data. When the external Universal Serial Bus audio device resumes data output and the effective data volume... Re-accumulate to the synchronization trigger threshold When the above is reached, the system will automatically revert to mixing mode.
[0108] See attached document Figure 2 When the synchronization state selection function When the value is 1, the audio hardware abstraction layer executes a specific audio data mixing algorithm. The core purpose of the audio data mixing algorithm is to merge the onboard audio data sequence and the external audio data sequence into a single-path digital audio stream, while ensuring that the merged data does not exceed the dynamic range that the digital audio system can represent.
[0109] This specific implementation uses a signal processing model combining linear superposition and amplitude clamping. The audio hardware abstraction layer first processes the signal from the onboard circular buffer. Read onboard audio data sequence and from external circular cache Read external audio data sequence Perform a weighted summation.
[0110] Define the original mixed signal Original mixed signal The calculation formula is as follows:
[0111] ;
[0112] In the formula, Defined as the weighting coefficient of the onboard audio data. Defined as the weighting coefficient of the external audio data. For the current processing frame, the first Onboard pulse code modulation data values at each sampling point. For the current processing frame, the first The external pulse-code modulation data values at each sampling point. In a standard no-attenuation mixing scenario, the weighting coefficients... With weighting coefficients The values are all set to 1.
[0113] Because pulse code modulation data is represented using fixed-point numbers in computer systems, direct addition operations may result in calculations exceeding the numerical range allowed by the data bit width. This phenomenon is known as overflow in signal processing. To prevent digital clipping distortion caused by overflow, the audio hardware abstraction layer introduces amplitude clamping functions.
[0114] Define amplitude clamping function Amplitude clamping function The mathematical expression is as follows:
[0115] ;
[0116] In the formula, Defined as the input value to be processed. Defined as the maximum pulse code modulation value allowed by the system. Defined as the minimum pulse code modulation value allowed by the system. This is the operator for finding the maximum value. The minimum value operator. Amplitude clamping function. This ensures that the output value is always confined to a closed interval. Inside.
[0117] For common 16-bit signed pulse code modulation formats, the maximum pulse code modulation value is... The value is 32767, the minimum pulse code modulation value. The value is -32768.
[0118] The audio hardware abstraction layer uses amplitude clamping functions to process the raw mixed signal. The signal is processed to obtain the final output audio signal. .
[0119] Final output audio signal The calculation formula is as follows:
[0120] ;
[0121] When the synchronization state selects the function When the value is 0, the audio hardware abstraction layer does not perform the above weighted summation operation. The function is selected in the synchronization state. When the value is 0, the final output audio signal is... The value is directly taken as the onboard audio data sequence. .
[0122] Final output audio signal The logical branch expression is as follows:
[0123] ;
[0124] The audio hardware abstraction layer calculates the final output audio signal. The data is then filled into the target buffer. The data in the target buffer is then submitted to the Android application framework layer. The Android application framework layer receives the final output audio signal. The audio is treated as a data source from a single logical recording device and processed accordingly. Through the above mixing logic, the Android terminal achieves dual-channel signal fusion from the onboard microphone and the external microphone without the application layer being aware of it.
[0125] See attached document Figure 2 When concurrent output process execution flag The value is At this time, the Audio Hardware Abstraction Layer (HHIL) responds to the audio output stream opening request issued by the Android application framework layer. Instead of implementing a single routing strategy, the HHIL executes dual-channel concurrent establishment logic. This dual-channel concurrent establishment logic aims to build an underlying data path capable of simultaneously driving both the onboard audio interaction system and the external audio interaction system.
[0126] The audio hardware abstraction layer is primarily designed for onboard audio interaction systems. Establish the first physical output channel. The audio hardware abstraction layer calls the advanced Linux sound architecture interface provided by the Linux kernel. The audio hardware abstraction layer outputs audio to the onboard audio output channel. The corresponding device node initiates an open operation. The audio hardware abstraction layer obtains the onboard audio output channel. The file descriptor. The audio hardware abstraction layer is based on the onboard audio output channel. The file descriptor constructs the onboard output handle.
[0127] In this specific implementation, the onboard output handle is defined as follows: Onboard output handle Includes onboard audio output channel The direct memory access buffer address and hardware configuration parameters. Hardware configuration parameters include onboard sampling rate, onboard channel count, and onboard data format.
[0128] The audio hardware abstraction layer then targets external audio interaction systems. Establish a second physical output channel. The audio hardware abstraction layer connects to an external audio output channel. The corresponding Universal Serial Bus (USB) audio device node initiates an open operation. The Audio Hardware Abstraction Layer (AHDL) obtains the external audio output channel. The file descriptor. The audio hardware abstraction layer is based on the external audio output channel. The file descriptor constructs an external output handle.
[0129] In this specific implementation, the external output handle is defined as follows: External output handle Includes external audio output channel The endpoint transmission buffer address and hardware configuration parameters. The audio hardware abstraction layer establishes the external output handle. At that time, try connecting the external audio output channel. The hardware configuration parameters are configured to match the onboard audio output channel. The hardware configuration parameters are consistent. If an external audio interaction system is connected... Onboard audio output channel not supported The hardware configuration parameters are recorded by the audio hardware abstraction layer for external audio interaction systems. The actual supported hardware configuration parameters are used for subsequent resampling processing.
[0130] To formally define the set of active devices in concurrent output scenarios, we define the active output set. Activity output set It is the set of target objects that the audio hardware abstraction layer needs to traverse in subsequent write operations.
[0131] Activity output set The set is defined as follows:
[0132] ;
[0133] In the formula, Defined as pointing to the onboard audio interaction system The initialized driver handle. Defined as a point of reference for external audio interaction systems The initialized driver handle. This is the flag used during concurrent output process execution. When the value is 0, the active output set Includes only onboard output handles .
[0134] The audio hardware abstraction layer will collect active outputs. The audio stream context structure is used for data transmission. After the audio hardware abstraction layer completes the channel establishment, it returns a virtual logical output stream handle to the Android application framework layer. The Android application framework layer then sends audio data through the logical output stream handle without needing to be aware of the underlying active output set. It contains two independent physical hardware handles. This virtualization process ensures the transparency and compatibility of upper-layer application logic.
[0135] See attached document Figure 2 The dual-channel concurrent audio output mechanism in this embodiment of the invention is implemented by constructing data distribution logic within the audio hardware abstraction layer. When the Android application framework layer generates a digital audio signal to be played, the Android application framework layer calls the output write interface provided by the audio hardware abstraction layer. The audio hardware abstraction layer receives the audio source data block passed in by the Android application framework layer.
[0136] In this specific implementation, the audio source data block is defined as... Audio source data block It is a pulse-code modulated data sequence with a fixed byte length. Audio source data block. Stored in a shared buffer in system memory.
[0137] The audio hardware abstraction layer receives audio source data blocks Afterwards, the buffer release operation is not performed immediately. The audio hardware abstraction layer reads the previously defined active output set. The audio hardware abstraction layer is based on the active output set. The number of elements in the loop is used to perform a circular write operation.
[0138] When the concurrent output process execution flag When the value is 1, the active output set Includes onboard output handle and external output handle The audio hardware abstraction layer first targets the onboard output handles. Perform the first write operation.
[0139] The mathematical expression for the first write operation is as follows:
[0140] ;
[0141] In the formula, Defined as a standard write function that calls the underlying driver. Defined as audio source data block The length in bytes. Defined as the return status value of the first write operation. Onboard audio interaction system. Received audio source data block Then, the digital signal is converted into an analog signal by the first audio codec and used to drive the first speaker to produce sound.
[0142] Next, the audio hardware abstraction layer addresses the external output handle. Perform the second write operation. Before performing the second write operation, the audio hardware abstraction layer checks the external audio interaction system. Configuration parameters and audio source data blocks Does the attribute match?
[0143] Define resampling processing function If an external audio interaction system is connected... Target sampling rate With audio source data blocks Source sampling rate Inconsistency exists between the audio hardware abstraction layer and the audio source data blocks. Perform resampling to generate adapted data blocks .
[0144] Adapted data blocks The generation logic is as follows:
[0145] ;
[0146] In the formula, Defined as audio source data block The sampling frequency. Defined as an external audio interaction system The hardware sampling frequency. When the two are not equal, the resampling processing function... The number of sample points in the audio data is converted according to the ratio.
[0147] The audio hardware abstraction layer will adapt data blocks. Write external output handle The mathematical expression for the second write operation is as follows:
[0148] ;
[0149] In the formula, Defined as an adaptation data block The length in bytes. Defined as the return status value of the second write operation. External audio interaction system. Received adaptation data block Then, the second speaker is driven to produce sound through the second audio codec.
[0150] To ensure the accuracy of system timing, the audio hardware abstraction layer's output write interface returns the number of bytes written to the Android application framework layer using the onboard output handle. The writing result shall prevail.
[0151] Define the final return write length Finally, the write length is returned. The calculation formula is as follows:
[0152] ;
[0153] In the formula, when the onboard output handle When data is successfully written, Equal to audio source data block byte length At this point, the write length is finally returned. equal The Android application framework layer writes based on the final returned length. Update the audio playback timestamp. This applies even with an external audio interaction system. Caused by Universal Serial Bus transmission blockage The return is delayed, and the system's main timeline is still controlled by the onboard audio interaction system. The consumption rate is determined by this. This time synchronization strategy, which uses the onboard device as an anchor point, ensures that the synchronization between the Android terminal's system interface animation and audio playback progress is not affected by the performance fluctuations of external devices in concurrent output mode.
[0154] See attached document Figure 2 With appendix Figure 3 This invention incorporates a dynamic handling mechanism for sudden hardware state changes and data transmission anomalies during system operation. During dual-channel concurrent audio control, the audio hardware abstraction layer continuously monitors the physical connection status of the universal serial bus host interface and the logical health status of the data transmission channel.
[0155] When an external Unicode audio device is physically disconnected from the Unicode host interface of an Android terminal, the operating system kernel generates a device removal event. The Audio Hardware Abstraction Layer (HHIL) captures this event. The HHIL immediately updates the connection state variables. The value is updated to 0. The audio hardware abstraction layer updates the connection state variable accordingly. Trigger resource reclamation logic.
[0156] The resource reclamation logic first terminates the sub-collection thread. The audio hardware abstraction layer directs data to the sub-acquisition thread. Send an exit signal. Sub-acquisition thread. Responding to the exit signal, stop the external audio input channel. The read operation is performed, and the external audio input channel is released. The system resources used.
[0157] The audio hardware abstraction layer then releases the external circular buffer. Memory space occupied. The audio hardware abstraction layer writes external pointers. and external read pointer Reset to the initial state. The audio hardware abstraction layer will synchronize the state selection function. The value is forcibly locked to 0. At this time, the aforementioned final output audio signal... The computational logic automatically reverts to include only the onboard audio data sequence. The pass-through mode ensures that the audio system can seamlessly switch to single-channel onboard operation mode the instant a physical disconnection occurs, avoiding popping or muting faults.
[0158] For concurrent output processes, the audio hardware abstraction layer detects connection state variables. When it becomes 0, iterate through the activity output set. The audio hardware abstraction layer (HAL) receives data from the active output set. Remove external output handle .
[0159] Updated activity output set The set is defined as follows:
[0160] ;
[0161] In the formula, Defined as the set difference operator. Defined as the updated set of active outputs. The audio hardware abstraction layer closes external output handles. The corresponding file descriptor. In subsequent audio write cycles, the audio hardware abstraction layer only targets... Remaining onboard output handles Perform a write operation.
[0162] In addition to physical disconnection, this specific implementation also defines an abnormal circuit breaker mechanism for logical transmission errors. During data transmission on a Universal Serial Bus (USB), data packet loss or transmission timeouts may occur due to electromagnetic interference or bus bandwidth contention. The audio hardware abstraction layer is for external audio interaction systems. Maintain an error counter .
[0163] Error counter The update logic is as follows:
[0164] ;
[0165] In the formula, Defined as the index of the current input and output operation cycle. Defined as the return status of a single underlying driver read / write operation. Defined as a state where a read / write operation returns an error code or the actual number of bytes transferred is less than the requested number of bytes. This is defined as the state of a successful read / write operation. When the underlying driver returns a success status, the audio hardware abstraction layer increments the error counter. Reset to zero.
[0166] The audio hardware abstraction layer has a preset maximum tolerance threshold. In this embodiment, It is set to run for 5 consecutive audio frame cycles. The audio hardware abstraction layer compares the error counter at the end of each operation cycle. With the maximum tolerance threshold .
[0167] Define the circuit breaker trigger function Abnormal circuit breaker trigger function The logical decision formula is as follows:
[0168] ;
[0169] When abnormal circuit breaker trigger function The value is At this time, the audio hardware abstraction layer determines that the external universal serial bus audio device is in a logically unavailable state. The audio hardware abstraction layer forces the connection state variable to be changed. Set as The system actively executes the aforementioned resource reclamation logic. This mechanism ensures that when an external UPS audio device is physically connected but functionally disabled, the Android terminal's main audio stream will not become blocked or frozen due to continuously waiting for an erroneous external device response. After executing the abnormal circuit breaker, the audio hardware abstraction layer initiates a timed polling mechanism to attempt to reset the external UPS audio device until the external UPS audio device regains normal responsiveness.
[0170] See attached document Figure 3 This invention also provides a dual-channel audio concurrent control device based on an Android terminal. This device runs in the audio hardware abstraction layer of the Android terminal, instantiating the aforementioned control method as independent software functional modules. These functional modules cooperate to jointly realize the control of the onboard audio interaction system. External audio interaction system Unified scheduling.
[0171] In this specific implementation, the audio concurrency control device is defined as a collection of functional modules. Functional module collection Its composition structure is as follows:
[0172] ;
[0173] In the formula, Defined as a connection monitoring module, Defined as a policy control module, Defined as a concurrent input processing module. Defined as a concurrent output processing module. Defined as an anomaly monitoring module.
[0174] The connection monitoring module is responsible for executing the physical listening logic for the Universal Serial Bus (USB) interface. It receives USB device events reported by the operating system kernel in real time. The module updates connection status variables based on device access or removal events. When a device access is detected, the module parses the device descriptor of the external USB audio device and constructs a set of device capabilities. The connection monitoring module transmits the updated status parameters to the policy control module.
[0175] The policy control module receives connection status variables and device capability sets from the connection monitoring module. It executes a logical decision algorithm to calculate the concurrent input process execution flag and the concurrent output process execution flag. Based on the calculation results, the policy control module issues start or stop commands to the concurrent input processing module and the concurrent output processing module.
[0176] The concurrent input processing module responds when the concurrent input process execution flag is set to 1. Internally, the concurrent input processing module builds and maintains a set of data acquisition threads. The concurrent input processing module allocates a data cache set in memory. The concurrent input processing module calculates the effective data volume of the external circular buffer in real time and updates the synchronization state selection function accordingly. The concurrent input processing module executes the mixing algorithm, based on... The state will be the onboard audio data sequence With external audio data sequence Weighted summation and amplitude clamping are performed to generate the final output audio signal. And submit it to the upper-layer application.
[0177] The concurrent output processing module responds when the concurrent output process execution flag is set to 1. The concurrent output processing module maintains an active output set. When an audio source data block is received, the concurrent output processing module iterates through the active output set. For external output handles, the concurrent output processing module determines whether a resampling operation is needed and generates an adaptation data block if necessary. The concurrent output processing module uses a time synchronization mechanism based on the onboard device to concurrently write data to both the onboard audio output channel and the external audio output channel.
[0178] The anomaly monitoring module operates throughout the entire system lifecycle. It maintains a counter for error handling in the underlying driver's read / write operations. It also executes the logical checks of the circuit breaker trigger function. When the maximum tolerance threshold is exceeded, or if a report is received from the monitoring module... When the value becomes 0, the anomaly monitoring module triggers the system reset process. The anomaly monitoring module instructs the concurrent input processing module to release the sub-acquisition thread and the external ring buffer, and instructs the concurrent output processing module to remove the failed handle from the active output set, ensuring that the system can safely roll back to the single-path onboard operation mode.
[0179] The functional modules communicate with each other through shared memory structures and semaphore mechanisms, realizing a closed-loop control system from hardware status awareness, logical strategy decision-making, concurrent data flow processing to anomaly protection.
Claims
1. A method for synchronous output of dual microphones (USB and host AUDIO) in an Android system, characterized in that, Includes the following steps: S1. Establish a listening thread for the Universal Serial Bus interface status through the audio hardware abstraction layer. When an external Universal Serial Bus audio device is detected to be connected, update the connection status variable and parse the device descriptor of the external Universal Serial Bus audio device to construct a set of device capabilities. The set of device capabilities includes input capability identifiers and output capability identifiers; S2. Based on the connection state variables and the device capability set, determine the concurrent input process execution identifier and the concurrent output process execution identifier through a logical decision algorithm; S3. When the concurrent input process execution flag is set to 1, the multi-threaded concurrent acquisition architecture is started to mix the onboard audio data sequence and the external audio data sequence to generate the final output audio signal. When the concurrent output process execution flag is set to 1, the dual-channel concurrent establishment logic is executed to concurrently write to the onboard audio output channel and the external audio output channel; In step S3, the specific steps for starting the multi-threaded concurrent acquisition architecture include: The audio hardware abstraction layer maintains a set of acquisition threads, which includes a main acquisition thread and sub-acquisition threads. The main acquisition thread calls the driver interface of the first audio codec to open the onboard audio input channel and periodically reads the onboard pulse code modulation data according to the preset frame length to generate the onboard audio data sequence. The sub-acquisition thread calls the driver interface of the second audio codec to open the external audio input channel and periodically reads the external pulse code modulation data according to the preset frame length to generate the external audio data sequence. The sub-acquisition thread runs independently and performs blocking read operations on the external audio input channel within the sub-acquisition thread; Step S3 also includes the following steps: A data cache set is allocated in the memory space, the data cache set including an onboard circular cache for storing the onboard audio data sequence and an external circular cache for storing the external audio data sequence; The external circular buffer maintains external write pointers and external read pointers; the sub-acquisition thread, as a data producer, writes the read external audio data sequence into the memory location pointed to by the external write pointer, and updates the external write pointer according to the modulo operation rules; Calculate the effective data volume in the external circular buffer, where the effective data volume is the number of data bytes in the external circular buffer that have not yet been read, calculated based on the difference between the external write pointer and the external read pointer; In step S3, the mixing process between the onboard audio data sequence and the external audio data sequence includes dynamic synchronization and threshold determination based on the effective data volume, specifically including: A preset synchronization trigger threshold is established, and the effective data volume is compared with the synchronization trigger threshold to determine the value of the synchronization state selection function; When the effective data volume is greater than or equal to the synchronization trigger threshold, the value of the synchronization state selection function is determined to be 1, and the audio mixing mode is entered. The main acquisition thread reads data from the onboard ring buffer and the external ring buffer at the same time, and updates the external read pointer according to the modulo operation rules. When the amount of valid data is less than the synchronization trigger threshold, the value of the synchronization state selection function is determined to be 0, and the system enters the pass-through mode. The main acquisition thread reads data only from the onboard circular buffer and keeps the current value of the external read pointer unchanged.
2. The Android system USB and host AUDIO dual-channel MIC hybrid synchronous output method according to claim 1, characterized in that, In step S2, the specific steps for determining the concurrent input process execution identifier and the concurrent output process execution identifier using the logical decision algorithm include: When the value of the connection state variable is 1 and the value of the input capability identifier is 1, the logical AND operation is performed to set the concurrent input process execution identifier to 1, indicating that the central processing unit enters the dual-channel audio concurrent recording process; When the value of the connection status variable is 1 and the value of the output capability identifier is 1, the logical AND operation is performed to set the concurrent output process execution identifier to 1, indicating that the central processing unit enters the dual-channel audio concurrent playback process.
3. The method for simultaneous output of dual-channel microphones (USB and host AUDIO) in an Android system according to claim 1, characterized in that, The mixing process employs a signal processing model combining linear superposition and amplitude clamping. Specific steps include: When the value of the synchronization state selection function is 1, the onboard audio data sequence read from the onboard ring buffer and the external audio data sequence read from the external ring buffer are weighted and summed to obtain the original mixed signal. The original mixed signal is then processed using the amplitude clamping function to obtain the final output audio signal. When the value of the synchronization state selection function is 0, the final output audio signal is directly taken as the onboard audio data sequence.
4. The method for simultaneous output of dual-channel microphones (USB and host AUDIO) in an Android system according to claim 1, characterized in that, In step S3, the specific steps for executing the dual-channel concurrent establishment logic include: Establish a first physical output channel for the onboard audio interaction system, obtain the file descriptor of the onboard audio output channel, and construct an onboard output handle; A second physical output channel is established for the external audio interaction system, the file descriptor of the external audio output channel is obtained, and an external output handle is constructed; Define an active output set, and store the onboard output handle and the external output handle in the active output set; After the channel is established, a virtual logical output stream handle is returned to the application framework layer.
5. The Android system USB and host AUDIO dual-channel MIC hybrid synchronous output method according to claim 4, characterized in that, In step S3, the specific steps for concurrently writing to the onboard audio output channel and the external audio output channel include: Receive the audio source data block passed from the application framework layer and traverse the active output set; for the onboard output handle, directly write the audio source data block; For the external output handle, check the configuration parameters. If the target sampling rate of the external audio interaction system is inconsistent with the source sampling rate of the audio source data block, perform resampling processing on the audio source data block to generate an adaptation data block, and write the adaptation data block into the external output handle. The final return write length is calculated based on the write result of the onboard output handle.
6. The Android system USB and host AUDIO dual-channel MIC hybrid synchronous output method according to claim 5, characterized in that, It also includes exception handling steps for physical connection drops: When a device removal event is detected, the value of the connection status variable is updated to 0, and resource reclamation logic is triggered; The resource reclamation logic includes terminating the operation of the sub-acquisition threads in the multi-threaded concurrent acquisition architecture, releasing the memory space occupied by the external circular cache, forcibly locking the value of the synchronization state selection function to 0, and falling back to the pass-through mode. Update the active output set, remove the external output handle from the active output set, and perform write operations only on the remaining onboard output handles.
7. The Android system USB and host AUDIO dual-channel MIC hybrid synchronous output method according to claim 6, characterized in that, It also includes an exception circuit breaker step for logical transmission errors: Maintain an error counter for the external audio interaction system and track the return status of read and write operations of the underlying driver; When the underlying driver read / write operation returns an error code or the actual number of bytes transferred is less than the requested number of bytes, the value of the error counter is incremented; At the end of each operation cycle, the error counter is compared with the maximum tolerance threshold. When the error counter exceeds the maximum tolerance threshold, the abnormal circuit breaker trigger function is executed to determine that the external universal serial bus audio device is in a logically unavailable state. The connection state variable is forcibly set to 0, and the resource reclamation logic is actively executed.