Audio playing method and device and electronic equipment
By generating audio transition data when the audio data buffer is idle and increasing the priority of the producer thread, the problem of interruption and stuttering caused by insufficient data in the audio player is solved, and the stability and efficiency of audio playback are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HANGZHOU EZVIZ SOFTWARE CO LTD
- Filing Date
- 2025-12-30
- Publication Date
- 2026-04-21
AI Technical Summary
During audio data playback, the audio player experiences interruptions and stuttering due to a lack of playable data, which is particularly difficult to resolve under high system load or uncertain scheduling conditions.
By generating audio transition data when the audio data buffer is idle and increasing the running priority of the audio producer thread, the buffer size is increased, ensuring a continuous supply of audio data.
It effectively prevents audio players from entering sleep or waiting states, reduces sound interruptions and stuttering, improves the stability and efficiency of audio playback, and reduces the probability of buffer idleness.
Smart Images

Figure CN121900903A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of audio playback technology, and in particular to an audio playback method, apparatus and electronic device. Background Technology
[0002] Traditional audio data production and playback rely heavily on the classic producer-consumer model. In some application scenarios, the business side needs to first generate playback data (producer) and then send the data to the audio player for playback (consumer). This process often involves issues related to XRUN (Underrun or Overrun). For example, if the business side is not ready when the audio player requests playback data, existing technical solutions may choose to wait for the business side to become ready, entering a sleep or waiting state.
[0003] If the sleep or waiting time is too long, the audio player may experience audio interruptions and stuttering due to a lack of playable data. Summary of the Invention
[0004] The purpose of this application is to provide an audio playback method, apparatus, and electronic device to reduce sound interruptions and stuttering during playback. The specific technical solution is as follows:
[0005] This application provides an audio playback method, in which the audio playback thread of an electronic device executes the following steps:
[0006] Receive data requests from the audio player;
[0007] Determine if the audio data buffer is currently empty; the audio data buffer is written to the audio data to be played in real time by the audio producer thread.
[0008] If the audio buffer is not currently empty, read audio data from the audio data buffer and return it to the audio player for playback;
[0009] When the audio data buffer is currently empty, audio transition data is generated, injected into the audio buffer, and returned to the audio player for playback; the running priority of the audio producer thread is increased so that the processor of the electronic device responds to the audio data writing operation of the audio producer thread first; and the size of the audio data buffer is increased.
[0010] In some embodiments, the audio data buffer is a circular buffer;
[0011] The audio producer thread writes audio data to the circular buffer in units of audio frames; the audio playback thread reads audio data from the circular buffer in units of audio frames.
[0012] In some embodiments, generating audio transition data includes: generating content-rich audio transition data related to the played audio data based on the current system load state; or generating content-free silent audio transition data.
[0013] In some embodiments, generating content-rich audio transition data related to the played audio data based on the current system load status; or generating content-free silent audio transition data, includes:
[0014] The system obtains the current system load status. If the current load is lower than a preset threshold, it performs signal analysis on the recorded previously played audio frame to obtain the signal characteristics of the previous audio frame. Based on the obtained signal characteristics, it predicts the next audio frame as an audio transition frame. If the current load is not lower than the preset threshold, it generates a silence frame as an audio transition frame.
[0015] The step of injecting the generated audio transition data into the audio buffer includes: writing the generated audio transition frame into the circular buffer.
[0016] In some embodiments, the write pointer and read pointer of the circular buffer correspond to the same position in the initial state;
[0017] Each time the audio producer thread writes an audio frame, it moves the write pointer of the circular buffer by one position; each time the audio playback thread reads an audio frame, it moves the read pointer of the circular buffer by one position.
[0018] The method of determining whether the audio data buffer is currently empty includes: determining whether there is an audio frame at the position corresponding to the current read pointer; if there is, the audio data buffer is not currently empty; if not, the audio data buffer is currently empty; or, determining whether the positions corresponding to the current read pointer and write pointer are the same; if so, the audio data buffer is currently empty; if not, the audio data buffer is not currently empty.
[0019] The step of injecting the generated audio transition data into the audio buffer includes: writing the generated audio transition frame to the position corresponding to the current read pointer.
[0020] In some embodiments, increasing the running priority of the audio producer thread includes:
[0021] Obtain the identifier of the audio producer thread;
[0022] Based on the identifier of the audio producer thread, the priority index of the audio producer thread is configured to be higher than the current priority.
[0023] In some embodiments, after injecting the generated audio transition data into the audio buffer and returning it to the audio player for playback, the method further includes: recording the increased running priority of the audio playback thread.
[0024] This application also provides an audio playback device, including:
[0025] The request receiving module is used to receive data requests sent by the audio player;
[0026] The idle detection module is used to determine whether the audio data buffer is currently idle; the audio data buffer is written to the audio to be played by the audio producer thread in real time.
[0027] The first playback module is used to read audio data from the audio data buffer and return it to the audio player for playback when the audio buffer is not currently empty;
[0028] The second playback module is used to generate audio transition data when the audio data buffer is currently empty, inject the generated audio transition data into the audio buffer, and return it to the audio player for playback; and to increase the running priority of the audio producer thread so that the processor of the electronic device responds to the audio data writing operation of the audio producer thread first; and to increase the size of the audio data buffer.
[0029] This application also provides an electronic device, including:
[0030] Memory, used to store computer programs;
[0031] The processor, when executing a program stored in memory, implements any of the above-mentioned audio playback methods.
[0032] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the above-described audio playback methods.
[0033] Beneficial effects of the embodiments in this application:
[0034] This application provides an audio playback method, apparatus, and electronic device. The audio playback method generates audio transition data when the audio data buffer is currently empty, keeping the audio player in playback mode and preventing it from entering a sleep or waiting state. This reduces sound interruptions and stuttering during playback due to a lack of playable data. Simultaneously, by increasing the running priority of the audio producer thread, the processor can prioritize responding to audio data write operations from the audio producer thread, ensuring timely replenishment of audio data in the audio data buffer and further reducing sound interruptions and stuttering. Moreover, by increasing the size of the audio data buffer, the producer thread can write more audio frames, thereby reducing the probability of the audio data buffer entering an empty state again, ensuring more stable operation of the entire audio link.
[0035] In addition, in this embodiment, the audio playback thread and the audio producer thread read and write to the same audio buffer. Compared with the prior art, which allocates memory separately for the audio playback thread and the audio producer thread and requires copying and moving between the two memory blocks during playback, this not only reduces memory space usage but also reduces memory copying and moving operations, thereby improving the efficiency of audio production and playback.
[0036] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0037] To more clearly illustrate the technical solutions in the embodiments of this application 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 of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0038] Figure 1 A flowchart illustrating an example of an audio playback method provided in an embodiment of this application.
[0039] Figure 2 A flowchart illustrating another example of an audio playback method provided in an embodiment of this application.
[0040] Figure 3 The following is an interactive flowchart illustrating another example of the audio playback method provided in the embodiments of this application.
[0041] Figure 4 A schematic diagram of an example of an audio playback device provided in this application embodiment.
[0042] Figure 5A schematic diagram of the structure of an example electronic device provided in this application embodiment. Detailed Implementation
[0043] 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 based on this application are within the scope of protection of this application.
[0044] To reduce the occurrence of sound interruptions and stuttering during audio playback, this application provides an audio playback method, apparatus, and electronic device, which will be described below.
[0045] See Figure 1 , Figure 1 A flowchart illustrating an example of an audio playback method provided in an embodiment of this application. This audio playback method, executed by the audio playback thread of an electronic device, includes the following steps:
[0046] Step S101: Receive a data request from the audio player;
[0047] Step S102: Determine whether the audio data buffer is currently empty; if the audio buffer is not currently empty, proceed to step S103; if the audio data buffer is currently empty, proceed to step S104.
[0048] The audio data buffer is written with audio data to be played in real time by the audio producer thread;
[0049] Step S103: Read audio data from the audio data buffer and return it to the audio player for playback;
[0050] Step S104: Generate audio transition data, inject the generated audio transition data into the audio buffer, and return it to the audio player for playback; increase the running priority of the audio producer thread so that the processor of the electronic device responds to the audio data writing operation of the audio producer thread first; and increase the size of the audio data buffer.
[0051] The audio playback method provided in this application can generate audio transition data when the audio data buffer is currently empty, allowing the audio player to maintain playback and preventing it from entering a sleep or waiting state. This reduces the occurrence of sound interruptions and stuttering during playback due to a lack of playable data. Simultaneously, by increasing the running priority of the audio producer thread, the processor can prioritize responding to the audio data writing operations of the audio producer thread, ensuring timely replenishment of audio data in the audio data buffer. This further reduces the occurrence of sound interruptions and stuttering during playback due to a lack of playable data. Furthermore, by increasing the size of the audio data buffer, the producer thread can write more audio frames, thereby reducing the probability of the audio data buffer entering an empty state again, ensuring more stable operation of the entire audio link.
[0052] In addition, in this embodiment, the audio playback thread and the audio producer thread read and write to the same audio buffer. Compared with the prior art, which allocates different memory areas for the audio playback thread and the audio producer thread respectively, and requires copying and moving between the two memory areas during playback, this not only reduces memory space usage, but also reduces memory copying and moving operations, thereby improving the efficiency of audio production and playback.
[0053] In some embodiments, the audio data buffer is a circular buffer; the audio producer thread writes audio data to the circular buffer in units of audio frames; the audio playback thread reads audio data from the circular buffer in units of audio frames. That is, after obtaining the audio data, the audio producer thread writes the audio data frame by frame into the circular buffer, and the audio playback thread reads one audio frame from the circular buffer and returns it to the audio player for playback each time it receives an audio data request from the audio player. Therefore, as... Figure 1 As shown, the audio playback thread continuously receives data requests from the audio player until playback ends.
[0054] In some embodiments, the audio transition data can be content-rich audio transition data generated based on the current system load state and related to the played audio data; or, content-free silent audio transition data can be generated. For example, when the system load is below a preset threshold, content-rich audio transition data can be predicted based on the last played audio data; or, when the system load is below a preset threshold, content-free silent audio transition data can be generated.
[0055] In this way, regardless of whether the current system load is high or low, audio transition data can be generated for playback, and the generated audio transition frames are written into the circular buffer, so that the audio player can keep playing.
[0056] For the specific procedures of audio playback, please refer to [link / reference]. Figure 2 , Figure 2 A flowchart illustrating another example of an audio playback method provided in an embodiment of this application, executed by an audio playback thread of an electronic device, includes the following steps:
[0057] Step S201: Initialize system parameters.
[0058] In this embodiment, the audio data buffer is a circular buffer; the audio producer thread writes audio data to the circular buffer in units of audio frames; the audio playback thread reads audio data from the circular buffer in units of audio frames.
[0059] In this step, you can configure the circular buffer size, system load threshold, frame interpolation algorithm parameters, etc. The system load threshold can be set based on the CPU utilization rate of the electronic device; for example, a CPU utilization rate exceeding 70% is considered high load, and below 70% is considered low load.
[0060] Step S202: Receive an audio frame request from the audio player.
[0061] Step S203: Determine whether the audio data buffer is empty. If not, proceed to step S204; if yes, proceed to step S205.
[0062] In this step, it can be to determine whether the circular buffer is empty.
[0063] In some embodiments, the write pointer and read pointer of the circular buffer correspond to the same position in the initial state; the audio producer thread moves the write pointer of the circular buffer by one position every time it writes an audio frame; the audio playback thread moves the read pointer of the circular buffer by one position every time it reads an audio frame.
[0064] In this scenario, determining whether the audio data buffer is currently empty can include: checking if there is an audio frame at the current read pointer position; if so, the audio data buffer is not currently empty; otherwise, it is empty. It's understandable that in an empty state, the read and write pointers are at the same position. Therefore, during playback, checking if the read and write pointers are at the same position can also determine whether the audio data buffer is currently empty. If they are at the same position, the audio data buffer is empty; if they are not, it is not empty.
[0065] Step S204: Return an audio frame to the audio player. Then proceed to step S211.
[0066] In this step, the audio playback thread reads audio frames from the circular buffer and returns them to the audio player for playback.
[0067] Step S205: Detect system load. Under low load, proceed to step S206; under high load, proceed to step S207.
[0068] In this step, the current CPU utilization rate can be read. If the current CPU utilization rate is lower than a preset threshold such as 70%, the current load is determined to be low load; if it is higher than 70%, the current load is determined to be high load.
[0069] Step S206: Predict audio transition frames using the LPC (Linear Predictive Coding) algorithm. Then proceed to step S208.
[0070] In this embodiment, the audio frame is recorded before each read audio frame is returned to the audio player for playback. If the next audio frame to be played is not audio transition data, the next frame is used to overwrite the current audio frame before returning it to the audio player for playback. If the next audio frame to be played is audio transition data, the previously recorded audio frame is retained.
[0071] In this step, the LPC algorithm can be used to first analyze the signal of the previous audio frame to obtain the signal characteristics of the previous audio frame, and then predict the next audio frame with content based on the obtained signal characteristics, which serves as the audio transition frame.
[0072] Step S207: Generate a silent audio transition frame.
[0073] In this step, a silent audio transition frame with no content can be generated. For example, a completely zero audio frame.
[0074] Step S208: Inject the audio transition frame into the playback stream.
[0075] Specifically, in this embodiment, the audio transition frame predicted in step S206 or the silent audio transition frame generated in step S207 can be written into the circular buffer.
[0076] In this embodiment, when the audio playback thread is idle, it generates an audio transition frame and injects it into the playback stream for playback. This execution process requires a certain amount of time, during which the audio producer thread can generate new audio frames and write them into the audio data buffer, ensuring continuous audio playback. This execution time effectively provides the audio producer thread with an asynchronous generation window, preventing the audio playback thread from entering a waiting or sleeping state during playback and failing to immediately resume from a sleeping state to a ready state. Therefore, it resolves the potential for audio playback stuttering during the recovery process. In this embodiment, injecting an audio transition frame replaces the sleeping and waiting in existing technologies, completely avoiding the risks caused by the uncertainty of operating system thread scheduling.
[0077] Step S209: Notify the scheduler to increase the priority of the producer thread.
[0078] In this step, the audio playback thread notifies the thread scheduler in the electronic device's system to increase the priority of the producer thread.
[0079] In this step, the PID (Process ID) of the audio producer thread can be obtained first; then, based on the PID, the priority index of the audio producer thread can be configured to be higher than the current priority.
[0080] Specifically, the priority of a producer thread can be increased by configuring its nice value to be lowered, ensuring that the producer thread can promptly preempt CPU resources when writing audio frames to the circular buffer next time. Taking Linux as an example, each thread has a unique PID, and the system provides an interface to adjust the thread's nice value based on the PID. The nice value typically ranges from -20 to 19, with lower values indicating higher priority. Increasing the priority ensures that the audio producer thread is called first. In this step, if the current audio producer thread's nice value is 18, the default value can be lowered, for example, by 3, adjusting the nice value to 15. In practical applications, the adjusted value can be set based on experience. No restrictions are imposed here.
[0081] Step S210: Update system status.
[0082] In this step, the increased running priority of the audio playback thread can be recorded, and the size of the audio data buffer can be increased.
[0083] In this embodiment, increasing the size of the audio data buffer, such as increasing the size of the circular buffer, allows the producer thread to write more audio frames, thereby reducing the probability of the audio data buffer entering an idle state next time and ensuring more stable operation of the entire audio link.
[0084] Step S211: Determine if an end command has been received. If yes, execute S212 to end; otherwise, return to step S202 to receive the next audio frame request from the audio player.
[0085] In this embodiment, the end command can be generated by the electronic device's system based on user operations, such as closing related software.
[0086] In existing technologies, according to the CPU scheduling strategy, if the audio playback thread enters sleep mode and is subsequently awakened, its timely awakening depends on the thread's priority and system load. The awakening time can vary significantly and depends on the system's scheduling resources. Therefore, this problem is frequently triggered on performance-constrained devices, resulting in intermittent audio playback for the user. In this embodiment, not only is the priority of the audio producer thread increased, but also, based on system load, audio transition frames with content are generated when the load is low, while silent audio transition frames are generated when the load is high. This avoids excessive impact on system load and further maintains the continuity of audio playback.
[0087] In some embodiments, the audio data buffer can be a circular buffer, and based on the MMAP (memory-mapped image) mechanism, the generated audio transition frames can be directly mapped to the circular buffer. For details, see [link to documentation]. Figure 3 , Figure 3 An interactive flowchart illustrating yet another example of the audio playback method provided in this application embodiment. The process includes:
[0088] Step 301, Initial state: Read / write pointers aligned.
[0089] In this embodiment, based on the MMAP (Memory Mapping Mapping) mechanism, the audio data buffer adopts a circular buffer. MMAP is a memory mapping mechanism provided by the operating system. Taking the Linux operating system as an example, the audio playback thread can request a contiguous physical memory block of DMA (Direct Memory Access) to serve as an audio data buffer. The audio producer thread and the audio playback thread write or read audio frames by reading the read / write pointers of this memory area. When it is necessary to insert an audio transition frame, the audio playback thread can generate the audio transition frame and read the read / write pointers of this memory area. Based on the current read / write pointer status, the audio transition frame can be directly written to this memory area, reducing memory copying and movement.
[0090] In this step, initially, the read and write pointers point to the same location in the circular buffer.
[0091] Step 302: The audio data acquisition device sends audio data to the audio producer thread in real time.
[0092] In practical applications, such as remote video surveillance, when users connect to the monitoring equipment via their mobile phones to view the monitored area (such as indoors in a home), if they need to make a call indoors, the mobile phone acts as an audio data acquisition device, sending the collected user's voice data to the indoor monitoring equipment.
[0093] In this step, the audio producer thread running the indoor monitoring equipment receives voice audio data sent by the user in real time.
[0094] Step 303: The audio producer thread writes the audio frame to the write pointer position.
[0095] Step 304: The audio producer thread updates the write pointer.
[0096] In this embodiment, the audio producer thread writes audio data frame by frame into a circular buffer. After each audio frame is written, the write pointer is moved forward one position.
[0097] In this embodiment, the audio producer thread executes steps 303 and 304 repeatedly to form an audio write stream that writes audio data to a circular buffer.
[0098] Step 305: The audio player sends an audio frame request to the audio playback thread.
[0099] Step 306: The audio playback thread determines whether the circular buffer is empty. If not, proceed to step 307; if yes, proceed to step 308.
[0100] Step 307: The audio playback thread reads an audio frame from the read pointer position. Then proceed to step 311.
[0101] Under normal circumstances, i.e., when the circular buffer is not empty, the audio producer thread writes audio frames to the circular buffer faster than the audio playback thread reads audio frames from it. The read pointer position lags behind the write pointer position; the audio frame has already been written to the read pointer position, and the audio playback thread can directly read the audio frame from the read pointer position. After reading, the read pointer is moved forward one position.
[0102] Step 308: The audio playback thread generates an audio transition frame.
[0103] When the circular buffer is unloaded, as before Figure 2 In steps S206 and S207, the audio playback thread generates a silent audio transition frame with no content when the load is high, and predicts an audio transition frame with content when the load is low.
[0104] In this embodiment, the running priority of the audio producer thread can be further increased, so that the processor of the electronic device responds to the audio data writing operation of the audio producer thread first. At the same time, the size of the circular buffer can be increased, allowing the producer thread to write more audio frames, thereby reducing the probability of the circular buffer entering an idle state again, and ensuring more stable operation of the entire audio link.
[0105] Step 309: The audio playback thread writes the audio transition frame to the circular buffer.
[0106] Specifically, when the circular buffer is empty, the read pointer and write pointer both point to the same location where there is no data. At this time, the audio playback thread writes the audio transition frame to this location where there is no data.
[0107] Step 310: The audio playback thread updates the write pointer.
[0108] Step 311: The audio playback thread updates the read pointer.
[0109] Step 312: The audio playback thread returns an audio frame to the player.
[0110] In this step, the audio playback thread can return audio frames read from the circular buffer, or audio transition frames produced by it, to the player.
[0111] In this embodiment, steps 305 to 312 are executed cyclically to form an audio playback stream.
[0112] In this embodiment, when an empty buffer is detected, a content-rich audio transition frame or a silent audio transition frame is generated in real time and injected into the audio playback stream. This achieves two goals: first, zero-latency response to playback requests to avoid audio interruption; and second, reserving an asynchronous generation time window for data producers to ensure continuous audio data supply. Furthermore, by increasing the priority of the producer thread, audio stuttering and frame dropping issues can be completely resolved, especially in scenarios with high system load where the CPU cannot respond promptly to stuttering and frame dropping triggered by the audio producer thread.
[0113] Corresponding to the audio playback method described above, this application also provides an audio playback device. See [link to related documentation]. Figure 4 Figure 4 A schematic diagram of an example structure of an audio playback device provided in this application embodiment. The audio playback device includes:
[0114] The request receiving module 401 is used to receive data requests sent by the audio player.
[0115] The idle detection module 402 is used to determine whether the audio data buffer is currently idle; the audio data buffer is written to the audio data to be played in real time by the audio producer thread.
[0116] The first playback module 403 is used to read audio data from the audio data buffer and return it to the audio player for playback when the audio buffer is not currently empty;
[0117] The second playback module 404 is used to generate audio transition data when the audio data buffer is currently empty, inject the generated audio transition data into the audio buffer, and return it to the audio player for playback; and to increase the running priority of the audio producer thread so that the processor of the electronic device responds to the audio data writing operation of the audio producer thread first; and to increase the size of the audio data buffer.
[0118] The audio playback device provided in this application corresponds to the audio playback method described above and can achieve the same beneficial effects as the audio playback method.
[0119] This application also provides an electronic device, such as... Figure 5 As shown, it includes:
[0120] Memory 501 is used to store computer programs;
[0121] When processor 502 executes the program stored in memory 501, it performs the following steps:
[0122] Receive data requests from the audio player;
[0123] Determine if the audio data buffer is currently empty; the audio data buffer is written to the audio data to be played in real time by the audio producer thread.
[0124] If the audio buffer is not currently empty, read audio data from the audio data buffer and return it to the audio player for playback;
[0125] When the audio data buffer is currently empty, audio transition data is generated, injected into the audio buffer, and returned to the audio player for playback; the running priority of the audio producer thread is increased so that the processor of the electronic device responds to the audio data writing operation of the audio producer thread first; and the size of the audio data buffer is increased.
[0126] Furthermore, the aforementioned electronic device may also include a communication bus and / or a communication interface, with the processor 502, communication interface, and memory 501 communicating with each other via the communication bus.
[0127] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0128] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0129] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0130] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0131] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described audio playback methods.
[0132] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to perform any of the audio playback methods described above.
[0133] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a solid-state drive (SSD), etc.
[0134] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0135] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0136] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. An audio playback method, characterized in that, The audio playback thread of the electronic device performs the following steps: Receive data requests from the audio player; Determine if the audio data buffer is currently empty; the audio data buffer is written to the audio data to be played in real time by the audio producer thread. If the audio buffer is not currently empty, read audio data from the audio data buffer and return it to the audio player for playback; When the audio data buffer is currently empty, audio transition data is generated, injected into the audio buffer, and returned to the audio player for playback; the running priority of the audio producer thread is increased so that the processor of the electronic device responds to the audio data writing operation of the audio producer thread first; and the size of the audio data buffer is increased.
2. The audio playback method according to claim 1, characterized in that, The audio data buffer is a circular buffer; The audio producer thread writes audio data to the circular buffer in units of audio frames; the audio playback thread reads audio data from the circular buffer in units of audio frames.
3. The audio playback method according to claim 2, characterized in that, The generation of audio transition data includes: generating audio transition data with content related to the played audio data based on the current system load status; or generating silent audio transition data without content.
4. The audio playback method according to claim 3, characterized in that, Based on the current system load status, generate content-rich audio transition data related to the played audio data; Alternatively, generate silent audio transition data without content, including: The system obtains the current system load status. If the current load is lower than a preset threshold, it performs signal analysis on the recorded previously played audio frame to obtain the signal characteristics of the previous audio frame. Based on the obtained signal characteristics, it predicts the next audio frame as an audio transition frame. If the current load is not lower than the preset threshold, it generates a silence frame as an audio transition frame. The step of injecting the generated audio transition data into the audio buffer includes: writing the generated audio transition frame into the circular buffer.
5. The audio playback method according to claim 2, characterized in that, The write pointer and read pointer of the circular buffer correspond to the same position in the initial state; Each time the audio producer thread writes an audio frame, it moves the write pointer of the circular buffer by one position; each time the audio playback thread reads an audio frame, it moves the read pointer of the circular buffer by one position. The method of determining whether the audio data buffer is currently empty includes: determining whether there is an audio frame at the position corresponding to the current read pointer; if there is, the audio data buffer is not currently empty; if not, the audio data buffer is currently empty; or, determining whether the positions corresponding to the current read pointer and write pointer are the same; if so, the audio data buffer is currently empty; if not, the audio data buffer is not currently empty. The step of injecting the generated audio transition data into the audio buffer includes: writing the generated audio transition frame to the position corresponding to the current read pointer.
6. The audio playback method according to claim 1, characterized in that, The step of increasing the running priority of the audio producer thread includes: Obtain the identifier of the audio producer thread; Based on the identifier of the audio producer thread, the priority index of the audio producer thread is configured to be higher than the current priority.
7. The audio playback method according to claim 1, characterized in that, After injecting the generated audio transition data into the audio buffer and returning it to the audio player for playback, the method further includes: recording the increased running priority of the audio playback thread.
8. An audio playback device, characterized in that, include: The request receiving module is used to receive data requests sent by the audio player; The idle detection module is used to determine whether the audio data buffer is currently idle; the audio data buffer is written to the audio to be played by the audio producer thread in real time. The first playback module is used to read audio data from the audio data buffer and return it to the audio player for playback when the audio buffer is not currently empty; The second playback module is used to generate audio transition data when the audio data buffer is currently empty, inject the generated audio transition data into the audio buffer, and return it to the audio player for playback; and to increase the running priority of the audio producer thread so that the processor of the electronic device responds to the audio data writing operation of the audio producer thread first; and to increase the size of the audio data buffer.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-7.