Audio playing method and electronic equipment

By setting up multiple cache and audio devices in the electronic device, the audio data storage and mixing of multiple processes is solved, and the problems of audio delay and process exclusiveness in the prior art are improved.

CN119690370APending Publication Date: 2025-03-25HUAWEI DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311249007.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-25
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

In the prior art, the process of audio data from the application program to the hardware device is complex, resulting in an increase in the delay of playing audio, a decrease in user experience, and when one process exclusively occupies the audio device, other processes cannot speak.

Method used

A method of playing audio is provided. By setting at least two caches and audio devices in an electronic device, the process stores the original audio data in each cache, and the audio device obtains the audio data to be played from the cache for mixing and playing, so as to realize that multiple processes are vocalizing at the same time.

Benefits of technology

It reduces the delay in audio data transmission, improves the problem of multiple processes simultaneous voice, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690370A_ABST
    Figure CN119690370A_ABST
Patent Text Reader

Abstract

The invention provides an audio playing method and electronic equipment, and relates to the field of terminals, the audio playing method is applied to the electronic equipment, the electronic equipment comprises at least two caches and audio equipment, each cache in the at least two caches is used for storing data of at least one process, and the audio equipment is used for playing audio. The method comprises the following steps: storing original audio data of each process in the at least one process to a cache corresponding to each process; the audio device obtains to-be-played audio data from the at least two caches, wherein the to-be-played audio data comprises the original audio data or data obtained by mixing at least two paths of original audio; the audio device carries out sound mixing on the obtained audio data to be played to obtain the audio data to be played after sound mixing; and the audio equipment plays the audio data to be played after audio mixing. According to the technical scheme provided by the invention, at least two processes can produce sound through the audio equipment, and the time delay of sound production is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of terminals, and in particular to a method for playing audio and an electronic device. Background Art

[0002] Audio playback is an important device capability of electronic devices. Through this device capability, users can be provided with a variety of user experiences such as playing music, playing videos, recording and making voice calls. With the continuous development of terminal technology, the compatibility and scalability of this device capability are also increasing. For example, it can play the sounds of more applications and beautify the sounds. However, it also lengthens the process of audio data from applications to hardware devices, which increases the delay of audio playback and reduces the user experience.

[0003] In the prior art, an application can monopolize an audio device, and the audio data of the application can be directly input into the cache corresponding to the audio device, thereby reducing the delay when playing the audio data of the application. However, this will cause other applications to be unable to use the audio device, that is, unable to play the sounds of other applications. Summary of the invention

[0004] In view of this, the present application provides a method for playing audio and an electronic device, which can enable at least two processes to emit sound through an audio device and reduce the delay of the sound.

[0005] In order to achieve the above-mentioned objectives, in a first aspect, an embodiment of the present application provides a method for playing audio, which is applied to an electronic device, wherein the electronic device includes at least two caches and an audio device, each of the at least two caches is used to store data of at least one process, and the method includes: storing the original audio data of each process in the at least one process to the cache corresponding to each process; the audio device obtains audio data to be played from the at least two caches respectively, and the audio data to be played includes the original audio data or data obtained by mixing at least two channels of the original audio; the audio device mixes the obtained audio data to be played to obtain the mixed audio data to be played; and the audio device plays the mixed audio data to be played.

[0006] In an embodiment of the present application, an electronic device includes at least two buffers and an audio device, and each of the at least two buffers is used to store data of at least one process. The original audio data of each process in at least one process can be stored in the buffer corresponding to each process, so the audio device can obtain the audio data to be played from at least two buffers respectively, and the audio data to be played includes the original audio data or the data obtained by mixing at least two original audios. The audio device obtains the audio data to be played and mixes the audio data to be played to obtain the mixed audio data to be played, and then plays the mixed audio data to be played. On the one hand, the transmission of the original audio data can be realized between the process and the audio device through only one read and write buffer, thereby reducing the delay of playing the original audio data. On the other hand, by providing at least two buffers, it is possible to realize that two or more processes transmit the original audio data to the audio device, improving the problem that other processes cannot make sound due to one process monopolizing the audio device.

[0007] If a cache stores data of a process, the data of the process can be isolated and protected, thereby improving the privacy and security of the data. In some implementations, different processes can belong to the same application, or different processes can belong to different applications.

[0008] In some implementations, the audio device may obtain the to-be-played audio data from at least two buffers, and mix the obtained at least two channels of to-be-played audio data.

[0009] In some implementations, a process may obtain a cache corresponding to the process through an audio service. Exemplarily, the process may send a cache allocation request to an audio device (specifically, an audio driver of the audio device) through the audio service, and the audio device allocates the corresponding cache to the process from the device buffer of the audio device.

[0010] In some implementations, each channel of original audio data may be regarded as an array, and at least two channels of original audio data may be superimposed, thereby achieving mixing of the two channels of original audio data.

[0011] In some embodiments, the at least two caches include at least one first cache and / or at least one second cache, the first cache is used to store data of one of the processes, and the second cache is used to store data of at least two of the processes.

[0012] In some implementations, the first cache is used to store data of a first process, and storing the original audio data of each of the at least one process in the cache corresponding to each process includes: storing the first original audio data of the first process in the first cache.

[0013] In some embodiments, the electronic device includes at least two first buffers, and each first buffer can store data of a process. The first process can store the original audio data of the process in the first buffer corresponding to the first process, and the audio device can obtain the original audio data from the first buffer.

[0014] In some embodiments, the second cache is used to store data of the second process and the third process, and storing the original audio data of each process in the at least one process to the cache corresponding to each process includes: storing the second original audio data of the second process to the second cache; and mixing the third original audio data corresponding to the third process with the second original audio data in the second cache.

[0015] In some embodiments, storing the second original audio data of the second process to the second cache includes: when storing the second original audio data to the second cache, determining whether the second cache is locked; if the second cache is not locked, locking the second cache through the second process; storing the second original audio data to the second cache; and unlocking the second cache through the second process.

[0016] In some implementations, locking the second cache by the second process includes: locking the second cache by an atomic operation, a mutex operation, or a spin lock operation.

[0017] In some embodiments, determining whether the second cache is locked includes: obtaining first status information corresponding to the second cache; if the first status information includes a first character, determining that the second cache is locked; if the first status information includes a second character, determining that the second cache is not locked, and the first character and the second character are different characters.

[0018] In some embodiments, storing the second original audio data of the second process to the second cache includes: determining whether the second cache is empty; if the second cache is empty, writing the second original audio data to the second cache; if the second cache is not empty, mixing the second original audio data with the data currently stored in the second cache in the second cache.

[0019] In some embodiments, determining whether the second cache is empty includes: obtaining second status information corresponding to the second cache; if the second status information includes a third character, determining that the second cache is empty; if the second status information includes a fourth character, determining that the second cache is not empty, and the third character and the fourth character are different characters.

[0020] By setting the first state information and the second state information corresponding to the second cache, each process can accurately determine the timing of storing the original video stream in the second cache through the first state information, so that two or more processes can store the original audio data in the second cache in an orderly manner, thereby improving the reliability of mixing at least two channels of original audio data in the second cache. Each process can accurately determine the method of storing the original audio data in the second cache through the second state information, including directly writing the original audio data into the second cache when the second cache is empty, thereby improving the efficiency of mixing at least two channels of original audio data in the second cache.

