Buffer dynamic adjustment method, device and equipment and computer readable storage medium

By dynamically adjusting the capacity of the circular buffer and combining the recording thread's calling behavior and data writing characteristics, the problem of data overwriting or loss in traditional echo cancellation technology is solved, thereby improving the accuracy of echo cancellation and voice quality.

CN121664931APending Publication Date: 2026-03-13HUIZHOU TCL MOBILE COMM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-14
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

In traditional echo cancellation technology, the playback signal is stored in a single buffer, which cannot adapt to the irregular calls of the recording thread, resulting in data overwriting or loss and increasing echo residue.

Method used

By acquiring the call behavior information of the recording thread and the data writing characteristics of the playback thread, the capacity of the circular buffer is dynamically adjusted to ensure that the reference signal read by the recording thread is always valid, and a multi-delay filter algorithm is used for echo cancellation.

Benefits of technology

It improves the accuracy of echo cancellation, avoids data overwriting or loss, ensures time alignment between recorded and playback signals, and enhances the quality of voice communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121664931A_ABST
    Figure CN121664931A_ABST
Patent Text Reader

Abstract

The invention discloses a buffer dynamic adjustment method and device, equipment and a computer readable storage medium. The method comprises the steps that calling behavior information of a recording thread and data writing characteristics of a playing thread are acquired; determining a target buffer area capacity of the circular buffer area based on the calling behavior information and the data writing characteristics; and dynamically adjusting the circular buffer based on the target buffer capacity. By the adoption of the method, the size of the buffer area can be flexibly expanded or reduced according to changes of system loads and thread behaviors, data coverage or loss is avoided, it is ensured that the reference signals read by the recording thread are always effective, and the accuracy of echo cancellation is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of echo technology, specifically to a method, apparatus, device, and computer-readable storage medium for dynamic adjustment of a buffer. Background Technology

[0002] In voice communication, echo cancellation technology is a key step in improving voice quality. Echo cancellation relies on precise time alignment between the playback signal (reference signal) and the recording signal. However, in traditional echo cancellation technology, the playback signal is stored in a single buffer. This single buffer cannot adapt to the unpredictable calls of the recording thread, making it prone to data overwriting or loss, resulting in increased echo residue. Summary of the Invention

[0003] This application provides a method, apparatus, device, and computer-readable storage medium for dynamic adjustment of a buffer, which can flexibly expand or shrink the buffer size according to changes in system load and thread behavior, thereby improving the accuracy of echo cancellation.

[0004] The technical solution adopted by this invention to solve the problem is as follows: Firstly, this application provides a method for dynamically adjusting a buffer zone, including: Obtain the call behavior information of the recording thread and the data writing characteristics of the playback thread; the recording thread is used to read audio data from the circular buffer, and the playback thread is used to write audio data to the circular buffer; The target buffer capacity of the circular buffer is determined based on call behavior information and data writing characteristics; The circular buffer is dynamically adjusted based on the target buffer capacity.

[0005] In some embodiments of this application, the target buffer capacity of the circular buffer is determined based on call behavior information and data write characteristics, including: Based on the call behavior information, determine the target call interval for the recording thread; The target buffer capacity of the circular buffer is determined based on the target call interval and data write characteristics.

[0006] In some embodiments of this application, the recording thread reads audio data from the circular buffer by calling the data reading module. The calling behavior information includes a first calling interval and a second calling interval. The first calling interval represents the historical average calling interval of the recording thread to the data reading module, and the second calling interval represents the most recent calling interval of the recording thread to the data reading module. Based on the call behavior information, determine the target call interval for the recording thread, including: Obtain the first weight information corresponding to the first call interval; The first weight information and the first parameter information are calculated to obtain the second weight information corresponding to the second call interval; The first call interval and the second call interval are weighted and fused based on the first weight information and the second weight information to obtain the target call interval of the recording thread.

[0007] In some embodiments of this application, the data writing characteristics include the data writing interval and the length of data written in a single operation; Based on the target call interval and data write characteristics, the target buffer capacity of the circular buffer is determined, including: Get the upper and lower limits of the circular buffer's capacity; The capacity of the first buffer is obtained by calculating the target call interval, the length of data written in a single operation, and the data write interval. The capacity of the second buffer is obtained by calculating the capacity and upper limit of the first buffer. The target buffer capacity of the circular buffer is obtained by calculating the capacity of the second buffer and its lower limit.

[0008] In some embodiments of this application, the circular buffer is dynamically adjusted based on the target buffer capacity, including: The effective data length of the circular buffer is obtained by calculating the original buffer capacity, the tail pointer position, and the head pointer position of the circular buffer. Based on the valid data length and the tail pointer position, obtain valid audio data from the circular buffer; Determine the updated circular buffer based on the target buffer capacity; Copy the valid audio data to the updated circular buffer, and adjust the tail pointer position and head pointer position based on the position of the valid audio data in the updated circular buffer.

