An audio processing method, apparatus, electronic device, and readable storage medium

By adjusting the number of sampling points for audio frames in the buffer, the problem of uneven audio data caused by network latency jitter was solved, resulting in more stable audio playback, reduced latency, and improved playback quality.

CN117692443BActive Publication Date: 2026-11-20HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211105894.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-09
Publication Date
2026-11-20
Estimated Expiration
2042-09-09

AI Technical Summary

Technical Problem

Network latency jitter causes uneven reception of audio data, affecting audio playback and causing issues such as playback pauses and increased latency.

Method used

By storing audio frames in a buffer and adjusting the number of sampling points for each audio frame, the system dynamically adjusts the increase or decrease of sampling points based on the number of audio frames in the buffer, ensuring a constant playback speed and optimizing the playback time of audio frames.

Benefits of technology

It reduces audio playback latency, improves the continuity and quality of audio playback, and avoids data loss and playback interruption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117692443B_ABST
    Figure CN117692443B_ABST
Patent Text Reader

Abstract

The application discloses an audio processing method and device, electronic equipment and a readable storage medium. The method comprises the following steps: saving a received audio frame in a buffer; obtaining the number of audio frames saved in the buffer; reading out an audio frame to be played from the buffer, adjusting the number of sampling points in the audio frame to be played according to the number of audio frames; and playing the audio frame to be played after the number of sampling points is adjusted. The application solves the problem that the received audio data is not uniform due to network delay jitter, thereby affecting audio playing, reduces the delay of audio playing, and improves the effect of audio playing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of audio, and more specifically, to an audio processing method, apparatus, electronic device, and readable storage medium. Background Technology

[0002] With the development of the internet, users can listen to various audio content online, such as recorded or live audio streams. However, during network transmission, due to network jitter, even if the audio data sent at the sending end is uniform and continuous, the audio data received at the receiving end may be uneven. Sometimes there may be no audio data for a period of time, while at other times a large amount of audio data may be received in a short period.

[0003] Figure 1 This is a schematic diagram illustrating audio delay caused by network jitter according to an embodiment of this application, such as... Figure 1 As shown, A, B, C, and D are four audio data packets. One audio data packet is sent every 30 milliseconds (ms) at the sending end. However, the network latency of each audio data packet is different. The network latency for audio data packets A, C, and D is 10ms, while the network latency for B is 30ms. Therefore, their final arrival times at the receiving end are also different. Figure 1 In the example, A arrives at 40ms, B at 90ms, C at 100ms, and D at 130ms. However, during playback, a 30ms interval is still required. Therefore, even if B and C arrive at similar times, their playback interval must still be 30ms.

[0004] For situations like B and C where a large amount of data arrives at once, the built-in audio data buffer can handle the problem. However, if no audio data is received for a period of time, and the audio data buffer is empty, then there is no audio data to play, resulting in a playback pause. After the pause, the previously blocked data arrives shortly, followed by a continuous stream of data, which accumulates in the audio buffer. Since the audio playback rate is constant, this delay, caused by network latency, prevents the receiver from receiving audio data, and simultaneously exhausts the audio data in the playback buffer, forcing a brief interruption. However, no audio data is lost, as subsequent audio data continues to arrive, resulting in a persistent accumulation of data in the audio buffer. This accumulation increases the audio playback latency because later data must wait for the preceding data to finish playing before playback can resume. Summary of the Invention

[0005] This application provides an audio processing method, apparatus, electronic device, and readable storage medium to at least solve the problem of uneven received audio data caused by network latency jitter, which affects audio playback.

[0006] According to one aspect of this application, an audio processing method is provided, comprising: storing received audio frames in a buffer; obtaining the number of audio frames stored in the buffer; reading audio frames to be played from the buffer; adjusting the number of sampling points in the audio frames to be played according to the number of audio frames; and playing the audio frames to be played after adjusting the number of sampling points.

[0007] Furthermore, adjusting the number of sampling points in the audio frame to be played includes: discarding one sampling point every K sampling points to reduce the data volume of the audio frame to be played; or, adding one sampling point every K sampling points to increase the data volume of the audio frame to be played, where K is a natural number and K is less than the total number of sampling points in the audio frame to be played.

[0008] Furthermore, the value of K is determined based on the number of audio frames in the buffer, wherein, when it is necessary to reduce the number of sampling points, the value of K decreases as the number of audio frames in the buffer increases; and / or, when it is necessary to increase the number of sampling points, the value of K decreases as the number of audio frames in the buffer decreases.

