USB audio equipment cache water level control method and device, USB audio equipment and storage medium
By applying a PID control algorithm and an anti-integral saturation mechanism to USB audio devices, the sampling rate conversion ratio is dynamically adjusted, solving the problem of unstable buffer levels in USB audio devices and achieving high-stability and low-latency audio data transmission.
Patent Information
- Application Number
- CN202511763424.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-27
- Publication Date
- 2026-02-10
AI Technical Summary
Existing USB audio devices suffer from buffer level instability due to clock drift. Current solutions suffer from drawbacks such as reliance on the host system for stability, high hardware costs, and significant latency.
By employing a PID control algorithm combined with an anti-integral saturation mechanism, the water level in the buffer zone is monitored in real time, and the sampling rate conversion ratio is dynamically adjusted to achieve autonomous and stable control of the water level in the buffer zone.
Implement high-performance, high-stability audio data buffer control in resource-constrained embedded environments, reduce hardware costs and latency, and avoid audio pops and interruptions.
Smart Images

Figure CN121501034A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of audio processing technology, and in particular to a method, apparatus, USB audio device, and storage medium for controlling the buffer level of a USB audio device. Background Technology
[0002] USB audio devices have become mainstream audio peripherals for PCs, game consoles, and mobile devices. Because the USB host and USB audio device may use different clock sources—for example, the USB host might use a 48kHz system clock while the USB audio device supports a 44.1kHz audio format—an inherent clock drift exists between them. The sample rate conversion module is central to solving this problem; it uses interpolation or decimation algorithms to convert the input audio data's sample rate to the device's required output sample rate. The sample rate conversion module requires a data buffer to temporarily store the audio data to be processed. Ideally, the input and output data rates are perfectly matched, and the buffer level remains stable. However, due to clock drift, this matching is ideal, and the level will continuously and slowly rise or fall. If the level is too low (i.e., the buffer is empty), it will cause audio output interruption, resulting in popping sounds; if the level is too high (i.e., the buffer overflows), it will cause newly input data to be lost, resulting in audio malfunctions.
[0003] Existing technologies employ two approaches to address this problem, but both have significant drawbacks.
[0004] One approach is a control scheme based on USB feedback endpoints, which adheres to the USB audio device class specification. USB audio devices periodically report their current clock frequency or data request rate to the USB host via a dedicated feedback endpoint. The USB host dynamically adjusts its data transmission rate to the device based on the feedback information. The stability and real-time performance of this scheme rely entirely on the host. The USB host's operating system is not a real-time system, and its latency in processing feedback requests is significantly affected by factors such as system load and drive efficiency. This unpredictable latency leads to sluggish response in the level control loop, resulting in instability on hosts with varying performance or load conditions, and is prone to audio stuttering or popping under high host load.
[0005] The second approach is a passive solution based on a large-capacity circular buffer. This solution absorbs the data volume differences caused by clock drift by designing a circular buffer with a capacity much larger than that of a single data packet in hardware. This is a passive solution that trades space for time, absorbing data rate differences through a large-capacity hardware buffer to avoid overflow or readout. Although a large buffer can tolerate longer clock drift periods, it has drawbacks such as increased cost and latency. Larger memory occupies more silicon area on the chip, directly increasing manufacturing costs. Audio data needs to be queued in a larger buffer, significantly increasing the total latency of the signal processing link, which is unacceptable for applications requiring low latency, such as real-time voice communication, music production, or game sound effects. It cannot fundamentally eliminate the trend of clock drift, but only delays the occurrence of overflow or readout; failures may still occur after long-term continuous operation. Summary of the Invention
[0006] This invention aims to at least solve one of the technical problems existing in the prior art. To this end, this invention proposes a method, apparatus, USB audio device, and storage medium for controlling the buffer level of a USB audio device, which can achieve high-performance and high-stability audio data buffer control in resource-constrained embedded environments.
[0007] On one hand, embodiments of the present invention provide a method for controlling the buffer level of a USB audio device, including: Preset target water level value S t proportionality coefficient K p Integral coefficient K i and differential coefficient K d ; With a fixed sampling period T i The current water level value X in the buffer of the periodic sampling rate conversion module is collected. k ; Based on the current water level X k With the target water level value S t Calculate the current water level deviation E k Cumulative error of water level S k and the rate of change of water level error D k The calculation formula related to water level deviation is: E k = S t - X k S k = E1 + E2 + ... + E k D k = E k - E k-1 , In the formula, E k S represents the current water level deviation. t X is the target water level value.k Current water level, S k For the cumulative error of water level, D k This represents the rate of change of water level error. Based on the current water level deviation E k Cumulative error of water level S k and the rate of change of water level error D k The output control value OV is calculated based on the PID control algorithm. The calculation formula of the PID control algorithm is as follows: OV = (K p * E k ) + (K i * S k ) + (K d * D k ) ; In the formula, K p E is the proportionality coefficient. k K represents the current water level deviation. i K is the integral coefficient. d S is the differential coefficient. k For the cumulative error of water level, D k This represents the rate of change of water level error. The output control value OV is limited so that S t The value of +OV is within the effective capacity range of the buffer; Based on the output control value OV after amplitude limiting, the sampling rate conversion ratio of the sampling rate conversion module is dynamically adjusted.
[0008] According to some embodiments of the present invention, the step of adjusting the current water level deviation E k Cumulative error of water level S k and the rate of change of water level error D k The step of calculating the output control value OV based on the PID control algorithm also includes: When the output control value OV reaches its upper or lower limit after being limited, the accumulation of water level error S is paused. k The accumulation of errors, or only the errors opposite to the current output direction.
[0009] According to some embodiments of the present invention, the dynamic adjustment of the sampling rate conversion ratio of the sampling rate conversion module includes: The sampling rate conversion ratio R is calculated using the formula R = R0 + α * OV. In the formula, R0 is the nominal sampling rate conversion ratio, and α is the preset scaling factor.
[0010] According to some embodiments of the present invention, the sampling period T i The value ranges from 1ms to 10ms.
[0011] According to some embodiments of the present invention, the scaling factor K p The value range is from 0.5 to 1.5, and the integral coefficient K i The value range is from 0.01 to 0.1, and the differential coefficient K d The value range is from 0.05 to 0.2.
[0012] According to some embodiments of the present invention, the target water level value S t Set to 40% to 60% of the total size of the buffer.
[0013] On the other hand, embodiments of the present invention provide a USB audio device buffer level control device for implementing the above-described USB audio device buffer level control method. The device includes: The water level acquisition unit is used to periodically acquire the current water level value X in the buffer of the sampling rate conversion module at a fixed sampling period Ti. k ; The error calculation unit is used to calculate the target water level value S. t Compared with the current water level value X k deviation E k Cumulative error of water level S k and the rate of change of water level error D k ; The PID control unit is used to execute the PID control algorithm and calculate the output control value OV. The limiting unit is used to limit the output control value OV. The ratio adjustment unit is used to dynamically adjust the sampling rate conversion ratio of the sampling rate conversion module according to the output control value OV after the amplitude limiting process.
[0014] According to some embodiments of the present invention, the USB audio device buffer level control device further includes an anti-integral saturation unit, which is used to control the accumulation of cumulative error Sk to be paused when the output value OV reaches the upper or lower limit after limiting processing, or to accumulate only the error opposite to the current output direction.
[0015] In another aspect, embodiments of the present invention provide a USB audio device, including the aforementioned USB audio device buffer level control device.
[0016] In another aspect, embodiments of the present invention provide a storage medium storing a computer program, which, when executed by a processor, implements the steps of the above-described USB audio device cache level control method.
[0017] The embodiments of the present invention have at least the following beneficial effects: This paper describes the migration of PID algorithms from industrial control to digital audio stream processing, achieving cross-domain algorithm portability. Addressing the discrete nature of audio data, the PID algorithm undergoes sampling period synchronization and parameter tuning, achieving discretization and real-time optimization. The sampling rate conversion ratio is dynamically adjusted directly through the PID output, rather than the passive buffering or host dependence of traditional solutions. By innovatively applying the PID control algorithm to the buffer level control of USB audio devices and combining it with optimization mechanisms such as anti-integral saturation, the inherent defects of existing technologies are overcome. High-performance, highly stable audio data buffer control is achieved in resource-constrained embedded environments, reducing end-to-end audio transmission latency and effectively avoiding audio pops and interruptions; it also enables complete autonomous control at the device end, reducing hardware costs and complexity.
[0018] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0019] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is a flowchart of a USB audio device buffer level control method according to an embodiment of the present invention; Figure 2 This is a functional block diagram of a USB audio device according to an embodiment of the present invention; Figure 3 This is a detailed flowchart of the USB audio device buffer level control method according to an embodiment of the present invention; Figure 4 This is a functional block diagram of a USB audio device buffer level control device according to an embodiment of the present invention. Detailed Implementation
[0020] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0021] In the description of this invention, it should be understood that the orientation descriptions, such as up, down, front, back, left, right, etc., are based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limiting this invention.
[0022] In the description of this invention, "several" means one or more, "multiple" means two or more, "greater than," "less than," "exceeding," etc. are understood to exclude the stated number, and "above," "below," "within," etc. are understood to include the stated number. If "first," "second," etc. are used in the description, they are only for the purpose of distinguishing technical features and should not be construed as indicating or implying relative importance or implicitly indicating the number of indicated technical features or the order of the indicated technical features.
[0023] In the description of this invention, unless otherwise explicitly defined, the terms "setting", "installing", "connecting" and "linking" should be interpreted broadly, and those skilled in the art can reasonably determine the specific meaning of the above terms in this invention in conjunction with the specific content of the technical solution.
[0024] The technical solution of the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0025] On the USB audio device side, a closed-loop automatic control system is constructed, with the water level in the sampling rate conversion module buffer as the controlled object, the target water level as the setpoint, and the sampling rate conversion ratio as the control variable. This system employs a digital PID (Proportion Integration Differentiation) controller as the core control algorithm. By monitoring the water level deviation in real time and intelligently adjusting the sampling rate conversion ratio, it actively stabilizes the buffer water level near the target value.
[0026] Please see Figure 1 and Figure 2 This embodiment provides a method for controlling the buffer level of a USB audio device, mainly including steps S101~S106: S101, Preset target water level value S t proportionality coefficient K p Integral coefficient K i and differential coefficient K d ; S102, with a fixed sampling period T i The current water level value X in the buffer of the periodic sampling rate conversion module is collected. k ; S103, Based on the current water level value X k With the target water level value S t Calculate the current water level deviation E k Cumulative error of water level S k and the rate of change of water level error D k ; S104, Based on the current water level deviation E k Cumulative error of water level S kand the rate of change of water level error D k The output control value OV is calculated based on the PID control algorithm. S105, Limit the output control value OV, so that S t The value of +OV is within the effective capacity range of the buffer; S106. Based on the output control value OV after amplitude limiting, dynamically adjust the sampling rate conversion ratio of the sampling rate conversion module.
[0027] The data flow is: USB data -> buffer -> converted output; the control flow is: water level detection -> PID calculation -> conversion ratio adjustment. The PID algorithm from industrial control is migrated to the digital audio stream processing scenario, achieving cross-domain algorithm portability. Addressing the discrete nature of audio data, the PID algorithm undergoes sampling period synchronization and parameter tuning, achieving discretization and real-time optimization. The sampling rate conversion ratio is dynamically adjusted directly through the PID output, rather than the passive buffering or host dependency of traditional solutions. This overcomes the inherent shortcomings of existing technologies, achieving high-performance, high-stability audio data buffering control in resource-constrained embedded environments, reducing end-to-end audio transmission latency, and effectively avoiding audio pops and interruptions.
[0028] Please see Figure 3 The USB audio device buffer level control method according to the embodiments of this application may include the following detailed steps: S201, Parameter initialization.
[0029] Preset target water level value S t This value is set within a reasonable range of the total size of the sampling rate conversion module buffer, for example, between 40% and 60%, preferably 50%.
[0030] Preset PID controller parameters: proportional coefficient K p Integral coefficient K i Differential coefficient K d These parameters can be obtained through prior simulation or experimental tuning. A fixed control sampling period T is preset. i For example, 1ms, 2ms or 5ms, this period can be synchronized with the audio interruption period.
[0031] S202, Periodic water level sampling.
[0032] With sampling period T i At intervals, the current real-time data volume of the buffer is obtained by periodically reading the status register inside the sampling rate conversion module or through other software interfaces, and denoted as the current water level sampling value X. k .
[0033] S203, PID error calculation.
[0034] Calculate the water level deviation at the current time (time k): E k = S t - X k .
[0035] Calculate the cumulative error (integral term): S k = S k-1 + E k ; In the formula, S k-1 This represents the cumulative error from the previous period.
[0036] Calculate the rate of change of error (differential term): D k = E k - E k-1 ; In the formula, E k-1 This represents the water level deviation at the previous moment.
[0037] S204, PID control quantity calculation.
[0038] Calculate the control output value OV based on the PID control algorithm formula: OV = (K p * E k ) + (K i * S k ) + (K d * D k ) ; In the formula, K p E is the proportionality coefficient. k K represents the current water level deviation. i K is the integral coefficient. d S is the differential coefficient. k For the cumulative error of water level, D k This represents the rate of change of water level error. The proportional term (P) is Kp * Ek: it provides a fast response proportional to the current deviation; the larger the deviation, the stronger the adjustment effect.
[0039] The integral term (I) is Ki * Sk: eliminating the steady-state error of the system. As long as there is a small deviation, the integral term will continue to accumulate until the deviation is zero.
[0040] The differential term (D) is Kd * Dk: predictive adjustment is made based on the rate of change of the deviation to suppress water level overshoot and oscillation, thereby improving system stability.
[0041] S205, Output Value Limiting Processing To prevent system instability caused by excessively large or small control values, the control output value OV needs to be limited. Calculate the target control point: St = S t + OV.
[0042] If S t If Buffer_Max (maximum buffer size) is true, then OV = Buffer_Max - S t .
[0043] If S t If <0, then OV = -S t ; Otherwise, OV remains unchanged.
[0044] An anti-integral saturation mechanism is introduced, which prevents the control output value OV from fully acting on the system due to amplitude limiting, i.e., the target water level value S t The error has exceeded the effective range; therefore, the calculation of the cumulative water level error S is suspended. k The accumulation of integral terms, or only the accumulation of errors opposite to the current control direction, is used to prevent excessive accumulation of integral terms that could lead to slow system recovery.
[0045] S206, Dynamically adjust the sampling rate conversion ratio.
[0046] The limited control output value OV is mapped to the actual sampling rate conversion ratio R of the sampling rate conversion module. This mapping can be a linear function. R = R0 + α * OV; In the formula, R0 is the nominal sampling rate conversion ratio. For example, to convert 44.1kHz to 48kHz, R0 = 44100 / 48000 = 0.91875; α is a preset scaling factor used to map the numerical range of OV to a reasonable ratio adjustment range, for example, α = 0.0001.
[0047] S207, Cyclic Sampling and Control.
[0048] Waiting for the next control cycle T i Upon arrival, the process returns to step S202 to achieve continuous closed-loop control of the water level.
[0049] Please see Figure 4 This application also provides a USB audio device buffer level control device for implementing the above-described USB audio device buffer level control method. The device includes: Water level acquisition unit 110 is used for sampling at a fixed period T i The current water level value X in the buffer of the periodic sampling rate conversion module is collected. k ; Error calculation unit 120 is used to calculate the target water level value S. t Compared with the current water level value X kdeviation E k Cumulative error of water level S k and the rate of change of water level error D k ; The PID control unit 130 is used to execute the PID control algorithm to calculate the output control value OV; Limiting unit 140 is used to limit the output control value OV. The ratio adjustment unit 150 is used to dynamically adjust the sampling rate conversion ratio of the sampling rate conversion module according to the output control value OV after the amplitude limiting process.
[0050] The USB audio device buffer level control device also includes an anti-integral saturation unit 160, which controls the pausing of the accumulated error S when the output value OV reaches the upper or lower limit after limiting processing. k The accumulation of errors, or only the errors opposite to the current output direction.
[0051] It should be noted that this embodiment of the USB audio device buffer level control device is based on the same inventive concept as the above-described embodiment of the USB audio device buffer level control method. For any content not covered in this embodiment of the USB audio device buffer level control device, please refer to the above-described embodiment of the USB audio device buffer level control method, which will not be repeated here.
[0052] This application also provides a USB audio device, which includes an audio codec, a USB interface controller, a sampling rate conversion module, and the aforementioned USB audio device buffer level control device.
[0053] This application also provides a storage medium that, when executed by a computer's processor, enables the computer to perform the USB audio device buffer level control method provided in the above embodiments. For example, the storage medium can be a ROM, RAM, CD-ROM, magnetic tape, floppy disk, USB flash drive, or optical data storage device. It is worth noting that the storage medium mentioned in this application can be a non-volatile storage medium; in other words, it can be a non-transient storage medium.
[0054] It should be understood that all or part of the steps of the above embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented in whole or in part as a computer program product. A computer program product includes one or more computer instructions; the computer instructions can be stored in the storage medium described above. That is, in some embodiments, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute the USB audio device buffer level control method provided in the above embodiments.
[0055] The following example illustrates this: 1. Hardware Platform USB audio device: Includes a digital-to-analog converter chip with a USB interface.
[0056] Main control chip: The chip integrates an ARM Cortex-M series MCU core and a hardware DSP.
[0057] Sampling rate conversion module: A high-quality asynchronous sampling rate converter built into the chip, with a buffer size of 1KB.
[0058] Memory: The chip has built-in SRAM and Flash.
[0059] 2. Software Implementation and Parameter Settings The control program is stored in Flash as firmware and is executed by the MCU core.
[0060] Target water level S t Set to 512 bytes (50% of the buffer size).
[0061] Control period T i Set to 1ms to synchronize with audio processing interruptions.
[0062] The PID parameters were initially tuned using the Ziegler-Nichols method and then optimized. First, K... i and K d Set K to zero and gradually increase it. p Until the system exhibits constant-amplitude oscillations (critical oscillations), record the critical gain K at this point. u and oscillation period T u Then set K p =0.6Ku, Ki=2K p / T u K d = Kp * T u / 8. After obtaining a set of initial parameters using this method, fine-tuning is performed based on actual audio stream testing to finally obtain a set of stable parameters.
[0063] proportionality coefficient K p = 1.2, Integral coefficient K i = 0.06, Differential coefficient K d = 0.15, The scaling factor α = 0.0001, The nominal conversion ratio R0 = 44100 / 48000 = 0.91875.
[0064] 3. Work process and effect verification (1) Initial state: The device is connected to the USB host and starts playing 44.1kHz audio. The sampling rate conversion module starts working, with an initial conversion ratio of R0.
[0065] (2) Disturbance simulation: By running complex computing tasks, a high CPU load is artificially created on the USB host to simulate a harsh environment.
[0066] (3) Control process: In the first control cycle (t=1ms), the water level acquisition unit reads the current water level X1=490 bytes.
[0067] (4) Calculate the output control value OV E1= S t - X1 = 512 - 490 = 22.
[0068] S1 = 0 + E1 = 0 + 22 = 22, assuming the initial cumulative error is 0.
[0069] D1 = E1 - 0 = 22 - 0 = 22, assuming the initial error is 0.
[0070] OV1= (K p * E k ) + (K i * S k ) + (K d * D k = (1.2 * 22) + (0.06 * 22) + (0.15 * 22) = 31.02.
[0071] After limiting, OV1 is effective.
[0072] The new conversion ratio R1 = R0 + α * OV = 0.91875 + 0.0001 * 31.02 = 0.92185.
[0073] This ratio is slightly higher than R0, which means that the sampling rate conversion output rate will increase slightly, consuming the data in the buffer and causing the water level to rise.
[0074] (5) Periodic adjustment After several cycles of adjustment, the system quickly reached a stable state. During a one-hour test, the buffer level was stably controlled within a narrow range of 500-525 bytes, i.e., S. t ±25 bytes, with no overflow or empty reads observed, and audio playback was smooth and noise-free.
[0075] (6) Comparative Experiment On the same hardware platform, only a traditional fixed ratio R0 was used for sample rate conversion. Due to clock drift, the buffer level slowly dropped from 512 bytes to below 50 bytes within approximately 10 minutes, triggering read-empty protection and producing noticeable audio pops.
[0076] (7) Conclusion Experiments show that even under high CPU load (e.g., >90%), smooth playback is maintained, while traditional feedback endpoint solutions exhibit significant failures. By introducing an anti-integral saturation mechanism, the system's recovery time to stable audio levels is reduced by approximately 60% under the impact of sudden audio stream start-stop. To achieve the same duration of audio stream smoothness (e.g., 24 hours), the required buffer size is only 1 / 3 of that of a circular buffer solution. This demonstrates high effectiveness and superiority, enabling high-performance, highly stable audio data buffer control in resource-constrained embedded environments.
[0077] The embodiments of the present invention have the following beneficial effects: 1. Achieve complete autonomous control on the device side: Completely eliminate the dependence on the response speed and stability of the USB host, solve the problem of audio instability caused by the non-real-time nature of the host, achieve autonomous control on the device side, and perform consistently on hosts with different performance and loads, thus improving the compatibility and robustness of the device.
[0078] 2. Reduce hardware cost and complexity: Through precise algorithm control, stable water level control can be achieved using a smaller hardware cache. Compared with the traditional ring cache solution, the stability that the traditional solution requires a large cache (e.g., 64KB) can be achieved with a smaller cache (e.g., 4KB). The buffer requirement can be reduced by about 50%, reducing chip area and cost.
[0079] 3. Achieve low audio latency: Due to the smaller buffer required, the smaller buffer means that the data queue time in the buffer is shorter, thereby reducing the end-to-end audio transmission latency. The overall audio data transmission latency is reduced, making it more suitable for audio applications with high real-time requirements.
[0080] 4. High control precision and fast response speed: The PID controller combines the speed of proportional control, the accuracy of integral control and the predictability of derivative control, which can quickly and smoothly stabilize the water level at the target value, effectively avoiding audio pops and interruptions.
[0081] 5. Improved audio quality: The adoption of PID control, especially the introduction of integral and derivative terms, can quickly and smoothly suppress water level fluctuations, effectively avoiding buffer overflow or readout, thereby eliminating the resulting audio pops and interruptions.
[0082] This embodiment provides a method and apparatus for controlling the buffer level of a USB audio device, migrating the PID algorithm from the industrial control field to the digital audio stream processing scenario, achieving cross-domain algorithm portability. Addressing the discrete nature of audio data, the PID algorithm undergoes sampling period synchronization and parameter tuning, achieving discretization and real-time optimization. The sampling rate conversion ratio is dynamically adjusted directly through the PID output, rather than the passive buffering or host dependence of traditional solutions. By innovatively applying the PID control algorithm to the buffer level control of USB audio devices, and combining it with optimization mechanisms such as anti-integral saturation, the inherent defects of existing technologies are overcome, resulting in device-side autonomy, high real-time performance, low resource dependence, and high robustness.
[0083] The embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the present invention is not limited to the above embodiments. Within the scope of knowledge possessed by those skilled in the art, various changes can be made without departing from the spirit of the present invention.
Claims
1. A method for controlling the buffer level of a USB audio device, characterized in that, include: Preset target water level value S t proportionality coefficient K p Integral coefficient K i and differential coefficient K d ; With a fixed sampling period T i The current water level value X in the buffer of the periodic sampling rate conversion module is collected. k ; Based on the current water level X k With the target water level value S t Calculate the current water level deviation E k Cumulative error of water level S k and the rate of change of water level error D k The calculation formula related to water level deviation is: THE k = S t - X k ,S k = E1 + E2 + … + E k ,D k = E k - THE k-1 , In the formula, E k S represents the current water level deviation. t X is the target water level value. k Current water level, S k For the cumulative error of water level, D k This represents the rate of change of water level error. Based on the current water level deviation E k Cumulative error of water level S k and the rate of change of water level error D k The output control value OV is calculated based on the PID control algorithm. The calculation formula of the PID control algorithm is as follows: OV = (K p * E k ) + (K i * S k ) + (K d * D k ) ; In the formula, K p E is the proportionality coefficient. k K represents the current water level deviation. i K is the integral coefficient. d S is the differential coefficient. k For the cumulative error of water level, D k This represents the rate of change of water level error. The output control value OV is limited so that S t The value of +OV is within the effective capacity range of the buffer; Based on the output control value OV after amplitude limiting, the sampling rate conversion ratio of the sampling rate conversion module is dynamically adjusted.
2. The USB audio device buffer level control method according to claim 1, characterized in that, The current water level deviation E k Cumulative error of water level S k and the rate of change of water level error D k The step of calculating the output control value OV based on the PID control algorithm also includes: When the output control value OV reaches its upper or lower limit after being limited, the accumulation of water level error S is paused. k The accumulation of errors, or only the errors opposite to the current output direction.
3. The USB audio device buffer level control method according to claim 1, characterized in that, The sampling rate conversion ratio of the dynamically adjusted sampling rate conversion module includes: The sampling rate conversion ratio R is calculated using the formula R = R0 + α * OV. In the formula, R0 is the nominal sampling rate conversion ratio, and α is the preset scaling factor.
4. The USB audio device buffer level control method according to claim 3, characterized in that, The sampling period T i The value ranges from 1ms to 10ms.
5. The USB audio device buffer level control method according to claim 4, characterized in that, The proportionality coefficient K p The value range is from 0.5 to 1.5, and the integral coefficient K i The value range is from 0.01 to 0.1, and the differential coefficient K d The value range is from 0.05 to 0.
2.
6. The USB audio device buffer level control method according to claim 1, characterized in that, The target water level value S t Set to 40% to 60% of the total size of the buffer.
7. A USB audio device buffer level control device, characterized in that, The method for controlling the buffer level of a USB audio device according to any one of claims 1 to 6 includes: The water level acquisition unit is used to periodically acquire the current water level value X in the buffer of the sampling rate conversion module at a fixed sampling period Ti. k ; The error calculation unit is used to calculate the target water level value S. t Compared with the current water level value X k deviation E k Cumulative error of water level S k and the rate of change of water level error D k ; The PID control unit is used to execute the PID control algorithm and calculate the output control value OV. The limiting unit is used to limit the output control value OV. The ratio adjustment unit is used to dynamically adjust the sampling rate conversion ratio of the sampling rate conversion module according to the output control value OV after the amplitude limiting process.
8. The USB audio device buffer level control device according to claim 7, characterized in that, The USB audio device buffer level control device also includes an anti-integral saturation unit, which is used to control the accumulation of cumulative error Sk to be paused when the output value OV reaches the upper or lower limit after the limiting processing, or to accumulate only the error opposite to the current output direction.
9. A USB audio device, characterized in that, Includes the USB audio device buffer level control device as described in any one of claims 7 to 8.
10. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed, implements the steps of the USB audio device buffer level control method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method for operating a hearing device and hearing device
CN103987009A
Clock recovery method, device and equipment and readable storage medium
CN112383305A
Distributed storage system cache water level control method and device
CN114115725A
Power saving method and system of battery power supply pressure transmitter
CN120890597A
Methods and systems for sampling and storing machine signals for analytics and maintenance using the industrial internet of things
US20200133256A1