[0009] In some embodiments of this application, the method further includes: The third call interval is obtained by calculating the target call interval and the first threshold of the recording thread; Based on the third call interval and the actual call interval of the recording thread, determine whether there is a call delay in the recording thread; When there is a call delay in the recording thread and the number of call delays reaches the second threshold, the tail pointer position of the circular buffer is adjusted to the head pointer position.

[0010] In some embodiments of this application, the method further includes: Receive the call request from the playback thread to the data writing module, and write the first audio data block into the circular buffer based on the head pointer position of the circular buffer; The head pointer position is adjusted based on the data length of the first audio data block.

[0011] In some embodiments of this application, the method further includes: Receive the call request from the recording thread to the data reading module, and read the second audio data block from the circular buffer based on the tail pointer position of the circular buffer; The position of the tail pointer is adjusted based on the length of the second audio data block.

[0012] Secondly, this application provides a buffer dynamic adjustment device, comprising: The data acquisition module is used to acquire the call behavior information of the recording thread and the data writing characteristics of the playback thread; the recording thread is used to read audio data from the circular buffer, and the playback thread is used to write audio data to the circular buffer. The capacity determination module is used to determine the target buffer capacity of the circular buffer based on call behavior information and data write characteristics; The dynamic adjustment module is used to dynamically adjust the circular buffer based on the target buffer capacity.

[0013] Thirdly, this application also provides a computer device, which includes: One or more processors; Memory; and One or more applications, wherein the applications are stored in memory and configured to be executed by a processor to implement the buffer dynamic adjustment method of any of the first aspects.

[0014] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, the computer program being loaded by a processor to perform the steps in the buffer dynamic adjustment method of any of the first aspects.

[0015] The beneficial effects of this invention are as follows: By determining the target buffer capacity of the circular buffer based on call behavior information and data writing characteristics, and dynamically adjusting the circular buffer based on the target buffer capacity, the buffer size can be flexibly expanded or reduced according to changes in system load and thread behavior, avoiding data overwriting or loss, ensuring that the reference signal read by the recording thread is always valid, and improving the accuracy of echo cancellation. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 This is a schematic diagram of a scenario for the dynamic buffer adjustment system provided in an embodiment of the present invention; Figure 2 This is a schematic flowchart of an embodiment of the buffer dynamic adjustment method provided by the present invention; Figure 3 This is a schematic diagram of a specific embodiment of the process for determining the target call interval provided by the present invention; Figure 4 This is a schematic flowchart of a specific embodiment of dynamically adjusting the circular buffer provided by the present invention; Figure 5 This is a schematic diagram of a specific embodiment of the buffer dynamic adjustment device provided in this invention. Figure 6 This is a schematic diagram of an embodiment of the computer device provided in this invention. Detailed Implementation

[0018] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0019] In the description of this application, the terms "first," "second," "third," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first," "second," "third," etc., may explicitly or implicitly include one or more features.

[0020] In this application, the term "exemplary" is used to mean "used as an example, illustration, or description." Any embodiment described as "exemplary" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use this application. Details are set forth in the following description for purposes of explanation. It should be understood that those skilled in the art will recognize that this application can be made without using these specific details. In other instances, well-known structures and processes are not described in detail to avoid obscuring the description of this application with unnecessary detail. Therefore, this application is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in this application.

[0021] It should be noted that since the method in this application embodiment is executed in a computer device, the processing objects of each computer device exist in the form of data or information, such as time, which is essentially time information. It is understood that if size, quantity, position, etc. are mentioned in subsequent embodiments, they are all corresponding data that exist so that the computer device can process them. Specific details will not be elaborated here.

[0022] This application provides a method, apparatus, device, and computer-readable storage medium for dynamic adjustment of a buffer, which will be described in detail below.

[0023] The buffer dynamic adjustment method provided in this application embodiment is applied to a buffer dynamic adjustment system. Please refer to [link / reference]. Figure 1 , Figure 1 This is a schematic diagram of a scenario for a dynamic buffer adjustment system provided in an embodiment of this application. The dynamic buffer adjustment system may include a data writing module, a data reading module, a buffer adjustment module, and an echo cancellation module.

[0024] In some embodiments, the data writing module is used to write audio data to the circular buffer based on the playback thread's call request and the head pointer position of the circular buffer, and adjust the head pointer position based on the length of the written audio data. This ensures that newly written data can correctly overwrite old data while avoiding data conflicts. Optionally, the playback thread can write audio data to the circular buffer at a fixed time interval (e.g., 20ms) and a fixed data length, or the playback thread can write audio data to the circular buffer at a varying time interval and / or a varying data length.

[0025] In some embodiments, the data reading module is used to read audio data from the circular buffer based on the recording thread's call request and the tail pointer position of the circular buffer, and adjust the tail pointer position based on the length of the read audio data. This ensures synchronization between the read and write operations, aligns the read reference signal with the recording signal in time, and provides accurate data support for echo cancellation. Optionally, the recording thread can read audio data from the circular buffer at fixed time intervals and with a fixed data length, or it can read audio data from the circular buffer at varying time intervals (e.g., 20ms, 40ms, or longer) and / or varying data lengths.

