CN-122027063-A - USB device audio synchronization method, USB device, storage medium and communication system
Abstract
The invention discloses a USB device audio synchronization method, a USB device, a storage medium and a communication system, wherein the USB device audio synchronization method comprises the steps of obtaining an SOF clock calculated by a USB device end, wherein the SOF clock calculated by the USB device end is obtained by simulating SOF interruption through software and recording SOF interruption time stamps, obtaining a target clock frequency of the USB device end according to a clock frequency of a USB host end, the SOF clock of the USB host end and the SOF clock calculated by the USB device end, and determining and adjusting the clock frequency of the USB device end according to the target clock frequency of the USB device end. The method of the invention can realize the real-time adjustment of the clock frequency of the USB equipment end, realize the audio synchronous transmission of the USB host end and the equipment end, reduce the accumulated error of the audio transmission, avoid the problem of data loss or inaccurate synchronization, and simultaneously, is not limited to specific USB host hardware, thereby improving the universality of USB audio data transmission.
Inventors
- Lin Shengken
- Tang Manliang
Assignees
- 晶晨半导体(深圳)有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20241112
Claims (15)
- 1. A method for audio synchronization of a USB device, comprising: Obtaining an SOF clock calculated by a USB equipment end, wherein the SOF clock calculated by the USB equipment end is obtained by simulating SOF interruption by software and recording SOF interruption time stamps; Obtaining a target clock frequency of the USB equipment according to the clock frequency of the USB host, the SOF clock of the USB host and the SOF clock calculated by the USB equipment; And adjusting the clock frequency of the USB equipment according to the target clock frequency of the USB equipment.
- 2. The method for audio synchronization of a USB device according to claim 1, wherein obtaining the SOF clock calculated by the USB device side includes: Simulating SOF interruption in a preset time by software, and recording a time stamp of each SOF interruption; obtaining a timestamp fitting curve according to the recorded timestamps of the SOFs; and obtaining the SOF clock calculated by the USB equipment end according to the timestamp simulation curve.
- 3. The method for audio synchronization of a USB device according to claim 2, wherein the preset time is a preset time when the USB host starts transmitting USB data.
- 4. The method for audio synchronization of USB devices according to claim 2, wherein simulating SOF interrupts for a predetermined time by software and recording a time stamp of each SOF interrupt comprises: starting a timer to count from receiving a first SOF interrupt sent by a USB host; After delaying a first preset time length, the timer detects a micro-frame counter once every second preset time length, wherein the micro-frame counter increases count once every time the micro-frame counter receives a USB data micro-frame of the USB host end, the first preset time length is smaller than a time interval of SOF interrupt sent by the USB host end, and the second preset time length is smaller than the first preset time length; and when the count of the micro-frame counter reaches a preset count threshold, completing simulation of the first SOF interrupt, wherein the current timing of the timer is the time stamp of the first SOF interrupt.
- 5. The method according to claim 4, wherein the first preset duration+the second preset duration×the preset count threshold=a time interval during which the USB host transmits the SOF interrupt.
- 6. The method for audio synchronization of a USB device according to claim 4, wherein the simulating SOF interrupts for a predetermined time by software and recording a time stamp of each SOF interrupt, further comprises: A polling step, wherein after the count of the micro-frame counter reaches the preset count threshold, the micro-frame counter is cleared, the micro-frame counter is detected once every the second preset time length by the timer count after the first preset time length is delayed, and when the count of the micro-frame counter reaches the preset count threshold, the simulation of SOF interruption is completed, and the current timing of the timer is the timestamp of the current simulated SOF interruption; And repeating the polling step until the timing of the timer reaches the preset time.
- 7. The USB device audio synchronization method of claim 6, the USB equipment audio synchronization method is characterized by further comprising the following steps: And when the count of the micro-frame counter does not reach the preset count threshold, delaying a third preset time length, and returning to the timer to detect the micro-frame counter, wherein the third preset time length is smaller than the second preset time length.
- 8. The method for audio synchronization of a USB device according to claim 4, wherein for a full-speed USB transmission mode, the value of the first preset time period t1 is 0.75ms and less than or equal to t1 and less than or equal to 0.85ms.
- 9. The method of audio synchronization of a USB device according to claim 2, wherein the obtaining a timestamp fitting curve from timestamps of a plurality of recorded SOF interrupts comprises: Obtaining time stamp data of a plurality of SOF interrupts in a fourth preset duration from which the USB host side plays data for the first time; and obtaining the timestamp fitting curve by using a linear regression model according to the timestamp data of the SOF interruption.
- 10. The method for audio synchronization of a USB device according to claim 2, wherein the SOF clock calculated by the USB device side is a slope of the timestamp analog curve.
- 11. The method for audio synchronization of a USB device according to claim 1, wherein the obtaining the target clock frequency of the USB device according to the clock frequency of the USB host, the SOF clock of the USB host, and the SOF clock calculated by the USB device comprises: and obtaining the target clock frequency according to the proportional relation which is satisfied by the clock frequency of the USB host, the SOF clock calculated by the USB equipment and the target clock frequency of the USB equipment.
- 12. The method of audio synchronization of a USB device according to claim 11, wherein the target clock frequency of the USB device is obtained by the following formula: ; Wherein, the For the target clock frequency to be the same, For the clock frequency of the USB host side, The SOF clock calculated for the USB device side, Is the SOF clock of the USB host.
- 13. A USB device, comprising: At least one processor; a memory communicatively coupled to the at least one processor; The memory stores a computer program executable by the at least one processor, the at least one processor implementing the USB audio synchronization method of any one of claims 1-12 when the computer program is executed.
- 14. A computer readable storage medium having stored thereon a computer program, characterized in that the computer program when executed implements the USB audio synchronization method according to any of claims 1-12.
- 15. A communication system comprising a USB host and at least one USB device according to claim 13, said USB host being communicatively coupled to said USB device via a USB bus.
Description
USB device audio synchronization method, USB device, storage medium and communication system Technical Field The present invention relates to the field of communications technologies, and in particular, to a USB device audio synchronization method, a USB device, a storage medium, and a communications system. Background In embedded audio systems, USB (Universal Serial Bus ) is one of the most common audio transmission media, and is widely used for audio data transmission between a USB host (e.g., a computer) and a USB device (e.g., a headset, a sound card, etc.). When the USB host is used as a data transmitting end and the USB equipment is used as a receiving end, audio data is transmitted from the host end to the equipment end through the USB interface, and the equipment end transmits the data to the sound card for playing after receiving the audio data, so that primary audio transmission is completed. In order to ensure the continuity of audio transmission, clock synchronization between the USB host and the device is critical. Because the clock frequencies of the host and the device generally have certain differences, along with continuous transmission of audio data, the inconsistency of the clock frequencies can cause data accumulation errors, so that loss or asynchronous phenomenon of the audio data is generated, and especially, the stability and the tone quality of transmission are affected when the audio data is continuously transmitted for a long time. In the prior art, the method for synchronously transmitting the USB audio data mainly comprises the steps that a feedback endpoint is introduced into a device end, and the device end sends the current required audio data frequency of the device to a host end at fixed time through the feedback endpoint, so that the host is required to adjust the transmission quantity of the audio data. Although the method can realize synchronous adjustment, the method depends on the fixity and controllability of host hardware, so that the method cannot adapt to any kind of USB host and has great limitation. Another approach is based on a buffer mechanism, i.e. by setting an audio buffer at the device side and dynamically adjusting the device clock frequency according to the state of the buffer. However, this method has a problem that the buffer adjustment has a certain delay, and the adjustment is triggered only when the data error is accumulated to a certain extent, so that the audio transmission scene with high real-time requirement cannot be satisfied, especially when the audio synchronization application with high requirement on the clock precision is performed, the audio loss or the synchronization error cannot be completely avoided. Disclosure of Invention The present invention aims to solve at least one of the technical problems existing in the prior art. Therefore, an object of the present invention is to provide an audio synchronization method for a USB device, which can realize real-time adjustment of clock frequency of the USB device, realize audio synchronization transmission between the USB host and the device, reduce accumulated errors of audio transmission, avoid the problem of data loss or inaccurate synchronization, and meanwhile, is not limited to specific USB host hardware, thereby improving the versatility of USB audio data transmission. A second object of the present invention is to provide a USB device. A third object of the present invention is to propose a computer readable storage medium. A fourth object of the present invention is to propose a communication system. In order to achieve the above purpose, the audio synchronization method for the USB device according to the embodiment of the first aspect of the present invention includes obtaining an SOF clock calculated by a USB device, wherein the SOF clock calculated by the USB device is obtained by software simulating SOF interruption and recording SOF interruption time stamps, obtaining a target clock frequency of the USB device according to a clock frequency of a USB host, the SOF clock of the USB host and the SOF clock calculated by the USB device, and adjusting the clock frequency of the USB device according to the target clock frequency of the USB device. According to the audio synchronization method of the USB device, the SOF (Start of Frame) interruption is simulated by software, and the SOF interruption time stamp is recorded, so that the SOF clock calculated by the USB device side can be obtained. The SOF interrupt is a signal sent at the beginning of each data transmission cycle in the USB protocol, and marks the beginning of a frame of data. By simulating this interruption, the device side can record the timestamp of the interruption at predetermined time intervals, thereby establishing a clock reference at the device side. The clock reference can truly reflect the clock frequency change of the USB equipment end in actual operation. The target clock frequency of the USB equipment end