[0009] Further, adjusting the number of sampling points in the audio frame to be played according to the number of audio frames includes: determining the range of the number of audio frames based on the number of audio frames in the buffer; adjusting the number of sampling points according to the range of the number of audio frames, wherein there are multiple ranges, and different ranges correspond to different adjusted numbers of sampling points.

[0010] Furthermore, the plurality of ranges includes ranges whose boundaries are integer multiples of S, where S is a natural number greater than 1, and S is determined according to the following formula:

[0011] S = [(Network latency / Normal playback duration of each audio frame)] + constant, where [] represents rounding up or rounding down, and the constant is a natural number.

[0012] Further, adjusting the number of sampling points according to the range of the number of audio frames includes: determining the value of K corresponding to the range of the number of audio frames, wherein a sampling point is discarded or added every K sampling points; and adjusting the number of sampling points according to the value of K corresponding to the range.

[0013] Further, reading the audio frame to be played from the buffer and adjusting the number of sampling points in the audio frame to be played according to the number of audio frames includes: reading the audio frame to be played from the buffer, wherein the audio frame to be played is an undecoded audio frame; decoding the audio frame to be played; and adjusting the number of sampling points in the decoded audio frame to be played according to the number of audio frames.

[0014] According to another aspect of this application, an audio processing apparatus is also provided, comprising: a receiving module for storing received audio frames in a buffer; an acquiring module for acquiring the number of audio frames stored in the buffer; an adjusting module for reading audio frames to be played from the buffer and adjusting the number of sampling points in the audio frames to be played according to the number of audio frames; and a processing module for playing the audio frames to be played after adjusting the number of sampling points.

[0015] Furthermore, the adjustment module is used to discard one sampling point every K sampling points to reduce the amount of data in the audio frame to be played; or, to add one sampling point every K sampling points to increase the amount of data in the audio frame to be played, wherein K is a natural number and K is less than the total number of sampling points in the audio frame to be played.

[0016] Furthermore, the value of K is determined based on the number of audio frames in the buffer, wherein, when it is necessary to reduce the number of sampling points, the value of K decreases as the number of audio frames in the buffer increases; and / or, when it is necessary to increase the number of sampling points, the value of K decreases as the number of audio frames in the buffer decreases;

[0017] Furthermore, the adjustment module is used to determine the range of the number of audio frames based on the number of audio frames in the buffer; and to adjust the number of sampling points based on the range of the number of audio frames, wherein there are multiple ranges, and the adjusted number of sampling points is different for different ranges.

[0018] Furthermore, the plurality of ranges includes ranges whose boundaries are integer multiples of S, where S is a natural number greater than 1, and S is determined according to the following formula:

[0019] S = [(Network latency / Normal playback duration of each audio frame)] + constant, where [] represents rounding up or rounding down, and the constant is a natural number.

[0020] Furthermore, the adjustment module is used to determine the value of K corresponding to the range of the number of audio frames, wherein a sampling point is discarded or added every K sampling points; and the number of sampling points is adjusted according to the value of K corresponding to the range.

[0021] Furthermore, the adjustment module is used to read the audio frame to be played from the buffer, wherein the audio frame to be played is an undecoded audio frame; decode the audio frame to be played; and adjust the number of sampling points in the decoded audio frame to be played according to the number of audio frames.

[0022] According to another aspect of this application, an electronic device is also provided, including a memory and a processor; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the above-described method steps.

[0023] According to another aspect of this application, a readable storage medium is also provided, on which computer instructions are stored, wherein the computer instructions, when executed by a processor, implement the above-described method steps.

[0024] In this embodiment, the received audio frames are stored in a buffer; the number of audio frames stored in the buffer is obtained; the audio frames to be played are read from the buffer, and the number of sampling points in the audio frames to be played is adjusted according to the number of audio frames; the audio frames to be played after adjusting the number of sampling points are played. This application solves the problem of uneven received audio data caused by network latency jitter, which affects audio playback, thereby reducing audio playback delay and improving the audio playback effect. Attached Figure Description

[0025] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0026] Figure 1 This is a schematic diagram illustrating audio delay caused by network jitter according to an embodiment of this application;

[0027] Figure 2 This is a flowchart of an audio processing method according to an embodiment of this application;

[0028] Figure 3 This is a time-based schematic diagram of normal audio playback according to an embodiment of this application;

[0029] Figure 4 This is a time-based schematic diagram of compressed audio playback according to an embodiment of this application;

[0030] Figure 5 This is a time-based schematic diagram of amplified audio playback according to an embodiment of this application;