[0021] In some embodiments, in order to improve mixing efficiency, the second state information can be ignored, that is, as long as the process successfully locks the second cache, the original audio data of the process can be directly mixed with the data in the second cache, thereby completing the storage of the original audio data in the second cache.

[0022] In some embodiments, the electronic device further includes a third cache, and the third cache is used to store data of the audio service. The audio service obtains a path of original audio data (such as the fourth original audio data) from a process (such as the fourth process), and writes the original audio data into the third cache. Alternatively, the audio data obtains at least two paths of original audio data (such as the fourth original audio data of the fourth process and the fifth original audio data of the fifth process) from at least two processes (such as the fourth process and the fifth process), mixes the at least two paths of original audio data, and stores the mixed data in the third cache. The audio device obtains the audio data to be played from the first cache and / or the second cache, and the third cache, mixes the obtained audio data to be played, obtains the mixed audio data to be played, and then plays the mixed audio data to be played.

[0023] In some implementations, the cache is disposed within a device buffer of the audio device.

[0024] In a second aspect, an embodiment of the present application provides a method for playing audio, which is applied to an electronic device, wherein the electronic device includes a second cache and an audio device, the second cache being used to store data of at least two processes, the method comprising: at least two of the processes, mixing at least two channels of original audio data in the second cache to obtain audio data to be played; the audio device obtaining the audio data to be played from the second cache; and the audio device playing the audio data to be played.

[0025] In an embodiment of the present application, the electronic device includes a second cache, and the second cache corresponds to at least two processes, and is used to store data of at least two processes. At least two processes mix at least two channels of original audio data in the second cache to obtain audio data to be played, and the audio device obtains the audio data to be played from the second cache and plays the audio data to be played. On the one hand, the transmission of original audio data can be achieved between the process and the audio device through only one read and write cache, thereby reducing the delay in playing the original audio data. On the other hand, by providing a second cache, two or more processes can transmit original audio data to the audio device, improving the problem that other processes cannot make sound due to one process monopolizing the audio device.

[0026] In some embodiments, the second cache is used to store data of the second process and the third process, and the at least two processes mix at least two channels of original audio data in the second cache to obtain audio data to be played, including: storing the second original audio data of the second process in the second cache; mixing the third original audio data corresponding to the third process with the second original audio data in the second cache to obtain the audio data to be played.

[0027] In some embodiments, storing the second original audio data of the second process to the second cache includes: when storing the second original audio data to the second cache, determining whether the second cache is locked; if the second cache is not locked, locking the second cache through the second process; storing the second original audio data to the second cache; and unlocking the second cache through the second process.

[0028] In some implementations, locking the second cache by the second process includes: locking the second cache by an atomic operation, a mutex operation, or a spin lock operation.

[0029] In some embodiments, determining whether the second cache is locked includes: obtaining first status information corresponding to the second cache; if the first status information includes a first character, determining that the second cache is locked; if the first status information includes a second character, determining that the second cache is not locked, and the first character and the second character are different characters.

[0030] In some implementations, storing the second original audio data of the second process into the second cache includes: determining whether the second cache is empty; if the second cache is empty, writing the second original audio data into the second cache;

[0031] If the second buffer is not empty, the second original audio data is mixed with the data currently stored in the second buffer in the second buffer.

[0032] In some embodiments, determining whether the second cache is empty includes: obtaining second status information corresponding to the second cache; if the second status information includes a third character, determining that the second cache is empty; if the second status information includes a fourth character, determining that the second cache is not empty, and the third character and the fourth character are different characters.

[0033] In some implementations, the second cache is disposed within a device buffer of the audio device.

[0034] In a third aspect, an embodiment of the present application provides a device for playing audio, which has the function of realizing the above-mentioned aspects and the electronic device behaviors in the possible implementation methods of the above-mentioned aspects. The functions can be implemented by hardware, or by hardware executing corresponding software implementations. The hardware or software includes one or more modules or units corresponding to the above-mentioned functions. For example, a transceiver module or unit, a processing module or unit, an acquisition module or unit, etc.

[0035] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising: a memory and a processor, the memory being used to store a computer program; the processor being used to execute the method described in any one of the first aspect or any one of the second aspect above when calling the computer program.

[0036] In a fifth aspect, an embodiment of the present application provides a chip system, which includes a processor, the processor is coupled to a memory, and the processor executes a computer program stored in the memory to implement the method described in any one of the first aspect or any one of the second aspect above.

[0037] The chip system may be a single chip or a chip module composed of multiple chips.

[0038] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method described in any one of the first aspect or any one of the second aspect is implemented.

[0039] In a seventh aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the method described in any one of the first aspect or any one of the second aspect.

[0040] It can be understood that the beneficial effects of the third to seventh aspects mentioned above can be found in the relevant descriptions in the first or second aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0042] Figure 2 A software structure block diagram of an electronic device provided in an embodiment of the present application;

[0043] Figure 3 A schematic diagram of an audio playback process provided in an embodiment of the present application;

[0044] Figure 4 A schematic diagram of another audio playback process provided in an embodiment of the present application;

[0045] Figure 5 A flowchart of a method for playing audio provided in an embodiment of the present application;

[0046] Figure 6 A schematic diagram of another audio playback process provided in an embodiment of the present application;

[0047] Figure 7 A flowchart of another method for playing audio provided by an embodiment of the present application;

[0048] Figure 8 A flow chart of a mixing method provided in an embodiment of the present application;

[0049] Fig. 9 A schematic diagram of another audio playback process provided in an embodiment of the present application;

[0050] Fig.10 A flowchart of another method for playing audio provided by an embodiment of the present application;

[0051] Fig.11 A schematic diagram of another audio playback process provided in an embodiment of the present application;

[0052] Fig.12 A flowchart of another method for playing audio provided in an embodiment of the present application. DETAILED DESCRIPTION

[0053] The method for playing audio provided in the embodiments of the present application can be applied to electronic devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), televisions, etc. The embodiments of the present application do not impose any restrictions on the specific types of electronic devices.

[0054] Figure 1 1 is a schematic diagram of the structure of an electronic device 100 provided in an embodiment of the present application. The electronic device 100 may include a processor 110, a memory 120, a communication module 130, an audio device 140, and the like.

[0055] Among them, the processor 110 may include one or more processing units, and the memory 120 is used to store program codes and data. In an embodiment of the present application, the processor 110 can execute computer-executable instructions stored in the memory 120 to control and manage the actions of the electronic device 100. In some embodiments, the memory 120 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function), etc. The data storage area may store data (such as audio data) created during the use of the electronic device 100, etc.

[0056] The communication module 130 can be used for communication between various internal modules of the electronic device 100, or communication between the electronic device 100 and other external electronic devices. Exemplarily, if the electronic device 100 communicates with other electronic devices via a wired connection, the communication module 130 may include an interface, such as a universal serial bus (USB) interface. The USB interface may be an interface that complies with USB standard specifications, specifically a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface can be used to connect a charger to charge the electronic device 100, and can also be used to transmit data between the electronic device 100 and peripheral devices. For example, the audio device 140 can be connected via a USB interface.

[0057] Alternatively, the communication module 130 may include a radio frequency circuit, a Bluetooth chip, a wireless fidelity (Wi-Fi) chip, a near-field communication (NFC) module, etc., and may enable interaction between the electronic device 100 and other electronic devices in a variety of different ways.