[0026] In some embodiments, the buffer adjustment module is used to acquire the call behavior information of the recording thread and the data write characteristics of the playback thread; based on the call behavior information and data write characteristics, determine the target buffer capacity of the circular buffer; and dynamically adjust the circular buffer based on the target buffer capacity. This allows for flexible expansion or reduction of the buffer size according to changes in system load and thread behavior, preventing data overwriting or loss and ensuring that the reference signal read by the recording thread is always valid. In some embodiments, the echo cancellation module is used to perform adaptive filtering operations to eliminate echoes based on the audio data (reference signal) read by the recording thread and the recorded signal. The echo cancellation module can use existing filtering algorithms such as multi-delay filter algorithm and multi-delay block frequency domain adaptive filter (MDF) algorithm for echo cancellation. Since the audio data (reference signal) read by the recording thread is precisely time-aligned with the recorded signal, the echo cancellation effect of the echo cancellation module can be improved.

[0027] Those skilled in the art will understand that Figure 1 The application environment shown is merely one application scenario of the solution in this application and does not constitute a limitation on the application scenario of the solution in this application. Other application environments may include more than one application scenario. Figure 1 More components are shown.

[0028] In addition, the buffer dynamic adjustment system may also include a memory for storing data, such as call behavior information, such as first interval information, second interval information, etc., and data write characteristics, such as data write interval, single write data length, etc.

[0029] It should be noted that, Figure 1The schematic diagram of the buffer dynamic adjustment system shown is merely an example. The buffer dynamic adjustment system and scenario described in this application embodiment are for the purpose of more clearly illustrating the technical solutions of this application embodiment and do not constitute a limitation on the technical solutions provided in this application embodiment. As those skilled in the art will know, with the evolution of the buffer dynamic adjustment system and the emergence of new business scenarios, the technical solutions provided in this application embodiment are also applicable to similar technical problems.

[0030] First, this application provides a method, apparatus, device, and computer-readable storage medium for dynamically adjusting a buffer. The execution subject of the method is a buffer dynamic adjustment device, which is applied to a computer device. The method includes: acquiring call behavior information of a recording thread and data writing characteristics of a playback thread; the recording thread reading audio data from a circular buffer and the playback thread writing audio data to the circular buffer; determining the target buffer capacity of the circular buffer based on the call behavior information and data writing characteristics; and dynamically adjusting the circular buffer based on the target buffer capacity.

[0031] like Figure 2 The diagram shown is a flowchart of an embodiment of the dynamic buffer adjustment method in this application. The dynamic buffer adjustment method may include the following steps S201 to S203, as detailed below: Step S201: Obtain the calling behavior information of the recording thread and the data writing characteristics of the playback thread; the recording thread is used to read audio data from the circular buffer, and the playback thread is used to write audio data to the circular buffer.

[0032] In this embodiment, the recording thread reads audio data from the circular buffer by calling the data reading module. The calling behavior information characterizes the recording thread's calling behavior towards the data reading module. This calling behavior information includes one or more of a first calling interval, a second calling interval, and calling interval variance. Specifically, the first calling interval characterizes the historical average calling interval of the recording thread towards the data reading module. The first calling interval can be obtained by acquiring multiple calling intervals of the recording thread towards the data reading module and averaging these intervals. The second calling interval characterizes the most recent calling interval of the recording thread towards the data reading module. The second calling interval can be obtained by acquiring the current calling time and the previous calling time of the recording thread towards the data reading module and calculating the time difference between these two times. The calling interval variance characterizes the dispersion of the recording thread's calling intervals towards the data reading module. The calling interval variance can be obtained by acquiring multiple calling intervals of the recording thread towards the data reading module and the average of these multiple calling intervals, and calculating the average of these multiple calling intervals.

[0033] Furthermore, the data write characteristics are used to characterize the attribute features of the playback thread when writing audio data to the circular buffer. The data write characteristics include at least one of data write interval and single write data length. The data write interval characterizes the time difference between two consecutive data write operations, and the single write data length characterizes the amount of data transferred in each write operation. Optionally, when the playback thread writes audio data to the circular buffer at a fixed time interval (e.g., 20ms) and a fixed data length, the data write interval is the fixed time interval, and the single write data length is the fixed data length. When the playback thread writes audio data to the circular buffer at varying time intervals and varying data lengths, the data write interval can be the average of multiple write intervals or the most recent write interval, and the single write data length can be the average of multiple write data lengths or the most recent write data length.

[0034] S202. Determine the target buffer capacity of the circular buffer based on the call behavior information and data writing characteristics.

[0035] In this embodiment of the application, the target buffer capacity is used to characterize the adjusted buffer capacity. Optionally, the target buffer capacity can be determined based on the call behavior information, data writing characteristics, and the correspondence between the call behavior information, data writing characteristics, and buffer capacity. Alternatively, the call behavior information and data writing characteristics can be input into a pre-trained artificial intelligence model, and the target buffer capacity can be output by the artificial intelligence model. Alternatively, the target call interval of the recording thread can be determined based on the call behavior information, and then the target buffer capacity of the circular buffer can be determined based on the target call interval and data writing characteristics.

