Audio playing method and deviceTechnical Field
The present application relates to the field of communications technologies, and in particular, to an audio playing method and apparatus.
Background
Currently, Android (Android) is widely applied to intelligent terminal devices, such as smart phones, tablet computers, televisions, digital cameras, game machines, smart watches and the like, as a Linux-based free and open source code operating system.
Fig. 1 is a schematic diagram of audio data streams of a prompt tone playing scheme in an existing android system. Arrows in the figure are used to indicate an audio data transmission path of an alert tone playing interface (soundport). As shown in fig. 1, in the conventional android system, an audio playing scheme implemented by using a prompt tone playing interface mainly includes the following steps:
firstly, the audio data to be played is decoded by the main processor, and the decoding result is copied to a system Kernel (Kernel) through memory mapping.
Then, the main processor sends the decoding result of the audio data to a shared memory between the main processor and an audio data processor (Adsp) in a kernel mode;
finally, the Audio data processor fetches the decoding result of the Audio data from the shared memory and sends the decoding result to an Audio decoder (Audio codec) for playing.
The inventor finds that the existing audio data playing scheme has a longer playing time delay, and thus cannot meet the low time delay requirement of many private network services (such as push-to-talk services).
Disclosure of Invention
In view of the above, the present invention provides an audio playing method and apparatus, which can shorten the audio playing time delay.
In order to achieve the purpose, the technical scheme provided by the invention is as follows:
an audio playback method, comprising:
the method comprises the steps that audio data of preset sound are stored in an audio data processor of the intelligent terminal in advance;
and when the intelligent terminal needs to play the sound, the corresponding audio playing program directly triggers the audio data processor to send the stored corresponding audio data to an audio decoder for playing.
Preferably, the storing comprises:
and when the intelligent terminal is started, storing the audio data in an audio data processor of the intelligent terminal.
Preferably, said directly triggering said audio data processor to send said stored corresponding audio data to an audio decoder for playing comprises:
the audio playing program sends an audio playing instruction to the audio data processor through the main processor;
and the audio data processor reads corresponding audio data from the storage space of the audio data processor according to the audio playing instruction and sends the audio data to the audio decoder for playing.
Preferably, the reading the corresponding audio data from the storage space of the audio decoder and sending the audio data to the audio decoder for playing includes:
the audio data processor reads corresponding audio data from a storage space of the audio data processor;
if the read audio data is decoded audio data, directly sending the read audio data to the audio decoder for playing; otherwise, after decoding the read audio data, sending the decoded audio data to the audio decoder for playing.
An audio playing device is arranged in an intelligent terminal and comprises: the intelligent terminal comprises a main processor, an audio data processor and an audio decoder, wherein the main processor is used for storing audio data of preset sound in the audio data processor of the intelligent terminal in advance; and when the audio playing program of the intelligent terminal needs to play the sound, the audio data processor is directly triggered to send the stored corresponding audio data to an audio decoder for playing.
Preferably, the main processor is specifically configured to:
and when the intelligent terminal is started, storing the audio data in an audio data processor of the intelligent terminal.
Preferably, the main processor is specifically configured to: sending an audio playing instruction of the audio playing program to the audio data processor;
the audio data processor is specifically configured to: and reading corresponding audio data from the storage space of the audio decoder according to the audio playing instruction, and sending the audio data to the audio decoder for playing.
Preferably, the reading the corresponding audio data from the storage space of the audio decoder and sending the audio data to the audio decoder for playing includes:
the audio data processor is specifically configured to: according to the audio playing instruction, after reading corresponding audio data from a storage space of the audio playing instruction, if the read audio data is decoded audio data, directly sending the read audio data to the audio decoder for playing; otherwise, after decoding the read audio data, sending the decoded audio data to the audio decoder for playing.
The present application also discloses a non-transitory computer-readable storage medium storing instructions that, when executed by a processor, cause the processor to perform the steps of the audio playback method as previously described.
The application also discloses an electronic device comprising the non-volatile computer-readable storage medium as described above, and the processor having access to the non-volatile computer-readable storage medium.
According to the technical scheme, the audio playing method and the audio playing device provided by the embodiment of the application have the advantages that the audio data of the sound to be played are prestored in the audio data processor, when the prestored sound is played, the prestored corresponding audio data are directly sent to the audio decoder hardware equipment by the audio data processor to be played, the processes of decoding by the main processor and transmitting the decoding result to the audio data processor are not needed, so that the obtaining path of the audio data is effectively shortened, the influence of system scheduling on audio playing is avoided, and therefore, low-delay playing can be realized.
Drawings
Fig. 1 is a schematic diagram of a transmission path of audio data in a prompt tone playing scheme of an existing android system;
FIG. 2 is a schematic flow chart of a method according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating transmission paths of audio data according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is further described in detail below by referring to the accompanying drawings and examples.
After the inventor carefully analyzes the existing audio playing scheme implemented by soundport, the inventor finds that the problem of the scheme that the time delay is large is caused by that: the whole process involves a plurality of links needing to be processed by the main processor, so that a plurality of links are influenced by system scheduling, namely, the CPU time slice of the main processor needs to be obtained for decoding, storing and the like of audio data, and the playing time delay is long. Based on this, in the embodiment of the present application, it is considered that the influence of system scheduling on audio playing is reduced as much as possible, the audio data to be played is stored in the audio data processor in advance, and the audio data processor directly sends the audio data to the audio decoder for playing, so that the influence of system scheduling on audio data playing is greatly reduced, low-delay playing can be realized, and the low-delay playing requirement of a service is met.
Fig. 2 is a schematic flow diagram of an audio playing method according to an embodiment of the present invention, and as shown in fig. 2, the audio playing method implemented in this embodiment mainly includes:
step 201, storing the audio data of the preset sound in an audio data processor of the intelligent terminal in advance.
In this step, in order to simplify a path for transmitting the audio data to the audio data processor when playing the sound, the audio data of the sound is stored in the audio data processor of the intelligent terminal in advance. Therefore, when sound is played, the corresponding audio playing program can trigger the audio data processor to directly acquire the corresponding audio data from the storage space of the audio data processor, and the influence of system scheduling on the audio data playing is effectively avoided.
Preferably, the sound source file may be stored in an audio data processor of the intelligent terminal when the intelligent terminal is powered on.
Specifically, the position of the audio data processor for storing the audio data may be a cache or a memory, and the storage is not limited thereto, as long as the storage belongs to a storage space that the audio data processor can directly access.
Step 202, when the intelligent terminal needs to play the sound, a corresponding audio playing program directly triggers the audio data processor to send the stored corresponding audio data to an audio decoder for playing.
In this step, as described above, unlike the conventional scheme, there is no need to go through the decoding of the main processor and the process of transmitting the decoding result to the audio data processor. Fig. 3 is a schematic diagram of a transmission path of audio data when the embodiment of the present invention is adopted, where a solid arrow in fig. 3 is used to indicate the transmission path of the audio data, and a dashed arrow is used to indicate a call flow of starting playing with low latency. As shown in fig. 3, the audio data for playing the sound is directly retrieved from the storage space directly accessible by the audio data processor and sent to the audio decoder hardware. Therefore, the steps can effectively avoid the influence of system scheduling on the audio data playing, greatly shorten the audio playing time delay, and further can meet the service requirement of low-time-delay playing.
Preferably, the following method can be adopted to directly trigger the audio data processor to send the stored corresponding audio data to an audio decoder for playing:
a1, the audio playing program sends the audio playing instruction to the audio data processor through the main processor.
a2, the audio data processor reads corresponding audio data from its own storage space according to the audio playing instruction, and sends the audio data to the audio decoder for playing.
In practical applications, the audio data pre-stored in the audio data processor of the intelligent terminal instep 201 may be undecoded or decoded, and when the audio data is undecoded data, in this step, the audio data processor reads corresponding audio data from its own storage space according to the audio playing instruction, and then needs to decode the audio data first and send the audio data to the audio decoder for playing.
According to the scheme, the method can realize low-delay playing of the sound. Through tests, when the method embodiment is adopted to play the prompt tone on the intelligent terminal, the total time for playing the prompt tone is reduced to 120ms from the original 280ms, the time delay of 160ms is saved, and the time delay for starting the private network service is greatly reduced.
Corresponding to the above method embodiment, the present application further provides an audio playing device, which is disposed in an intelligent terminal, and includes: the intelligent terminal comprises a main processor, an audio data processor and an audio decoder, wherein the main processor is used for storing audio data of preset sound in the audio data processor of the intelligent terminal in advance; and when the audio playing program of the intelligent terminal needs to play the sound, the audio data processor is directly triggered to send the stored corresponding audio data to an audio decoder for playing.
Preferably, the main processor is specifically configured to:
and when the intelligent terminal is started, storing the audio data in an audio data processor of the intelligent terminal.
Preferably, the main processor is specifically configured to: sending an audio playing instruction of the audio playing program to the audio data processor;
the audio data processor is specifically configured to: and reading corresponding audio data from the storage space of the audio decoder according to the audio playing instruction, and sending the audio data to the audio decoder for playing.
Preferably, the reading the corresponding audio data from the storage space of the audio decoder and sending the audio data to the audio decoder for playing includes:
the audio data processor is specifically configured to: according to the audio playing instruction, after reading corresponding audio data from a storage space of the audio playing instruction, if the read audio data is decoded audio data, directly sending the read audio data to the audio decoder for playing; otherwise, after decoding the read audio data, sending the decoded audio data to the audio decoder for playing.
Furthermore, the present application also provides a non-transitory computer-readable storage medium storing instructions that, when executed by a processor, cause the processor to perform the steps of the audio playback method as described above.
Further, the present application provides an electronic device comprising the non-volatile computer-readable storage medium as described above, and the processor having access to the non-volatile computer-readable storage medium.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.