[0058] The audio device 140 can implement audio functions, including converting audio electrical signals into sound signals. For example, playing music, playing call voice, etc. In some embodiments, the audio device 140 can also convert sound signals into audio electrical signals. For example, recording, collecting call voice, etc. Exemplarily, the audio device 140 can include a sound card, a speaker, a loudspeaker, a headset, a speaker, etc.

[0059] In some embodiments, the audio device 140 may include a digital signal processor (DSP). A DSP is a microprocessor suitable for performing digital signal processing operations, and can implement various digital signal processing algorithms in real time and quickly. Exemplarily, a DSP can implement conversion between digital signals and analog signals, and modify, delete, and enhance digital signals. In some embodiments, a DSP can be integrated in the processor 110.

[0060] Optionally, the electronic device 100 may further include a display screen 150 , and the display screen 150 may display images or videos in a human-computer interaction interface.

[0061] It should be understood that, in addition to Figure 1 In addition to the various components or modules listed in the figure, the embodiment of the present application does not specifically limit the structure of the electronic device 100. In other embodiments of the present application, the electronic device 100 may also include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure can be implemented in hardware, software, or a combination of software and hardware.

[0062] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. Figure 2 The layered architecture shown is taken as an example to illustrate the software structure of the electronic device 100.

[0063] Figure 2 It is a software structure block diagram of the electronic device 100 according to an embodiment of the present application.

[0064] The layered architecture divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the electronic device 100 includes an application, an audio service, and a kernel layer, wherein the kernel layer includes an audio driver. In some embodiments, the electronic device 100 may also include a hardware abstract layer (HAL).

[0065] Applications may include calls, navigation, music, games, etc. Applications may generate audio data during operation. For example, the call voice sent by other electronic devices obtained by the call program during the call, the navigation voice played by the navigation program during the navigation process, the songs played by the music program, the sound effects in the game, etc. It is understandable that these applications are third-party applications or system applications. It is also understandable that in actual applications, the electronic device 100 may also include more or fewer applications that can generate audio data.

[0066] The audio service can provide an application programming interface (API) and a programming framework to the application. The audio service includes some predefined functions. In some embodiments, the audio service can process the audio data of the application, such as volume adjustment, mixing in the case of multi-application playback, sound effect processing, etc. In some embodiments, the audio service can manage the use of audio resources by the application, manage the strategy for processing audio data, etc. Exemplarily, the audio service can be used to obtain or release the cache used to store audio data.

[0067] The kernel layer (and the hardware abstraction layer) can be used to connect the hardware with the software in the upper layer. For example, the audio driver can be used to connect the audio device with the software in the upper layer. The audio driver (and the hardware abstraction layer) can shield the underlying details of the audio device, so that the software in the upper layer can implement various operations on the audio device through the audio driver (and the hardware abstraction layer).

[0068] The following is an example of the workflow of the software and hardware of the electronic device 100, with reference to the scenario of playing music.

[0069] When the user opens the music program and plays music, the processor 110 obtains the music program from the memory 120 and creates a process of the music program. The process obtains audio data from the server corresponding to the music program through the communication module 130. The process sends the audio data to the audio service, and the audio service processes the audio data. After that, the processed audio data is sent to the audio device 140 for playback through intermediate layers such as the audio driver and the hardware abstraction layer. In some embodiments, the process can send one or more instructions to the audio device through the audio service, thereby controlling the audio device to implement various operations, such as increasing the volume, decreasing the volume, pausing playback, resuming playback, etc.

[0070] In order to facilitate understanding of the technical solutions in the embodiments of the present application, the application scenarios of the embodiments of the present application are first introduced below.

[0071] Audio playback is an important device capability of electronic devices. Through this device capability, users can be provided with a variety of user experiences such as playing music, playing videos, recording and making voice calls. With the continuous development of terminal technology, the compatibility and scalability of this device capability are also increasing. For example, it can play the sounds of more applications and beautify the sounds. However, it also lengthens the process of audio data from applications to hardware devices, which increases the delay of audio playback and reduces the user experience.

[0072] The application generates audio data and writes the audio data into the cache corresponding to the audio service. The audio service obtains the audio data from the cache corresponding to the audio service and processes it, and writes the processed audio data into the cache corresponding to the audio device. The audio device obtains the processed audio data from the cache corresponding to the audio device through the audio driver and plays the processed audio data.

[0073] Among them, multiple caches can constitute a cache queue. When data is written to or read from the cache queue in a loop, the cache queue can be regarded as a circular cache queue, or a cache queue of infinite length. A cache can store one frame of audio data, and one frame of audio data can be obtained by packaging one or more samples by an application, and the size of one frame of audio data can be determined by the hardware conditions of the audio device. In some embodiments, one frame can be the unit of read / write operation, that is, at least one frame of audio data is written to the cache each time or at least one frame of audio data is read from the cache each time.

[0074] In order to ensure the continuity of audio playback, it is necessary to ensure that the data in the read and write cache is also continuous, that is, a frame of audio data can be read only after a frame of audio data is written. In some implementations, the duration corresponding to a frame of audio data can be used as a cycle, and the application can write a frame of audio data into the cache in each cycle, which can ensure continuous audio playback.

[0075] From the above, we can see that in the process of playing audio, audio data needs to go through multiple layers of read and write cache from the application to the audio device, and each layer of read and write cache must ensure writing before reading, and even one or more frames of audio data must be reserved between the read cache and the write cache. Therefore, the delay in playing audio is very large.

[0076] In some implementations, an exclusive mode and a shared mode may be set, and audio data may be played according to different audio playback processes for the exclusive mode and the shared mode.

[0077] Please refer to Figure 3 , is an audio playback process in a shared mode provided by an embodiment of the present application. In the shared mode, multiple processes can use the audio device together. Figure 3 As shown, application 1 corresponds to cache queue 1, and application 2 corresponds to cache queue 2. Application 1 can store data 1 of application 1 in the cache in cache queue 1, and application 2 can store data of application 2 in the cache in cache queue 2. Data 1 and data 2 can be the original audio data of application 1 and application 2, respectively. The audio service obtains data 1 from the cache corresponding to application 1 and data 2 from the cache corresponding to application 2, mixes data 1 and data 2 to obtain mixed data, and stores the mixed data in the cache in cache queue 3. The audio driver obtains the mixed data from cache queue 3 and controls the audio device to play the mixed data.

[0078] Please refer to Figure 4 , is an audio playback process in an exclusive mode provided by an embodiment of the present application. In the exclusive mode, a certain application program can exclusively occupy the audio device. Figure 4 As shown, application 1 can directly store data 1 of application 1 into the cache in cache queue 3, so the audio driver can directly obtain data 1 from cache queue 3 and control the audio device to play data 1.

[0079] Combination Figure 3 and Figure 4It can be seen that in shared mode, although multiple applications can make sound through the audio device, they need to go through two read-write caches, so the delay in playing the audio data is very large. In exclusive mode, although the audio data can be played through a single read-write cache, only one application can make sound at this time, which greatly reduces the user experience.

[0080] To solve at least some of the above technical problems, the present application provides a method for playing audio. The technical solution of the present application is described in detail with specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.

[0081] In order to facilitate understanding of the technical solutions in the embodiments of the present application, some of the terms involved in the embodiments of the present application are first explained below:

[0082] An application is a computer program that is designed to complete one or more specific tasks. It is a description of instructions, data, and their organizational form.