[0036] In some embodiments, refer to Figure 3 As shown, the step S202 above, which determines the target buffer capacity of the circular buffer based on the call behavior information and data write characteristics, may include steps S301 to S302, as detailed below: S301. Based on the call behavior information, determine the target call interval for the recording thread.

[0037] In this embodiment, the target call interval is used to characterize the next call interval of the recording thread predicted based on call behavior information. The target call interval can be determined based on call behavior information and the correspondence between call behavior information and call interval. Alternatively, the call behavior information can be input into a pre-trained artificial intelligence model, and the target call interval can be output through the pre-trained artificial intelligence model. Or, the target call interval can be obtained by calculating the call behavior information.

[0038] In some embodiments, the recording thread reads audio data from the circular buffer by calling the data reading module. The calling behavior information includes a first calling interval and a second calling interval. The first calling interval represents the historical average calling interval of the recording thread to the data reading module, and the second calling interval represents the most recent calling interval of the recording thread to the data reading module. The step of determining the target calling interval of the recording thread based on the calling behavior information specifically includes: obtaining first weight information corresponding to the first calling interval; calculating the first weight information and the first parameter information to obtain second weight information corresponding to the second calling interval; and performing a weighted fusion of the first calling interval and the second calling interval based on the first weight information and the second weight information to obtain the target calling interval of the recording thread.

[0039] In this embodiment, the first weight information is used to characterize the contribution of the first call interval to the target call interval. The first weight information can be set according to actual needs. In some embodiments, the step of calculating the first weight information and the first parameter information to obtain the second weight information corresponding to the second call interval specifically includes: subtracting the first weight information and the first parameter information to obtain the second weight information corresponding to the second call interval. Optionally, the process of determining the second weight information can be expressed as: ,in, This represents the second weighting information. This represents the first weight information. In some embodiments, the first parameter information is represented. ,For example, The process of determining the second weight information can be expressed as follows: .

[0040] In some embodiments, the process of determining the target call interval can be expressed as: T_pred = * T_avg+ * T_last, where T_pred represents the target call interval, T_avg represents the first interval information, and T_last represents the second interval information. This represents the first weight information. This indicates the first parameter information. Optionally, ,For example, The process of determining the target call interval can be expressed as: T_pred = * T_avg+ * T_last.

[0041] S302. Determine the target buffer capacity of the circular buffer based on the target call interval and data write characteristics.

[0042] In this embodiment, when determining the target buffer capacity of the circular buffer based on the target call interval and data write characteristics, the target buffer capacity can be determined based on the target call interval, data write characteristics, and the correspondence between the call interval, data write characteristics, and buffer capacity. Alternatively, the target call interval and data write characteristics can be input into a pre-trained artificial intelligence model, which outputs the target buffer capacity. The target buffer capacity can also be calculated from the target call interval and data write characteristics. This embodiment, by determining the target buffer capacity based on the target call interval and data write characteristics, can improve the accuracy of the determined target buffer capacity, ensuring precise temporal alignment between the read reference signal and the recorded signal, and providing accurate data support for echo cancellation.

[0043] In some embodiments, the data write characteristics include a data write interval and a single write data length. The data write interval represents the time difference between two consecutive data write operations, and the single write data length represents the amount of data transmitted in each write operation. The step of determining the target buffer capacity of the circular buffer based on the target call interval and data write characteristics specifically includes: obtaining the upper limit and lower limit of the circular buffer capacity; calculating the first buffer capacity by considering the target call interval, the single write data length, and the data write interval; calculating the second buffer capacity by considering the first buffer capacity and the upper limit; and calculating the target buffer capacity of the circular buffer by considering the second buffer capacity and the lower limit. This embodiment combines the upper limit and lower limit of the circular buffer capacity to determine the target buffer capacity, which can improve the accuracy of the determined target buffer capacity.

[0044] In some embodiments, the step of calculating the target call interval, the single write data length, and the data write interval to obtain the first buffer capacity specifically includes: multiplying the target call interval and the single write data length to obtain the third buffer capacity; and dividing the third buffer capacity and the data write interval to obtain the first buffer capacity.

[0045] Optionally, the process of determining the capacity of the first buffer can be expressed as: ,in, Indicates the capacity of the first buffer. Indicates the target call interval. Indicates the length of data written in a single operation. Indicates the data write interval.

[0046] In some embodiments, the step of calculating the capacity of the first buffer and its upper limit to obtain the capacity of the second buffer specifically includes: comparing the capacity of the first buffer and its upper limit; determining the upper limit as the capacity of the second buffer when the capacity of the first buffer is greater than the upper limit; and determining the capacity of the first buffer as the capacity of the second buffer when the capacity of the first buffer is less than or equal to the upper limit. Optionally, the process of determining the capacity of the second buffer can be expressed as follows: , Indicates the capacity of the second buffer. Indicates the maximum capacity value. Indicates taking and The smaller value.

