Frequency modulation method for audio playback and electronic equipment
By dynamically adjusting the processor frequency in a small embedded system, and obtaining audio clips based on the total playable time after decoding and task scheduling interval time, the lag problem caused by the long decoding time of the audio file is solved, and the smooth audio playback is achieved sex.
Patent Information
- Application Number
- CN202411076615.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2044-08-07
AI Technical Summary
In small embedded systems with limited resources and performance, audio files are decoding too long, resulting in poor audio sound lag and not smooth.
By adjusting the processor frequency, the processor frequency is dynamically adjusted according to the total playable time after decoding and the task scheduling interval time, thereby obtaining the audio clips for decoding and ensuring the smoothness of audio playback.
It realizes fluency during audio playback, reduces lag, and further ensures smooth audio playback through frequency adjustment in the pre-play stage.
Smart Images

Figure CN118609610B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of audio technology, and in particular to a frequency modulation method for audio playback and electronic equipment. Background Art
[0002] In small embedded systems with limited resources and performance, when playing audio, the audio file decoding time is too long, and the audio sound may be stuck and not smooth. For example, the MCU (Microcontroller Unit) reads an audio file from an external storage device (such as a USB flash drive, Flash, etc.), and can only read a small amount of data at a time, and then decodes the original PCM (Pulse Code Modulation) data according to the file encoding method for playback. In this process, the data decoded and played at a time is relatively small, and the playable time is only a few hundred milliseconds. Due to the scheduling and operation of other tasks in the system, the time to read and decode the next segment of data may be longer than the time it takes to play the previous segment of data, so the audio sounds like it is missing some content, noise appears, or even stuck. Summary of the invention
[0003] The technical problem to be solved by the present invention is that, in view of at least one defect of the related technology mentioned in the above background technology: when playing audio, the audio file decoding time is too long, and the audio sound will be stuck and not smooth, and a frequency modulation method and electronic device for audio playback are provided.
[0004] The technical solution adopted by the present invention to solve the technical problem is: constructing a frequency modulation method for audio playback, applied to a processor, comprising the following steps:
[0005] S11: Entering the formal playback phase, obtaining the total playable time after the i-1th decoding, the interval time of each task scheduling at the current processor frequency, and the time required for decoding at the current processor frequency, where i≥2;
[0006] S12: By determining the relationship between the total playable time after the i-1th decoding, the interval time of each task scheduling at the current processor frequency, and the decoding time required at the current processor frequency, the frequency of the current processor is adjusted or maintained, and at least one audio clip for the i-th decoding is obtained;
[0007] S13: Scheduling a task to decode the acquired at least one audio segment;
[0008] S14: Determine whether all audio clips in the audio file have been decoded. If not, execute step S15; if yes, end;
[0009] S15: Calculate the total playable time after the i-th decoding;
[0010] S16: Set i = i+1, and return to execute step S11.
[0011] Preferably, step S12 includes:
[0012] S121-1: Calculate the remaining playback time after the i-1th decoding according to the total playable time after the i-1th decoding and the interval time of each task scheduling at the current processor frequency;
[0013] S122-1: adjusting or maintaining the frequency of the current processor by comparing the remaining playback time after the i-1th decoding with the time required for decoding at the current processor frequency, and obtaining at least one audio clip for the i-th decoding;
[0014] Alternatively, step S12 includes:
[0015] S121-2: Calculate the remaining playback time after the i-1th decoding according to the total playable time after the i-1th decoding, the interval time of each task scheduling at the current processor frequency, and the time required for decoding at the current processor frequency;
[0016] S122-2: By comparing the weighted remaining playback time after the i-1th decoding with the sum of the interval time of each task scheduling at the current processor frequency and the decoding time required at the current processor frequency, the frequency of the current processor is adjusted or maintained, and at least one audio clip for the i-th decoding is obtained.
[0017] Preferably, step S121-1 includes:
[0018] The remaining playback time after the i-1th decoding is obtained by subtracting the interval time of each task scheduling under the current processor frequency from the total playable time after the i-1th decoding;
[0019] Step S122-1 includes:
[0020] When it is determined that the remaining playback time after the i-1th decoding is greater than 2 times the time required for decoding at the current processor frequency, the frequency of the current processor is reduced, and at least one audio segment for the i-th decoding is obtained;
[0021] When it is determined that the remaining playback time after the i-1th decoding is less than or equal to the time required for decoding at the current processor frequency, the frequency of the current processor is increased, and at least one audio segment for the i-th decoding is obtained;
[0022] When it is determined that the remaining playback time after the i-1th decoding is greater than the time required for decoding at the current processor frequency, and is less than or equal to 2 times the time required for decoding at the current processor frequency, the current processor frequency is maintained, and at least one audio segment for the i-th decoding is obtained.
[0023] Preferably, step S121-2 includes:
[0024] The remaining playback time after the i-1th decoding is obtained by subtracting the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency from the total playable time after the i-1th decoding;
[0025] Step 122-2 includes:
[0026] Weighting the remaining playback time after the (i-1)th decoding to obtain a first threshold;
[0027] If it is determined that the first threshold is greater than 2 times the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, the frequency of the current processor is reduced, and at least one audio clip for performing the i-th decoding is obtained;
[0028] When it is determined that the first threshold is less than or equal to the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, the frequency of the current processor is increased, and at least one audio segment for performing the i-th decoding is obtained;
[0029] When it is determined that the first threshold is greater than the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, and is less than or equal to 2 times the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, the frequency of the current processor is maintained, and at least one audio clip for the i-th decoding is obtained.
[0030] Preferably, step S15 includes:
[0031] S151-1: Obtaining the corresponding playable time of at least one audio segment after the i-th decoding and re-obtaining the time required for decoding at the current processor frequency;
[0032] S152-1: Calculate the total playable time after the i-th decoding according to the remaining playable time after the i-1th decoding, the time required for decoding at the current processor frequency, and the corresponding playable time of at least one audio clip after the i-th decoding;
[0033] Alternatively, step S15 includes:
[0034] S151-2: Obtaining the corresponding playable time of at least one audio segment after the i-th decoding and re-obtaining the time required for decoding at the current processor frequency and the interval time of each task scheduling at the current processor frequency;
[0035] S152-2: Calculate the total playable time after the i-1th decoding based on the weighted remaining playable time after the i-1th decoding, the time required for decoding at the current processor frequency, the interval time of each task scheduling at the current processor frequency, and the corresponding playable time of at least one audio segment after the i-th decoding.
[0036] Preferably, step S152-1 includes:
[0037] The remaining playback time after the i-1th decoding is subtracted from the time required for decoding at the current processor frequency, and the corresponding playable time of at least one audio segment after the i-th decoding is added to obtain the total playable time after the i-th decoding;
[0038] Alternatively, step S152-2 includes:
[0039] The weighted remaining playback time after the i-1th decoding is subtracted from the time required for decoding at the current processor frequency and the interval time of each task scheduling at the current processor frequency, and the corresponding playable time of at least one audio segment after the i-th decoding is added to obtain the total playable time after the i-th decoding.
[0040] Preferably, before step S11, the method further includes:
[0041] Entering the formal playback phase, obtaining at least one audio segment for the first decoding;
[0042] Scheduling a task to decode the acquired at least one audio segment, and obtaining a corresponding playable time of the at least one audio segment after the first decoding;
[0043] The corresponding playable time of at least one audio segment after the first decoding is used as the total playable time after the first decoding.
[0044] Preferably, the method further comprises:
[0045] S21: Entering the pre-playing stage, obtaining at least one audio segment for performing the j-th pre-decoding, where j≥1;
[0046] S22: Scheduling tasks to decode the acquired at least one audio segment, obtaining the interval time of each task scheduling at the current processor frequency, the time required for decoding at the current processor frequency, and the corresponding playable time of the at least one audio segment after the j-th pre-decoding;
[0047] S23: pre-determining whether a formal playback condition is met according to the interval time of each task scheduling at the current processor frequency, the time required for decoding at the current processor frequency, and the corresponding playable time of at least one audio segment after the j-th pre-decoding;
[0048] S24: If not, adjust the frequency of the current processor, set j=j+1, and return to step S21;
[0049] S25: If yes, determine the frequency of the current processor to enter the formal playback phase.
[0050] Preferably, step S23 includes:
[0051] Determine whether the corresponding playable time of at least one audio segment after the j-th pre-decoding is greater than or equal to the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency;
[0052] Alternatively, step S23 includes:
[0053] Weighting the corresponding playable time of at least one audio segment after the j-th pre-decoding to obtain a second threshold;
[0054] Determine whether the second threshold is greater than or equal to the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency;
[0055] Furthermore, step S24 includes:
[0056] If not, the frequency of the current processor is increased, j=j+1, and the process returns to step S21.
[0057] The present invention also constructs an electronic device, comprising:
[0058] one or more processors;
[0059] A storage device is used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the frequency modulation method for audio playback as described in any one of the above items.
[0060] By implementing the present invention, the following beneficial effects are achieved:
[0061] The present invention can dynamically adjust the frequency of the processor through the frequency modulation method in the formal playing stage, so as to ensure the smoothness of the sound and reduce the jamming when the audio is formally played.
[0062] In addition, the frequency modulation method in the pre-play stage can be used to adjust the frequency of the processor before formal playback, further ensuring the smoothness of the sound when the audio is officially played. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0064] Figure 1 A flow chart showing the formal playback phase in the frequency modulation method for audio playback according to an embodiment of the present invention is shown;
[0065] Figure 2 The flow chart of step S12 in the frequency modulation method of audio playback according to an embodiment of the present invention is shown. Figure 1 ;
[0066] Figure 3 The flow chart of step S15 in the frequency modulation method of audio playback according to an embodiment of the present invention is shown. Figure 1 ;
[0067] Figure 4 The flow chart of step S12 in the frequency modulation method of audio playback according to another embodiment of the present invention is shown. Figure 2 ;
[0068] Figure 5 The flow chart of step S15 in the frequency modulation method of audio playback according to another embodiment of the present invention is shown. Figure 2 ;
[0069] Figure 6 A flow chart showing a pre-playing stage in a frequency modulation method for audio playback according to an embodiment of the present invention is shown;
[0070] Figure 7 A flowchart showing step S23 of the pre-playing stage in the frequency modulation method for audio playback according to an embodiment of the present invention is shown;
[0071] Figure 8 A logical structure diagram of an electronic device according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0072] In order to have a clearer understanding of the technical features, purposes and effects of the present invention, specific embodiments of the present invention are now described in detail with reference to the accompanying drawings.
[0073] It should be noted that the flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor do they have to be executed in the order described. For example, some operations / steps can be decomposed, while some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0074] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0075] like Figure 1 As shown, some embodiments of the present invention disclose a frequency modulation method for audio playback, which is applied to a processor, such as an MCU, etc. The MCU here is only an example and is not intended to limit the present application. During formal playback, due to the fluctuation of system load tasks, the interval time of each task scheduling will also be different, so it is also necessary to dynamically adjust the frequency of the processor. Therefore, the frequency modulation method for audio playback includes the following steps:
[0076] S11: Entering the formal playback phase, obtaining the total playable time after the i-1th decoding, the interval time of each task scheduling at the current processor frequency, and the time required for decoding at the current processor frequency, where i≥2;
[0077] S12: By determining the relationship between the total playable time after the i-1th decoding, the interval time of each task scheduling at the current processor frequency, and the decoding time required at the current processor frequency, the frequency of the current processor is adjusted or maintained, and at least one audio clip for the i-th decoding is obtained;
[0078] S13: Scheduling a task to decode the acquired at least one audio segment;
[0079] S14: Determine whether all audio clips in the audio file have been decoded. If not, execute step S15; if yes, end, and when the next audio file (i.e., the next song) needs to be played, enter the formal playback phase of the next audio file at the current processor frequency, or enter the pre-playing phase of the next audio file at the current processor frequency;
[0080] S15: Calculate the total playable time after the i-th decoding;
[0081] S16: Set i = i+1, and return to execute step S11.
[0082] The at least one audio segment can be one, two or any number of audio segments, which is not limited here. An audio file will be divided into multiple audio segments. When one audio segment is obtained each time, the audio segments are decoded one by one. When at least two audio segments are obtained each time, at least two audio segments are decoded at one time.
[0083] It should be noted that the total playable time after decoding refers to the total playable time of all currently decoded audio. The interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency will change in real time with the change of task load.
[0084] The frequency of the processor refers to the clock frequency of the processor, which will affect the interval time of each task scheduling and the time required for decoding. When the clock frequency is increased, the interval time of each task scheduling and the time required for decoding will be shortened. When the clock frequency is reduced, the interval time of each task scheduling and the time required for decoding will be longer. The external clock source is determined by the external crystal oscillator. The external clock source inputs the reference clock frequency to the processor. There will be a clock multiplication circuit inside the processor. The clock multiplication circuit can output the corresponding multiplied clock frequency according to the set parameters, that is, multiplying the reference clock frequency by the multiplication, so that the performance of the processor can be adjusted. And one of the embodiments of this scheme is that the clock frequency can be adjusted by adjusting the parameters of the clock multiplication circuit. It should be noted that this method is only one of many implementation methods and is not the only limitation here. In actual applications, chip manufacturers generally give the use range of the processor frequency (such as 20-100 MHz), and users will use the chip between the highest value less than the use range and the lowest value greater than the use range. The frequency modulation of this scheme will also be adjusted within this use range.
[0085] The complete audio playback process is: during the first decoding, a task is scheduled to decode at least one audio segment, after the decoding is completed, the interval time of task scheduling is waited, and then the second task is scheduled to decode at least one audio segment, and so on, until all audio segments are decoded.
[0086] In some embodiments, during the actual playback, the remaining playback time after the last decoding can be calculated and then compared with the time required for decoding at the current processor frequency to perform dynamic frequency modulation during playback. Figure 2 As shown, step S12 includes:
[0087] S121-1: Calculate the remaining playback time after the i-1th decoding according to the total playable time after the i-1th decoding and the interval time of each task scheduling at the current processor frequency;
[0088] S122-1: By comparing the remaining playback time after the i-1th decoding with the time required for decoding at the current processor frequency, the frequency of the current processor is adjusted or maintained, and at least one audio segment for the i-th decoding is obtained.
[0089] In some embodiments, step S121-1 includes:
[0090] The remaining playback time after the i-1th decoding is obtained by subtracting the interval time of each task scheduling under the current processor frequency from the total playable time after the i-1th decoding;
[0091] Step S122-1 includes:
[0092] When it is determined that the remaining playback time after the i-1th decoding is greater than 2 times the time required for decoding at the current processor frequency, the frequency of the current processor is reduced, and at least one audio segment for the i-th decoding is obtained;
[0093] When it is determined that the remaining playback time after the i-1th decoding is less than or equal to the time required for decoding at the current processor frequency, the frequency of the current processor is increased, and at least one audio segment for the i-th decoding is obtained;
[0094] When it is determined that the remaining playback time after the i-1th decoding is greater than the time required for decoding at the current processor frequency, and is less than or equal to 2 times the time required for decoding at the current processor frequency, the current processor frequency is maintained, and at least one audio segment for the i-th decoding is obtained.
[0095] In addition, when the present invention determines that the remaining playback time after the i-1th decoding is greater than the time required for decoding at the current processor frequency, and is less than or equal to 2 times the time required for decoding at the current processor frequency, if the task load becomes heavier, the interval time of each task scheduling at the current processor frequency becomes longer, and the frequency of the current processor should be increased; or if the task load becomes lighter, the interval time of each task scheduling at the current processor frequency becomes shorter, and the frequency of the current processor should be reduced. However, the present invention does not adjust the frequency of the current processor, maintains the frequency of the current processor, which is equivalent to forming a buffer period, and obtains at least one audio clip for performing the i-th decoding.
[0096] In some embodiments, Figure 3 As shown, step S15 includes:
[0097] S151-1: Obtaining the corresponding playable time of at least one audio segment after the i-th decoding and re-obtaining the time required for decoding at the current processor frequency;
[0098] S152-1: Calculate the total playable time after the i-th decoding according to the remaining playable time after the i-1th decoding, the time required for decoding at the current processor frequency, and the corresponding playable time of at least one audio segment after the i-th decoding.
[0099] In some embodiments, step S152-1 includes:
[0100] The remaining play time after the i-1th decoding is subtracted from the time required for decoding at the current processor frequency, and the corresponding playable time of at least one audio segment after the i-th decoding is added to obtain the total playable time after the i-th decoding.
[0101] In some embodiments, before step S11, the following steps are further included:
[0102] Entering the formal playback phase, obtaining at least one audio segment for the first decoding;
[0103] Scheduling a task to decode the acquired at least one audio segment, and obtaining a corresponding playable time of the at least one audio segment after the first decoding;
[0104] The corresponding playable time of at least one audio segment after the first decoding is used as the total playable time after the first decoding.
[0105] The specific implementation is as follows:
[0106] Entering the formal playback phase, obtaining an audio clip for the first decoding;
[0107] Schedule a task to decode the acquired audio segment, and obtain that the corresponding playable time of an audio segment after the first decoding is 380 milliseconds;
[0108] The corresponding playable time (380 milliseconds) of an audio segment after the first decoding is used as the total playable time after the first decoding;
[0109] When the second decoding is required, the total playable time after the first decoding is 380 milliseconds, the interval time of each task scheduling under the current processor frequency is 80 milliseconds, and the time required for decoding under the current processor frequency is 200 milliseconds;
[0110] Calculation 1: The remaining playback time after the first decoding = the total playable time after the first decoding - the interval time of each task scheduling under the current processor frequency, that is, 380-80=300 milliseconds;
[0111] If it is determined that the remaining playback time after the first decoding is greater than the time required for decoding at the current processor frequency and less than or equal to 2 times the time required for decoding at the current processor frequency, that is, 300 milliseconds is between 1 times and 2 times of 200 milliseconds, the current processor frequency is maintained, and an audio segment for the second decoding is obtained;
[0112] Schedule tasks to decode the acquired audio clips;
[0113] Determine whether all audio clips in the audio file are decoded, if so, end; if not, perform the following steps;
[0114] The corresponding playable time of an audio clip after the second decoding is 350 milliseconds, and the time required for re-obtaining the decoding at the current processor frequency is still 200 milliseconds;
[0115] Calculation 2: Total playable time after the second decoding = remaining playable time after the first decoding - time required for decoding at the current processor frequency + corresponding playable time of an audio clip after the second decoding, that is, 300-200+350=450 milliseconds;
[0116] When the third decoding is needed, the total playable time after the second decoding is 450 milliseconds, the interval time of each task scheduling under the current processor frequency is 80 milliseconds, and the time required for decoding under the current processor frequency is 200 milliseconds;
[0117] Calculation 1: The remaining playback time after the second decoding = the total playable time after the second decoding - the interval time of each task scheduling under the current processor frequency, that is, 450-80=370 milliseconds;
[0118] If it is determined that the remaining playback time after the second decoding is greater than the time required for decoding at the current processor frequency and less than or equal to 2 times the time required for decoding at the current processor frequency, that is, 370 milliseconds is between 1 times and 2 times of 200 milliseconds, the current processor frequency is maintained, and an audio segment for the third decoding is obtained;
[0119] Schedule tasks to decode the acquired audio clips;
[0120] Determine whether all audio clips in the audio file are decoded, if so, end; if not, perform the following steps;
[0121] The corresponding playable time of an audio clip after the third decoding is 350 milliseconds, and the time required for re-obtaining the decoding at the current processor frequency is still 200 milliseconds;
[0122] Calculation 2: The total playable time after the third decoding = the remaining playable time after the second decoding - the time required for decoding at the current processor frequency + the corresponding playable time of one audio clip after the third decoding, that is, 370-200+350=520 milliseconds;
[0123] At this time, when the remaining playback time after the second decoding is greater than the time required for decoding at the current processor frequency, and less than or equal to 2 times the time required for decoding at the current processor frequency, when the task load is heavy, the interval time of each task scheduling becomes longer and becomes 100 milliseconds, but the frequency of the current processor will not be adjusted;
[0124] When the fourth decoding is required, the total playable time after the third decoding is 520 milliseconds, the interval time of each task scheduling under the current processor frequency is 100 milliseconds, and the time required for decoding under the current processor frequency is 200 milliseconds;
[0125] Calculation 1: The remaining playback time after the third decoding = the total playable time after the third decoding - the interval time of each task scheduling under the current processor frequency, that is, 520-100=420 milliseconds;
[0126] When the remaining playback time after the third decoding is greater than twice the time required for decoding at the current processor frequency, that is, 420 milliseconds is greater than twice 200 milliseconds, the frequency of the current processor is reduced, and an audio segment for the fourth decoding is obtained;
[0127] Schedule tasks to decode the acquired audio clips;
[0128] Determine whether all audio clips in the audio file are decoded, if so, end; if not, perform the following steps;
[0129] The corresponding playable time of an audio clip after the fourth decoding is obtained as 350 milliseconds, and the time required for decoding at the current processor frequency is obtained again as 340 milliseconds;
[0130] Calculation 2: The total playable time after the fourth decoding = the remaining playable time after the third decoding - the time required for decoding at the current processor frequency + the corresponding playable time of one audio clip after the fourth decoding, that is, 420-340+350=430 milliseconds;
[0131] When the fifth decoding is required, the total playable time after the fourth decoding is 430 milliseconds, the interval time of each task scheduling under the current processor frequency is 100 milliseconds, and the time required for decoding under the current processor frequency is 340 milliseconds;
[0132] Calculation 1: The remaining playback time after the fourth decoding = the total playable time after the fourth decoding - the interval time of each task scheduling at the current processor frequency, that is, 430-100=330 milliseconds;
[0133] When it is determined that the remaining playback time after the fourth decoding is less than or equal to the time required for decoding at the current processor frequency, that is, 330 milliseconds is less than 340 milliseconds, the frequency of the current processor is increased, and an audio clip for the fifth decoding is obtained;
[0134] Schedule tasks to decode the acquired audio clips;
[0135] Determine whether all audio clips in the audio file are decoded, if so, end; if not, perform the following steps;
[0136] The corresponding playable time of an audio clip after the fifth decoding is obtained as 350 milliseconds, and the decoding time required under the current processor frequency is obtained again as 250 milliseconds;
[0137] Calculation 2: The total playable time after the fifth decoding = the remaining playable time after the fourth decoding - the time required for decoding at the current processor frequency + the corresponding playable time of one audio clip after the fifth decoding, that is, 330-250+350=430 milliseconds;
[0138] The above steps are repeated in this way. By reserving one more bit of calculation in advance, the lag is reduced.
[0139] In some embodiments, Figure 4 As shown, a weighted approach can also be used to dynamically adjust the frequency of the processor in the formal playback phase. Step S12 includes:
[0140] S121-2: Calculate the remaining playback time after the i-1th decoding according to the total playable time after the i-1th decoding, the interval time of each task scheduling at the current processor frequency, and the time required for decoding at the current processor frequency;
[0141] S122-2: By comparing the weighted remaining playback time after the i-1th decoding with the sum of the interval time of each task scheduling at the current processor frequency and the decoding time required at the current processor frequency, the frequency of the current processor is adjusted or maintained, and at least one audio clip for the i-th decoding is obtained.
[0142] In some embodiments, step S121-2 includes:
[0143] The remaining playback time after the i-1th decoding is obtained by subtracting the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency from the total playable time after the i-1th decoding;
[0144] Step 122-2 includes:
[0145] The remaining playback time after the i-1th decoding is weighted to obtain a first threshold. That is, the remaining playback time after the i-1th decoding is multiplied by a first coefficient to obtain the first threshold, for example, the first coefficient is 3, and the 3 here is only an example and is not intended to limit the present application;
[0146] If it is determined that the first threshold is greater than 2 times the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, the frequency of the current processor is reduced, and at least one audio clip for performing the i-th decoding is obtained;
[0147] When it is determined that the first threshold is less than or equal to the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, the frequency of the current processor is increased, and at least one audio segment for performing the i-th decoding is obtained;
[0148] When it is determined that the first threshold is greater than the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, and is less than or equal to 2 times the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, the frequency of the current processor is maintained, and at least one audio clip for the i-th decoding is obtained.
[0149] In some embodiments, Figure 5 As shown, step S15 includes:
[0150] S151-2: Obtaining the corresponding playable time of at least one audio segment after the i-th decoding and re-obtaining the time required for decoding at the current processor frequency and the interval time of each task scheduling at the current processor frequency;
[0151] S152-2: Calculate the total playable time after the i-1th decoding based on the weighted remaining playable time after the i-1th decoding, the time required for decoding at the current processor frequency, the interval time of each task scheduling at the current processor frequency, and the corresponding playable time of at least one audio segment after the i-th decoding.
[0152] In some embodiments, step S152-2 includes:
[0153] The weighted remaining playback time after the i-1th decoding is subtracted from the time required for decoding at the current processor frequency and the interval time of each task scheduling at the current processor frequency, and the corresponding playable time of at least one audio segment after the i-th decoding is added to obtain the total playable time after the i-th decoding.
[0154] Therefore, steps S121-1, S122-1, S151-1 and S152-1 constitute one embodiment. Steps S121-2, S122-2, S151-2 and S152-2 constitute another embodiment.
[0155] In some embodiments, Figure 6 As shown, the method also includes:
[0156] S21: Entering the pre-playing stage, obtaining at least one audio segment for performing the j-th pre-decoding, where j≥1;
[0157] S22: Scheduling tasks to decode the acquired at least one audio segment, obtaining the interval time of each task scheduling at the current processor frequency, the time required for decoding at the current processor frequency, and the corresponding playable time of the at least one audio segment after the j-th pre-decoding;
[0158] S23: pre-determining whether a formal playback condition is met according to the interval time of each task scheduling at the current processor frequency, the time required for decoding at the current processor frequency, and the corresponding playable time of at least one audio segment after the j-th pre-decoding;
[0159] S24: If not, adjust the frequency of the current processor, set j=j+1, and return to step S21;
[0160] S25: If yes, determine the frequency of the current processor to enter the formal playback phase.
[0161] It should be noted that the data decoded in the pre-playback stage is not played directly, but is only used to calculate a series of initial values of the processor at the current frequency, namely, the interval time of each task scheduling at the current processor frequency, the time required for decoding at the current processor frequency, and the corresponding playable time of at least one audio segment after the jth pre-decoding.
[0162] The interval time of each task scheduling refers to the period of time that the processor executes a task in a loop, the decoding time refers to the time taken for the decoding process, and the corresponding playable time of at least one audio segment after decoding refers to the time that at least one audio segment can be played. The higher the frequency of the processor, the shorter the interval time of each task scheduling will be, and the shorter the time required to decode a single audio segment will be.
[0163] In some embodiments, step S21 includes:
[0164] Entering the pre-playing stage, at least one audio segment for the j-th pre-decoding is obtained from the storage and cached. For example, audio information (such as the song name, etc.) can be obtained from the storage in sequence, and then the audio segment (such as song data) can be obtained, and stored in local storage or external storage. It can be understood that the at least one audio segment can be one, two or any number of audio segments, and the at least one audio segment can be 2KB, 4KB, etc., which is not limited here.
[0165] In some embodiments, step S23 includes:
[0166] It is determined whether the corresponding playable time of at least one audio segment after the j-th pre-decoding is greater than or equal to the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency.
[0167] Furthermore, step S24 includes:
[0168] If not, it indicates that the processor is not sufficient to support smooth audio playback at the current processor frequency, and the frequency of the current processor needs to be increased, so j=j+1 is set, and the process returns to step S21.
[0169] The specific implementation is as follows:
[0170] As shown in Table 1 below, when entering the pre-playing stage, the processor obtains an audio segment of 4KB for the first pre-decoding, and then schedules a task to decode the audio segment. The time required for decoding at the current processor frequency is 300 milliseconds, the interval time for each task scheduling at the current processor frequency is 100 milliseconds, and the corresponding playable time of the audio segment after the first pre-decoding is 350 milliseconds. At this time, the corresponding playable time of the audio segment after the first pre-decoding (350 milliseconds) is significantly less than the sum of the interval time for each task scheduling at the current processor frequency (100 milliseconds) and the time required for decoding at the current processor frequency (300 milliseconds), so the first frequency modulation is required.
[0171] After increasing the processor frequency, the processor obtains a 4KB audio clip for the second pre-decoding. At this time, due to the increase in the processor frequency, the decoding time required at the current processor frequency becomes 200 milliseconds, and the interval time of each task scheduling at the current processor frequency becomes 80 milliseconds, while the corresponding playable time of the audio clip after the second pre-decoding is still 350 milliseconds. At this time, the corresponding playable time of the audio clip after the second pre-decoding (350 milliseconds) is significantly greater than the sum of the interval time of each task scheduling at the current processor frequency (80 milliseconds) and the decoding time required at the current processor frequency (200 milliseconds), then the formal playback stage can be entered. If the playback condition is still not met after the first frequency adjustment, the above process is repeated until the condition is met.
[0172] Table 1
[0173]
[0174] It should be noted that the above 100 milliseconds, 300 milliseconds, 80 milliseconds, 200 milliseconds and 350 milliseconds are only examples and are not intended to limit the present application.
[0175] In some embodiments, Figure 7As shown, a weighted approach can also be used to pre-judge whether the formal playback condition is met, so step S23 includes:
[0176] S231: Weighting the corresponding playable time of at least one audio segment after the j-th pre-decoding to obtain a second threshold. That is, multiplying the corresponding playable time of at least one audio segment after the j-th pre-decoding by a second coefficient to obtain the second threshold, for example, the second coefficient is 0.8, which is only an example and is not intended to limit the present application;
[0177] S232: Determine whether the second threshold is greater than or equal to the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency.
[0178] Furthermore, step S24 includes:
[0179] If not, it indicates that the processor is not sufficient to support smooth audio playback at the current processor frequency, and the frequency of the current processor needs to be increased, so j=j+1 is set, and the process returns to step S21.
[0180] like Figure 8 As shown, some embodiments of the present invention disclose an electronic device, including:
[0181] one or more processors;
[0182] The storage device is used to store one or more programs. When the one or more programs are executed by one or more processors, the one or more processors implement the frequency modulation method for audio playback as described in any of the above embodiments, which will not be repeated here.
[0183] By implementing the present invention, the following beneficial effects are achieved:
[0184] The present invention can dynamically adjust the frequency of the processor through the frequency modulation method in the formal playing stage, so as to ensure the smoothness of the sound and reduce the jamming when the audio is formally played.
[0185] In addition, the frequency modulation method in the pre-play stage can be used to adjust the frequency of the processor before formal playback, further ensuring the smoothness of the sound when the audio is officially played.
[0186] It can be understood that the above embodiments only express some implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the patent scope of the present invention. It should be pointed out that for ordinary technicians in this field, without departing from the concept of the present invention, the above embodiments or technical features can be freely combined, and several deformations and improvements can be made, which all belong to the protection scope of the present invention, that is, the embodiments described in "some embodiments" can be freely combined with any of the above and below embodiments; therefore, all equivalent changes and modifications made to the scope of the claims of the present invention should fall within the scope of the claims of the present invention.
Claims
1. A frequency modulation method for audio playback, characterized in that: Applied to the processor, including the following steps: S11: Entering the formal playback phase, obtaining the total playable time after the i-1th decoding, the interval time of each task scheduling at the current processor frequency, and the decoding time required at the current processor frequency, where i ≥ 2; S12: adjusting or maintaining the current processor frequency by determining the relationship between the total playable time after the (i-1)th decoding, the interval between each task scheduling at the current processor frequency, and the time required for decoding at the current processor frequency, and obtaining at least one audio clip for performing the i-th decoding; wherein the processor frequency affects the interval between each task scheduling and the time required for decoding; S13: Scheduling a task to decode the acquired at least one audio segment; S14: Determine whether all audio clips in the audio file have been decoded. If not, execute step S15; if yes, end; S15: Calculate the total playable time after the i-th decoding; S16: Set i = i + 1, and return to step S11; Wherein, step S12 includes: S121-1: Calculate the remaining playback time after the (i-1)th decoding based on the total playable time after the (i-1)th decoding and the interval time of each task scheduling at the current processor frequency; S122-1: Adjust or maintain the frequency of the current processor by comparing the remaining playback time after the (i-1)th decoding with the decoding time required at the current processor frequency, and obtain at least one audio clip for the i-th decoding; Alternatively, step S12 includes: S121-2: Calculate the remaining playback time after the (i-1)th decoding based on the total playable time after the (i-1)th decoding, the interval between each task scheduling at the current processor frequency, and the decoding time required at the current processor frequency; S122-2: Adjust or maintain the current processor frequency by comparing the weighted remaining playback time after the (i-1)th decoding with the sum of the interval between each task scheduling at the current processor frequency and the decoding time required at the current processor frequency, and obtain at least one audio clip for the (i)th decoding; Step S15 includes: S151-1: Obtaining the corresponding playable time of at least one audio segment after the i-th decoding and re-obtaining the decoding time required at the current processor frequency; S152-1: Calculate the total playable time after the i-th decoding based on the remaining playable time after the i-1th decoding, the decoding time required at the current processor frequency, and the corresponding playable time of at least one audio clip after the i-th decoding; Alternatively, step S15 includes: S151-2: Obtaining the corresponding playable time of at least one audio segment after the i-th decoding, and re-obtaining the decoding time at the current processor frequency and the interval time of each task scheduling at the current processor frequency; S152-2: Calculate the total playable time after the i-th decoding based on the weighted remaining playable time after the i-1th decoding, the time required for decoding at the current processor frequency, the interval time of each task scheduling at the current processor frequency, and the corresponding playable time of at least one audio segment after the i-th decoding.
2. The method for frequency modulation of audio playback according to claim 1, wherein: Step S121-1 includes: The remaining playback time after the i-1th decoding is obtained by subtracting the interval time of each task scheduling at the current processor frequency from the total playable time after the i-1th decoding; Step S122-1 includes: If it is determined that the remaining playback time after the (i-1)th decoding is greater than twice the decoding time at the current processor frequency, the frequency of the current processor is reduced, and at least one audio clip for performing the (i)th decoding is obtained; If it is determined that the remaining playback time after the (i-1)th decoding is less than or equal to the decoding time required at the current processor frequency, the frequency of the current processor is increased, and at least one audio clip for performing the (i)th decoding is obtained; When it is determined that the remaining playback time after the i-1th decoding is greater than the time required for decoding at the current processor frequency and is less than or equal to twice the time required for decoding at the current processor frequency, the current processor frequency is maintained and at least one audio clip for the i-th decoding is obtained.
3. The frequency modulation method for audio playback according to claim 1, wherein: Step S121-2 includes: The remaining playback time after the i-1th decoding is obtained by subtracting the interval time of each task scheduling at the current processor frequency and the decoding time required at the current processor frequency from the total playable time after the i-1th decoding; Step 122-2 includes: Weighting the remaining playback time after the (i-1)th decoding to obtain a first threshold; If the first threshold is greater than twice the sum of the interval between each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, the frequency of the current processor is reduced, and at least one audio clip for performing the i-th decoding is obtained; When it is determined that the first threshold is less than or equal to the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, the frequency of the current processor is increased, and at least one audio clip for performing the i-th decoding is obtained; When it is determined that the first threshold is greater than the sum of the interval time for each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, and is less than or equal to twice the sum of the interval time for each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency, the current processor frequency is maintained and at least one audio clip for the i-th decoding is obtained.
4. The method for frequency modulation of audio playback according to claim 1, wherein: Step S152-1 includes: The total playable time after the i-th decoding is obtained by subtracting the time required for decoding at the current processor frequency from the remaining playable time after the i-1th decoding and adding the corresponding playable time of at least one audio segment after the i-th decoding. Alternatively, step S152-2 includes: The total playable time after the i-th decoding is obtained by subtracting the time required for decoding at the current processor frequency and the interval time of each task scheduling at the current processor frequency from the weighted remaining playable time after the i-1th decoding, and adding the corresponding playable time of at least one audio clip after the i-th decoding.
5. The frequency modulation method for audio playback according to claim 1, characterized in that: Before step S11, the following steps are also included: Entering the formal playback phase, obtaining at least one audio segment for the first decoding; Scheduling a task to decode the acquired at least one audio segment, and obtaining a corresponding playable time of the at least one audio segment after the first decoding; The corresponding playable time of the at least one audio segment after the first decoding is used as the total playable time after the first decoding.
6. The frequency modulation method for audio playback according to claim 1 or 5, characterized in that: The method further comprises: S21: Entering the pre-playing phase, obtaining at least one audio segment for performing the j-th pre-decoding, where j≥1; S22: Scheduling tasks to decode the acquired at least one audio clip, obtaining an interval between each task scheduling at a current processor frequency, a decoding time required at the current processor frequency, and a corresponding playable time of the at least one audio clip after the j-th pre-decoding; S23: Preliminarily determining whether a formal playback condition is met based on the interval between each task scheduling at the current processor frequency, the decoding time at the current processor frequency, and the corresponding playable time of the at least one audio segment after the j-th pre-decoding; S24: If not, adjust the frequency of the current processor, set j=j+1, and return to step S21; S25: If yes, determine the frequency of the current processor to enter the formal playback phase.
7. The frequency modulation method for audio playback according to claim 6, characterized in that: Step S23 includes: Determine whether the playable time corresponding to at least one audio segment after the j-th pre-decoding is greater than or equal to the sum of the interval time of each task scheduling at the current processor frequency and the decoding time at the current processor frequency; Alternatively, step S23 includes: weighting the corresponding playable time of at least one audio segment after the j-th pre-decoding to obtain a second threshold; Determine whether the second threshold is greater than or equal to the sum of the interval time of each task scheduling at the current processor frequency and the time required for decoding at the current processor frequency; Furthermore, step S24 includes: If not, the frequency of the current processor is increased, j=j+1 is set, and the process returns to step S21.
8. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the frequency modulation method for audio playback as described in any one of claims 1 to 7.