[0031] Figure 6 This is a schematic diagram of audio processing using multiple buffers according to embodiments of this application; and,

[0032] Figure 7 This is a schematic diagram of audio processing after merging the buffer and threads according to an embodiment of this application. Detailed Implementation

[0033] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0034] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0035] First, let's explain the technical terms used in this embodiment. A digital-to-analog converter (D / A converter, or DAC for short) is used to convert digital signals into analog signals. An analog-to-digital converter (A / D converter, or ADC for short) is used to convert analog signals into digital signals, and its working mechanism is the opposite of that of a DAC. A system on a chip (SoC) is an integrated circuit or chip with a specific purpose, containing a software system. An integrated circuit built-in audio (Inter-IC Sound, or I2S) bus is a bus standard for audio data transmission between digital audio devices. The I2S bus uses separate wires to transmit clock and data signals, avoiding distortion caused by time differences and saving users the cost of purchasing specialized equipment to combat audio jitter. Direct Memory Access (DMA) allows hardware devices of different speeds to communicate without relying on a large interrupt load from the processor (CPU).

[0036] In existing technologies, due to network delays in audio data, the previously delayed audio data is sent back in a concentrated manner after the network recovers, resulting in a continuous accumulation of data in the audio buffer. This accumulation of data increases the audio playback delay. One approach is to directly discard the unplayed audio data in the buffer, but this results in audio data loss and is not a preferred method.

[0037] To address the aforementioned problems, the following embodiments adjust the sampling data included in the audio frames. By increasing or decreasing the sampling data in the audio frames without changing the playback speed, the playback duration can be increased or decreased, thereby resolving the audio playback problem caused by network latency. The following embodiments also provide an audio processing method. Figure 2 This is a flowchart of an audio processing method according to an embodiment of this application, such as... Figure 2 As shown below, Figure 2 The steps involved are explained.

[0038] Step S202: Save the received audio frames in a buffer.

[0039] Step S204: Obtain the number of audio frames stored in the buffer.

[0040] Step S206: Read the audio frame to be played from the buffer, and adjust the number of sampling points in the audio frame to be played according to the number of audio frames.

[0041] This step involves sampling points. The following explains audio sampling: Sound waves are mechanical waves, therefore possessing wavelength and amplitude characteristics. Wavelength corresponds to the time axis, and amplitude corresponds to the sample value axis. Waves are infinitely smooth and can be considered as composed of countless points. Since storage space is relatively limited, points on the wave must be sampled during digital encoding. The sampling process involves extracting the sample value of a specific point. The more points extracted per unit time, the richer the wavelength information obtained. Therefore, this step adjusts the number of sampling points in the audio frame. Because the amount of data included in this audio frame is adjusted, the playback time of this audio frame will also change accordingly at the same playback speed.

[0042] Step S208: Play the audio frame to be played after adjusting the number of sampling points.

[0043] The above steps take into account the number of audio frames in the buffer. This number reflects the relationship between audio frame reception and playback. Therefore, the playback time can be adjusted appropriately based on the number of audio frames in the buffer. For example, when there are many data frames in the buffer, the playback time can be shortened. Shortening the playback time means that more audio frames can be played within the same amount of time, thus reducing the number of data frames in the buffer. Considering that the playback speed is constant, the above steps adjust the amount of data in each audio frame by adjusting the number of sampling points, thereby adjusting the playback time of each audio frame. Therefore, these steps solve the problem of uneven received audio data caused by network latency jitter, which affects audio playback, thereby reducing audio playback delay and improving the audio playback effect.

[0044] When the number of audio frames stored in the buffer is relatively large, it indicates that the playback time needs to be shortened. In this case, the number of sampling points in the audio frames to be played can be reduced. After the number of sampling points in the audio frames is reduced, the playback time will also be shortened accordingly, allowing more audio frames to be played per unit time, thus reducing the number of audio frames stored in the buffer. When the number of audio frames stored in the buffer is relatively small, it indicates that there may be network latency, and the next audio frame to be played has not yet been received. In this case, the number of sampling points in the audio frames to be played can be increased. After the number of sampling points is increased, the playback time will also increase accordingly, which is equivalent to increasing the time available for receiving audio frames, providing a time basis for improving the continuity of audio playback.

