1. Field of the Invention
The invention relates to a method and an apparatus applied to an audio player and, more particularly, to a method and an apparatus used to estimate the audio length of an audio file.
2. Description of the Prior Art
Most audio players have a function of seeking. In general, the seeking function of an audio player is to display a seeking bar which shows the audio length of an audio file and indicates the time that the audio file has been played as well. Therefore, a user can click any point of the seeking bar to appoint the time which the user desires to render the audio file. And, after the user clicks the seeking bar, the audio player will calculate the proportion of the clicked position to the entire seeking bar. Then, the audio player will multiply the audio length of the audio file by the proportion to figure out the point which the user desires to render the audio file. In this way, the position of the audio frame which the user desires to render the audio file can be found. In view of this, the audio player must obtain an estimated audio length of the audio file before seeking, and the deviation of the estimated audio length must not be huge. If the deviation of the estimated audio length is huge, the sought audio frame may not be come up to the point estimated by the user, and even the corresponding audio frame can not be located.
Nowadays, there are two main types of the compression for audio files: the constant bit rate and the variable bit rate. Compressing an audio file by the constant bit rate is to store audio data of fixed time with fixed data amount. Thus, the audio length of the audio file compressed by constant bit rate is easy to be estimated. However, in order to maintain audio quality, in the audio file compressed by variable bit rate, the storing bit rate is adjusted according to the characteristic of the audio data. Therefore, the amount of each audio data of fixed time may be different, and the audio length of the audio file compressed by the variable bit rate is also hard to be estimated.
In order to solve the problem that the audio length is hard to be estimated, certain audio files compressed by the variable bit rate will use tags (ex., ID3 and VBRI/Xing Header) to store the related data of audio length in the audio file beforehand. However, not all of the audio files provide the related data of audio length. Therefore, when playing the audio file without any related data of audio length, an audio player must calculate the audio length of the audio file by itself. And, the most accurate way to calculate audio length is to read the entire audio file, and then analyze the number of all audio frames to obtain the audio length. However, it needs a lot of time and system resource to read and analyze the entire audio file, using this method in a resource-limited embedded system is not practical at all.
There are also two main methods of estimating audio length nowadays: the predictive estimation and the real-time estimation. The predictive estimation method is to select several audio frames from the audio file before playing an audio file and use the average bit rate of these selected audio frames to estimate the audio length of the audio file which will be played soon. After the audio file is played, the audio player will fixedly display the audio length which is figured out at first, which will not be calculated or adjusted later. The advantage of predictive estimation method is that it is easy to practice, but its drawback is that the estimated result is not accurate. Due to the difference between the average bit rate of the selected audio frames and the average bit rate of the entire audio file, the audio length calculated by the predictive estimation method may be very different from the practical audio length of the audio file.
The real-time estimation method is to continuously calculate the average bit rate of the played parts in the process of playing an audio file, and constantly update the displayed audio length according to this average bit rate. The advantage of the real-time estimation method is that the estimated audio length will be closer to the correct audio length in accordance with the increase of playing audio frames, yet the drawback is that the estimated audio length of the audio played at the beginning may be very different from the correct audio length of the played audio. For example, if the average bit rates of the beginning audio frames of a certain audio file are lower, then the audio length estimated by the real-time estimation method in the beginning will be much larger than the correct audio length, and the estimated audio length will slowly converge to the correct audio length of the audio file afterwards.
From the above mentioned, it is known that either the predictive estimation method or the real-time estimation method has its own drawback, which is not an ideal way to estimate audio length.
The scope of the invention is to provide a method for an audio player to estimate a more accurate audio length before seeking. This method combines the above mentioned predictive estimation method and real-time estimation method. In the beginning of playing an audio file, the audio length estimated by the predictive estimation method is provided, and then the audio length is adjusted to the audio length estimated by the real-time estimation method in the process of playing the audio file.
From a file system, the total data amount (Stotal) of the audio file can be known. At first, the predictive estimation method is used to calculate a predicted audio length L0 in advance. Afterward, when the audio player of the invention has already played the audio file to the ith audio frame (assume the audio file includes N audio frames, and i is an integer index ranging from 1 to N), the played data amount can be added up as Splayed(i), and the time of the played audio length can be added up as Tplayed(i). The main scope of the invention is to calculate the estimated audio length LE(i) of the ith audio frame according to the above information.
In an estimating method of a preferred embodiment according to the invention, the predictive estimation method is used to calculate a predicted audio length L0 before playing the audio file, and to assume an initial adjustable audio length LA(0) equal to L0. Afterward, a procedure is performed after the ith audio frame is played. First, the procedure uses real-time estimation method to calculate a reference audio length LR(i) of the ith audio frame according to Stotal, Splayed(i) and Tplayed(i). Then, a variation proportion of the ith audio frame R(i) is calculated according to LR(i) and LR(i−1). It is judged whether LR(i) is stable by confirming whether R(i) is smaller than a predetermined threshold. If it is stable, then the adjustable audio length of the ith audio frame LA(i) is calculated referring to LR(i) and LA(i−1); if not, LA(i)=LA(i−1) is maintained. Finally, according to LA(i) and LR(i), an estimated audio length of the ith audio frame LE(i) is generated file to the entire audio file Splayed(i)/Stotal as a weight to feedback and output when enquired.
An estimating apparatus of another preferred embodiment according to the invention includes a processor and a memory. The memory is used to store a software program code and an audio file; moreover, it can temporarily save audio length data. The processor performs the software program code stored in the memory device. The procedures of the software program code include firstly calculating a predicted audio length L0 by using the predictive estimation method, and then using the above mentioned real-time estimation method to generate an estimated audio length LE within each audio frame; and eventually, saving the estimated audio length in a memory device to provide feedback and output when enquired.
The advantage and spirit of the invention may be understood by the following recitations together with the appended drawings.
A scope of the invention is to provide a method for an audio player to estimate a more accurate audio length before seeking. This method combines the above mentioned predictive estimation method and real-time estimation method. In the beginning of playing an audio file, the audio length estimated by the predictive estimation method is provided, and then the audio length is adjusted to the audio length estimated by the real-time estimation method in the process of playing the audio file.
From a file system relative to the audio file, the total data amount (Stotal) of the audio file can be known. At first, the predictive estimation method is used to calculate a predicted audio length L0 in advance. Afterward, when the audio player of the invention has already played the audio file to the ith audio frame (assume the audio file includes N audio frames, and i is an integer index ranging from 1 to N), the played data amount can be added up as Splayed(i), and the time of the played audio length can be added up as Tplayed(i). The main scope of the invention is to calculate the estimated audio length LE(i) of the ith audio frame according to the above information.
LR(i)=[Stotal/Splayed(i)]*Tplayed(i), (Equation 1)
wherein Stotal is the total data amount of the audio file, Splayed(i) is the sum of data amount of the audio file from the first audio frame to the ith audio frame, Tplayed(i) is the time interval between the time that the audio file is started to be played and the time that the ith audio frame is played.
Step 210 is to calculate the variation ratio of the ith audio frame R(i) according to a second equation and judge whether LR(i) is stable according to whether the variation ratio is smaller than a predetermined threshold. The second equation can be represented as:
R(i)=abs[LR(i)−LR(i−1)]/LR(i), (Equation 2)
wherein LR(0) is set as 0.
The variation ratio R(i) represents the variation degree between the reference audio length of the ith audio frame LR(i) and the reference audio length of the (i−1)th audio frame LR(i−1). If R(i) is too large, larger than the predetermined threshold, it means that the average bit rate of the audio file is not stable yet, or compared to the bit rate of other audio frames, the bit rate of the ith audio frame has huge variation. The threshold can be determined according to experiment results.
If the judging result of step 210 is YES, it means that the average bit rate of the audio file has already approached the stability. Step 211 is to calculate the adjustable audio length of the ith audio frame LA(i) according to a third equation represented as:
LA(i)=LA(i−1)*(1−P)+LR(i)*P, (Equation 3)
wherein P is a predetermined constant, and 0<P<1. This constant can be determined according to experiment results.
As shown in Equation 3, when the average bit rate of the audio file has already approached the stability, the estimating method of the invention is to combine LA(i−1) and the newest reference audio length LR(i) with a fixed proportion to obtain an adjustable audio length of the ith audio frame LA(i). This will make LA(i) gradually approach the stable reference audio length.
If the judging result of step 210 is NO, then step 212 is to calculate the adjustable audio length of the ith audio frame LA(i) according to a fourth equation represented as:
LA(i)=LA(i−1), (Equation 4)
As shown in Equation 4, because the average bit rate of the audio file is not stable yet, according to the estimating method of the invention, LA(i) is not adjusted immediately based on the newest reference audio length LR(i), but equals to the former adjustable audio length LA(i−1). In this way, the adjustable audio length can avoid generating huge variation with the temporary bit rate.
In practical conditions, the last few audio frames of certain audio files are silence audio frames. Because the bit rate of these silence audio frames is much smaller than the average bit rate, it induces that the average bit rate drops immediately. Thus, the reference audio length LR(i) will be increased immediately. However, the adjustable audio length LA(i) will not be increased immediately following the reference audio length LR(i). This phenomenon causes that the adjustable audio length LA(i) does not be equal to the correct audio length when the last audio frame is played. According to the estimating method of the invention, the above mentioned problems will be solved by step 220.
Step 220 is to calculate the estimated audio length of the ith audio frame LE(i) which is displayed by the audio player at last according to a fifth equation represented as:
LE(i)=LA(i)*(1−W)+LR(i)*W, (Equation 5)
wherein W=[Splayed(i)/Stotal], namely the proportion of data amount of the part which has already been played to the entire audio file.
The Nth estimated audio length LE(N) calculated from Equation 5 must be equal to LR(N), that is to say, the Nth estimated audio length is assumed to converge to the correct audio length of the audio file.
Finally, in step 230, the ith estimated audio length LE(i) calculated from step 220 is stored for further feedback and output when the seeking function is enquired.
According to the invention,
(1) before the audio file is played, calculating a predicted audio length L0 and setting an initial adjustable audio length LA(0) equal to the predicted audio length L0; and
(2) when the ith audio frame of the audio file being played, performing the following sub-steps:
(2a) calculating a reference audio length LR(i) of the ith audio frame;
(2b) calculating a variation ratio R(i) of the ith audio frame according to LR(i) and LR(i−1), and judging whether R(i) is smaller than a predetermined threshold; if YES, performing the sub-step (2c); if NO, performing the sub-step (2d);
(2c) calculating an adjustable audio length LA(i) of the ith audio frame according to LA(i−1) and LR(i), and performing the sub-step (2e);
(2d) setting an adjustable audio length LA(i) of the ith audio frame equal to LA(i−1), and performing the sub-step (2e);
(2e) calculating the estimated audio length LE(i) of the ith audio frame according to LA(i), LR(i), a cumulative played data amount Splayed(i), and a total data amount of the audio file Stotal.;
(2f) storing the estimated audio length of the ith audio frame LE(i) in the memory 63, and feeding back and outputting it when the seeking function is enquired.
It should be noticed that the predictive estimation method can be used to calculate the predicted audio length L0 in the step (1) of the software program code performed by the processor 62, and the predictive estimation method includes the following sub-steps:
(1a) selecting a plurality of audio frames from the audio file;
(1b) calculating an average bit rate of the plurality of selected audio frames; and
(1c) dividing the total data amount Stotal of the audio file by the average bit rate to obtain the predicted audio length L0.
In practical applications, the predicted audio length L0 can be directly obtained according to the file header information in the step (1) of the software program code performed by the processor 62. This method includes the following sub-steps:
(3a) judging whether the file header information of audio file includes audio length related information; if YES, performing the sub-step (3b); if NO, performing the sub-steps (1a), (1b), and (1c) of the predictive estimation method;
(3b) obtaining the predicted audio length L0 directly.
In practical applications, the predicted audio length L0 can be directly calculated according to the audio file size in the step (1) of the software program code performed by the processor 62. This method includes the following sub-steps:
(4a) judging whether the total data amount Stotal of the audio file is smaller than a total amount threshold; if YES, performing the sub-step (4b); if NO, performing the sub-steps (1a), (1b), and (1c) of the predictive estimation method; and
(4b) directly reading and calculating the sum of all audio frames in the audio file to obtain the predicted audio length information L0.
The method and apparatus based on the invention can be used to various audio files coded by the way of audio frames, and it also can provide a stable estimated audio length which is getting more and more accurate. The probability of obtaining the audio frame which is not corresponding to the user-selected time point by the audio player or obtaining no audio frame corresponding to the user-selected time point can be reduced.
With the example and explanations above, the features and spirits of the invention will be hopefully well described. Those skilled in the art will readily observe that numerous modifications and alterations of the device may be made while retaining the teaching of the invention. Accordingly, the above disclosure should be construed as limited only by the metes and bounds of the appended claims.
Number | Date | Country | Kind |
---|---|---|---|
95129681 A | Aug 2006 | TW | national |
Number | Name | Date | Kind |
---|---|---|---|
20020031065 | Kajiyama et al. | Mar 2002 | A1 |
20030228131 | Miyazawa | Dec 2003 | A1 |
20060153524 | Damstra et al. | Jul 2006 | A1 |
20060206324 | Skilling et al. | Sep 2006 | A1 |
20070189128 | Chung | Aug 2007 | A1 |
Number | Date | Country | |
---|---|---|---|
20080039965 A1 | Feb 2008 | US |