A cross-device audio synchronization method based on a harmonious distributed bus
By adopting a cross-device audio synchronization method based on HarmonyOS distributed bus, the problems of high-precision synchronization and networking flexibility of traditional solutions under HarmonyOS ecosystem are solved. It achieves high-precision, low-latency cross-device audio synchronization, adapts to multi-terminal collaboration and distributed audio-visual playback scenarios, and improves the stability and smoothness of synchronized playback.
Patent Information
- Application Number
- CN202611333999.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-27
AI Technical Summary
Traditional cross-device audio synchronization solutions struggle to achieve high-precision synchronization and low-latency transmission within the HarmonyOS distributed ecosystem. Furthermore, they lack networking flexibility and cannot adapt to dynamic device online/offline status or heterogeneous device compatibility.
A cross-device audio synchronization method based on HarmonyOS distributed bus is adopted. Device discovery and networking are completed through HarmonyOS distributed bus, a globally unified time standard is established, audio codec parameter negotiation and matching are performed, and high-precision clock synchronization is achieved through clock drift rate prediction. Graded compensation is performed by combining fine-grained sampling rate fine-tuning and coarse-grained queue adjustment.
It achieves high precision, low latency, and flexible networking for cross-device audio synchronization, adapting to multi-terminal collaboration and distributed audio-visual playback scenarios, and improving the stability and smoothness of synchronized playback.
Smart Images