[0047] In some embodiments, the step of calculating the target buffer capacity of the circular buffer by comparing the second buffer capacity and the lower limit value specifically includes: comparing the second buffer capacity and the lower limit value; determining the second buffer capacity as the target buffer capacity of the circular buffer when the second buffer capacity is greater than or equal to the lower limit value; and determining the lower limit value as the target buffer capacity of the circular buffer when the second buffer capacity is less than the lower limit value. Optionally, the process of determining the target buffer capacity can be expressed as: ,in, Indicates the target buffer capacity. Indicates the lower limit of capacity. Indicates taking and The larger value in the range.

[0048] S203. Based on the target buffer capacity, dynamically adjust the circular buffer.

[0049] In this embodiment, when dynamically adjusting the circular buffer based on the target buffer capacity, the circular buffer can be directly shrunk or expanded based on the target buffer capacity, or a new circular buffer can be constructed based on the target buffer capacity, and the valid data in the original circular buffer can be copied to the new circular buffer. This embodiment dynamically adjusts the circular buffer based on the target buffer capacity, flexibly expanding or shrinking the buffer size according to changes in system load and thread behavior, avoiding data overwriting or loss, and ensuring that the reference signal read by the recording thread is always valid.

[0050] In some embodiments, refer to Figure 4 As shown, the dynamic adjustment of the circular buffer based on the target buffer capacity in step S203 above may include steps S401 to S404, as detailed below: S401. Calculate the original buffer capacity, the tail pointer position, and the head pointer position of the circular buffer to obtain the effective data length of the circular buffer.

[0051] In this embodiment, the original buffer capacity refers to the buffer capacity of the circular buffer before dynamic adjustment based on the target buffer capacity. The original buffer capacity can be greater than the target buffer capacity, or equal to the target buffer capacity, or less than the target buffer capacity. When the original buffer capacity is greater than the target buffer capacity, dynamic adjustment of the circular buffer based on the target buffer capacity can dynamically reduce the buffer size, thereby reducing memory resource waste. When the original buffer capacity is less than the target buffer capacity, dynamic adjustment of the circular buffer based on the target buffer capacity can dynamically expand the buffer size, avoiding data overwriting or loss, and ensuring that the reference signal read by the recording thread is always valid.

[0052] Furthermore, a circular buffer refers to a fixed-size contiguous memory space, logically considered as a ring structure with its head and tail connected. The head pointer points to the next free position in the circular buffer where data can be written, and the tail pointer points to the position of the first valid data in the circular buffer (i.e., the next data to be read). The tail pointer position refers to the position pointed to by the tail pointer in the circular buffer, which is the position of the first valid data in the circular buffer, and the head pointer position refers to the position pointed to by the head pointer in the circular buffer, which is the next free position in the circular buffer where data can be written.

[0053] In some embodiments, the step of calculating the effective data length of the circular buffer by taking the original buffer capacity, the tail pointer position, and the head pointer position of the circular buffer specifically includes: subtracting the original buffer capacity and the tail pointer position to obtain a first data length; and adding the first data length and the head pointer position to obtain the effective data length of the circular buffer. Optionally, the process of determining the effective data length of the circular buffer can be expressed as: ,in, Indicates the length of valid data. Indicates the original buffer capacity. This indicates the position of the tail pointer of the circular buffer. This indicates the position of the head pointer of the circular buffer.

[0054] S402. Based on the valid data length and the tail pointer position, obtain valid audio data from the circular buffer.

[0055] In this embodiment, valid audio data refers to audio data in the circular buffer that the recording thread has not yet acquired. The length of valid audio data is the valid data length, and the position of valid audio data starts from the tail pointer position, that is, the position of the first valid data in the circular buffer (i.e., the next data to be read). Therefore, acquiring valid audio data from the circular buffer means acquiring continuous audio data with a length equal to the valid data length, starting from the position pointed to by the tail pointer in the circular buffer.

[0056] S403. Determine the updated circular buffer based on the target buffer capacity.

[0057] In this embodiment of the application, the updated circular buffer can be a newly created circular buffer with the target buffer capacity, or the updated circular buffer can be a circular buffer that has been expanded or shrunk based on the target buffer capacity.

[0058] S404. Copy the valid audio data to the updated circular buffer, and adjust the tail pointer position and head pointer position based on the position of the valid audio data in the updated circular buffer.

[0059] In this embodiment, when copying valid audio data to the updated circular buffer, the copy can be performed from the beginning of the circular buffer or from any position within the buffer. After copying, all data except the valid audio data is deleted from the circular buffer, and the tail pointer is adjusted to the beginning of the valid audio data, while the head pointer is adjusted to the position after the end of the valid audio data. This allows the circular buffer to dynamically shrink and expand based on the recording thread's call behavior and the playback thread's data writing characteristics. Furthermore, by dynamically adjusting the head and tail pointers during dynamic shrinking and expansion, synchronization between read and write operations can be ensured. For example, valid audio data can be copied from the 0th position of the circular buffer; after copying, the tail pointer is adjusted to the 0th position of the circular buffer, and the head pointer is adjusted to the position after the end of the valid audio data.