[0045] The above analysis shows that increasing or decreasing the number of sampling points in an audio frame determines the playback time, which in turn affects the number of audio frames stored in the buffer. There are many ways to adjust the number of sampling points. For example, when increasing sampling points, they can be randomly added at different positions within the audio frame; conversely, when decreasing sampling points, sampling points with lower loudness within the audio frame can be selected and reduced. Regardless of the method used to adjust the number of sampling points, as long as the number of sampling points for the audio frame to be played is adjusted according to the number of audio frames in the buffer, the problems existing in the current technology can be solved.

[0046] To improve the playback quality of audio frames, as an optional implementation, sampling points can be added or removed at equal intervals within an audio frame. Specifically, adjusting the number of sampling points in the audio frame to be played can include the following steps: discarding one sampling point every K sampling points to reduce the data volume of the audio frame; or adding one sampling point every K sampling points to increase the data volume of the audio frame, where K is a natural number less than the total number of sampling points in the audio frame. With this optional implementation, the distance between the added or removed sampling points in the audio frame is the same, making the adjustment of sampling points relatively smooth. This ensures that the playback quality of the audio frame after the adjustment is not significantly different from that of the audio frames before the adjustment, thus guaranteeing a good listening experience for the user.

[0047] The aforementioned K value can be a pre-set fixed value. In another alternative embodiment, considering the different number of audio frames in the buffer, the aforementioned K value can also be determined based on the number of audio frames in the buffer, wherein, when it is necessary to reduce the number of sampling points, the value of K decreases as the number of audio frames in the buffer increases; and / or, when it is necessary to increase the number of sampling points, the value of K decreases as the number of audio frames in the buffer decreases.

[0048] For example, if the buffer contains a large number of audio frames, and the playback time of each audio frame needs to be shortened to play all the audio frames in the buffer as quickly as possible, then K can be chosen as 3. This means that one sample point is reduced every three sample points, reducing the original four sample points to three. Therefore, the data volume is reduced by 1 / 4, and the playback time is also reduced by 1 / 4. If the number of audio frames in the buffer continues to increase when K is chosen as 3, then the playback time of the audio frames needs to be further shortened. In this case, K can be chosen as 1, meaning the data volume is reduced by half, and the playback time is also reduced by 1 / 2. This example shows that when it is necessary to reduce the number of sample points, the value of K decreases as the number of audio frames in the buffer increases.

[0049] For example, when the number of audio frames in the buffer is relatively small, it's necessary to extend the playback time of each audio frame to wait for the next frame to be received. In this case, K can be chosen as 2, which is equivalent to adding one sample point every two sample points. This increases the amount of data in the audio frame by 1 / 3, and the playback time also increases by 1 / 3. If using K as 2 doesn't increase the number of audio frames in the buffer, then the value of K can be chosen as 1, meaning the amount of data in the audio frame increases by half, and the playback time also increases by half. This example shows that when it's necessary to increase the number of sample points, the value of K decreases as the number of audio frames in the buffer decreases.

[0050] Reducing sample points is relatively easy; simply delete the sample points to be reduced from the audio frame. For increasing sample points, obtain the values ​​of N sample points before and after the position where the sample point to be added is located, and then take the average of these values ​​as the value of the added sample point. In another optional implementation, when adding audio sample points, determine the position of the audio sample point to be added every K sample points, and the volume value of the added audio sample point. For example, first determine the position of the added audio sample point, which is N*K sample points after the addition, where N is the number of each audio sample point in the audio frame sequence before amplification, and K is the interval between adding an audio sample point. Next, determine the volume value of the added audio sample point, which is R, where R = (R(N*K) + R(N*K+1)) / 2, where R(N*K) is the volume value of the N*Kth audio sample point before amplification, and R(N*K+1) is the volume value of the N*K+1th audio sample point before amplification, which is the average of the two adjacent sample points at the insertion point. This processing method also ensures that the numerical difference between the added sampling points and the original sampling points is not significant, and the playback of audio frames will be relatively smooth.

[0051] As can be seen from the above implementation methods, when the number of audio frames in the buffer is large, the number of audio frame sampling points can be reduced; conversely, when the number of audio frames in the buffer is small, the number of audio frame sampling points can be increased. As an optional implementation method, the number of sampling points increased or decreased can be linked to the number of audio frames in the buffer. For example, the more audio frames in the buffer, the more sampling points are reduced; conversely, the fewer audio frames in the buffer, the more sampling points are increased. In this optional implementation method, adjusting the number of sampling points in the audio frame to be played based on the number of audio frames can include the following steps: determining the range of the number of audio frames in the buffer; adjusting the number of sampling points according to the range of the number of audio frames, wherein there are multiple ranges, and different ranges correspond to different adjusted sampling point numbers. Through this optional implementation method, the number of sampling points of the adjusted audio frame can be determined according to different ranges, thereby achieving better results.