[0083] A process is an operation activity of an application on a certain data set. It is the basic unit for resource allocation in the system and the foundation of the operating system structure. A process is an entity of a running application and can therefore also be referred to as an instance. In some embodiments, a process may have a process ID, which may be used to identify and distinguish the process. In some embodiments, a process may be created based on the same application, i.e., one application may correspond to one process. In some embodiments, multiple processes may be created based on one application, i.e., one application may correspond to multiple processes. In some embodiments, multiple processes belonging to the same application may share the same memory area.

[0084] A cache may be a memory area used for data transmission, and is used to store data during the data transmission process. Exemplarily, a data sender (such as a software program) may write data to the cache at a faster speed, and a data receiver (such as another software program or a hardware device) may read data from the cache at a slower speed. In some embodiments, the cache may be set in a device buffer of an audio device. In some embodiments, a cache may correspond to an application, so that the application is used to transmit data to an audio device. In some embodiments, a cache may correspond to a process, so that the process is used to transmit data to an audio device. In some embodiments, the cache may include a first cache and / or a second cache, wherein the first cache may be used to store data of a process, and the second cache may be used to store data of at least two processes.

[0085] The cache queue may include multiple caches. In some implementations, when data is cyclically written to or read from each cache in the cache queue, the cache queue may be viewed as a circular cache queue, or a cache queue of infinite length.

[0086] Audio data (audio stream) is an abstract object that makes sound and is a continuous data series of sound.

[0087] Mixing refers to the process of mixing multiple audio data into one audio data. When the electronic device includes audio data generated by at least two processes, the at least two audio data can be mixed into one audio data, so that when the audio data is played, the user can hear the sound of the at least two processes.

[0088] Raw audio data refers to audio data generated by the process and not mixed.

[0089] The audio data to be played refers to the audio data obtained by the audio device from the cache.

[0090] The mixed audio data to be played refers to data obtained by mixing at least two channels of audio data to be played.

[0091] Please refer to Figure 5 , is a flowchart of a method for playing audio provided by an embodiment of the present application. Among them, different processes can be processes of different applications or different processes of the same application. The electronic device includes at least two first caches, each of which can store data of a process, so that the data of different processes can be isolated and protected, thereby improving the privacy and security of the data. It should be noted that the method does not Figure 5 The specific order described below is a limitation, and it should be understood that in other embodiments, the order of some steps in the method can be interchanged according to actual needs, or some steps can be omitted or deleted. The method includes the following steps:

[0092] S501: A process stores original audio data of the process into a first cache corresponding to the process.

[0093] By providing two or more first buffers, and each first buffer corresponds to a process, two or more processes can store original audio data in the first buffer concurrently, thereby enabling the two or more processes to emit sound.

[0094] It should be noted that each process can be any process in an electronic device. And it is understandable that different processes have different sound requirements, so the original audio data generated can be different. For example, the original audio data generated by the process of a game application may include special effects dubbing, ambient sound, user voice, etc. in the game scene; the original audio data generated by the process of a music application may include music, songs, etc.; the original audio data generated by the process of a communication application may include various message prompts, voice messages or voice calls, etc.

[0095] In some implementations, a process may obtain a cache corresponding to the process through an audio service. Exemplarily, the process may send a cache allocation request to an audio device (specifically, the audio driver of the audio device) through an audio service, and the audio device allocates the corresponding cache to the process from the device buffer of the audio device. The cache may include a portion of the storage area in the device buffer. It is understandable that in actual applications, the cache may also be allocated in other ways.

[0096] In some implementations, a process may obtain the time when the audio device reads the first cache through an audio service. The process may store the original audio data in the first cache before the audio device reads the first cache based on the time when the audio device reads the first cache. It is understandable that different processes may store the original audio data in the first cache corresponding to each process at different times.

[0097] S502: The audio device obtains audio data to be played from at least two first buffers, where the audio data to be played includes original audio data.

[0098] The audio device can obtain the audio data to be played from at least two first buffers respectively, thereby obtaining at least two channels of original audio data.

[0099] On the one hand, the original audio data can be transmitted between the process and the audio device through only one read and write cache, thereby reducing the delay in playing the original audio data. On the other hand, by providing two or more first caches, two or more processes can transmit the original audio data to the audio device, improving the problem that one process monopolizes the audio device and causes other processes to be unable to make sound.

[0100] In some implementations, after the audio device obtains the original audio data from the first cache, it may set the first cache to be empty so that the process corresponding to the first cache can store new original audio data into the first cache again.

[0101] S503: The audio device mixes at least two channels of audio data to be played to obtain mixed audio data to be played.

[0102] From the foregoing, it can be seen that the audio device obtains the audio data to be played from at least two first caches, so the audio device can obtain at least two channels of original audio data, and the at least two channels of original audio data come from different processes. Then, in order to play the at least two channels of original audio data simultaneously through the audio device, the audio device can mix the at least two channels of original audio data to obtain the mixed audio data to be played.

[0103] In some embodiments, each channel of original audio data can be regarded as an array, and at least two channels of original audio data can be superimposed to achieve mixing of the two channels of original audio data. And it can be understood that in practical applications, in order to achieve a better mixing effect, at least two channels of original audio data can also be mixed in other ways or more complex ways. Exemplarily, before superimposing at least two channels of original audio data, the at least two channels of original audio data can be converted into original audio data of the same sampling frequency, and the at least two channels of original audio data can be subjected to noise reduction, etc. Exemplarily, after superimposing at least two channels of original audio data, the obtained mixed audio data to be played can be subjected to noise reduction.

[0104] S504: The audio device plays the mixed audio data to be played.

[0105] The audio device can convert the mixed audio data to be played into a sound signal through a speaker to play the sound. Since the mixed audio data to be played is obtained by mixing the original audio data of at least two processes, the user can hear a mixed signal including the sound signals of at least two processes.

[0106] For example, the at least two processes include a process of a game application and a process of a communication application, and the user can hear the superposition of the special effect dubbing in the game application and the prompt sound of the notification message of the communication application.

[0107] For another example, the at least two processes include two processes of a game application, and the user can hear the superposition of two special effect dubbings in the game application.

[0108] It is understandable that, in order to more clearly explain the details that may be included between the audio device obtaining the original audio data from the first cache and playing the sound signal, the embodiment of the present application divides the process from the audio device obtaining the original audio data from the first cache to playing the sound signal into S502, S503 and S504, and in actual applications, the operations included in S502, S503 and S504 can be considered to be completed in the same step, or, can be considered to be completed at the same time. That is, when the audio device obtains the original audio data from at least two first caches, it immediately mixes and plays the at least two channels of original audio data obtained.

[0109] In an embodiment of the present application, the electronic device includes at least two first caches, and each first cache can store data of a process. The process can store the original audio data of the process in the first cache corresponding to the process, and the audio device can obtain the audio data to be played from the first cache, and the audio data to be played includes the original audio data. Therefore, the transmission of the original audio data can be realized between the process and the audio device through only one read and write cache, thereby reducing the delay of playing the original audio data. The electronic device can also mix the at least two channels of audio data to be played obtained to obtain the mixed audio data to be played, and play the mixed audio data to be played, so as to realize two or more processes to make sound through the audio device, thereby improving the problem that other processes cannot make sound due to one process monopolizing the audio device.

[0110] Please refer to Figure 6 , is a schematic diagram of an audio playback process provided in an embodiment of the present application. This process can be used as Figure 5 A specific example of the method shown.