[0060] In some embodiments, the above-described dynamic buffer adjustment method further includes: calculating a third call interval by considering the target call interval of the recording thread and a first threshold; determining whether the recording thread experiences call latency based on the third call interval and the actual call interval of the recording thread; and adjusting the tail pointer position of the circular buffer to the head pointer position when the recording thread experiences call latency and the number of call latencies reaches a second threshold. This embodiment adjusts the tail pointer position of the circular buffer to the head pointer position when the recording thread experiences call latency and the number of call latencies reaches the second threshold, ensuring that the latest reference signal can be read even when the recording thread experiences multiple call latencies, thus improving data alignment efficiency.

[0061] In this embodiment, the process of determining the target call interval of the recording thread has been described in detail in the aforementioned step S301. For details, please refer to the aforementioned step S301. To avoid repetition, this embodiment will not repeat it here.

[0062] Optionally, the step of calculating the target call interval of the recording thread and the first threshold to obtain the third call interval specifically includes: multiplying the target call interval of the recording thread and the first threshold to obtain the third call interval. In some embodiments, the process of determining the third call interval can be expressed as: ,in, Indicates the third call interval. Indicates the target call interval. This represents the first threshold.

[0063] Optionally, the first threshold can be set according to actual needs; in some embodiments, ,For example, The process of determining the third call interval can be expressed as: .

[0064] In some embodiments, the step of determining whether the recording thread has a call delay based on the third call interval and the actual call interval of the recording thread specifically includes: comparing the third call interval with the actual call interval of the recording thread; if the actual call interval of the recording thread is greater than the third call interval, determining that the recording thread has a call delay; if the actual call interval of the recording thread is less than or equal to the third call interval, determining that the recording thread does not have a call delay.

[0065] In some embodiments, the above-described buffer dynamic adjustment method further includes: receiving a call request from the playback thread to the data writing module; writing a first audio data block into the circular buffer based on the head pointer position of the circular buffer; and adjusting the head pointer position based on the data length of the first audio data block. Here, adjusting the head pointer position based on the data length of the first audio data block means moving the head pointer forward by the data length of the first audio data block, so that the head pointer can point to the next available position where data can be written. In this embodiment, when the playback thread calls the data writing module to write audio data, the head pointer position is adjusted synchronously, ensuring that the newly written data correctly overwrites the old data while avoiding data conflicts.

[0066] In some embodiments, the above-described buffer dynamic adjustment method further includes: receiving a call request from the recording thread to the data reading module; reading a second audio data block from the circular buffer based on the tail pointer position of the circular buffer; and adjusting the tail pointer position based on the length of the second audio data block. Here, adjusting the tail pointer position based on the length of the second audio data block means moving the tail pointer forward by the length of the second audio data block, so that the tail pointer can point to the next data to be read. In this embodiment, when the recording thread calls the data reading module to read audio data, the tail pointer position is adjusted synchronously, ensuring the synchronization between the read and write operations, and ensuring that the read reference signal and the recorded signal are precisely aligned in time, providing accurate data support for echo cancellation.

[0067] In some embodiments, the above-described buffer dynamic adjustment method further includes: determining whether the recording thread is continuously called; if the recording thread is continuously called, monitoring whether the tail pointer position exceeds the head pointer position; when the tail pointer position exceeds the head pointer position, adjusting the tail pointer position to not exceed the head pointer position, so as to avoid the recording thread reading unwritten data, making the read reference signal and the recorded signal precisely aligned in time, and improving the accuracy of echo cancellation.

[0068] To better implement the buffer dynamic adjustment method in the embodiments of this application, based on the buffer dynamic adjustment method, the embodiments of this application also provide a buffer dynamic adjustment device, such as... Figure 5 As shown, the buffer dynamic adjustment device 600 includes: The data acquisition module 610 is used to acquire the calling behavior information of the recording thread and the data writing characteristics of the playback thread; the recording thread is used to read audio data from the circular buffer, and the playback thread is used to write audio data to the circular buffer. The capacity determination module 620 is used to determine the target buffer capacity of the circular buffer based on the call behavior information and data write characteristics; The dynamic adjustment module 630 is used to dynamically adjust the circular buffer based on the target buffer capacity.

[0069] In this embodiment, the target buffer capacity of the circular buffer is determined based on the call behavior information and data writing characteristics. Based on the target buffer capacity, the circular buffer is dynamically adjusted. The buffer size can be flexibly expanded or reduced according to changes in system load and thread behavior, avoiding data overwriting or loss, ensuring that the reference signal read by the recording thread is always valid, and improving the accuracy of echo cancellation.

[0070] In some embodiments of this application, the capacity determination module 620 is specifically used for: Based on the call behavior information, determine the target call interval for the recording thread; The target buffer capacity of the circular buffer is determined based on the target call interval and data write characteristics.

