Method, system, storage medium and device for implementing USB audio device device mode
Patent Information
- Application Number
- CN202510995053.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2045-07-18
AI Technical Summary
因此,USB音频设备在音频数据传输过程中只能作为控制端,通常固定工作在单一模式下,缺乏动态角色切换能力,无法适应复杂的音频系统架构需求
本发明采用电压阈值检测与状态机控制相结合的角色识别算法,确保了模式切换的快速性和准确性,控制响应时间;
Smart Images

Figure CN120872885B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of USB audio device optimization technology, and in particular to a method, system, storage medium, and device for implementing USB audio device Device mode. Background Technology
[0002] USB audio devices are now widely used in consumer electronics, professional audio production, and emerging smart hardware. The standard is based on the USB Audio Class specification, and the traditional implementation method mainly adopts the Host mode, where the device acts as a USB Host to manage audio data transmission. Therefore, USB audio devices can only act as control terminals during audio data transmission, usually operating in a fixed single mode, lacking the ability to dynamically switch roles, and cannot adapt to the needs of complex audio system architectures.
[0003] Traditional USB audio devices lack Device mode support, leading to compatibility issues in scenarios such as multi-device cascading, audio matrix switching, and professional audio processing. In complex audio systems, this limitation results in poor device interoperability, particularly in professional audio applications requiring multi-device collaboration, hindering flexible master-slave switching and limiting the device's application scope and market competitiveness. Furthermore, traditional solutions fail to effectively address key technical issues such as audio latency synchronization, device cascading management, and power consumption optimization. Simultaneously, the current USB audio protocol stack design is relatively static, struggling to adapt to rapidly changing audio application needs and lacking intelligent configuration management mechanisms. These technical deficiencies severely impact the application performance and user experience of USB audio devices in modern audio systems.
[0004] Despite the ongoing updates to protocol specifications in the market, breakthroughs have not yet been achieved in key technologies such as dynamic role switching and cross-platform adaptability. System-level innovation is urgently needed to address these industry pain points. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method, system, storage medium and device for implementing USB audio device Device mode. Through an innovative dynamic role switching mechanism, it successfully realizes the intelligent switching of USB audio devices between Host mode and Device mode, and completely breaks through the technical bottleneck of the single function of traditional USB audio devices.
[0006] On the one hand, a method for implementing USB audio device Device mode is provided, including the following steps: S1: Dynamically identify the connection type, including Host mode and Device mode, by detecting the voltage threshold of the USB data line, and dynamically load the corresponding protocol stack module based on the connection type; S2: In Device mode, a multi-level buffering mechanism is used to manage the audio data stream. The number and size of the buffers are dynamically allocated according to the target delay time, and clock synchronization with the host is achieved based on an adaptive clock recovery algorithm. S3: Dynamically adjusts device power consumption through a multi-level power state machine, switches between various working states according to audio activity status and data transmission requirements, and supports remote wake-up function; S4: Based on the device fingerprint recognition result, it matches the compatibility strategy library, automatically adapts to the protocol characteristics and audio formats of different host devices, and manages audio playback through audio quality monitoring and self-optimization.
[0007] Further, in step S1, the connection type is dynamically identified using a voltage threshold comparison method, specifically including: A voltage threshold is set, which is obtained by calculating the average of the standard voltage in Host mode and the standard voltage in Device mode. The change in USB data line voltage is continuously measured for a certain period of time after the device is powered on. If the measured voltage continues to exceed the voltage threshold for a preset duration, the Host mode determination is triggered. Otherwise, the Device mode check will be triggered.
[0008] Further, in step S1, the dynamic loading of the corresponding protocol stack module based on the connection type includes: If the system is determined to be in Host mode, then the USB Host protocol stack is loaded. If the device is determined to be in Device mode, the USB Host mode protocol stack is automatically unloaded, the USB Device protocol stack is loaded, and the USB device audio class descriptor is configured through a dynamic generation algorithm to correctly identify its own function. The descriptor includes a device descriptor, a configuration descriptor, an interface descriptor, and an endpoint descriptor.
[0009] Preferably, the dynamic loading process of the protocol stack includes memory allocation, interrupt vector configuration and DMA channel mapping operations, uses a state machine to switch the protocol stack, and rolls back to the initialization state when the connection is lost or an error occurs; The dynamic generation algorithm for the descriptor configures corresponding parameters based on the actual audio capabilities of the device. These parameters include the sampling rate range, the number of channels, and the bit depth, ensuring compatibility with various host devices.
[0010] Furthermore, in step S2, the clock synchronization is achieved through a compensation algorithm, which adopts the principle of a PID controller and specifically includes: The clock deviation value is calculated by analyzing the timestamp of the received audio packets. Control parameters for the integral, derivative, and proportional values of the deviation are set. The local clock frequency is corrected in real time after weighting the integral, derivative, and proportional values of the deviation according to the control parameters. The control parameters are adjusted according to the specific application scenario to achieve compensation optimization.
[0011] Preferably, the caching mechanism described in step S2 further includes packet reassembly and error recovery, specifically including: Serial number detection can be used to determine packet loss and out-of-order delivery during USB transmission. When packet loss is detected, the optimal error recovery strategy is selected based on the error type and severity. Error recovery strategies include silent insertion, data interpolation, and request retransmission. When duplicate packets are detected, redundant data is discarded.
[0012] Furthermore, in step S3, the dynamic adjustment of device power consumption further includes: The CPU frequency is dynamically adjusted according to the audio processing requirements. The adjustment amount is based on the audio load prediction. The difference between the actual number of received samples and the expected number of samples is calculated per unit time. The adjustment amount for the next cycle is predicted by combining historical deviation data with the sliding window averaging method. It monitors audio signal amplitude and transmission activity, and intelligently adjusts its operating status based on the audio activity state and data transmission requirements. If audio activity stops and the idle time exceeds the standby threshold, switch to standby mode; If the idle time exceeds the suspension threshold, the system enters a suspension state and reduces power consumption to below the set ratio of the active state.
[0013] Further, in step S3, remote wake-up includes: When the USB bus is detected to be idle for more than a preset time threshold, it automatically enters a suspend state and enables the remote wake-up function, supporting wake-up sources including audio signal triggering, physical button operation and timer interrupt; By stabilizing and accelerating the clock and optimizing the protocol handshake, we ensure that the wake-up response time is less than a set threshold.
[0014] Further, in step S4, the device fingerprint is generated through a hash operation, specifically including: The system collects the host device's VID, PID, protocol version, and special behavior identifiers as input, outputs a unique fingerprint code through hash calculation, and queries the pre-stored compatibility policy library to obtain optimization parameters.
[0015] Preferably, step S4 further includes adaptive audio format conversion, specifically including: Prioritize the highest quality format supported by both the host and the device. The quality score is calculated by comprehensively considering the sampling rate, bit depth, and number of channels. If format conversion is required, the original audio signal is forcibly converted to a signal with the target sampling rate using a high-quality resampling algorithm to ensure that the audio data can be processed correctly.
[0016] More preferably, step S4 also includes delay compensation optimization, specifically including: The total end-to-end system latency is measured by loopback testing, and the total latency includes transmission latency, processing latency, and buffer latency components. The buffer depth is dynamically adjusted based on the difference between the target latency requirement and the measured system latency. If the calculated optimized buffer depth is less than the minimum value supported by the device, it is forcibly set to the minimum buffer depth.
[0017] Further, in step S4, the audio quality monitoring and self-optimization includes: Real-time monitoring of the harmonic distortion, signal-to-noise ratio, and frequency response characteristics of the output audio signal generates a quality assessment matrix; If any quality indicator exceeds the threshold, the buffer size, clock recovery coefficient, and power consumption strategy parameters are dynamically optimized using a genetic algorithm. A neural network preference model is built based on users' historical usage patterns to predict and apply personalized audio processing parameters.
[0018] On the other hand, a USB audio device Device mode implementation system is provided, including: The connection identification and protocol loading module is used to dynamically identify the connection type, including Host mode and Device mode, by detecting the voltage threshold of the USB data line, and dynamically load the corresponding protocol stack module based on the connection type. The adaptive data stream management module is used to manage audio data streams in Device mode using a multi-level buffering mechanism. It dynamically allocates the number and size of buffers according to the target latency time and achieves clock synchronization with the host based on an adaptive clock recovery algorithm. The intelligent dynamic power consumption management module is used to dynamically adjust the power consumption of the device through a multi-level power state machine, switch between various working states according to the audio activity status and data transmission requirements, and support remote wake-up function. The full-stack compatibility optimization module is used to match the compatibility strategy library based on the device fingerprint recognition result, automatically adapt to the protocol characteristics and audio formats of different host devices, and control audio playback through audio quality monitoring and self-optimization.
[0019] In addition, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the USB audio device Device mode implementation method described in any of the preceding claims.
[0020] Meanwhile, an electronic device is provided, comprising: one or more processors; and a storage device for storing one or more programs, which, when executed by the one or more processors, cause the one or more processors to implement the USB audio device Device mode implementation method described in any of the preceding claims.
[0021] Compared with the prior art, the beneficial effects of the present invention are: This invention employs a role recognition algorithm that combines voltage threshold detection with state machine control, ensuring the speed and accuracy of mode switching and controlling response time. This invention enables the system to achieve professional-grade audio synchronization accuracy in Device mode through multi-level buffer management and adaptive clock recovery technology, achieving a total harmonic distortion plus noise (THD+N) index better than -90dB, effectively eliminating popping and dropout phenomena in audio playback; This invention introduces an intelligent power management strategy, which successfully reduces device power consumption and significantly extends the battery life of wireless audio devices through dynamic frequency adjustment and multi-level power state switching. This invention achieves seamless compatibility with mainstream platforms through a compatibility adaptation mechanism, performing device fingerprint recognition and adaptive protocol processing, and supports automatic negotiation of the full range of sampling rates from 8kHz to 192kHz. This invention introduces a quality monitoring and self-optimization system. Based on genetic algorithms and neural network learning mechanisms, it can automatically adjust system parameters according to user habits, thereby improving user satisfaction and system stability. Attached Figure Description
[0022] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart of a USB audio device Device mode implementation method according to the present invention; Figure 2 This is a block diagram of a USB audio device Device mode implementation system according to the present invention; Figure 3 This is a schematic diagram of an embodiment of an electronic device according to the present invention. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0024] This invention adds Device mode support to USB audio devices, achieves seamless switching between master and slave modes through a dynamic role switching mechanism, adopts an adaptive protocol stack design that can automatically identify and configure the working mode according to the connection environment, introduces an intelligent buffer management algorithm to ensure the stability of audio data transmission in Device mode, uses a handshake protocol design to enable the device to achieve good compatibility with host devices from different manufacturers, and achieves mode switching through software definition without additional hardware costs, greatly improving the flexibility and applicability of the device.
[0025] The specific embodiments of the present invention will be described below with reference to the accompanying drawings and examples.
[0026] Example 1 Device mode refers to a USB audio device operating as a USB Device, accepting control and data transfer from the USB Host device. Unlike the traditional Host mode, in Device mode, the device does not initiate data transfer but responds to requests from the host. This mode switching allows the same device to function as both an audio output device (such as when connected to a computer) and an audio control device (such as when connected to a mobile phone).
[0027] like Figure 1 As shown, this embodiment provides a technical solution for implementing USB audio device Device mode, which includes the following steps: S1: Dynamically identify the connection type, including Host mode and Device mode, by detecting the voltage threshold of the USB data line, and dynamically load the corresponding protocol stack module based on the connection type; S2: In Device mode, a multi-level buffering mechanism is used to manage the audio data stream. The number and size of the buffers are dynamically allocated according to the target delay time, and clock synchronization with the host is achieved based on an adaptive clock recovery algorithm. S3: Dynamically adjusts device power consumption through a multi-level power state machine, switches between various working states according to audio activity status and data transmission requirements, and supports remote wake-up function; S4: Based on the device fingerprint recognition result, it matches the compatibility strategy library, automatically adapts to the protocol characteristics and audio formats of different host devices, and manages audio playback through audio quality monitoring and self-optimization.
[0028] When a USB audio device is connected to an external device, the connection status is first detected in step S1. The system dynamically identifies the connection type by monitoring voltage changes on the USB data line and using a voltage threshold comparison method, specifically including: A voltage threshold is set, which is obtained by calculating the average of the standard voltages in Host mode and Device mode. The change in USB data line voltage is continuously measured for a certain period of time after the device is powered on. If the measured voltage continues to exceed the voltage threshold for a preset duration, the Host mode determination is triggered. Otherwise, the Device mode check will be triggered.
[0029] The standard voltage for Host mode is typically 5V, while the standard voltage for Device mode is typically 0V. This detection process is completed within the first 100ms after device startup to ensure a rapid response.
[0030] In this embodiment, when the smart speaker is connected to the computer, a 5V voltage is detected, and the system automatically identifies it as Device mode, preparing it to work as a USB audio output device. Specifically, the USB data line voltage detection is based on the USB OTG (On-The-Go) standard, identifying the device role by monitoring changes in the VBUS line voltage, including: When the device is connected to the USB Host, the HOST provides 5V power, and the VBUS voltage is 5V. When the device is working as a host, it provides its own power supply, with a VBUS voltage of 5V; When the device is only connected as a Device, the VBUS voltage is close to 0V; This embodiment achieves fast and accurate role recognition by setting 2.5V as the judgment threshold.
[0031] Based on the above test results, the system dynamically loads the corresponding USB protocol stack module. Specifically, this includes: If the system is determined to be in Host mode, then the USB Host protocol stack is loaded. If the device is determined to be in Device mode, the USB Host mode protocol stack is automatically unloaded, the USB Device protocol stack is loaded, and the USB device audio class descriptor is configured through a dynamic generation algorithm to correctly identify its own function. The descriptor includes a device descriptor, a configuration descriptor, an interface descriptor, and an endpoint descriptor.
[0032] Specifically, the dynamic loading process includes operations such as memory allocation, interrupt vector configuration, and DMA channel mapping. Through modular design, it ensures that only necessary protocol stack components are loaded, optimizing memory usage efficiency.
[0033] The dynamic loading process of the protocol stack includes memory allocation, interrupt vector configuration and DMA channel mapping operations. A state machine is used to switch the protocol stack and roll back to the initialization state when the connection is lost or an error occurs. The dynamic generation algorithm for the descriptor configures corresponding parameters based on the actual audio capabilities of the device. These parameters include the sampling rate range, the number of channels, and the bit depth, ensuring compatibility with various host devices.
[0034] Specifically, in this embodiment, when the device detects that it is working as a Device, the system automatically unloads the host protocol stack module and loads the Device protocol stack, including components such as endpoint configuration and descriptor settings.
[0035] Regarding device descriptor configuration, the audio class descriptor is configured according to the USB Audio Class 2.0 specification, as shown below: Audio_Descriptor = { bLength: 0x09, bDescriptorType: USB_AUDIO_INTERFACE, bInterfaceSubclass: USB_AUDIO_STREAMING, bInterfaceProtocol: IP_VERSION_02_00, bNumEndpoints: 0x02 } The descriptor dynamic generation algorithm configures corresponding parameters based on the actual audio capabilities of the device, including sampling rate range, number of channels, bit depth, etc. This configuration ensures compatibility with various host devices and supports plug-and-play functionality.
[0036] Next, step S2, audio data stream management, is performed. In Device mode, audio data stream management employs a multi-level buffering mechanism. The system dynamically allocates buffer sizes based on the audio format and transmission requirements. This multi-level buffering mechanism uses a circular buffer design and includes the following levels: L1 buffer: Hardware FIFO buffer, capacity 256 samples, used as the base buffer for USB transmission; L2 buffer: Driver layer buffer, capacity 1024-4096 samples, used for protocol processing and format conversion; L3 buffer: Application layer buffer, variable capacity, used for audio processing and playback scheduling; The multi-level design ensures that audio playback continuity is maintained even with network jitter or processing latency.
[0037] Based on this, the buffer allocation algorithm formula is expressed as follows: , , Here, Buffer_Duration is the duration of a single buffer (typically 1-10ms), Latency_Target is the target latency, Sample_Rate is the audio sampling frequency, Channels is the number of audio channels, Bit_Depth is the quantization bit depth of a single sample, Buffer_Duration is the duration of audio stored in a single buffer, Buffer_Size is the memory size required for a single buffer, Optimal_Buffers is the optimal number of buffers, and Latency_Target is the maximum end-to-end latency allowed by the system. The system maintains multiple buffers using the above algorithm to perform ping-pong operations, ensuring the continuity of audio data.
[0038] In this embodiment, for 48kHz / 16bit / stereo audio with a target latency of 5ms, the size of a single buffer is 960 bytes, and the system will allocate 4 buffers for cyclic use.
[0039] Secondly, USB audio device mode requires strict clock synchronization with the host device. Adaptive Clock Recovery (ACR) is a key technology for resolving clock domain differences in asynchronous audio transmission. The host and device have independent clock sources, with slight frequency differences (typically within ±100ppm).
[0040] This invention analyzes the time interval of received audio packets, calculates the clock deviation, and adjusts the local clock using a PLL (phase-locked loop) to achieve precise synchronization with the host clock, thus avoiding popping and dropouts in audio playback.
[0041] Specifically, in this embodiment, the clock synchronization in step S2 is achieved through a compensation algorithm. The compensation algorithm adopts the PID controller principle and specifically includes: The clock deviation value is calculated by analyzing the timestamp of the received audio packets. Control parameters for the integral, derivative, and proportional values of the deviation are set. The local clock frequency is corrected in real time after weighting the integral, derivative, and proportional values of the deviation according to the control parameters. The control parameters are adjusted according to the specific application scenario to achieve compensation optimization.
[0042] The adaptive clock recovery algorithm is expressed as follows: , , Wherein, Received_Sample is the total number of audio samples actually received, Expected_Samples is the theoretical total number of samples to be received, Total_Time is the length of the statistical time window, Clock_Drift is the clock drift rate (parts per million), Base_Clock is the device's base clock frequency, Correction_Factor is the calibration coefficient (0~1.0), and Adjusted_Clock is the adjusted actual operating clock. This formula algorithm achieves a detection accuracy of 0.1 ppm (10 times better than traditional methods).
[0043] The system then analyzes the timestamps of the received audio data packets, calculates the clock deviation, and performs compensation. The compensation algorithm employs a PID controller principle to ensure long-term stability. in, This is the instantaneous sample bias. , , The control parameters for the proportional, integral, and derivative terms need to be optimized according to the specific application scenario. For the deviation integral, The deviation change rate is calculated. This is the final clock correction amount.
[0044] We use the proportional term in this formula to instantly correct the current deviation, the integral term to eliminate historical accumulated errors, and the differential term to predict future trends. Synchronization accuracy reaches ±5ppm (CD-level standard), completely eliminating pops (caused by clock abrupt changes), dropouts (buffer underflow), and phase drift (long-term accumulated errors).
[0045] In this implementation, when a sample shortage of 50 is detected within 100ms, the PID controller automatically calculates the correction value, reduces the local clock from 24.576MHz to 24.575MHz, and restores synchronization within 200ms.
[0046] Data packet loss or out-of-order delivery may occur during USB transmission, and the system implements an intelligent reassembly mechanism. Therefore, the caching mechanism described in step S2 also includes data packet reassembly and error recovery, specifically including: Serial number detection can be used to determine packet loss and out-of-order delivery during USB transmission. When packet loss is detected, the optimal error recovery strategy is selected based on the error type and severity. Error recovery strategies include silent insertion, data interpolation, and request retransmission. When duplicate packets are detected, redundant data is discarded.
[0047] Error recovery strategies include various methods such as silence insertion, data interpolation, and retransmission requests. The system selects the optimal recovery strategy based on the error type and severity. In this embodiment, when three consecutive data packets are lost, the system inserts silence data of the corresponding duration and requests the host to retransmit, ensuring the continuity of audio playback.
[0048] Subsequently, power management in Device mode is crucial, especially for wireless audio devices. Therefore, we perform power optimization management in step S3, where dynamically adjusting device power consumption further includes: The CPU frequency is dynamically adjusted according to the audio processing requirements. The adjustment amount is based on the audio load prediction. The difference between the actual number of received samples and the expected number of samples is calculated per unit time. The adjustment amount for the next cycle is predicted by combining historical deviation data with the sliding window averaging method. It monitors audio signal amplitude and transmission activity, and intelligently adjusts its operating status based on the audio activity state and data transmission requirements. If audio activity stops and the idle time exceeds the standby threshold, switch to standby mode; If the idle time exceeds the suspension threshold, the system enters a suspension state and reduces power consumption to below the set ratio of the active state.
[0049] The system implements the following multi-level power consumption states: Power_States = { ACTIVE: Full_Power, STANDBY: 0.7 × Full_Power, SUSPEND: 0.1 × Full_Power, DEEP_SLEEP: 0.01 × Full_Power } The system intelligently adjusts its operating status by monitoring audio signal amplitude and transmission activity. This method extends battery life by 20-30% and reduces device heat generation.
[0050] In addition, there is an intelligent frequency tuning strategy that dynamically adjusts the CPU frequency based on audio processing needs, balancing performance and power consumption. The frequency tuning algorithm is based on audio load prediction. The prediction algorithm uses a sliding window averaging method to avoid frequent frequency tuning, and the formula is expressed as follows: in, The weighting coefficient is for the i-th time window, with more recent data having higher weighting. Let be the historical CPU load value for the i-th time window. To obtain the result, adjust the window size as needed. This is a predicted CPU load value for the future cycle. Using this formula algorithm, power consumption can be further reduced by 15-25% while maintaining audio quality.
[0051] In this embodiment, when When, the CPU frequency / voltage is reduced using Reduce_Frequency() (DVFS technology); when When maintaining a working state, avoid frequent frequency adjustments; when In such cases, the CPU frequency can be increased using Increase_Frequency() to ensure real-time performance.
[0052] Step S3 also provides a remote wake-up method, specifically including: When the USB bus is detected to be idle for more than a preset time threshold, it automatically enters a suspend state and enables the remote wake-up function, supporting wake-up sources including audio signal triggering, physical button operation and timer interrupt; By stabilizing and accelerating the clock and optimizing the protocol handshake, we ensure that the wake-up response time is less than a set threshold.
[0053] The wake-up mechanism supports multiple trigger sources, including audio input detection, key presses, and timers. A wake-up response time optimization algorithm ensures rapid recovery; the calculation formula is as follows: , Where Base_Wakeup is the base wake-up latency, Clock_Stabilization is the clock stabilization time, Protocol_Handshake is the protocol handshake time, and the calculated result Wakeup_Time is the total wake-up response time. This formula is executed under the condition that Target_Wakeup < 10ms, where Target_Wakeup is the upper limit of the target wake-up time. Through the dynamic calibration algorithm of this formula, a pre-loaded temperature compensation coefficient is applied, reducing calibration time by 80%.
[0054] In this embodiment, when the user pauses audio playback for 3 seconds, the device automatically enters a suspend state, and the power consumption drops to 10% of the normal working level. After pressing the play button, it will wake up within 8ms.
[0055] USB host devices from different manufacturers may have different protocol implementations, and the system implements an adaptive compatibility mechanism. Therefore, in step S4, we set the fingerprint recognition algorithm to automatically adapt to the protocol characteristics and audio formats of different host devices. Device fingerprint recognition collects the unique identification information of USB devices to generate a feature code for device identification and compatibility matching. The collected information includes: VID (Vendor ID): Vendor identifier, a 16-bit value assigned by the USB-IF; PID (Product ID): Product identifier, a 16-bit value defined by the supplier; Protocol version: The USB specification version supported by the device (such as USB 2.0, USB 3.0, etc.). Special behavior identifiers, identifiers for non-standard behaviors or extended functions unique to the equipment; Then, a hash algorithm is used to synthesize this information into a unique fingerprint, which is used to quickly match compatibility strategies.
[0056] This embodiment specifically includes: The system collects the host device's VID, PID, protocol version, and special behavior identifiers as input, outputs a unique fingerprint code through hash calculation, and queries the pre-stored compatibility policy library to obtain optimization parameters.
[0057] The fingerprint recognition algorithm formula is expressed as follows: , , Wherein, VID is the Vendor ID, PID is the Product ID, Protocol_Version is the USB protocol version, Quirks are special behavior identifiers, Hash() function represents the fingerprint generation algorithm, and the calculated Device_Fingerprint is the device fingerprint; Lookup_Table represents the compatibility policy library, and Compatibility_Mode is the matching result, which includes compatibility configurations such as buffer size / clock parameters and other optimization settings.
[0058] The compatibility database contains special processing rules for mainstream devices, such as the special timing requirements for Apple devices and audio routing for Android devices.
[0059] In this embodiment, when connected to an iPad, the system automatically enables Apple Audio Optimization Mode, adjusts the buffer size to 512 samples, and enables hardware volume control via the method described above.
[0060] It supports automatic negotiation and conversion of multiple audio formats. Step S4 also includes adaptive audio format conversion, specifically including: Prioritize the highest quality format supported by both the host and the device. The quality score is calculated by comprehensively considering the sampling rate, bit depth, and number of channels. If format conversion is required, the original audio signal is forcibly converted to a signal with the target sampling rate using a high-quality resampling algorithm to ensure that the audio data can be processed correctly.
[0061] The algorithm that prioritizes the highest quality format supported by both the host and the device is represented as follows: , , The Quality_Score is calculated by comprehensively considering the sampling rate, bit depth, and number of channels, and the formula is expressed as follows: , When format conversion is required, a high-quality resampling algorithm is used, as shown below: , Here, Host_Formats is the list of audio formats supported by the host device, Device_Formats is the list of audio formats supported by the device, Common_Formats is the intersection of formats supported by both the host and device, Optimal_Format is the optimal audio format; Sample_Rate is the audio sampling frequency, Bit_Depth is the quantization bit depth of a single sample, Channels is the number of audio channels, and Format_Efficiency is the format encoding efficiency coefficient. Let i be the i-th sample of the input audio. Represents the Singer function. Input sampling rate, To output the sampling rate, The time point index of the output signal is used to calculate the result. This is the resampled audio sample.
[0062] also, The function ensures frequency domain characteristics are preserved, with Fs_out and Fs_in representing the output and input sampling rates, respectively. This algorithm supports a full range of sampling rates from 8kHz to 192kHz, with THD+N better than -90dB.
[0063] Step S4 also includes delay compensation optimization, specifically including: The total end-to-end system latency is measured by loopback testing, and the total latency includes transmission latency, processing latency, and buffer latency components. The buffer depth is dynamically adjusted based on the difference between the target latency requirement and the measured system latency. If the calculated optimized buffer depth is less than the minimum value supported by the device, it is forcibly set to the minimum buffer depth.
[0064] The delay measurement uses the loop closure test method, and the formula is expressed as follows: , , The processing latency is predicted through algorithm complexity analysis, as shown below: , The delay compensation algorithm dynamically adjusts the buffer depth, where Total_Latency is the total end-to-end system delay, Transmission_Delay is the physical delay of USB transmission, Processing_Delay is the audio processing algorithm delay, Buffer_Delay is the delay introduced by the buffer, Round_Trip_Time is the signal round-trip time, and Transmission_Delay is the one-way transmission delay. Let i be the number of single-sample processing cycles for the i-th algorithm. The number of audio samples to be processed. CPU operating frequency, This represents the total processing latency. The algorithm pioneered a three-level decomposition model of "transmission + processing + buffering," enabling precise latency tracing and breaking through traditional empirical formulas to establish a theoretically optimal solution.
[0065] In the game application of this embodiment, the system detects the need for low latency and automatically adjusts the buffer to the minimum value to achieve an end-to-end latency of less than 15ms.
[0066] The audio quality monitoring and self-optimization in step S4 includes: Real-time monitoring of the harmonic distortion, signal-to-noise ratio, and frequency response characteristics of the output audio signal generates a quality assessment matrix; If any quality indicator exceeds the threshold, the buffer size, clock recovery coefficient, and power consumption strategy parameters are dynamically optimized using a genetic algorithm. A neural network preference model is built based on users' historical usage patterns to predict and apply personalized audio processing parameters.
[0067] The distortion measurement algorithm formula is expressed as follows: , , Frequency response measurement uses Fast Fourier Transform: When quality indicators exceed thresholds, the system automatically adjusts parameters or switches algorithms. Quality assessment matrix: , , Where THD stands for Total Harmonic Distortion, expressed as a percentage (%), Harmonic_i is the amplitude (RMS value) of the i-th harmonic, i is usually taken as 2, 3, 4, ... (integer multiples of the fundamental frequency), Fundamental is the amplitude (RMS value) of the fundamental frequency (signal main frequency), SNR is the signal-to-noise ratio, Signal_RMS is the root mean square of the original signal, and Noise_RMS is the root mean square of the noise signal. Frequency_Response[k] is the system amplitude-frequency response at the k-th frequency point, FFT(Output)[k] is the complex FFT result of the system output signal at the k-th frequency point, FFT(Input)[k] is the complex FFT result of the system input signal (reference signal) at the k-th frequency point, and k is the discrete frequency point index; THD_Score is the normalized score for the THD index, SNR_Score is the normalized score for the SNR index, Frequency_Score is the frequency response flatness / consistency score, THD_Weight is the weight of THD in the overall evaluation, SNR_Weight is the weight of SNR in the overall evaluation, Frequency_Weight is the weight of frequency response characteristics in the overall evaluation, Quality_Matrix is the weighted score vector of each index, and Overall_Quality is the overall audio quality score.
[0068] The above algorithm formula allows the system to adjust the audio processing algorithm in real time based on Overall_Quality, ensuring stable output quality.
[0069] Furthermore, based on quality monitoring results, the system achieves adaptive parameter tuning. A genetic algorithm is used to optimize key parameters, as shown in the following formula: , , Among them, Fitness_Function is the individual fitness score in the genetic algorithm, Quality_Score is the comprehensive audio quality score calculated previously, Latency_Penalty is the latency penalty (positive value) calculated from the audio processing latency, Power_Penalty is the power consumption penalty (positive value) calculated from the system power consumption; Population is the current generation set of individuals, Selection() is the operation of selecting high-quality individuals based on fitness, Crossover() is the operation of swapping some parameters of two individuals (such as single-point crossover) to generate new individuals, Mutation() is the operation of randomly modifying individual parameters (such as Gaussian perturbation) to increase population diversity, and the output value New_Generation is the newly generated population used for the next generation of evolution.
[0070] Parameters include buffer size, clock recovery factor, and power consumption strategy. The optimization process runs in the background and does not affect normal audio playback. The above formula algorithm achieves asynchronous background optimization (without affecting normal audio playback), multi-objective trade-offs (sound quality / latency / power consumption), and dynamic adaptation (automatic tuning for different audio content).
[0071] In this embodiment, if the system detects slight distortion in specific audio content, it automatically adjusts the DSP processing parameters to reduce THD from 0.1% to 0.05%.
[0072] Finally, learning optimization based on usage patterns is implemented. The user preference model built by the learning algorithm is represented as follows: Here, Neural_Network() is the neural network structure, Usage_History is the input data: user historical behavior dataset, Optimal_Settings is the output data: personalized optimal parameter configuration, and Preference_Model represents the trained user preference prediction model.
[0073] The system pre-adjusts parameters based on learning results to provide a personalized audio experience. This formula algorithm improves user satisfaction by 25% and enhances system stability by 30%.
[0074] Through the implementation of all the above technical solutions, USB audio devices successfully support Device mode operation, significantly improving device compatibility and application flexibility. This solution is implemented in software, requiring no additional hardware costs, and possesses excellent engineering practicality and market promotion value. Firstly, the combination of voltage threshold detection algorithm and dynamic loading of the USB protocol stack solves the technical challenge of role recognition; this hardware-software co-design approach is pioneering in the USB audio field. Secondly, the adaptive clock recovery algorithm combined with PID control theory creatively solves the audio synchronization problem in Device mode, achieving professional-grade audio quality assurance. Thirdly, a learning-based optimization mechanism based on genetic algorithms and neural networks introduces artificial intelligence technology into USB audio device management, enabling personalized user experience optimization. Furthermore, the multi-level power management strategy, through intelligent frequency tuning and dynamic state switching, significantly reduces power consumption while ensuring audio performance, providing key technical support for the practical application of wireless audio devices.
[0075] Based on this, this embodiment also provides a USB audio device Device mode implementation system, such as... Figure 2 As shown, it includes: The connection identification and protocol loading module 10 is used to dynamically identify the connection type, including Host mode and Device mode, by detecting the voltage threshold of the USB data line, and dynamically load the corresponding protocol stack module based on the connection type. The adaptive data stream management module 20 is used to manage audio data streams in Device mode using a multi-level buffering mechanism. It dynamically allocates the number and size of buffers according to the target delay time and achieves clock synchronization with the host based on an adaptive clock recovery algorithm. The intelligent dynamic power consumption management module 30 is used to dynamically adjust the power consumption of the device through a multi-level power state machine, switch between various working states according to the audio activity status and data transmission requirements, and support remote wake-up function. The full-stack compatibility optimization module 40 is used to match the compatibility strategy library based on the device fingerprint recognition result, automatically adapt to the protocol characteristics and audio formats of different host devices, and control audio playback through audio quality monitoring and self-optimization.
[0076] It should be noted that the steps in the USB audio device Device mode implementation method provided in this embodiment can be implemented based on the corresponding modules in the USB audio device Device mode implementation system. Those skilled in the art can refer to the technical solution of the system to implement the steps of the method. That is, the embodiments in the system can be understood as preferred examples of implementing the method, and will not be elaborated here.
[0077] This embodiment also provides an electronic device, such as... Figure 3As shown, the electronic device includes a processor 14 and a memory 13. The memory 13 stores machine-executable instructions that can be executed by the processor 14, which executes the machine-executable instructions to implement the above-described audio control method.
[0078] Furthermore, Figure 3 The electronic device shown also includes a bus 12 and a communication interface 11, with the processor 14, the communication interface 11 and the memory 13 connected via the bus 12.
[0079] The memory 13 may include high-speed random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 11 (which can be wired or wireless), such as the Internet, wide area network, local area network, metropolitan area network, etc. The bus 12 may be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 3 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0080] Processor 14 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 14 or by instructions in software form. Processor 14 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in this embodiment. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this embodiment can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in memory 1001. Processor 1000 reads the information in memory 1001 and combines it with its hardware to complete the steps of the audio control method.
[0081] This disclosure also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, storing a computer program that, when run on a computer, causes the computer to perform the steps of an audio control method.
[0082] Finally, it should be noted that the above description is only a preferred embodiment of the present invention, and the scope of protection of the present invention is not limited to the above embodiments. All technical solutions falling within the scope of the present invention's concept are within the scope of protection of the present invention. It should be pointed out that for those skilled in the art, any improvements and modifications made without departing from the principle of the present invention should also be considered within the scope of protection of the present invention.
[0083] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
Claims
1. A method for implementing USB audio device Device mode, characterized in that, Includes the following steps: S1: The connection type, including Host mode and Device mode, is dynamically identified by detecting the USB data line voltage threshold, and the corresponding protocol stack module is dynamically loaded based on the connection type. Specifically, the connection type is dynamically identified using a voltage threshold comparison method, which includes: setting a voltage threshold, which is obtained by calculating the average of the standard voltage in Host mode and the standard voltage in Device mode; continuously measuring the USB data line voltage change for a certain period after device startup; if the measured voltage continuously exceeds the voltage threshold for a preset duration, Host mode determination is triggered; otherwise, Device mode determination is triggered. The dynamic loading of the corresponding protocol stack module based on the connection type includes: if it is determined to be Host mode, then loading the USBHost protocol stack; if it is determined to be Device mode, automatically unloading the USB Host mode protocol stack, loading the USB Device protocol stack, and configuring the USB device audio class descriptor through a dynamic generation algorithm to correctly identify its own function, wherein the descriptor includes a device descriptor, a configuration descriptor, an interface descriptor, and an endpoint descriptor. S2: In Device mode, a multi-level buffering mechanism is used to manage the audio data stream. The number and size of the buffers are dynamically allocated according to the target delay time, and clock synchronization with the host is achieved based on an adaptive clock recovery algorithm. The clock synchronization is achieved through a compensation algorithm, which adopts the PID controller principle. Specifically, it includes: calculating the clock deviation value by analyzing the timestamp of the received audio packet, setting control parameters for the integral, derivative, and proportional values of the deviation, and correcting the local clock frequency in real time after weighting the integral, derivative, and proportional values of the deviation according to the control parameters. The control parameters are also adjusted according to the specific application scenario to achieve compensation optimization. S3: Dynamically adjust device power consumption through a multi-level power state machine, switching between various working states according to audio activity status and data transmission requirements, and supporting remote wake-up function; the dynamic adjustment of device power consumption further includes: dynamically adjusting the CPU frequency according to audio processing requirements, the adjustment amount is based on audio load prediction, statistically analyzing the difference between the actual number of received samples and the expected number of samples per unit time, and predicting the adjustment amount for the next cycle by combining historical deviation data through a sliding window averaging method; monitoring audio signal amplitude and transmission activity, and intelligently adjusting the working state based on audio activity status and data transmission requirements, wherein, if audio activity is detected to have stopped and the idle time exceeds the standby threshold, switch to standby state; if the idle time is detected to have exceeded the suspension threshold, enter the suspension state and reduce the power consumption to below the set ratio of the active state; S4: Based on the device fingerprint recognition result, a compatibility strategy library is matched to automatically adapt to the protocol characteristics and audio formats of different host devices. At the same time, audio playback is controlled through audio quality monitoring and self-optimization. The device fingerprint is generated by hash operation, specifically including: collecting the host device's VID, PID, protocol version and special behavior identifier as input, outputting a unique fingerprint code through hash operation, and querying the pre-stored compatibility strategy library to obtain optimization parameters, including buffer size and clock parameters.
2. The USB audio device Device mode implementation method according to claim 1, characterized in that, The dynamic loading process of the protocol stack includes memory allocation, interrupt vector configuration, and DMA channel mapping operations. A state machine is used to switch the protocol stack and roll back to the initialization state when the connection is lost or an error occurs. The dynamic generation algorithm for the descriptor configures corresponding parameters based on the actual audio capabilities of the device. These parameters include the sampling rate range, the number of channels, and the bit depth, ensuring compatibility with various host devices.
3. The USB audio device Device mode implementation method according to claim 1, characterized in that, The buffering mechanism described in step S2 also includes packet reassembly and error recovery, specifically including: Serial number detection can be used to determine packet loss and out-of-order delivery during USB transmission. When packet loss is detected, the optimal error recovery strategy is selected based on the error type and severity. Error recovery strategies include silent insertion, data interpolation, and request retransmission. When duplicate packets are detected, redundant data is discarded.
4. The USB audio device Device mode implementation method according to claim 1, characterized in that, In step S3, remote wake-up includes: When the USB bus is detected to be idle for more than a preset time threshold, it automatically enters a suspend state and enables the remote wake-up function, supporting wake-up sources including audio signal triggering, physical button operation and timer interrupt; By stabilizing and accelerating the clock and optimizing the protocol handshake, we ensure that the wake-up response time is less than a set threshold.
5. The USB audio device Device mode implementation method according to claim 4, characterized in that, Step S4 also includes adaptive audio format conversion, specifically including: Prioritize the highest quality format supported by both the host and the device. The quality score is calculated by comprehensively considering the sampling rate, bit depth, and number of channels. If format conversion is required, the original audio signal is forcibly converted to a signal with the target sampling rate using a high-quality resampling algorithm to ensure that the audio data can be processed correctly.
6. The USB audio device Device mode implementation method according to claim 1, characterized in that, Step S4 also includes delay compensation optimization, specifically including: The total end-to-end system latency is measured by loopback testing, and the total latency includes transmission latency, processing latency, and buffer latency components. The buffer depth is dynamically adjusted based on the difference between the target latency requirement and the measured system latency. If the calculated optimized buffer depth is less than the minimum value supported by the device, it is forcibly set to the minimum buffer depth.
7. The USB audio device Device mode implementation method according to claim 1, characterized in that, In step S4, the audio quality monitoring and self-optimization includes: Real-time monitoring of the harmonic distortion, signal-to-noise ratio, and frequency response characteristics of the output audio signal generates a quality assessment matrix; If any quality indicator exceeds the threshold, the buffer size, clock recovery coefficient, and power consumption strategy parameters are dynamically optimized using a genetic algorithm. A neural network preference model is built based on users' historical usage patterns to predict and apply personalized audio processing parameters.
8. A USB audio device Device mode implementation system, characterized in that, include: The connection identification and protocol loading module is used to dynamically identify the connection type, including Host mode and Device mode, by detecting the USB data line voltage threshold, and dynamically load the corresponding protocol stack module based on the connection type. Specifically, the connection type is dynamically identified using a voltage threshold comparison method, which includes: setting a voltage threshold, which is obtained by calculating the average of the standard voltage in Host mode and the standard voltage in Device mode; continuously measuring the USB data line voltage change for a certain period after device startup; if the measured voltage continuously exceeds the voltage threshold for a preset duration, a Host mode determination is triggered; otherwise, a Device mode determination is triggered. The dynamic loading of the corresponding protocol stack module based on the connection type includes: if it is determined to be Host mode, then loading the USBHost protocol stack; if it is determined to be Device mode, automatically unloading the USB Host mode protocol stack, loading the USB Device protocol stack, and configuring the USB device audio class descriptor through a dynamic generation algorithm to correctly identify its own function, wherein the descriptor includes a device descriptor, a configuration descriptor, an interface descriptor, and an endpoint descriptor. The adaptive data stream management module is used to manage audio data streams in Device mode using a multi-level buffering mechanism. It dynamically allocates the number and size of buffers based on the target latency time and achieves clock synchronization with the host based on an adaptive clock recovery algorithm. The clock synchronization is achieved through a compensation algorithm, which adopts the PID controller principle. Specifically, it includes: calculating the clock deviation value by analyzing the timestamp of the received audio packets, setting control parameters for the integral, derivative, and proportional values of the deviation, weighting the integral, derivative, and proportional values of the deviation based on the control parameters, correcting the local clock frequency in real time, and adjusting the control parameters according to the specific application scenario to achieve compensation optimization. The intelligent dynamic power consumption management module is used to dynamically adjust the device power consumption through a multi-level power state machine, switching between various working states according to audio activity status and data transmission requirements, and supporting remote wake-up functionality. The dynamic adjustment of device power consumption further includes: dynamically adjusting the CPU frequency according to audio processing requirements, with the adjustment amount based on audio load prediction; statistically analyzing the difference between the actual number of received samples and the expected number of samples per unit time, and combining historical deviation data to predict the adjustment amount for the next cycle using a sliding window averaging method; monitoring audio signal amplitude and transmission activity, and intelligently adjusting the working state based on audio activity status and data transmission requirements. Specifically, if audio activity stops and the idle time exceeds a standby threshold, the module switches to standby mode; if the idle time exceeds a suspension threshold, the module enters a suspension state and reduces power consumption to below a set ratio for the active state. The full-stack compatibility optimization module is used to match the compatibility strategy library based on the device fingerprint recognition result, automatically adapt to the protocol characteristics and audio formats of different host devices, and control audio playback through audio quality monitoring and self-optimization. The device fingerprint is generated by hash operation, specifically including: collecting the host device's VID, PID, protocol version and special behavior identifier as input, outputting a unique fingerprint code through hash operation, and querying the pre-stored compatibility strategy library to obtain optimization parameters, including buffer size and clock parameters.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the USB audio device Device mode implementation method as described in any one of claims 1-7.
10. An electronic device, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the USB audio device Device mode implementation method as described in any one of claims 1-7.
Citation Information
Patent Citations
USB audio coding and decoding SoC chip and power consumption management mode switching method thereof
CN117037819A
Intelligent centralized control and protection integrated system for high-low voltage switch cabinet
CN119602464A
Universal serial bus (USB) master / slave function dual-port switching module for digital audio decoding system chip
CN201945997U