[0111] The electronic device includes n first processes, process 1 to process n, and it is understandable that the n first processes can be different processes respectively; and also includes cache queues 1 to cache queues n, each cache queue can include m first caches. n and m can be integers greater than or equal to 2.

[0112] First, process 1 to process n may generate data 1 to data n (ie, first original audio data) respectively, and store data 1 to data n in cache queues 1 to n respectively.

[0113] Then, the audio device obtains data 1 to data n (ie, the audio data to be played) from the cache queues 1 to n respectively. The audio device mixes data 1 to data n to obtain mixed data 1 (ie, the mixed audio data to be played), and plays mixed data 1.

[0114] Depend on Figure 5 It can be seen that the first buffer can store the original audio data of the first process, but is not used for mixing. During the audio playback process, the audio device mixes and plays the n channels of original audio data when or after obtaining the original audio data from the first buffer.

[0115] Please refer to Figure 7 , is a flow chart of a method for playing audio provided by an embodiment of the present application. The electronic device includes a second cache, and the second cache can store data of at least two processes. It should be noted that the method does not Figure 7The specific order described below is a limitation, and it should be understood that in other embodiments, the order of some steps in the method can be interchanged according to actual needs, or some steps can be omitted or deleted. The method includes the following steps:

[0116] S701, at least two processes, mixing at least two channels of original audio data in a second buffer.

[0117] At least two paths of original audio data are mixed in the second cache by at least two processes, so that two or more processes can store the original audio data in the second cache, and further the two or more processes can make sounds.

[0118] Among them, at least two processes can store at least two channels of original audio data in the second cache in sequence, so as to achieve mixing of the at least two channels of original audio data in the second cache.

[0119] In some embodiments, after the audio device reads the audio data to be played from the second cache, the second cache can be set to empty, such as setting all the data in the second cache to 0. The first process that stores the original audio data in the second cache can directly write the original played audio data of the process into the second cache, or it can also be understood that the first process mixes the original audio data of the process with the empty data in the second cache. The second process that stores the original audio data in the second cache can mix the original audio data of the process with the original audio data stored in the second cache. The third process that stores the original audio data in the second cache can mix the original audio data of the process with the mixed data stored in the second cache again. And so on, until all processes corresponding to the second cache complete storing the original audio data in the second cache.

[0120] In addition, the way in which each process executes S701 can also be referred to in the following Figure 8 A detailed description of the mixing method is shown.

[0121] It should be noted that, during the execution of S701, although the process may need to wait for another process to store original audio data in the second cache before mixing the original audio data of the process with the data stored in the second cache, the time for the process to wait for another process and perform the mixing is very short, for example, it may be tens of milliseconds or even less, so the total time required to execute S701 is still much less than the time required to read and write the cache once.

[0122] It should also be noted that, in actual applications, at least two processes can mix at least two channels of original audio data in the second cache in other ways.

[0123] S702: The audio device obtains audio data to be played from a second buffer, where the audio data to be played includes data obtained by mixing at least two channels of original audio data.

[0124] On the one hand, the original audio data can be transmitted between the process and the audio device through only one read and write cache, thereby reducing the delay in playing the original audio data. On the other hand, by providing a second cache, two or more processes can transmit original audio data to the audio device, improving the problem that one process monopolizes the audio device and causes other processes to be unable to make sound.

[0125] The audio data to be played obtained by the audio device from the second buffer may be data obtained by mixing at least two channels of original audio data.

[0126] S703: The audio device waits to play the audio data to be played.

[0127] The way in which the audio device executes S703 may be the same as or similar to the way in which the audio device executes S504.

[0128] In an embodiment of the present application, the electronic device includes a second cache, and the second cache corresponds to at least two processes, and is used to store data of at least two processes. At least two processes mix at least two channels of original audio data in the second cache to obtain audio data to be played, and the audio device obtains the audio data to be played from the second cache and plays the audio data to be played. On the one hand, the transmission of original audio data can be achieved between the process and the audio device through only one read and write cache, thereby reducing the delay in playing the original audio data. On the other hand, by providing a second cache, two or more processes can transmit original audio data to the audio device, improving the problem that other processes cannot make sound due to one process monopolizing the audio device.

[0129] It is understandable that the second cache can be used to store data of at least two processes, but in actual applications, the second cache may only store data of one process. Exemplarily, the second cache is used to store data of the second process and the third process, but before the audio device obtains the audio data to be played from the second cache, only the second process stores the second original audio data in the second cache, so when the audio device obtains the audio data to be played from the second cache, the audio data to be played only includes the second original audio data. That is, the audio data to be played obtained by the audio device from the second cache may also be original audio data.

[0130] Please refer to Figure 8 , is a flow chart of a mixing method provided in an embodiment of the present application. The method can be used as a detailed description of the aforementioned S701, and the method can be used for each process in the aforementioned S701. It should be noted that the method is not based on Figure 8 The specific order described below is a limitation, and it should be understood that in other embodiments, the order of some steps in the method can be interchanged according to actual needs, or some steps can be omitted or deleted. The method includes the following steps:

[0131] S801, when the process stores the original audio data in the second cache, the process locks the second cache. If the process successfully locks the second cache, S802 can be continued. If the locking fails, S801 can be returned to try to lock the second cache again.

[0132] The process locks the second cache, which can improve the problem that the process interrupts other processes' operations on the second cache, and the problem that the process's operations on the second cache are interrupted by other processes.

[0133] In some embodiments, the process may obtain the first state information corresponding to the second cache, and the first state information may be used to indicate whether the second cache is locked. When the first state information includes the first character, it may indicate that the second cache is locked. When the first state information includes the second character, it may indicate that the second cache is not locked. The process may lock the second cache and set the first state information to the first character string.

[0134] The first character and the second character are different, and the first character and the second character string can be obtained by presetting. For example, the first character can include 1 and the second character can include 0; or the first character can include "locked" and the second character can include "unlocked"; or the first character can include "processing" and the second character can include "end". Of course, in actual applications, the first character and the second character can also be other types of characters.

[0135] In some embodiments, the process can lock the second cache through atomic operations. Atoms refer to indivisible basic particles in chemical reactions. Extending atoms to computer scenarios, atomic operations refer to operations that cannot be divided and exclusively read and write data. Atomic operations are operations that cannot be interrupted during the process. When an atomic operation on a value is being performed, the processor will not perform other operations on the value. In order to achieve such rigor, atomic operations will only be represented and completed by an independent processor instruction.

[0136] In some embodiments, a process may lock the second cache through a mutex operation. The mutex is a sleep-waiting type lock. When a process locks the second cache through a mutex, other processes requesting access to the second cache are suspended. When the process unlocks the second cache, another process requesting access to the second cache is awakened and continues to lock the second cache.

[0137] In some embodiments, the process may lock the second cache through a spin lock operation. The spin lock is a busy-waiting type lock. When a process requests to lock the second cache through a spin lock operation, the process may perform busy waiting and continuously request to lock the second cache until the lock is successful.

[0138] It is understandable that, in practical applications, the second cache may also be locked through other types of locking operations.

[0139] S802, the process determines whether the second cache is empty, if so, executes S803, otherwise, executes S805.

[0140] The second buffer is empty, that is, no audio data is stored in the second buffer. The second buffer is not empty, that is, one channel of audio data is stored in the second buffer, and the audio data may be original audio data, or the audio data may be data obtained by mixing at least two channels of original audio data.