[0071] Optionally, the recording thread reads audio data from the circular buffer by calling the data reading module. The calling behavior information includes a first calling interval and a second calling interval. The first calling interval represents the historical average calling interval of the recording thread to the data reading module, and the second calling interval represents the most recent calling interval of the recording thread to the data reading module. The capacity determination module 620 is further used for: Obtain the first weight information corresponding to the first call interval; The first weight information and the first parameter information are calculated to obtain the second weight information corresponding to the second call interval; The first call interval and the second call interval are weighted and fused based on the first weight information and the second weight information to obtain the target call interval of the recording thread.

[0072] In some embodiments, the data write characteristics include the data write interval and the length of data written in a single operation, and the capacity determination module 620 is further configured to: Get the upper and lower limits of the circular buffer's capacity; The capacity of the first buffer is obtained by calculating the target call interval, the length of data written in a single operation, and the data write interval. The capacity of the second buffer is obtained by calculating the capacity and upper limit of the first buffer. The target buffer capacity of the circular buffer is obtained by calculating the capacity of the second buffer and its lower limit.

[0073] In some embodiments, the dynamic adjustment module 630 is specifically used for: The effective data length of the circular buffer is obtained by calculating the original buffer capacity, the tail pointer position, and the head pointer position of the circular buffer. Based on the valid data length and the tail pointer position, obtain valid audio data from the circular buffer; Determine the updated circular buffer based on the target buffer capacity; Copy the valid audio data to the updated circular buffer, and adjust the tail pointer position and head pointer position based on the position of the valid audio data in the updated circular buffer.

[0074] In some embodiments, the buffer dynamic adjustment device further includes: The first calculation module is used to calculate the target call interval and the first threshold of the recording thread to obtain the third call interval; The delay determination module is used to determine whether there is a call delay in the recording thread based on the third call interval and the actual call interval of the recording thread; The first adjustment module is used to adjust the tail pointer position of the circular buffer to the head pointer position when there is a call delay in the recording thread and the number of call delays reaches a second threshold.

[0075] In some embodiments, the buffer dynamic adjustment device further includes: The data writing module is used to receive the call request from the playback thread and write the first audio data block into the circular buffer based on the head pointer position of the circular buffer. The second adjustment module is used to adjust the position of the head pointer based on the data length of the first audio data block.

[0076] In some embodiments, the buffer dynamic adjustment device further includes: The data reading module is used to receive the call request from the recording thread and read the second audio data block from the circular buffer based on the position of the tail pointer of the circular buffer; The third adjustment module is used to adjust the position of the tail pointer based on the length of the second audio data block.

[0077] This application also provides a computer device that integrates any of the buffer dynamic adjustment devices provided in this application. The computer device includes: One or more processors; Memory; and One or more applications, wherein the applications are stored in memory and configured to be executed by a processor from the steps of the buffer dynamic adjustment method in any of the embodiments described above.

[0078] This application also provides a computer device that integrates any of the buffer dynamic adjustment settings provided in this application. For example... Figure 6As shown, it illustrates a structural schematic diagram of the computer device involved in the embodiments of this application, specifically: The computer device may include components such as a processor 801 with one or more processing cores, a memory 802 with one or more computer-readable storage media, a power supply 803, and an input unit 804. Those skilled in the art will understand that... Figure 6 The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein: The processor 801 is the control center of the computer device. It connects various parts of the computer device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 802, and by calling data stored in the memory 802, it performs various functions of the computer device and processes data, thereby providing overall monitoring of the computer device. Optionally, the processor 801 may include one or more processing cores; preferably, the processor 801 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 801.

[0079] The memory 802 can be used to store software programs and modules. The processor 801 executes various functional applications and data processing by running the software programs and modules stored in the memory 802. The memory 802 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 802 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 802 may also include a memory controller to provide the processor 801 with access to the memory 802.

[0080] The computer device also includes a power supply 803 that supplies power to the various components. Preferably, the power supply 803 can be logically connected to the processor 801 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 803 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0081] The computer device may also include an input unit 804, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0082] Although not shown, the computer device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 801 in the computer device loads the executable files corresponding to the processes of one or more application programs into the memory 802 according to the following instructions, and the processor 801 runs the application programs stored in the memory 802 to realize various functions, as follows: Obtain the call behavior information of the recording thread and the data writing characteristics of the playback thread; the recording thread is used to read audio data from the circular buffer, and the playback thread is used to write audio data to the circular buffer; The target buffer capacity of the circular buffer is determined based on call behavior information and data writing characteristics; The circular buffer is dynamically adjusted based on the target buffer capacity.

[0083] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0084] Therefore, embodiments of this application provide a computer-readable storage medium, which may include: read-only memory (ROM), random access memory (RAM), a disk, or an optical disk, etc. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in any of the buffer dynamic adjustment methods provided in embodiments of this application. For example, the computer program loaded by the processor can execute the following steps: Obtain the call behavior information of the recording thread and the data writing characteristics of the playback thread; the recording thread is used to read audio data from the circular buffer, and the playback thread is used to write audio data to the circular buffer; The target buffer capacity of the circular buffer is determined based on call behavior information and data writing characteristics; The circular buffer is dynamically adjusted based on the target buffer capacity.