[0052] The ranges in the above optional embodiments can be determined based on empirical values. Considering that the number of audio frames stored in the buffer is related to network latency, different ranges can also be determined based on network latency. In one optional embodiment, the plurality of ranges includes a range whose boundary is an integer multiple of S, where S is a natural number greater than 1, and S is determined according to the following formula: S = [(network latency / normal playback duration of each audio frame)] + constant, where [] represents rounding up or rounding down, and the constant is a natural number.

[0053] For example, different ranges can include: 1 to 2 seconds, 2 seconds to 3 seconds, 3 seconds to 6 seconds, and greater than 6 seconds. This optional implementation allows the range to be determined in relation to network latency, thereby better addressing audio playback issues caused by network latency.

[0054] The above optional embodiments can also be used in combination, that is, adjusting the number of sampling points according to the range of the number of audio frames may include the following steps: determining the value of K corresponding to the range of the number of audio frames, wherein a sampling point is discarded or added every K sampling points; adjusting the number of sampling points according to the value of K corresponding to the range.

[0055] For example, the range from S to 2S is selected as 4 as the K value, the range from 2S to 3S is selected as 3 as the K value, the range from 3S to 6S is selected as 4 as the K value, and the range greater than 6S is selected as 1 as the K value, etc.

[0056] For example, when the number of audio frames in the buffer is greater than 5*S frames, it means that there is a lot of data accumulated in the buffer. In this case, K is set to 1 for data compression playback. When the number of audio frames in the buffer is less than or equal to 5*S frames but greater than 3*S frames, K is set to 2 for data compression playback. When the number of audio frames in the buffer is less than or equal to 3*S frames but greater than S frames, K is set to 4 for data compression playback.

[0057] The following description uses an optional embodiment. In this optional embodiment, the above-mentioned process of adjusting the sampling points is called smoothing processing, and the buffer is called the audio receiving smoothing buffer (or simply smoothing buffer). In this optional embodiment, the key to audio smoothing processing is to dynamically adopt audio data amplification and compression strategies based on the amount of audio in the audio receiving smoothing buffer, thereby reducing the accumulated amount of audio data in the audio receiving smoothing buffer while ensuring the continuity of the played audio as much as possible.

[0058] Figure 3This is a time diagram illustrating normal audio playback according to an embodiment of this application; as shown in Figure 3, it describes the audio playback time required for a segment of audio data to play normally. Here, 120 milliseconds (ms) is considered to be the audio playback time required for one frame of audio data to play normally.

[0059] If the number of audio frames in the current audio receiving smoothing buffer is greater than S frames, the audio data needs to be reduced. After obtaining one frame of audio data, the audio data is decoded. For the decoded audio data, one sample point is discarded every K sampling points, where K is greater than or equal to 1 and K is less than the total number of sampling points per frame. In this optional embodiment, the device audio sampling rate is 48kHz (the device audio sampling rate is not less than 16kHz; a low audio sampling rate will cause audio distortion after compression). In this way, the amount of audio data in each frame is reduced by 1 / (K+1). Since the amount of audio data is reduced, but the audio playback speed remains unchanged, it is equivalent to increasing the audio playback speed. In the maximum case, the audio playback speed can be increased by 1 / 2 (corresponding to the case where K=1).

[0060] Assuming the smoothing buffer contains M audio frames, when M is greater than 5*S frames, it indicates a large amount of data has accumulated in the audio buffer. In this case, the data in the audio receiving smoothing buffer needs to be played out as soon as possible, and K is set to 1 for data compression playback. When M is less than or equal to 5*S frames but greater than 3*S frames, it indicates some data has accumulated in the audio receiving smoothing buffer, and K is set to 2 for data compression playback. When M is less than or equal to 3*S frames but greater than S frames, it indicates a small amount of data has accumulated in the audio receiving smoothing buffer, and K is set to 4 for data compression playback. When the number of audio data frames in the audio receiving smoothing buffer is less than or equal to S, it indicates that the data accumulation is small, and audio data compression playback is no longer performed. The size of S depends on the network latency and the normal playback duration of each audio frame. The minimum value of S = (network latency / normal playback duration of each audio frame) + constant. The constant (e.g., 1, 2, 3, etc., with 2 being a better value) is added because the network latency may be very small, but some audio data needs to be retained in the audio receiving smoothing buffer to handle occasional packet loss. If network latency is high, then more data can remain in the buffer to allow for buffering in case of network packet loss and retransmission or network jitter.