[0141] In some embodiments, the process may obtain second state information corresponding to the second cache, and the second state information may be used to indicate whether the second cache is empty. When the second state information includes the third character, it may indicate that the second cache is empty. When the second state information includes the fourth character, it may indicate that the second cache is not empty.

[0142] The third character and the fourth character are different, and the third character and the fourth character string can be obtained by setting in advance. Exemplarily, the second state information is a count value, which indicates the number of times the second buffer has received the original audio data, the third character may include 0, and the second character may include 1 or any positive integer. Of course, in actual applications, the first character and the second character may also be other types of characters.

[0143] S803: The process writes the original audio data of the process into the second cache.

[0144] Since the second buffer is empty, the process can directly write the original audio data of the process into the second buffer. Alternatively, it can also be understood that the process overwrites the data in the second buffer with the original audio data.

[0145] S804: The process sets the second cache to be non-empty.

[0146] In some implementations, the process may update the second state information corresponding to the second cache to a fourth character string. In some implementations, if the second state information is a count value, the process may increase the count value by 1.

[0147] S805: The process mixes the original audio data of the process with the data currently stored in the second cache.

[0148] Since the second cache has stored original audio data or data mixed from at least two channels of original audio data, the process can remix the original audio data of the process with the data stored in the second cache, thereby updating the data stored in the second cache.

[0149] S806: The process keeps the second cache non-empty.

[0150] In some implementations, if the second state information is a count value, the process may increase the count value by 1.

[0151] In some embodiments, when the count value is greater than or equal to the preset value, the data currently stored in the second cache may be about to overflow or have overflowed, so the count value may be set to 0, and the data in the second cache may be cleared. The preset value may be obtained by setting in advance, and the embodiment of the present application does not limit the method for setting the preset value and the specific size of the preset value.

[0152] S807: The process unlocks the second cache.

[0153] When a process stores the original audio data of the process in the second cache, the second cache may be unlocked so that other processes continue to lock the second cache and store other original audio data in the second cache.

[0154] The process may unlock the second cache in an unlocking manner corresponding to locking the second cache.

[0155] In some implementations, the process may update the first state information to the second character.

[0156] In some implementations, the audio device may update the second state information corresponding to the second cache to the third character after reading the data stored in the second cache from the second cache.

[0157] In an embodiment of the present application, the second cache is correspondingly provided with first state information and second state information. Each process can accurately determine the timing of storing the original video stream in the second cache through the first state information, so that two or more processes can orderly store the original audio data in the second cache, thereby improving the reliability of mixing at least two channels of original audio data in the second cache. Each process can accurately determine the method of storing the original audio data in the second cache through the second state information, including directly writing the original audio data into the second cache when the second cache is empty, thereby improving the efficiency of mixing at least two channels of original audio data in the second cache.

[0158] It can be seen from the aforementioned S801-S807 that the execution of S802, S804 and S806 is to distinguish between S803 and S805, two ways of storing original audio data in the second cache. When the second cache is empty, the process directly writes the original audio data to the second cache, and the result obtained is the same as the process mixing the original audio data with the empty data in the second cache. Therefore, in some embodiments, in order to improve the mixing efficiency, S802-S804 and S806 can be omitted, that is, as long as the process successfully locks the second cache through S801, the original audio data of the process can be directly mixed with the data in the second cache, thereby completing the storage of the original audio data in the second cache. Afterwards, there is no need to update the second state information of the second cache, but the second cache can be directly unlocked.

[0159] Alternatively, since in S802, whether to execute S803 or S805 can be determined by whether the count value corresponding to the second cache is 0, and when the count value is greater than or equal to 1, S805 will be executed. Therefore, in other embodiments, S802 can be retained, and when the count value corresponding to the second cache is greater than or equal to 1, the operation of increasing the count value by 1 in S804 and S806 can be omitted.

[0160] Please refer to Fig. 9 , is a schematic diagram of an audio playback process provided in an embodiment of the present application. This process can be used as Figure 7 and Figure 8 A specific example of the method shown.

[0161] The electronic device includes processes 1 to n, each of which may be a second process or a third process, and the second process and the third process may represent any two processes that store data in the second cache in sequence; and further includes a cache queue 1, which may include m second caches. n and m may be integers greater than or equal to 2.

[0162] The second cache in the cache queue 1 is correspondingly provided with state information such as a lock state and a count value, wherein the lock state can be used as the first state information, and the count value can be used as the second state information.

[0163] Assume that process 1 (i.e., the second process) first stores data 1 (i.e., the second audio data) in cache 3 (i.e., the second cache) in cache queue 1. The lock state corresponding to cache 3 obtained by process 1 is unlocked, and the count value is 0. Process 1 updates the lock state to locked, and directly writes data 1 to cache 3. When process 1 completes writing data 1, it updates the lock state to unlocked and the count value to 1.

[0164] Next, process 2 (i.e., the third process) continues to store data 2 (i.e., the third audio data) in cache 3 in cache queue 1. Process 2 obtains the lock state and count value corresponding to cache 3. If the lock state is locked, process 2 continues to obtain the lock state until the lock state is unlocked, and process 2 updates the lock state to locked. Since the count value is 1, process 2 mixes data 2 with data 1 in cache 3, and then process 2 updates the lock state to unlocked.

[0165] By analogy, until process n also stores data n in cache 3, cache 3 stores mixed data 1 obtained by mixing data 1 to data n. The audio device can obtain mixed data 1 (i.e., audio data to be played) from cache 3 and play mixed data 1 directly.

[0166] Depend on Fig. 9 It can be seen that the second cache can store original audio data and is also used for mixing. During the audio playback process, at least two processes store at least two channels of original audio data in the second cache, and at the same time, the at least two channels of original audio data are mixed. The audio data to be played from the second cache by the audio device is the data obtained by mixing, so the audio device can directly play the audio data to be played.

[0167] Please refer to Fig.10 , is a flow chart of a method for playing audio provided by an embodiment of the present application. The method can be obtained by combining the above-mentioned method embodiments. Among them, the electronic device includes at least one first cache and at least one second cache, the first cache is used to store data of one process, and the second cache is used to store data of at least two processes. It should be noted that the method does not Fig.10 The specific order described below is a limitation, and it should be understood that in other embodiments, the order of some steps in the method can be interchanged according to actual needs, or some steps can be omitted or deleted. The method includes the following steps:

[0168] S1001, original audio data of a process corresponding to a first cache is stored in the first cache corresponding to the process, and at least two processes corresponding to a second cache mix at least two channels of original audio data in the second cache.

[0169] Exemplarily, the first cache corresponds to the first process, and the second cache corresponds to the second process and the third process. The first process can store the first original audio data of the first process in the first cache, and the second process and the third process can mix the second original data with the third audio data in the second cache.

[0170] The process corresponding to the first cache may store the original audio data of the process into the first cache corresponding to the process in the same or similar manner as S501.

[0171] The process corresponding to the second cache can store the original audio data of the process into the second cache corresponding to the process in the same or similar manner as S701 and S801-S807.

[0172] S1002: The audio device obtains audio data to be played from at least one first buffer and at least one second buffer, where the audio data to be played includes original audio data or data obtained by mixing at least two channels of original audio data.