[0085] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the detailed descriptions of other embodiments above, which will not be repeated here.

[0086] In practice, each of the above units or structures can be implemented as an independent entity or can be arbitrarily combined to be implemented as the same or several entities. For the specific implementation of each of the above units or structures, please refer to the previous method embodiments, which will not be repeated here.

[0087] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0088] The above provides a detailed description of a method, apparatus, device, and computer-readable storage medium for dynamic adjustment of a buffer according to embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, those skilled in the art will recognize that there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A method for dynamically adjusting a buffer zone, characterized in that, include: Obtain information on the recording thread's call behavior and the playback thread's data writing characteristics; The recording thread is used to read audio data from the circular buffer, and the playback thread is used to write audio data to the circular buffer; Based on the call behavior information and the data writing characteristics, the target buffer capacity of the circular buffer is determined; The circular buffer is dynamically adjusted based on the target buffer capacity.

2. The method for dynamically adjusting the buffer according to claim 1, characterized in that, Determining the target buffer capacity of the circular buffer based on the call behavior information and the data write characteristics includes: Based on the call behavior information, the target call interval of the recording thread is determined; The target buffer capacity of the circular buffer is determined based on the target call interval and the data write characteristics.

3. The method for dynamically adjusting the buffer according to claim 2, characterized in that, The recording thread reads audio data from the circular buffer by calling the data reading module. The calling behavior information includes a first calling interval and a second calling interval. The first calling interval represents the historical average calling interval of the recording thread to the data reading module, and the second calling interval represents the most recent calling interval of the recording thread to the data reading module. Determining the target call interval for the recording thread based on the call behavior information includes: Obtain the first weight information corresponding to the first call interval; The first weight information and the first parameter information are calculated to obtain the second weight information corresponding to the second call interval; The first call interval and the second call interval are weighted and fused based on the first weight information and the second weight information to obtain the target call interval of the recording thread.

4. The method for dynamically adjusting the buffer according to claim 2, characterized in that, The data writing characteristics include the data writing interval and the length of data written in a single instance; Determining the target buffer capacity of the circular buffer based on the target call interval and the data write characteristics includes: Obtain the upper and lower limits of the capacity of the circular buffer; The first buffer capacity is obtained by calculating the target call interval, the single write data length, and the data write interval; The capacity of the second buffer is obtained by calculating the capacity of the first buffer and the upper limit of the capacity; The target buffer capacity of the circular buffer is obtained by calculating the capacity of the second buffer and the lower limit of the capacity.

5. The method for dynamically adjusting the buffer according to claim 1, characterized in that, The step of dynamically adjusting the circular buffer based on the target buffer capacity includes: The effective data length of the circular buffer is obtained by calculating the original buffer capacity, the tail pointer position, and the head pointer position of the circular buffer. Based on the effective data length and the tail pointer position, obtain effective audio data from the circular buffer; Based on the target buffer capacity, determine the updated circular buffer; The valid audio data is copied to the updated circular buffer, and the tail pointer position and the head pointer position are adjusted based on the position of the valid audio data in the updated circular buffer.

6. The method for dynamically adjusting the buffer according to claim 1, characterized in that, The method further includes: The target call interval and the first threshold of the recorded thread are calculated to obtain the third call interval; Based on the third call interval and the actual call interval of the recording thread, determine whether there is a call delay in the recording thread; When the recording thread experiences a call delay and the number of call delays reaches a second threshold, the tail pointer position of the circular buffer is adjusted to the head pointer position.

7. The method for dynamically adjusting the buffer according to claim 1, characterized in that, The method further includes: Receive the call request from the playback thread to the data writing module, and write the first audio data block into the circular buffer based on the head pointer position of the circular buffer; The head pointer position is adjusted based on the data length of the first audio data block; The method further includes: Receive the call request from the recording thread to the data reading module, and read the second audio data block from the circular buffer based on the tail pointer position of the circular buffer; The position of the tail pointer is adjusted based on the length of the second audio data block.

8. A buffer dynamic adjustment device, characterized in that, include: The data acquisition module is used to acquire the calling behavior information of the recording thread and the data writing characteristics of the playback thread; The recording thread is used to read audio data from the circular buffer, and the playback thread is used to write audio data to the circular buffer; A capacity determination module is used to determine the target buffer capacity of the circular buffer based on the call behavior information and the data write characteristics; The dynamic adjustment module is used to dynamically adjust the circular buffer based on the target buffer capacity.

9. A computer device, characterized in that, The computer device includes: One or more processors; Memory; and One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the buffer dynamic adjustment method of any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, It stores a computer program, which is loaded by a processor to perform the steps in the buffer dynamic adjustment method according to any one of claims 1 to 7.