Audio data reading method and processing system
Technical Field
The invention relates to the field of audio data processing, in particular to an audio data reading method and an audio data processing system.
Background
All sounds heard by human beings are called audio, which may include noise, after the sounds are recorded, whether speaking, singing and musical instruments can be processed by digital music software, and then the audio is stored in a computer, actually, if the computer is provided, and a corresponding audio card (which is often called a sound card), all sounds can be recorded, and acoustic characteristics (such as sound level and the like) of the sounds can be stored in a hard disk file of the computer.
In the digital era, excellent tone quality and good audio call experience are pursued, many existing operating systems (such as android) can support audio input of microphones and the like, in order to solve problems of audio delay, blockage and the like caused by unstable network transmission, audio data buffer packet loss can be performed when audio data are read, and the existing buffer packet loss processing method is complex and low in efficiency, so that under the condition of meeting requirements, how to adopt a simple method capable of realizing low audio delay to perform audio data reading processing has very important significance.
Disclosure of Invention
In view of this, the present application provides an audio data processing method, which determines whether to discard data according to a preset relationship between the size of the audio data to be read and the size of the remaining data amount of the audio buffer by reading the size of the remaining data amount of the audio buffer, wherein the criterion is simple, the data processing efficiency is high, and the requirement of low audio delay can be met. In order to solve the technical problems, the technical scheme provided by the invention is as follows:
an audio data reading method, comprising:
obtaining a buffer audio data volume m;
acquiring the amount n of audio data to be read;
obtaining an allowable buffering audio data amount p;
and judging the relation between m and n, if m is more than n + p, discarding s buffered audio data, and then reading n buffered audio data, wherein m- (s + n) is more than or equal to 0 and less than or equal to p.
Further, the method further comprises:
if n is less than or equal to m and less than or equal to n + p, directly reading n buffered audio data.
Further, the method further comprises:
and if m is less than n, directly reading the m buffered audio data, or continuously waiting until the amount of the buffered audio data reaches n, and reading the n audio data.
Further, the step of obtaining the amount of buffered audio data m includes:
receiving an audio data reading command;
finding a buffer data node according to the audio data reading command;
and obtaining the buffered audio data volume m through the buffered data node.
Further, where p is n, the act of discarding s buffered audio data comprises: discarding s buffered audio data according to equation (1):
s=(INT(m/n)-1)*n (1),
where INT denotes the rounding function.
An audio data processing system comprising:
a buffered audio data amount acquisition module: for obtaining a buffered audio data volume m;
the audio data volume to be read acquisition module: the method comprises the steps of obtaining an audio data volume n to be read;
an allowed buffered audio data amount acquisition module: for obtaining an allowable buffered audio data amount p;
a judgment processing module: and the method is used for judging the relation between m and n and selecting a mode for reading the audio data according to the judgment result.
Further, the judgment processing module further includes an audio data waiting unit: and the judgment processing module is used for continuously waiting until the amount of the buffered audio data reaches n and then reading the n audio data when m is less than n.
Further, still include:
an audio data read command receiving module: for receiving an audio data read command;
the buffer data node searching module: for searching the buffered data node according to the audio data read command.
Further, the judgment processing module includes an audio data discarding function storage unit: the audio data processing module discards buffered audio data according to the audio data discarding function.
The audio data processing method provided by the invention judges whether to discard the data or directly read the audio data according to the relationship between the preset size of the audio data amount to be read and the size of the remaining data amount of the audio buffer area by reading the size of the remaining data amount of the audio buffer area, has simple criterion and high data processing efficiency, and can meet the requirement of low audio delay.
Drawings
Fig. 1 is a flowchart of the method provided in example 1.
Fig. 2 is a block diagram schematically illustrating the structure of an audio data processing system according to embodiment 2.
Detailed Description
In order to make the technical solutions of the present invention better understood by those skilled in the art, the present invention will be further described in detail with reference to the accompanying drawings and specific embodiments.
Example 1
As shown in fig. 1, the present embodiment provides an audio data reading method, including:
s1: obtaining a buffer audio data volume m;
s2: acquiring the amount n of audio data to be read;
s3: obtaining an allowable buffering audio data amount p;
s4: and judging the relation between m and n, if m is more than n + p, discarding s buffered audio data, and then reading n buffered audio data, wherein m- (s + n) is more than or equal to 0 and less than or equal to p.
It should be noted that the present embodiment can be applied to an android system or other operating systems, for example, an audio driver is provided in a system kernel, a buffer is provided in the audio drive, audio data is stored in the buffer, and, in step S1, the remaining audio data amount m may be calculated by the formula period size period count, wherein, period _ size refers to the minimum data size read from the buffer in the audio driver each time, and period _ count refers to how many period _ sizes are in the buffer, in the specific implementation of this embodiment, the period _ size is preset, the remaining audio data amount m is read only once before the audio data is read each time, and after the audio data is read, if the audio data needs to be read again, since the amount of remaining audio data in the buffer in the audio drive is dynamically changing, a new amount m of remaining audio data needs to be read again.
It should be noted that the value of the audio data amount n to be read refers to an audio data amount that the system wants to read, and this value may be dynamically changed, so that the sizes of m and n are determined, on one hand, when the remaining data amount m exceeds the required data n, it is indicated that the audio has a delay, and if the delay is to be reduced, a part of data needs to be discarded.
It should be noted that in step S4, the S audio data in the buffer may be discarded at will for efficiency, and if the relevant data needs to be discarded accurately, the VAD algorithm may be used for the discarding process.
Preferably, the method provided by this embodiment further includes:
if n is less than or equal to m and less than or equal to n + p, directly reading n buffered audio data.
It should be noted here that although the remaining data amount in the buffer may cause audio delay, the action of discarding data may also occupy system resources and waste processing time, and therefore, if the remaining data amount is not greater than p after reading the audio data, the audio delay of the system may be acceptable, and thus, the setting allows the remaining audio data to balance the relationship between the audio delay and the system efficiency, of course, if necessary, the value of p may be set to be smaller, even 0, so that after data packet loss, the audio delay may be very small or even zero, and user experience may be effectively improved.
Preferably, the method further comprises: and if m is less than n, directly reading the m buffered audio data, or continuously waiting until the amount of the buffered audio data reaches n, and reading the n audio data.
It should be noted here that when m < n, the audio data may be read in two ways, one is to directly read all the remaining audio data in the buffer, and the other is to read the audio data after the number of the audio data in the buffer reaches n.
Preferably, the step of obtaining the amount of buffered audio data m, i.e., step S1, includes:
receiving an audio data reading command;
finding a buffer data node according to the audio data reading command;
and obtaining the buffered audio data volume m through the buffered data node.
It should be noted here that the buffered data node is an interface made by an audio driver of a system kernel, and a user can obtain or write some data through the node to achieve an interaction between a user plane and a kernel space, and obtaining the buffered audio data amount m through the buffered data node means analyzing the searched buffered data node, opening the node, then reading a character string to a place, and then analyzing a numerical value behind the read character string, thereby obtaining the buffered audio data amount m.
Preferably, in step S4, when p is equal to n, the action of discarding S buffered audio data includes: discarding s data within the buffer according to equation (1):
s=(INT(m/n)-1)*n (1),
where INT denotes the rounding function.
Example 2
As shown in fig. 2, the present embodiment provides an audio data processing system including:
a buffered audio data amount acquisition module: for obtaining a buffered audio data volume m;
the audio data volume to be read acquisition module: the method comprises the steps of obtaining an audio data volume n to be read;
an allowed buffered audio data amount acquisition module: for obtaining an allowable buffered audio data amount p;
a judgment processing module: and the method is used for judging the relation between m and n and selecting a mode for reading the audio data according to the judgment result.
Preferably, the judgment processing module further includes an audio data waiting unit: and the judgment processing module is used for continuously waiting until the amount of the buffered audio data reaches n and then reading the n audio data when m is less than n.
Preferably, this embodiment further includes:
an audio data read command receiving module: for receiving an audio data read command;
the buffer data node searching module: for searching the buffered data node according to the audio data read command.
Preferably, the judgment processing module includes an audio data discarding function storage unit: for storing an audio data discarding function according to which the audio data processing module discards buffered audio data, the specific way in which the respective modules perform operations has been described in detail in the embodiments related to the method, and will not be elaborated herein.
The above is only a preferred embodiment of the present invention, and it should be noted that the above preferred embodiment should not be considered as limiting the present invention, and the protection scope of the present invention should be subject to the scope defined by the claims. It will be apparent to those skilled in the art that various modifications and adaptations can be made without departing from the spirit and scope of the invention, and these modifications and adaptations should be considered within the scope of the invention.