[0173] Since each first cache corresponds to one process and each second cache corresponds to at least two processes, at least three processes can transmit original audio data to the audio device through at least one first cache and at least one second cache. On the one hand, the original audio data can be transmitted between the process and the audio device through only one read and write cache, thereby reducing the delay in playing the original audio data. On the other hand, by providing a first cache and a second cache, three or more processes can transmit original audio data to the audio device, improving the problem that other processes cannot make sound due to one process monopolizing the audio device.

[0174] The audio data to be played obtained by the audio device from the first buffer may be original audio data, and the audio data to be played obtained from the second buffer may be data obtained by mixing at least two channels of original audio data. The audio device may obtain the audio data to be played from the first buffer in the same or similar manner as S502, and obtain the audio data to be played from the second buffer in the same or similar manner as S702.

[0175] Exemplarily, the audio data to be played obtained by the audio device from the first buffer includes first original audio data, and the audio data to be played obtained from the second buffer includes data obtained by mixing the second original audio data and the third original audio data.

[0176] S1003: The audio device mixes the acquired audio data to be played to obtain mixed audio data to be played.

[0177] The way in which the audio device executes S1003 may be the same as or similar to the way in which the audio device executes S503.

[0178] Exemplarily, the audio device may mix the first original audio data with data obtained by mixing the second original audio data and the third original audio data to obtain mixed audio data to be played.

[0179] S1004: The audio device plays the mixed audio data to be played.

[0180] The way in which the audio device executes S1004 may be the same as or similar to the way in which the audio device executes S504.

[0181] In an embodiment of the present application, the electronic device includes at least one first cache and at least one second cache, each first cache corresponds to one process, and each second cache corresponds to at least two processes. Each process corresponding to the first cache stores the original audio data of the process in the first cache corresponding to the process. At least two processes corresponding to the second cache mix at least two channels of original audio data in the second cache. The audio device obtains the original audio data from at least one first cache, obtains the data obtained by mixing at least two channels of original audio data from at least one second cache, and mixes the original audio data with the data obtained by mixing at least two channels of original audio data again to obtain the mixed audio data to be played, and plays the mixed audio data to be played. Therefore, at least three processes and the audio device can realize the transmission of original audio data through only one read and write cache, thereby reducing the delay in playing the original audio data and improving the problem that other processes cannot make sound due to one process monopolizing the audio device.

[0182] Please refer to Fig.11 , which is a schematic diagram of an audio playback process provided in an embodiment of the present application. Fig.11 The method shown can be used as Fig.10 It should be noted that, in order to concisely and more clearly explain the method, Fig.11 Only one first cache and one second cache are shown.

[0183] The electronic device includes processes 1 to 3, process 1 is a first process, process 2 and process 3 may be a second process and a third process; and also includes cache queue 1 and cache queue 2, cache queue 1 may include m first caches, cache queue 2 may include m second caches. n and m may be integers greater than or equal to 2.

[0184] Each cache in the cache queue 2 is correspondingly provided with status information such as a lock status and a count value, wherein the lock status can be used as the first status information, and the count value can be used as the second status information.

[0185] Process 1 (ie, the first process) may generate data 1 (ie, the first original audio data), and store data 1 in cache 3 (ie, the first cache) in cache queue 1 .

[0186] Process 2 (i.e., the second process) can generate data 2 (i.e., the second original audio data) and first write data 2 into cache 3 (i.e., the second cache) in cache queue 2. Process 3 (i.e., the third process) can generate data 3 (i.e., the third original audio data) and mix data 3 with data 2 in cache 3 to obtain mixed data 1.

[0187] The audio device obtains data 1 (i.e., audio data to be played) from cache queue 1, obtains mixed data 1 (i.e., audio data to be played) from cache queue 2, mixes data 1 and mixed data 1, obtains mixed data 2 (i.e., mixed audio data to be played) and plays mixed data 2.

[0188] Depend on Fig.11 It can be seen that the first cache can store original audio data, but is not used for mixing. The second cache can store original audio data and is also used for mixing. During the audio playback process, at least two processes store at least two channels of original audio data in the second cache, and also mix the at least two channels of original audio data. The audio device obtains the audio data to be played from the first cache and the second cache, wherein the audio data to be played obtained from the first cache includes the original audio data, and the audio data to be played obtained from the second cache includes data obtained by mixing at least two channels of original audio data. The audio device mixes the two channels of audio data to be played again to obtain the mixed audio data to be played, and plays the mixed audio data to be played.

[0189] It is understandable that the embodiments of the present application Figure 5-Figure 11 The method for playing audio shown in the figure can also be used in conjunction with the aforementioned Figure 3The method for playing audio shown is combined. In some embodiments, the electronic device also includes a third cache, and the third cache is used to store data of the audio service. The audio service obtains a channel of original audio data (such as the fourth original audio data) from a process (such as the fourth process), and writes the original audio data to the third cache. Alternatively, the audio data obtains at least two channels of original audio data (such as the fourth original audio data of the fourth process and the fifth original audio data of the fifth process) from at least two processes (such as the fourth process and the fifth process), mixes the at least two channels of original audio data, and stores the mixed data in the third cache. The audio device obtains the audio data to be played from the first cache and / or the second cache, and the third cache, mixes the obtained audio data to be played, obtains the mixed audio data to be played, and then plays the mixed audio data to be played.

[0190] Please refer to Fig.12 , is a flowchart of a method for playing audio provided by an embodiment of the present application. The method can be obtained by combining the aforementioned method embodiments, wherein the electronic device includes at least two caches and an audio device, and each of the at least two caches is used to store data of at least one process. It should be noted that the method does not Fig.12 The specific order described below is a limitation, and it should be understood that in other embodiments, the order of some steps in the method can be interchanged according to actual needs, or some steps can be omitted or deleted. The method includes the following steps:

[0191] S1201, the electronic device stores original audio data of each process in at least one process into a cache corresponding to each process.

[0192] Among them, each process can store the original audio data of the process into the cache corresponding to the process in the same or similar manner as shown in the aforementioned S501, S701, S801-S807 and S1001.

[0193] S1202: The audio device obtains audio data to be played from at least two buffers respectively. The audio data to be played includes original audio data or data obtained by mixing at least two channels of original audio.

[0194] The audio device may obtain the audio data to be played from at least two buffers in the same or similar manner as shown in the aforementioned S502 and S702.

[0195] S1203: The audio device mixes the acquired audio data to be played to obtain mixed audio data to be played.

[0196] The audio device may mix the to-be-played audio data obtained from at least two buffers in the same or similar manner as shown in the aforementioned S503.

[0197] S1204: The audio device plays the mixed audio data to be played.

[0198] The audio device may play the mixed audio data to be played in the same or similar manner as shown in the aforementioned S504.

[0199] In some implementations, the audio device may obtain one channel of audio data to be played from one buffer for playback, or obtain at least two channels of audio data to be played from at least two buffers, mix the at least two channels of audio data to be played, and then play them.

[0200] It should be noted that when the audio device obtains the audio data to be played from the cache, whether to play the audio data to be played directly or to mix the audio data to be played with other audio data to be played may have nothing to do with whether the audio data to be played is original audio data, but only depends on the number of caches read and the number of audio data to be played obtained. When only one audio data to be played is obtained from one cache, the audio data can be played directly; when at least two audio data to be played are obtained from at least two caches, the two audio data to be played can be mixed to obtain the mixed audio data to be played, and the mixed audio data to be played can be played.