[0061] Figure 4 This is a time-based schematic diagram of compressed audio playback according to an embodiment of this application. Figure 4 The playback time performance of the compressed audio data is described, such as... Figure 4 As shown, the actual playback time of an audio frame that originally required 120ms to play became 80ms.

[0062] In addition, the amount of audio data per frame has been reduced to decrease audio latency, thus reducing the audio waiting time during each audio processing step. For example, if each frame of audio data originally took 40ms to process, reducing it to 10ms reduces the audio processing latency by 30ms per step. This improvement and optimization primarily involves adjusting the interval between audio data transmissions on the bus. For instance, instead of transmitting every 40ms, data is now transmitted every 10ms; and instead of decoding every 40ms, audio data is decoded every 10ms.

[0063] If the current audio frame count in the audio receiving smoothing buffer is equal to 1 frame, then the audio data needs to be amplified. After acquiring one frame of audio data, the audio data is decoded. For the decoded audio data, an additional sample point is added every K sampling points. The value of this added sample point is the average of the values ​​of the preceding and following sample points, where K is greater than or equal to 1 and less than the total number of sampling points per frame. The device's audio sampling rate is 48kHz (the device's audio sampling rate should not be lower than 16kHz; a lower audio sampling rate will cause audio distortion after compression). In this way, the data size of each frame of audio data is increased by 1 / (K+1). Since the audio data size increases, but the audio playback speed remains unchanged, it is equivalent to slowing down the audio playback speed. In the maximum case, the audio playback speed is reduced by 1 / 2 (corresponding to the case where K=1). Figure 5 This is a time-based schematic diagram of amplified audio playback according to an embodiment of this application; as shown below. Figure 5 As shown, the actual playback time of an audio frame that originally required 120ms to play became 180ms.

[0064] In the above optional implementation, a buffer is involved to buffer the received audio frames. If the audio frame needs to be decoded, a separate decoding buffer is typically set up. Setting multiple buffers increases the audio processing steps and may increase latency. Figure 6 This is a schematic diagram of audio processing using multiple buffers according to an embodiment of this application. The following is in conjunction with... Figure 6 The audio processing flow, which involves setting up multiple buffers and threads, is explained.

[0065] like Figure 6As shown, the audio device includes a playback unit and a capture unit. The playback unit can be a speaker, and the capture unit can be a microphone (including hanging microphones, wireless microphones, and array microphones), a pickup, a computer, etc. The sound captured by the capture unit is converted by an ADC and sent to the I2S receive queue, which can be a first-in-first-out (FIFO) queue, and then sent to the DMA. The DMA sends the audio frame to the I2S receive buffer, and then enters the encoding channel. It is encoded and encapsulated by the data processing thread through the Advanced Audio Coding (AAC) buffer. Then, it is sent to the network data transmission processing module through the callback send buffer using the data transmission thread via the send buffer. The network data transmission processing module buffers the audio data in the User Datagram Protocol (UDP) network data transmission queue buffer through the operating system (e.g., Linux kernel), and then sends the data to the DMA of the network card through the network send data buffer. The network card performs transmission processing through the data transmission FIFO queue.

[0066] For audio data reception, the audio device receives audio data sent from the network via a gigabit network interface card (GMAC). The data is then processed by the network interface card's DMA via a data receive FIFO queue. The data received by the network interface card is sent to the network interface card receive data buffer in the Linux kernel via DMA, and then processed through the UDP network data receive queue buffer. In other words, the audio data is processed by the Linux kernel, and after processing, the network data is received by the application software. The application software receives hidden data through a network data receive thread, a receive wait buffer, and a callback receive buffer. It then places the received audio data into the audio data receive buffer. The next level of software retrieves data from the audio data buffer, performs audio decoding (ACC decoding and AAC decapsulation) through a data processing thread, and places the decoded data into the audio decoding buffer. The audio data send thread then mixes the audio data and sends it to the I2S DMA send buffer. Finally, the I2S reads the audio data from the DMA buffer and sends it to the DAC via the I2S interface, ultimately transmitting it to the speaker for playback. It should be noted that when the AAC decoding buffer is full, the DSP will update the AAC decoding buffer status to control audio latency. However, this processing method results in the loss of audio data, making it a less than optimal approach.