Figure CN123185178A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of distributed communication technology, and specifically to a cross-device audio synchronization method based on HarmonyOS distributed bus. Background Technology
[0002] With the rapid development of the Internet of Things (IoT), smart homes, and distributed terminal collaboration technologies, various smart terminal devices such as mobile phones, tablets, smart speakers, smart screens, and in-vehicle terminals are gradually entering a new stage of ubiquitous interconnection and multi-device collaboration. Cross-device audio synchronization has become a core foundational capability for scenarios such as smart audio-visual experiences, distributed interaction, and whole-house audio linkage. Users' demands for the smoothness, synchronization accuracy, and scene adaptability of multi-device audio collaborative playback continue to increase, creating an urgent need to achieve millisecond-level synchronous output of audio data between multiple terminal devices to ensure an immersive and integrated auditory interaction experience.
[0003] Currently, most mainstream cross-device audio synchronization solutions in the industry are based on traditional technical architectures such as Bluetooth, Wi-Fi LAN, and NTP network clock synchronization. However, these solutions have many inherent defects in distributed multi-device collaborative scenarios, making it difficult to meet the core requirements of dynamic networking of multiple terminals, high-precision synchronization, and low-latency transmission under the HarmonyOS distributed ecosystem. Among them, Bluetooth audio synchronization solutions have high transmission latency and weak anti-interference capabilities. The audio latency difference between devices is generally in the range of 50ms-200ms, and the human ear can clearly perceive problems such as sound misalignment, sound field dispersion, and audio-visual asynchrony. Moreover, it only supports simple point-to-point connections and cannot adapt to dynamic networking scenarios of multiple devices. LAN audio synchronization solutions based on NTP clocks have low clock synchronization accuracy, which can only achieve coarse-grained time alignment and cannot eliminate the timing deviation caused by the inherent drift of device hardware clocks and network fluctuations. Long-term playback is prone to audio stuttering, audio-visual disconnection, and asynchronous playback of multiple devices. At the same time, traditional centralized synchronization architectures rely on central master control equipment scheduling, resulting in poor networking flexibility and making them unsuitable for application scenarios such as dynamic online / offline of devices and adaptation of heterogeneous devices in distributed networks. In response, we propose a cross-device audio synchronization method based on HarmonyOS distributed bus. Summary of the Invention
[0004] To address the aforementioned technical issues, a cross-device audio synchronization method based on HarmonyOS distributed bus is provided. This technical solution solves the problems of traditional centralized synchronization architecture relying on central control device scheduling, poor networking flexibility, and inability to adapt to application scenarios involving dynamic device online / offline status and heterogeneous device adaptation in distributed networks.
[0005] To achieve the above objectives, the technical solution adopted by this invention is: a cross-device audio synchronization method based on HarmonyOS distributed bus, the specific steps of which are as follows: S1. Through the HarmonyOS distributed bus, the device discovery and networking within the network are completed, audio source devices and playback devices are distinguished, dedicated communication links between devices are established, and audio codec parameters are negotiated and matched. S2. Based on the HarmonyOS distributed bus clock synchronization service, a globally unified time standard is established among interactive devices; the clock offset is calculated between devices through interactive clock synchronization messages, the clock drift rate is calculated based on multiple clock offset samples, and the clock offset at future moments is predicted based on the clock drift rate. S3. The audio source device collects audio signals, completes frame encoding according to a fixed frame length, adds a transmission timestamp to each frame of audio data based on a global time reference, and transmits the timestamped audio data frames to the playback device through a distributed bus low-latency channel. S4. After receiving the data, the playback device combines the measured and predicted clock offset to correct the timestamp, calculates the target playback time for each frame of audio, sorts it, and stores it in the playback buffer queue. S5. Decode and play according to the predetermined time, monitor the queue depth and data arrival delay in real time, and ensure the synchronization effect through a hierarchical compensation mechanism: when the delay exceeds the first preset threshold, fine-grained compensation is achieved by adjusting the sampling rate; when it exceeds the second preset threshold, coarse-grained compensation is achieved by adjusting the buffer queue length.
[0006] Preferably, in S1, the HarmonyOS distributed bus completes device discovery and networking within the network by simultaneously detecting surrounding devices through mDNS broadcasting of the Wi-Fi network and Bluetooth BLE low-power broadcasting. After the device comes online, it completes identity authentication and capability registration within a preset time window, and automatically constructs a virtual bus topology covering the heterogeneous network.
[0007] Preferably, the audio encoding and decoding parameters in S1 include audio sampling rate, encoding format, frame length, number of channels, and buffer configuration parameters. The audio source device and the audio playback device negotiate and determine the optimal combination of encoding and decoding parameters that they both support through capability exchange messages.
[0008] Preferably, the clock drift rate in S2 is calculated as follows: at least three clock offset samples are collected within a preset time window, and linear regression fitting is performed with the sampling time point as the independent variable and the clock drift rate as the dependent variable. The resulting regression slope is used as the clock drift rate. The clock drift rate at future times is obtained by multiplying and summing the current clock drift rate and the clock drift rate.
[0009] Preferably, the HarmonyOS distributed bus clock synchronization service described in S2 adopts a multi-level clock synchronization system, including a hardware-level timestamp calibration layer based on the improved IEEE 1588 protocol, a software-level time synchronization layer based on the NTP protocol, and a service-level synchronization layer based on the service clock.
[0010] Preferably, the low-latency channel in S3 adopts the multi-link collaborative transmission mechanism of HarmonyOS distributed soft bus. Control signaling is transmitted through Bluetooth BLE link, and audio data frames are transmitted through Wi-Fi link. When the Wi-Fi link signal quality is lower than a preset threshold, it automatically switches to Bluetooth link for reduced-speed transmission.
[0011] Preferably, the target playback time in S4 is calculated by comparing the corrected timestamp with the local clock of the playback device and adding a preset playback buffer delay to obtain the target playback time of each audio data frame; the playback buffer queue adopts a priority queue structure arranged in ascending order of the target playback time.
[0012] Preferably, in S5, the first preset threshold ranges from 10 to 50 milliseconds, and the second preset threshold ranges from 50 to 200 milliseconds; the adjustment range of the fine-tuning sampling rate is controlled within ±0.1% of the nominal sampling rate, so that the change in sampling rate is within the range imperceptible to the human ear.
[0013] Preferably, adjusting the buffer queue length in S5 includes: increasing the buffer queue capacity to improve jitter tolerance when the buffer queue depth is lower than a preset lower limit; and decreasing the buffer queue capacity to reduce playback latency when the buffer queue depth is higher than a preset upper limit.
[0014] Preferably, the specific steps also include using the virtualization capabilities of HarmonyOS devices to achieve dynamic role switching between audio source devices and audio playback devices. When the current audio source device is detected to be offline or lacks computing power, the device with the best computing power in the distributed network is automatically selected as the new audio source device, and the audio acquisition and encoding tasks of the original audio source device are migrated to the new device.
[0015] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention, based on the HarmonyOS distributed bus, enables autonomous device discovery, dynamic networking, and adaptive parameter matching, significantly improving the networking flexibility and adaptability of cross-device audio collaboration. It eliminates the need for traditional central control devices, automatically identifying audio source and playback devices within the distributed network, quickly establishing dedicated distributed communication links, and automatically negotiating and matching audio codec parameters. This avoids the problems of traditional Wi-Fi and Bluetooth networking methods, such as limited connectivity, poor adaptability, and low compatibility with heterogeneous devices. Furthermore, it supports dynamic device online / offline status, adapting to complex and dynamic scenarios such as whole-house smart home systems, multi-terminal collaboration, and distributed audio-visual playback, greatly expanding the application boundaries of cross-device audio synchronization.
[0016] This invention achieves high-precision, error-free global clock synchronization through multi-sampling clock offset calculation and clock drift rate prediction, fundamentally improving cross-device audio synchronization accuracy. Unlike traditional NTP clock synchronization, which can only achieve single static clock calibration and cannot suppress clock drift, this invention builds a globally unified time base based on the HarmonyOS distributed bus clock synchronization service. It accurately calculates the device clock drift rate through multiple clock offset samplings and dynamically predicts future clock offsets based on the drift rate. This can correct the inherent deviation of the device hardware clock and the dynamic timing errors during operation in real time, completely solving the problem of clock error accumulation in long-term playback scenarios, ensuring long-term consistency of audio timing across multiple devices, and achieving millisecond-level high-precision audio synchronization.
[0017] This invention generates precise audio frame transmission timestamps based on a globally unified time reference at the audio source device end, and dynamically corrects the timestamps at the playback device end by combining real-time clock offset and predicted offset, accurately calculates the target playback time for each frame of audio data, and achieves orderly playback through queue sorting. This effectively avoids problems such as audio frame timing disorder, playback misalignment, and audio-visual asynchrony caused by transmission delay and clock deviation in traditional solutions, and greatly improves the regularity and smoothness of multi-device audio synchronous playback.
[0018] This invention innovatively sets up a hierarchical adaptive compensation mechanism that combines fine-grained sampling rate adjustment with coarse-grained queue adjustment, greatly improving the anti-interference capability and operational stability of audio synchronization. For minor network fluctuations and small transmission delay deviations, fine-grained delay compensation is achieved by finely adjusting the playback sampling rate to avoid audio stuttering and playback jumps. For abnormal scenarios with severe network fluctuations and delays exceeding thresholds, coarse-grained calibration is performed by adjusting the buffer queue length to quickly correct large synchronization deviations. The hierarchical compensation strategy adapts to different network and device operating states, taking into account both synchronization accuracy and playback stability, and solving the technical problems of traditional solutions having a single compensation method, poor adaptability, and easy synchronization failure. Attached Figure Description
[0019] Figure 1 This is a simplified flowchart of the steps of the present invention; Figure 2 This is a schematic diagram of the overall process flow of the present invention. Detailed Implementation
[0020] The following description is intended to disclose the invention and enable those skilled in the art to implement it. The preferred embodiments described below are merely examples, and other obvious variations will occur to those skilled in the art.
[0021] like Figure 1 and Figure 2As shown, this embodiment provides a cross-device audio synchronization method based on HarmonyOS distributed bus. This method is applied to a distributed network scenario containing at least one audio source device and at least one audio playback device. The audio source device is a smart terminal with audio acquisition and encoding capabilities, including but not limited to smartphones, tablets, smart screens, and in-vehicle terminals; the audio playback device is a terminal device with audio decoding and playback capabilities, including but not limited to smart speakers, soundbars, wireless headphones, and smart screens. Each device runs the HarmonyOS operating system and supports the HarmonyOS distributed soft bus protocol. The following describes a method for cross-device audio synchronization based on HarmonyOS distributed bus. Figure 1 and Figure 2 Each step is explained in detail.
[0022] S1. Through the HarmonyOS distributed bus, cross-device discovery and networking are performed, audio source devices and audio playback devices in the distributed network are identified, distributed bus communication links between devices are established, and audio codec parameters are negotiated and matched.
[0023] Specifically, such as Figure 2 As shown in the S1 area, cross-device discovery and networking employ a hybrid discovery mechanism based on the HarmonyOS distributed soft bus. This mechanism uses both Wi-Fi network mDNS broadcast and Bluetooth BLE Low Energy broadcast to detect surrounding devices in parallel. mDNS (Multicast DNS) broadcast is suitable for device discovery within the Wi-Fi LAN coverage area. Devices send service discovery messages via port 5353 of the multicast address 224.0.0.251, announcing their device identifier, supported service types, and capabilities. Bluetooth BLE Low Energy broadcast is suitable for short-range device discovery and low-power scenarios. Devices send beacon frames containing their device UUID and service ID via a broadcast channel. These two discovery mechanisms operate in parallel and complement each other: Wi-Fi networks have a wider coverage but higher power consumption, while BLE has a shorter coverage but extremely low power consumption. The combination of these two mechanisms enables device discovery capabilities across heterogeneous networks.
[0024] After devices come online, they complete identity authentication and capability registration within a preset time window. Identity authentication adopts the HarmonyOS distributed device authentication mechanism, which completes two-way identity verification based on the trust relationship between devices (same account authentication, QR code authentication, or PIN code authentication) to ensure that only trusted devices join the distributed network. During capability registration, each device registers its own device capability description information with the HarmonyOS distributed soft bus, including device type, audio acquisition capabilities, audio playback capabilities, codec support list, network interface type, etc. After the soft bus aggregates the capability information of each device, it automatically constructs a virtual bus topology covering heterogeneous networks. In this virtual bus topology, audio source devices and audio playback devices interact with each other through a unified distributed bus communication link, without relying on a central master control device for scheduling.
[0025] Audio codec parameters include audio sampling rate, encoding format, frame length, number of channels, and buffer configuration parameters. The audio source device and audio playback device negotiate and determine the optimal combination of codec parameters they both support through capability exchange messages. The specific negotiation process is as follows: the audio source device initiates a capability exchange request, carrying a list of codec parameters it supports; the audio playback device responds to the capability exchange request, returning its own list of supported codec parameters; after taking the intersection of the two lists, the optimal parameter combination is selected according to a preset priority rule. For example, when the audio source device supports a sampling rate set of {44100Hz, 48000Hz, 96000Hz} and the audio playback device supports a sampling rate set of {44100Hz, 48000Hz}, the optimal sampling rate determined through negotiation is 48000Hz; the encoding format is preferentially selected as a low-latency encoding format (such as Opus, AAC-LC), and the frame length is preferentially selected as a shorter frame length (such as 10ms~20ms) to reduce end-to-end latency; the buffer configuration parameters include the size of the transmit buffer and the size of the receive buffer, which are adaptively configured according to the sampling rate and frame length determined through negotiation.
[0026] Once S1 is completed, the distributed bus communication link is established, forming a virtual bus connection between the audio source device and the audio playback device that allows direct communication, providing a basic communication guarantee for subsequent clock synchronization and audio data transmission.
[0027] S2. The clock synchronization service based on HarmonyOS distributed bus establishes a globally unified time reference between the audio source device and the audio playback device. It calculates the clock offset between devices by exchanging clock synchronization messages, calculates the clock drift rate based on multiple clock offset samples, and predicts the clock offset at future times based on the clock drift rate.
[0028] Specifically, such as Figure 2 As shown in the S2 area, the clock synchronization service of HarmonyOS distributed bus adopts a multi-level clock synchronization system, including a hardware-level timestamp calibration layer based on the improved IEEE 1588 protocol, a software-level time synchronization layer based on the NTP protocol, and a service-level synchronization layer based on the service clock.
[0029] The hardware-level timestamp calibration layer is based on the improved IEEE 1588 Precise Time Synchronization Protocol (PTP), achieving nanosecond-level time synchronization accuracy through hardware timestamping at the physical layer (MAC layer). During synchronization, the master clock device (usually the device with the highest clock accuracy in the network) sends Sync and FollowUp messages, records the received timestamps from the clock device, and calculates the link transmission delay by exchanging DelayReq and DelayResp messages, ultimately obtaining the clock offset between devices. The improved IEEE 1588 protocol adds an adaptive filter to the standard protocol to smooth out delay measurement errors caused by network jitter, thus improving time synchronization accuracy.
[0030] The software-level time synchronization layer is based on the NTP (Network Time Protocol) and is suitable for devices that do not support hardware timestamps. It calculates round-trip delay and clock offset through client-server message exchange. Let the local timestamp of the NTP request message sent by the audio source device be... The timestamp of the audio playback device receiving the message is The timestamp of the NTP response message returned by the audio playback device is The local timestamp of the audio source device receiving the response message is Then the clock offset and round-trip delay The calculation formula is: ; ; The business-level synchronization layer, based on the business clock, performs fine-tuning calibration for audio synchronization requirements, building upon hardware and software-level synchronization. It embeds timestamp information during audio data frame transmission and dynamically fine-tunes the clock synchronization results by monitoring the deviation between the arrival time and expected playback time of audio frames in real time, ensuring that audio synchronization accuracy meets business requirements.
[0031] Through the aforementioned multi-level clock synchronization system, a globally unified time reference is established between the audio source device and the audio playback device. Each device uses this time reference to manage the timing of audio data, achieving time alignment with microsecond-level precision.
[0032] Based on establishing a globally unified time base, the clock offset between devices is calculated by exchanging clock synchronization messages. Since the crystal oscillators in the devices have inherent frequency deviations, the clock offset is not a fixed value but varies linearly with time. Therefore, it is necessary to further calculate the clock drift rate to describe the trend of clock offset variation.
[0033] The clock drift rate is calculated as follows: At least three clock offset samples are collected within a preset time window. A linear regression is performed with the sampling time point as the independent variable and the clock offset as the dependent variable. The resulting regression slope is used as the clock drift rate. The specific calculation process is as follows: Set in the preset time window Internal collection Second-rate( Clock offset sample, number The time point for the second sampling was The corresponding clock offset is Then the clock drift rate The following was obtained through linear regression fitting using the least squares method: ; in, This represents the average value at the sampling time points. This represents the mean of the clock offset samples. Regression slope. This is the clock drift rate, measured in ms / s or μs / s, representing the change in clock offset per second. This indicates that the playback device's clock is faster than the source device's clock, and the deviation continues to increase. This indicates that the playback device's clock is slower than the source device's clock, and the deviation continues to increase. The magnitude of the value reflects the severity of clock drift.
[0034] The clock offset at future times is obtained by summing the product of the current clock offset and the clock drift rate. Let the current time be... The clock offset is Clock drift rate Then the future moment Predicted clock offset for: ; in, This is the cumulative term of the clock drift rate multiplied by the time interval, representing the predicted change in clock offset from the current moment to a future moment. By predicting the clock offset in the future moment using the clock drift rate, feedforward compensation can be performed before the actual clock offset occurs, eliminating the impact of accumulated clock errors on audio synchronization at its source and ensuring long-term consistency of audio timing across multiple devices in long-duration playback scenarios.
[0035] After S2 is completed, a globally unified time reference with microsecond-level precision is established between the audio source device and the audio playback device, and the ability to predict clock drift rate and future offset is obtained, providing a time reference guarantee for the accurate timestamp correction of subsequent audio data frames.
[0036] S3. The audio source device collects audio data and performs frame encoding according to a fixed frame length. Based on a globally unified time reference, it generates a transmission timestamp for each audio data frame and transmits the audio data frame carrying the transmission timestamp to the audio playback device through the low-latency data channel of the distributed bus.
[0037] Specifically, such as Figure 2 As shown in area S3, the audio source device acquires raw audio data through an audio acquisition module (such as a microphone array, line-in interface, or digital audio interface). The acquired audio data is then processed into frames according to the fixed frame length negotiated in S1. For example, when the negotiated frame length is 20ms, the sampling rate is 48000Hz, and the dual-channel 16-bit quantization is used, each audio data frame contains... There are 1 sampling point, and the frame data size is 1 Bytes. The segmented audio data frames are encoded and compressed according to the negotiated encoding format to generate encoded audio data frames.
[0038] A transmission timestamp is generated for each audio data frame based on a globally unified time reference. The transmission timestamp records the global time value at the moment the audio data frame is encoded and ready for transmission. This timestamp references the globally unified time reference established in S2 to ensure the comparability of timestamps generated by different devices. Let the... The transmission timestamp of each audio data frame is .
[0039] The low-latency data channel employs a multi-link collaborative transmission mechanism using the HarmonyOS distributed soft bus. Control signaling is transmitted via the Bluetooth BLE link, while audio data frames are transmitted via the Wi-Fi link. The BLE link features low power consumption and stable connection, making it suitable for transmitting control signaling with small data volumes (such as synchronization control commands, link status reports, parameter adjustment commands, etc.); the Wi-Fi link features high bandwidth, making it suitable for transmitting audio data frames with large data volumes. The two links work collaboratively, separating control signaling from data transmission, avoiding bandwidth contention between signaling and data transmission, and improving transmission efficiency and reliability.
[0040] When the Wi-Fi link signal quality falls below a preset threshold, the system automatically switches to a Bluetooth link for reduced-speed transmission. Specifically, the system monitors the Received Signal Strength Indicator (RSSI) and packet loss rate of the Wi-Fi link in real time. When the RSSI falls below a preset threshold (e.g., -75dBm) or the packet loss rate exceeds a preset threshold (e.g., 5%), the system determines that the Wi-Fi link signal quality has deteriorated and automatically switches the audio data frame transmission to the Bluetooth link. Although the Bluetooth link has lower bandwidth, it has better anti-interference capabilities and connection stability, and can maintain basic audio synchronization transmission in scenarios with poor Wi-Fi signals, avoiding audio interruptions. When the Wi-Fi link signal quality recovers to above the preset threshold, the system automatically switches back to the Wi-Fi link to resume normal transmission.
[0041] Audio data frames carrying a transmission timestamp are transmitted to the audio playback device via a low-latency data channel. During transmission, the transmission timestamp is transmitted along with the audio data frame as metadata, for use by the audio playback device for timestamp correction.
[0042] S4. The audio playback device receives audio data frames, corrects the transmission timestamp based on the clock offset and the clock offset predicted based on the clock drift rate to obtain the corrected timestamp, calculates the target playback time for each audio data frame in conjunction with the local clock of the playback device, and writes the audio data frames into the playback buffer queue in order of the target playback time.
[0043] Specifically, such as Figure 2 As shown in the S4 area, after receiving the audio data frame, the audio playback device extracts the transmission timestamp carried in it. Because there is a clock offset between the audio source device and the audio playback device, and this clock offset drifts over time, the transmission timestamp needs to be corrected.
[0044] The correction timestamp is calculated based on the current clock offset. Clock offset based on clock drift rate prediction Perform feedforward correction on the transmission timestamp. Let the first... The correction timestamp of each audio data frame is ,but: ; in, , This is the estimated transmission delay for audio data frames from transmission to reception. The correction process also takes into account the current static clock offset. and by clock drift rate The resulting dynamic offset prediction term achieves feedforward prediction compensation, fundamentally suppressing the impact of clock error accumulation on audio timestamp correction.
[0045] The target playback time is calculated as follows: the corrected timestamp is compared with the local clock of the playback device, and a preset playback buffer delay is added to obtain the target playback time for each audio data frame. Let the current reading of the local clock of the playback device be... The preset playback buffer delay is Then the first The target playback time of each audio data frame for: ; Preset playback buffer delay The value is usually between 50ms and 200ms, which is used to absorb network transmission jitter and small clock deviations to ensure that the audio data frame has arrived at the playback device and completed decoding preparation before the target playback time.
[0046] The playback buffer queue uses a priority queue structure arranged in ascending order of target playback time. Each audio data frame is enqueued according to its target playback time. The insertion position is determined in the priority queue to ensure that audio data frames in the queue are always arranged in ascending order of the target playback time. The playback scheduling module reads the earliest audio data frame with the target playback time from the head of the queue, decodes and plays it, ensuring that the playback order of audio frames is consistent with the timing sequence. The priority queue is implemented using a min-heap data structure, and the time complexity of the enqueue operation is O(log n). The time complexity of the dequeue operation is ,in This represents the number of audio data frames in the queue, meeting the low-latency scheduling requirements for real-time audio playback.
[0047] After S4 is completed, the audio data frames are arranged in the playback buffer queue according to the target playback time, waiting for the playback scheduling module to read and play them.
[0048] S5. The playback scheduling module reads audio data frames from the playback buffer queue according to the target playback time and decodes and plays them. At the same time, it monitors the buffer queue depth and the arrival delay of the data frames in real time. When the arrival delay exceeds the first preset threshold but does not exceed the second preset threshold, it performs fine-grained compensation by fine-tuning the playback sampling rate. When the arrival delay exceeds the second preset threshold, it performs coarse-grained compensation by adjusting the length of the buffer queue to maintain cross-device audio synchronization.
[0049] Specifically, such as Figure 2 As shown in the S5 area, the playback scheduling module uses the local clock of the playback device as a reference and schedules playback according to the target playback time. Audio data frames are read sequentially from the head of the playback buffer queue, decoded, and then sent to the audio output module for playback. During playback, the playback scheduling module monitors two key metrics in real time: Buffer queue depth: The number of audio data frames waiting to be played in the current playback buffer queue, reflecting the buffer capacity at the playback end; Data frame arrival delay: The time difference between the expected arrival time and the actual arrival time of an audio data frame, reflecting the combined impact of network transmission and clock skew. Let the... The expected arrival time of each audio data frame is The actual arrival time is Then the arrival delay for: ; when Time indicates the delay (lag) in the arrival of data frames. This indicates that the data frame arrived ahead of schedule. The playback scheduling module focuses on cases where the arrival delay is positive.
[0050] Based on the magnitude of the arrival delay, the system executes a tiered compensation strategy: Level 1, Normal Playback: When the delay is reached... Not exceeding the first preset threshold When the synchronization deviation is determined to be within the normal range, the playback scheduling module reads and decodes audio data frames according to the normal process, without requiring compensation. At this time, the synchronization deviation caused by network transmission and clock deviation is small, and it is within the playback buffer delay range. Within the absorption range, it does not affect the user experience.
[0051] Level 2, fine-grained compensation: when arrival delay... Exceeding the first preset threshold And it did not exceed the second preset threshold. If a slight synchronization deviation is detected, fine-grained compensation is performed by adjusting the playback sampling rate. First preset threshold. The value range is 10-50 milliseconds, and the second preset threshold is... The value range is 50-200 milliseconds. The adjustment range of the playback sampling rate is controlled within ±0.1% of the nominal sampling rate to keep the sampling rate change imperceptible to the human ear. For example, when the nominal sampling rate is 48000Hz, the sampling rate adjustment range is... Hz. When the arrival delay is positive (data frame lag), the playback sampling rate is appropriately reduced (e.g., reduced to 47960Hz) to slightly slow down the playback speed and allow buffer time for subsequent data frames to arrive; when the arrival delay is negative (data frame lead), the playback sampling rate is appropriately increased (e.g., increased to 48040Hz) to slightly speed up the playback speed and consume excess buffered data. Since a ±0.1% change in sampling rate corresponds to a difference of approximately 48 sampling points per second, which is within the imperceptible threshold of human hearing for changes in sampling rate, it will not introduce perceptible sound quality degradation.
[0052] Level 3, coarse-grained compensation: when arrival delay Exceeding the second preset threshold When a severe synchronization deviation is detected, network transmission may experience significant jitter or congestion. Fine-tuning the sampling rate alone is insufficient for effective compensation. In this case, coarse-grained compensation is achieved by adjusting the buffer queue length. Adjusting the buffer queue length includes two operating modes: When the buffer queue depth falls below a preset lower limit, the buffer queue capacity is increased to improve jitter tolerance. The lower limit is typically set to 20%–30% of the maximum queue capacity. When the queue depth is below this lower limit, it indicates insufficient available buffer data, posing a risk of playback interruption. Increasing the buffer queue capacity (e.g., from the default 100 frames to 150 frames) allows the playback scheduling module to continue reading data frames from the queue even when the queue depth is low, providing more time for network transmission recovery and preventing audio stuttering or interruptions.
[0053] When the buffer queue depth exceeds the preset upper limit, the buffer queue capacity is reduced to decrease playback latency. The upper limit is typically set to 70% to 80% of the maximum queue capacity. When the queue depth exceeds the upper limit, it indicates excessive buffer data backlog, leading to increased playback latency. In this case, reducing the buffer queue capacity (e.g., from the default 100 frames to 60 frames) accelerates the consumption of backlogged buffer data, bringing playback latency back to normal levels and preventing audio-visual desynchronization.
[0054] Through the aforementioned tiered compensation strategy, the system achieves adaptive handling of synchronization deviations of varying degrees: minor deviations are compensated for with fine-tuning of the sampling rate, resulting in a smooth and imperceptible compensation process; severe deviations are quickly corrected by adjusting the queue length, preventing synchronization failure. The two compensation methods work synergistically—fine-tuning of the sampling rate handles minor jitter, while adjusting the queue length addresses significant delays, balancing synchronization accuracy and playback stability.
[0055] like Figure 2 As shown in the dashed box on the right, the specific steps also include using HarmonyOS device virtualization capabilities to achieve dynamic role switching between audio source devices and audio playback devices.
[0056] Specifically, HarmonyOS Distributed Soft Bus provides device virtualization capabilities, supporting dynamic allocation of device roles within a distributed network. During synchronized audio playback, the system continuously monitors the operating status of the current audio source device, including indicators such as device online status, CPU utilization, memory usage, and network bandwidth availability.
[0057] When the current audio source device is detected to be offline or lacking sufficient computing power (e.g., CPU utilization consistently exceeds 80% or the device suddenly loses network connection), the system automatically triggers a role switching process. The role switching process includes the following steps: Each device in the distributed network broadcasts its own computing power evaluation metrics, including the number of CPU cores, clock speed, available memory, and network bandwidth. The system selects the device with the best computing power in the distributed network as the new audio source device based on a comprehensive score of computing power evaluation indicators. The audio acquisition and encoding tasks of the original audio source device are migrated to the new device, which takes over the functions of acquiring, encoding, and sending timestamps of audio data frames. The audio playback device does not need to be re-networked; it only needs to update the audio source device identifier and continue to operate according to the existing clock synchronization and playback scheduling logic.
[0058] Through device virtualization and dynamic role switching, the system can seamlessly switch to backup devices when the audio source device fails or the computing power is insufficient, ensuring the continuity and reliability of synchronized audio playback and demonstrating the decentralized advantages of HarmonyOS's distributed architecture.
[0059] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely principles of the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the claimed invention.
Claims
1. A cross-device audio synchronization method based on HarmonyOS distributed bus, characterized in that, The specific steps are as follows: S1. Through the HarmonyOS distributed bus, the device discovery and networking within the network are completed, audio source devices and playback devices are distinguished, dedicated communication links between devices are established, and audio codec parameters are negotiated and matched. S2. Based on the HarmonyOS distributed bus clock synchronization service, a globally unified time standard is established among interactive devices; the clock offset is calculated between devices through interactive clock synchronization messages, the clock drift rate is calculated based on multiple clock offset samples, and the clock offset at future moments is predicted based on the clock drift rate. S3. The audio source device collects audio signals, completes frame encoding according to a fixed frame length, adds a transmission timestamp to each frame of audio data based on a global time reference, and transmits the timestamped audio data frames to the playback device through a distributed bus low-latency channel. S4. After receiving the data, the playback device combines the measured and predicted clock offset to correct the timestamp, calculates the target playback time for each frame of audio, sorts it, and stores it in the playback buffer queue. S5. Decode and play according to the predetermined time, monitor the queue depth and data arrival delay in real time, and ensure the synchronization effect through a hierarchical compensation mechanism: when the delay exceeds the first preset threshold, fine-grained compensation is achieved by adjusting the sampling rate; when it exceeds the second preset threshold, coarse-grained compensation is achieved by adjusting the buffer queue length.
2. The cross-device audio synchronization method based on HarmonyOS distributed bus according to claim 1, characterized in that: The HarmonyOS distributed bus described in S1 completes device discovery and networking within the network. It detects surrounding devices in parallel through mDNS broadcasting of Wi-Fi network and BLE low power broadcasting of Bluetooth. After the device comes online, it completes identity authentication and capability registration within a preset time window and automatically builds a virtual bus topology covering heterogeneous networks.
3. The cross-device audio synchronization method based on HarmonyOS distributed bus according to claim 1, characterized in that: The audio encoding and decoding parameters mentioned in S1 include audio sampling rate, encoding format, frame length, number of channels, and buffer configuration parameters. The audio source device and the audio playback device negotiate and determine the optimal combination of encoding and decoding parameters that they both support through capability exchange messages.
4. The cross-device audio synchronization method based on HarmonyOS distributed bus according to claim 1, characterized in that, The clock drift rate described in S2 is calculated as follows: at least three clock offset samples are collected within a preset time window, and linear regression fitting is performed with the sampling time point as the independent variable and the clock offset as the dependent variable. The resulting regression slope is used as the clock drift rate. The clock offset at future times is obtained by multiplying and summing the current clock offset and the clock drift rate.
5. The cross-device audio synchronization method based on HarmonyOS distributed bus according to claim 1, characterized in that: The HarmonyOS distributed bus clock synchronization service described in S2 adopts a multi-level clock synchronization system, including a hardware-level timestamp calibration layer based on the improved IEEE1588 protocol, a software-level time synchronization layer based on the NTP protocol, and a service-level synchronization layer based on the service clock.
6. The cross-device audio synchronization method based on HarmonyOS distributed bus according to claim 1, characterized in that: The low-latency channel described in S3 adopts a multi-link collaborative transmission mechanism of HarmonyOS distributed soft bus. Control signaling is transmitted through Bluetooth BLE link, and audio data frames are transmitted through Wi-Fi link. When the Wi-Fi link signal quality is lower than a preset threshold, it automatically switches to Bluetooth link for reduced-speed transmission.
7. The cross-device audio synchronization method based on HarmonyOS distributed bus according to claim 1, characterized in that, The target playback time mentioned in S4 is calculated by comparing the corrected timestamp with the local clock of the playback device and adding a preset playback buffer delay to obtain the target playback time of each audio data frame; the playback buffer queue adopts a priority queue structure arranged in ascending order of the target playback time.
8. The cross-device audio synchronization method based on HarmonyOS distributed bus according to claim 1, characterized in that: In S5, the first preset threshold ranges from 10 to 50 milliseconds, and the second preset threshold ranges from 50 to 200 milliseconds; the adjustment range of the fine-tuning sampling rate is controlled within ±0.1% of the nominal sampling rate, so that the change in sampling rate is within the range imperceptible to the human ear.
9. A cross-device audio synchronization method based on HarmonyOS distributed bus according to claim 1, characterized in that, The adjustment of the buffer queue length described in S5 includes: increasing the buffer queue capacity to improve jitter tolerance when the buffer queue depth is lower than the preset lower limit; and decreasing the buffer queue capacity to reduce playback latency when the buffer queue depth is higher than the preset upper limit.
10. A cross-device audio synchronization method based on HarmonyOS distributed bus according to claim 1, characterized in that: The specific steps also include using HarmonyOS device virtualization capabilities to achieve dynamic role switching between audio source devices and audio playback devices. When the current audio source device is detected to be offline or lacking computing power, the device with the best computing power in the distributed network is automatically selected as the new audio source device, and the audio acquisition and encoding tasks of the original audio source device are migrated to the new device.