[0201] For example, in Figure 6 and Fig. 9 In the playback process shown, if only process 1 stores data 1 in cache queue 1, then the audio device can only obtain data 1, and the audio device can directly play data 1. This situation can be understood as process 1 monopolizing the audio device. If each process corresponds to an application, this situation can also be understood as the application corresponding to process 1 monopolizing the audio device.

[0202] For example, in Fig. 9 In the playback process shown, process 1 to process n store data 1 to data n in cache queue 1, so that cache queue 1 stores mixed data 1 obtained by mixing data 1 to data n. Then the audio device can only obtain mixed data 1, and the audio device can directly play mixed data 1. If each process corresponds to a different application, this situation can be understood as process 1 to process n sharing the audio device, or the applications corresponding to process 1 to process n sharing the audio device. If these n processes correspond to the same application, this situation can be understood as the application monopolizing the audio device.

[0203] For example, in Fig.11In the play process shown, when process 2 and process 3 store data 2 and data 3 in cache queue 2, cache queue 2 stores mixed data 1 obtained by mixing data 2 and data 3, but the audio device can still mix mixed data 1 with data 1 obtained from cache queue 1 again to obtain mixed data 2 and play mixed data 2. If process 1 corresponds to one application, and process 2 and process 3 correspond to another application, this situation can be understood as the two applications sharing the audio device.

[0204] In an embodiment of the present application, an electronic device includes at least two buffers and an audio device, and each of the at least two buffers is used to store data of at least one process. The original audio data of each process in at least one process can be stored in the buffer corresponding to each process, so the audio device can obtain the audio data to be played from at least two buffers respectively, and the audio data to be played includes the original audio data or the data obtained by mixing at least two original audios. The audio device obtains the audio data to be played and mixes the audio data to be played to obtain the mixed audio data to be played, and then plays the mixed audio data to be played. On the one hand, the transmission of the original audio data can be realized between the process and the audio device through only one read and write buffer, thereby reducing the delay of playing the original audio data. On the other hand, by providing at least two buffers, it is possible to realize that two or more processes transmit the original audio data to the audio device, improving the problem that other processes cannot make sound due to one process monopolizing the audio device.

[0205] Based on the same inventive concept, as an implementation of the above method, an embodiment of the present application provides a device for playing audio, and the device embodiment corresponds to the above method embodiment. For ease of reading, the present device embodiment will no longer repeat the details of the above method embodiment one by one, but it should be clear that the device in this embodiment can correspond to all the contents in the above method embodiment.

[0206] Based on the same inventive concept, an embodiment of the present application further provides an electronic device. The electronic device comprises: a memory and a processor, wherein the memory is used to store a computer program; and the processor is used to execute the method described in the above method embodiment when calling the computer program.

[0207] The electronic device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.

[0208] Based on the same inventive concept, an embodiment of the present application further provides a chip system, which includes a processor coupled to a memory, and the processor executes a computer program stored in the memory to implement the method described in the above method embodiment.

[0209] The chip system may be a single chip or a chip module composed of multiple chips.

[0210] The embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the method described in the above method embodiment is implemented.

[0211] The embodiment of the present application also provides a computer program product. When the computer program product is run on an electronic device, the electronic device implements the method described in the above method embodiment when executing the computer program product.

[0212] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may at least include: any entity or device, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium that can carry the computer program code to the device / electronic device that plays audio. For example, a USB flash drive, a mobile hard disk, a disk or an optical disk.

[0213] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0214] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0215] In the embodiments provided in the present application, it should be understood that the disclosed devices / equipment and methods can be implemented in other ways. For example, the device / equipment embodiments described above are merely schematic, for example, the division of the modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0216] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0217] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0218] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0219] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0220] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0221] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for playing audio, characterized in that: Applied to an electronic device, the electronic device includes at least two caches and an audio device, each of the at least two caches is used to store data of at least one process, and the method includes: Storing original audio data of each process in the at least one process into a cache corresponding to each process; The audio device obtains the audio data to be played from the at least two buffers respectively, where the audio data to be played includes the original audio data or data obtained by mixing at least two channels of the original audio data; The audio device mixes the acquired audio data to be played to obtain mixed audio data to be played; The audio device plays the mixed audio data to be played.

2. The method according to claim 1, characterized in that: The at least two caches include at least one first cache and / or at least one second cache, the first cache is used to store data of one of the processes, and the second cache is used to store data of at least two of the processes.

3. The method according to claim 2, characterized in that The first cache is used to store data of the first process, and storing the original audio data of each process in the at least one process in the cache corresponding to each process includes: The first original audio data of the first process is stored in the first buffer.

4. The method according to claim 2 or 3, characterized in that: The second cache is used to store data of the second process and the third process, and storing the original audio data of each process in the at least one process to the cache corresponding to each process includes: storing the second original audio data of the second process into the second buffer; The third original audio data corresponding to the third process and the second original audio data are mixed in the second buffer.

5. A method for playing audio, characterized in that: Applied to an electronic device, the electronic device includes a second cache and an audio device, the second cache is used to store data of at least two processes, and the method includes: At least two of the processes mix at least two channels of original audio data in the second buffer to obtain audio data to be played; The audio device obtains the to-be-played audio data from the second buffer; The audio device plays the audio data to be played.

6. The method according to claim 5, characterized in that The second cache is used to store data of the second process and the third process, and the at least two processes mix at least two channels of original audio data in the second cache to obtain audio data to be played, including: storing the second original audio data of the second process into the second buffer; The third original audio data corresponding to the third process and the second original audio data are mixed in the second buffer to obtain the audio data to be played.

7. The method according to claim 4 or 6, characterized in that: The storing the second original audio data of the second process into the second buffer comprises: When storing the second original audio data in the second buffer, determining whether the second buffer is locked; If the second cache is not locked, locking the second cache by the second process; storing the second original audio data into the second buffer; The second cache is unlocked by the second process.

8. The method according to claim 7, characterized in that The locking of the second cache by the second process includes: The second cache is locked through an atomic operation, a mutex operation, or a spin lock operation.

9. The method according to claim 7 or 8, characterized in that: The determining whether the second cache is locked includes: Obtaining first state information corresponding to the second cache; If the first state information includes a first character, determining that the second cache has been locked; If the first state information includes a second character, it is determined that the second cache is not locked, and the first character and the second character are different characters.

10. The method according to any one of claims 4 or 6-9, characterized in that: The storing the second original audio data of the second process into the second buffer comprises: Determine whether the second cache is empty; If the second buffer is empty, writing the second original audio data into the second buffer; If the second buffer is not empty, the second original audio data is mixed with the data currently stored in the second buffer in the second buffer.

11. The method according to claim 10, characterized in that The determining whether the second cache is empty includes: Obtaining second state information corresponding to the second cache; If the second state information includes a third character, determining that the second cache is empty; If the second state information includes the fourth character, it is determined that the second cache is not empty, and the third character and the fourth character are different characters.

12. The method according to any one of claims 1 to 4 or any one of claims 7 to 11, characterized in that: The cache is set in a device buffer of the audio device.

13. The method according to claim 5 or 6, characterized in that: The second cache is set in a device buffer of the audio device.

14. An electronic device, characterized in that: include: A memory and a processor, wherein the memory is used to store a computer program; and the processor is used to execute the method according to any one of claims 1 to 13 when calling the computer program.

15. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 13 is implemented.

16. A computer program product, characterized in that When the computer program product runs on an electronic device, the electronic device is enabled to execute the method according to any one of claims 1 to 13.