[0067] exist Figure 6The AAC decoding buffer and decoding thread shown in the flowchart are redundant and can be optimized. Each additional audio buffer increases audio latency during audio processing, so the fewer audio buffers, the better. Similarly, each additional audio processing thread increases audio latency due to the non-real-time nature of scheduling, so the fewer threads involved in audio processing, the better.

[0068] As an optional implementation, a buffer can be used for receiving and decoding audio frames. Specifically, in this optional method, the audio frame to be played is read from the buffer (where the audio frame to be played is an undecoded audio frame); the audio frame to be played is directly decoded; then, the number of sample points in the decoded audio frame to be played is adjusted according to the number of audio frames. Using a single buffer for audio frame decoding and reception helps to shorten the latency of audio frame processing. It should be noted that decoding and adjusting the number of sample points can be completed by a single thread; if mixing is also required, decoding, adjusting the number of sample points, and mixing are also completed by the same thread. Figure 7 This is a schematic diagram of audio processing after merging the buffer and threads according to an embodiment of this application. The following is in conjunction with... Figure 7 The audio processing flow after merging the buffer and threads is explained.

[0069] like Figure 7 As shown, with Figure 6 The transmission process shown is the same. The audio device includes a playback unit and a capture unit. The playback unit can be a speaker, and the capture unit can be a microphone (including hanging microphones, wireless microphones, and array microphones), a pickup, a computer, etc. The sound captured by the capture unit is converted by an ADC and sent to the I2S receive queue, which can be a first-in-first-out (FIFO) queue, and then sent to the DMA. The DMA sends the audio frame to the I2S receive buffer, and then enters the encoding channel. AAC encoding and AAC encapsulation are performed using the data processing thread through the high-level audio encoding buffer. Then, the data is sent to the network data transmission processing module through the callback send buffer using the data transmission thread via the send buffer. The network data transmission processing module buffers the audio data in the User Datagram Protocol (UDP) network data transmission queue buffer through the operating system (e.g., Linux kernel), and then sends the data to the DMA of the network card through the network send data buffer. The network card performs transmission processing through the data transmission FIFO queue.

[0070] For audio reception, to optimize latency, the audio data decoding buffer is removed and merged with the reception buffer; the merged buffer is the reception smoothing buffer (i.e., ...). Figure 7The separate audio decoding thread is removed and merged with the existing audio data sending and mixing thread (including the receive buffer and network jitter smoothing buffer). The merged thread is the audio decoding and sending thread (i.e.,...). Figure 7 (Data processing thread in the system). After the network data receiving thread receives audio data from the Linux kernel, it puts the data into the audio receiving smoothing buffer. Then, the audio decoding and sending thread directly retrieves the data from the audio receiving smoothing buffer, performs audio decoding, audio smoothing, and audio mixing, and then places the audio data into the I2S sending DMA buffer before sending it out for playback via I2S. This reduces one audio processing thread and audio processing buffer, reducing some unnecessary audio latency.

[0071] In this embodiment, an electronic device is provided, including a memory and a processor. The memory stores a computer program, and the processor is configured to run the computer program to perform the methods described in the above embodiments.

[0072] The aforementioned program can run on a processor or be stored in memory (or computer-readable medium). Computer-readable medium includes both permanent and non-permanent, removable and non-removable media, and information storage can be achieved by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable medium does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0073] These computer programs may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes can be implemented using different modules, and different steps can be implemented using different modules.

[0074] This embodiment provides such a device. The device is referred to as an audio processing device, characterized in that it includes:

[0075] The receiving module is used to store the received audio frames in a buffer;

[0076] The acquisition module is used to acquire the number of audio frames stored in the buffer;

[0077] An adjustment module is used to read the audio frame to be played from the buffer and adjust the number of sampling points in the audio frame to be played according to the number of audio frames.

[0078] The processing module is used to play the audio frame to be played after adjusting the number of sampling points.

[0079] The system or apparatus is used to implement the functions of the methods in the above embodiments. Each module in the system or apparatus corresponds to each step in the method, as has been described in the method and will not be repeated here.

[0080] For example, the adjustment module is used to discard one sampling point every K sampling points to reduce the amount of data in the audio frame to be played; or, to add one sampling point every K sampling points to increase the amount of data in the audio frame to be played, where K is a natural number and K is less than the total number of sampling points in the audio frame to be played.

[0081] Optionally, the value of K is determined based on the number of audio frames in the buffer, wherein, when it is necessary to reduce the number of sampling points, the value of K decreases as the number of audio frames in the buffer increases; and / or, when it is necessary to increase the number of sampling points, the value of K decreases as the number of audio frames in the buffer decreases.

[0082] For example, the adjustment module is used to determine the range of the number of audio frames based on the number of audio frames in the buffer; and to adjust the number of sampling points based on the range of the number of audio frames, wherein there are multiple ranges, and the number of adjusted sampling points is different for different ranges.

[0083] Optionally, the plurality of ranges includes ranges whose boundaries are integer multiples of S, where S is a natural number greater than 1, and S is determined according to the following formula:

[0084] S = [(Network latency / Normal playback duration of each audio frame)] + constant, where [] represents rounding up or rounding down, and the constant is a natural number.

[0085] For example, the adjustment module is used to determine the value of K corresponding to the range of the number of audio frames, wherein a sampling point is discarded or added every K sampling points; and the number of sampling points is adjusted according to the value of K corresponding to the range.

[0086] For example, the adjustment module is used to read the audio frame to be played from the buffer, wherein the audio frame to be played is an undecoded audio frame; decode the audio frame to be played; and adjust the number of sampling points in the decoded audio frame to be played according to the number of audio frames.

[0087] The above optional implementation methods solve the problem of uneven received audio data caused by network latency jitter, which affects audio playback, thereby reducing audio playback delay and improving audio playback effect.

[0088] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. An audio processing method, characterized in that, include: The received audio frames are stored in a buffer; Get the number of audio frames stored in the buffer; The audio frame to be played is read from the buffer, wherein the audio frame to be played is an undecoded audio frame; Decode the audio frames to be played; The range of the number of audio frames in the buffer is determined based on the number of audio frames in the buffer, and the value of K corresponding to the range is determined based on the range of the number of audio frames in the buffer. There are multiple ranges, and the number of adjusted sampling points corresponding to different ranges is different. K is a natural number and is less than the total number of sampling points of the audio frames to be played. The number of sampling points in the decoded audio frame to be played is adjusted according to the value of K corresponding to the range. Specifically, one sampling point is discarded every K sampling points to reduce the amount of data in the audio frame to be played; or, one sampling point is added every K sampling points to increase the amount of data in the audio frame to be played. Play the audio frame to be played after adjusting the number of sampling points; Among these ranges, the bounds include ranges whose limits are integer multiples of S, where S is a natural number greater than 1. S is determined according to the following formula: S = [(network latency / normal playback duration of each audio frame)] + constant, where [ ] represents rounding up or rounding down, and the constant is a natural number; and, if the number of audio frames in the buffer is greater than S frames, the number of sampling points in the audio frames to be played is reduced.

2. The method according to claim 1, characterized in that, The value of K is determined based on the number of audio frames in the buffer, wherein, when it is necessary to reduce the number of sampling points, the value of K decreases as the number of audio frames in the buffer increases; and / or, when it is necessary to increase the number of sampling points, the value of K decreases as the number of audio frames in the buffer decreases.

3. An audio processing device, characterized in that, include: The receiving module is used to store the received audio frames in a buffer; The acquisition module is used to acquire the number of audio frames stored in the buffer; An adjustment module is used to read audio frames to be played from the buffer, wherein the audio frames to be played are undecoded audio frames; decode the audio frames to be played; determine the range of the number of audio frames based on the number of audio frames in the buffer, and determine the value of K corresponding to the range based on the range of the number of audio frames, wherein there are multiple ranges, and the number of adjusted sampling points corresponding to different ranges is different, wherein K is a natural number and less than the total number of sampling points of the audio frames to be played; adjust the number of sampling points in the decoded audio frames to be played according to the value of K corresponding to the range, wherein, every K sampling points, one sampling point is discarded to reduce the amount of data of the audio frames to be played; or, every K sampling points, one sampling point is added to increase the amount of data of the audio frames to be played; wherein, the multiple ranges include ranges whose boundaries are integer multiples of S, where S is a natural number greater than 1, and S is determined according to the following formula: S = [(network latency / normal playback duration of each audio frame)] + constant, wherein, [ The constant is a natural number and is used for rounding up or down; furthermore, if the number of audio frames in the buffer is greater than S frames, the number of sampling points in the audio frames to be played is reduced. The processing module is used to play the audio frame to be played after adjusting the number of sampling points.

4. An electronic device comprising a memory and a processor; wherein, The memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the steps of the method of claim 1 or 2.

5. A readable storage medium having computer instructions stored thereon, wherein, When executed by a processor, the computer instructions implement the steps of the method described in claim 1 or 2.

Citation Information

Patent Citations

  • Bluetooth audio data processing method, transmitter, receiver and transceiver

    CN113365129A