CN116778950B - Sampling rate matching method, system and storage medium for audio data transmission - Google Patents
Sampling rate matching method, system and storage medium for audio data transmission Download PDFInfo
- Publication number
- CN116778950B CN116778950B CN202311044496.8A CN202311044496A CN116778950B CN 116778950 B CN116778950 B CN 116778950B CN 202311044496 A CN202311044496 A CN 202311044496A CN 116778950 B CN116778950 B CN 116778950B
- Authority
- CN
- China
- Prior art keywords
- conversion ratio
- audio data
- data
- frame length
- audio
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000005070 sampling Methods 0.000 title claims abstract description 248
- 238000000034 method Methods 0.000 title claims abstract description 83
- 230000005540 biological transmission Effects 0.000 title claims abstract description 56
- 238000006243 chemical reaction Methods 0.000 claims abstract description 483
- 238000012545 processing Methods 0.000 claims abstract description 129
- 230000003139 buffering effect Effects 0.000 claims abstract description 19
- 230000007704 transition Effects 0.000 claims description 38
- 238000009499 grossing Methods 0.000 claims description 20
- 230000003247 decreasing effect Effects 0.000 claims description 7
- 230000000694 effects Effects 0.000 abstract description 18
- 238000012952 Resampling Methods 0.000 abstract description 6
- 238000010586 diagram Methods 0.000 description 6
- 230000000903 blocking effect Effects 0.000 description 5
- 239000013078 crystal Substances 0.000 description 5
- 238000009825 accumulation Methods 0.000 description 3
- 230000007423 decrease Effects 0.000 description 3
- 230000002159 abnormal effect Effects 0.000 description 2
- 238000006467 substitution reaction Methods 0.000 description 2
- NAWXUBYGYWOOIX-SFHVURJKSA-N (2s)-2-[[4-[2-(2,4-diaminoquinazolin-6-yl)ethyl]benzoyl]amino]-4-methylidenepentanedioic acid Chemical compound C1=CC2=NC(N)=NC(N)=C2C=C1CCC1=CC=C(C(=O)N[C@@H](CC(=C)C(O)=O)C(O)=O)C=C1 NAWXUBYGYWOOIX-SFHVURJKSA-N 0.000 description 1
- 230000003044 adaptive effect Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 125000004122 cyclic group Chemical group 0.000 description 1
- 238000009795 derivation Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000035772 mutation Effects 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 238000003672 processing method Methods 0.000 description 1
- 230000001105 regulatory effect Effects 0.000 description 1
- 238000004904 shortening Methods 0.000 description 1
- 230000005236 sound signal Effects 0.000 description 1
- 238000011105 stabilization Methods 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G10—MUSICAL INSTRUMENTS; ACOUSTICS
- G10L—SPEECH ANALYSIS TECHNIQUES OR SPEECH SYNTHESIS; SPEECH RECOGNITION; SPEECH OR VOICE PROCESSING TECHNIQUES; SPEECH OR AUDIO CODING OR DECODING
- G10L21/00—Speech or voice signal processing techniques to produce another audible or non-audible signal, e.g. visual or tactile, in order to modify its quality or its intelligibility
- G10L21/04—Time compression or expansion
- G10L21/043—Time compression or expansion by changing speed
Landscapes
- Engineering & Computer Science (AREA)
- Computational Linguistics (AREA)
- Quality & Reliability (AREA)
- Signal Processing (AREA)
- Health & Medical Sciences (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Human Computer Interaction (AREA)
- Physics & Mathematics (AREA)
- Acoustics & Sound (AREA)
- Multimedia (AREA)
- Signal Processing For Digital Recording And Reproducing (AREA)
Abstract
The embodiment of the application relates to the technical field of signal processing, and discloses a sampling rate matching method, a system and a storage medium for audio data transmission, wherein the method comprises the following steps: performing sampling rate conversion processing, namely resampling processing on the audio data by initial conversion comparison to obtain processed audio data; transmitting the processed audio data to a buffer unit of an audio playing system for buffering, so that the audio playing system acquires and plays the processed audio data from the buffer unit; acquiring the data volume of the processed audio data buffered in the buffer unit; and adjusting the initial conversion ratio according to the size relation between the data quantity and the preset threshold value, obtaining the adjusted conversion ratio, and carrying out sampling rate conversion processing on the audio data according to the adjusted conversion ratio. Through the mode, the embodiment of the application realizes the effect of improving the playing of the audio data.
Description
Technical Field
The embodiment of the application relates to the technical field of signal processing, in particular to a sampling rate matching method, a sampling rate matching system and a storage medium for audio data transmission.
Background
Along with development of science and technology, the living standard of people is greatly improved, and audio data transmission generally occurs in daily life of people, for example, when people use headphones and hearing aids to listen to music, audio data transmission is performed between terminal devices such as mobile phones and tablet computers and audio devices such as headphones and hearing aids, at this time, the terminal devices such as mobile phones and tablet computers are usually called audio transmission systems, and the audio devices such as headphones and hearing aids are called audio playing systems. Such transmission of audio data may also occur between two chips in one device, such as an audio data acquisition chip and an audio playback chip, hereinafter collectively referred to as an audio transmission system and an audio playback system.
In many scenarios, the audio transmission system and the audio playing system are two independent different audio systems, and the nominal frequencies of the two different audio systems may be different, that is, the sampling rate of the audio transmission system and the sampling rate of the audio playing system may be different, so that sampling rate conversion processing, that is, resampling processing, needs to be performed on the audio data, so as to achieve the effects of clear and natural sound, no jamming and no noise when playing the audio data. In addition, each audio system is provided with an independent clock system and is controlled by a crystal oscillator, so that clocks of the audio transmission system and the audio playing system are usually asynchronous, namely asynchronous, and if the adaptive matching of sampling rates is not carried out on audio data, even if the nominal sampling rates of the audio transmission system and the audio playing system are the same, the problems of blocking, distortion and the like of the played audio data are caused by the fact that accumulated errors are larger and larger due to the extremely small difference of the actual sampling rates of the audio transmission system and the audio playing system, and the playing effect is seriously affected.
In summary, when audio data is transmitted in two independent different audio systems, how to perform sampling rate conversion processing on the audio data, so that the audio data can be effectively transmitted, and normal playing of the audio data is ensured.
Disclosure of Invention
In view of the above problems, embodiments of the present application provide a sampling rate matching method, system and computer readable storage medium for audio data transmission, which are used for solving the problem of poor audio data playing effect in the prior art.
According to an aspect of an embodiment of the present application, there is provided a sample rate matching method for audio data transmission, the method including: performing sample rate conversion processing on the audio data by initial conversion comparison to obtain processed audio data; transmitting the processed audio data to a buffer unit of an audio playing system for buffering, so that the audio playing system acquires and plays the processed audio data from the buffer unit; acquiring the data volume of the processed audio data cached in the buffer unit; and adjusting the initial conversion ratio according to the size relation between the data quantity and a preset threshold value to obtain an adjusted conversion ratio, and performing sampling rate conversion processing on the audio data according to the adjusted conversion ratio.
In an optional manner, the adjusting the initial conversion ratio according to the magnitude relation between the data amount and the preset threshold value to obtain an adjusted conversion ratio further includes: if the data volume is smaller than the preset threshold value, the initial conversion ratio is increased, and a first conversion ratio is obtained; and if the data quantity is larger than the preset threshold value, reducing the initial conversion ratio to obtain a second conversion ratio, wherein the second conversion ratio is smaller than the first conversion ratio.
In an optional manner, the frame length of the audio data before the sampling rate conversion processing is taken as an original frame length by the initial conversion ratio, the frame length of the audio data after the sampling rate conversion processing is taken as an initial conversion frame length by the initial conversion ratio, and the step of increasing the initial conversion ratio to obtain a first conversion ratio further includes: determining a first frame length, wherein the first frame length is longer than the initial conversion frame length; calculating a first ratio of the first frame length to the original frame length, and determining the first ratio as the first conversion ratio; said reducing said initial conversion ratio to obtain a second conversion ratio, further comprising: determining a second frame length, wherein the second frame length is shorter than the initial transition frame length; calculating a second ratio of the second frame length to the original frame length, and determining the second ratio as the second conversion ratio in an alternative manner, the first frame length is increased by one sample length from the initial conversion frame length, and the second frame length is decreased by one sample length from the initial conversion frame length.
In an alternative manner, the first frame lengthL B Is determined by the following formula:wherein, the method comprises the steps of, wherein,L A for the original frame length,/a->Nominal sample rate of audio transmission system for transmitting audio data,/->To receive and play the nominal sampling rate of the audio playing system of the processed audio data, a symbol is calculatedx]Representing that is not greater thanxDelta is a positive integer; the second frame lengthL B ’Is determined by the following formula: />Wherein, the method comprises the steps of, wherein,L A for the original frame length,/a->Nominal sample rate of audio transmission system for transmitting audio data,/->To receive and play the nominal sampling rate of the audio playing system of the processed audio data, a symbol is calculatedx]Representing that is not greater thanxDelta is a positive integer.
In an alternative manner, after the initial conversion ratio is increased if the data amount is smaller than the preset threshold value, to obtain a first conversion ratio, and after the initial conversion ratio is decreased if the data amount is larger than the preset threshold value, to obtain a second conversion ratio, the method further includes: step S1, transmitting the audio data obtained by sampling rate conversion processing of the audio data according to the adjusted conversion ratio to the buffer unit for buffering; step S2, obtaining the data volume of the audio data cached in the buffer unit; step S3, if the data volume is larger than the preset threshold, sampling rate conversion processing is carried out on the audio data according to the second conversion ratio; step S4, if the data volume is smaller than the preset threshold value, sampling rate conversion processing is carried out on the audio data according to the first conversion ratio; the steps S1 to S4 are performed for each data frame of audio data to be processed.
In an alternative manner, when the conversion ratio switching occurs, before the sampling rate conversion processing is performed on the audio data at the second conversion ratio in the step S3, and before the sampling rate conversion processing is performed on the audio data at the first conversion ratio in the step S4, the following steps are further performed: determination of the firstkIndividual spots and the firstkSampling interval of +1 samplesWherein->,/>For preset initial value, ++>,),/>,L A For the frame length of the audio data before the sample rate conversion processing at the initial conversion ratio, +.>Nominal sample rate of audio transmission system for transmitting audio data,/->To receive and play the nominal sample rate of the audio play system of the processed audio data,kis a natural number, andk≤/>the method comprises the steps of carrying out a first treatment on the surface of the In duration->According to the firstkIndividual spots and the firstkSampling interval of +1 samples +.>Processing the audio data to obtain processed transition frame audio data, wherein the sampling time of the 0 th sampling point is 0,/for>。
In an alternative manner, before said adjusting the initial conversion ratio according to the magnitude relation between the data amount and a preset threshold value, the method further comprises:
smoothing the data volume and obtaining processed data Measuring amountD(n) Wherein the smoothing process is performed on the data amount by the following formula:wherein->Is a preset smoothing coefficient, and +.>,D(n1) the amount of data buffered by said buffer unit obtained after said smoothing at the previous time,d(n) The data quantity cached by the buffer unit is queried at the current moment; the initial conversion ratio is adjusted according to the size relation between the data quantity and a preset threshold value, and the method further comprises the following steps: and adjusting the initial conversion ratio according to the size relation between the processed data quantity and a preset threshold value.
According to another aspect of an embodiment of the present application, there is provided an audio transmission system including: a processor. The processor is used for carrying out sampling rate conversion processing on the audio data by initial conversion comparison to obtain processed audio data; transmitting the processed audio data to a buffer unit of an audio playing system for receiving and playing the processed audio data for buffering, so that the audio playing system receives and plays the processed audio data; acquiring the data quantity cached in a buffer unit of the audio playing system; and adjusting the initial conversion ratio according to the size relation between the data quantity and a preset threshold value to obtain an adjusted conversion ratio, and performing sampling rate conversion processing on the audio data according to the adjusted conversion ratio.
According to another aspect of an embodiment of the present application, there is provided an audio playing system including: a processor and a buffer unit. The processor is used for carrying out sampling rate conversion processing on the received audio data according to an initial conversion ratio to obtain processed audio data, and transmitting the processed audio data to the buffer unit; the buffer unit is used for receiving and buffering the processed audio data; the processor is further configured to obtain a data amount of the processed audio data buffered in the buffer unit, adjust the initial conversion ratio according to a size relationship between the data amount and a preset threshold, obtain an adjusted conversion ratio, and perform sampling rate conversion processing on the audio data according to the adjusted conversion ratio.
According to still another aspect of embodiments of the present application, there is provided a computer-readable storage medium having stored therein executable instructions for causing an audio system to perform operations corresponding to the sample rate matching method for audio data transmission as described above.
In the embodiment of the application, the situation that errors exist in the nominal sampling rate and the actual sampling rate of the audio system is fully considered, the sampling rate conversion processing is carried out on the audio data by the initial conversion ratio, the processed audio data is buffered to the buffer unit, the conversion ratio is timely adjusted according to the magnitude relation between the data quantity and the preset threshold value by acquiring the data quantity buffered in the buffer unit of the audio playing system, and then the sampling rate conversion processing is carried out on the audio data by the adjusted conversion ratio, so that the data quantity in the buffer unit is maintained within a certain range, the problem of too much or too little data quantity buffered in the buffer unit is avoided, the playing effect of the audio data is improved, and the problems of clamping, noise and the like in the audio playing process are avoided.
The foregoing description is only an overview of the technical solutions of the embodiments of the present application, and may be implemented according to the content of the specification, so that the technical means of the embodiments of the present application can be more clearly understood, and the following specific embodiments of the present application are given for clarity and understanding.
Drawings
The drawings are only for purposes of illustrating embodiments and are not to be construed as limiting the application. Also, like reference numerals are used to designate like parts throughout the figures. In the drawings:
fig. 1 shows an application scenario schematic diagram provided by an embodiment of the present application;
fig. 2 is a flow chart illustrating a sample rate matching method for audio data transmission according to an embodiment of the present application;
FIG. 3 shows a schematic flow chart of substeps of step 140 of FIG. 2;
FIG. 4 shows a frame of audio data before sample rate conversion according to an embodiment of the present applicationS A0 And one frame of data of the audio data after the sample rate conversionS B0 Schematic of (2);
fig. 5 is a flowchart illustrating a sample rate matching method for audio data transmission according to another embodiment of the present application;
fig. 6 is a flowchart of a sample rate matching method for audio data transmission according to another embodiment of the present application;
Fig. 7 is a schematic structural diagram of an audio transmission system according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of an audio playing system according to an embodiment of the present application.
Detailed Description
Exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application may be embodied in various forms and should not be limited to the embodiments set forth herein.
When the audio data are transmitted by two independent audio systems, the sampling rate of the audio transmission system and the sampling rate of the audio playing system may be different, so that the audio data need to be subjected to sampling rate conversion processing, and the effects of clear and natural sound, no blocking and no noise are achieved when the audio data are played. In addition, each audio system has an independent clock system, and the clock precision of the clock system depends on the precision of the crystal oscillator used by the clock system, so the clocks of the audio transmission system and the audio playing system are usually asynchronous, namely asynchronous, so that if the sampling rate conversion processing is not performed on the audio data, the problems of blocking, distortion and the like of the played audio data can be caused, and the playing effect is reduced.
The inventors of the present application have found that in the prior art, in order to solve the problem of clock non-synchronization of two audio systems, integrated circuit built-in audio (Inter-IC Sound, I 2 S) bus to transfer audio data due to I 2 The S bus adopts the design of independent wires for transmitting clock and data signals, and the data and the clock signals are separated, so that the distortion induced by time difference is avoided. If using I 2 S bus transmission, requiring the audio system to have a corresponding I 2 S interface, however, many audio systems do not currently have I 2 S interface, thus fail to pass I 2 The S bus transmits audio data, and thus a sample rate conversion process is required for the audio data.
The audio playing system generally includes a buffer unit, and after the audio data received from the audio transmitting system is subjected to sampling rate conversion, the processed audio data is transmitted to the buffer unit of the audio playing system, so as to buffer the processed audio data, and the audio playing system acquires and plays the processed audio data from the buffer unit. In order to ensure that the audio playing system can normally and effectively play audio data, i.e. no jamming or noise occurs, the data volume buffered in the buffer unit needs to be controlled to be in a dynamic balance state, i.e. the data volume buffered in the buffer unit after the sampling rate conversion processing and the data volume played by the audio playing system should be in a dynamic balance state.
The audio sending system may also be provided with a buffer unit for buffering the audio data, and the audio data in the buffer unit is generally subjected to sampling rate conversion processing and then transmitted to the audio playing system. The inventor finds that, because a certain error exists between the nominal sampling rate and the actual sampling rate of the audio system, if the conversion ratio of the sampling rate conversion process of the audio data is determined according to the nominal sampling rate of the audio transmission system and the nominal sampling rate of the audio playing system, the data volume buffered to the buffer unit after the sampling rate conversion process and the data volume played by the audio playing system are likely to be in a balanced state, i.e. the data volume buffered to the buffer unit after the sampling rate conversion process is greater than the data volume played by the audio playing system, or the data volume buffered to the buffer unit after the sampling rate conversion process is less than the data volume played by the audio playing system, finally the data volume in the buffer unit is in an out-of-control state, so that the playing effect of the audio data is reduced.
Based on the above considerations, the present inventors have conducted intensive studies to propose a sampling rate matching method for audio data transmission. According to the method, the audio data are subjected to sampling rate conversion processing by initial conversion comparison, the processed audio data are transmitted to the buffer unit for buffering, the initial conversion ratio is timely adjusted according to the data amount buffered in the buffer unit, and then the audio data are subjected to sampling rate conversion processing by the adjusted conversion ratio, so that the problem that the buffered data in the buffer unit overflow or are too small is avoided, and the playing effect of the audio data is improved.
Fig. 1 is a schematic view of an application scenario provided in an embodiment of the present application, as shown in fig. 1, an audio sending system transmits audio data to an audio playing system, so that the audio playing system plays the audio data. The audio transmission system may be any type of electronic device or terminal, such as a mobile phone, a tablet computer, a game device, a Personal Digital Assistant (PDA), a desktop computer, a notebook computer, and other various terminal devices; the audio playback system may be any type of electronic device or terminal, such as a hearing aid, an earpiece.
Fig. 2 shows a flowchart of a sample rate matching method for audio data transmission according to an embodiment of the present application, and as shown in fig. 2, the method includes the following steps:
step 110: and carrying out sampling rate conversion processing on the audio data by initial conversion comparison to obtain processed audio data.
The audio data is obtained by sampling, for example, MP3 audio data, so that each segment of audio data has a specific sampling rate. Audio playback systems also typically have their own sample rate for playing audio data. Because the sampling rates of different audio systems are not always identical, the sampling rate of the audio data sent by the audio sending system and received by the audio playing system is not always consistent with the sampling rate of the audio playing system, so that the sampling rate of the audio data needs to be converted into the sampling rate of the audio playing system, that is, the sampling rate conversion processing is performed on the audio data, so that the audio playing system can play the audio data normally. Where sample rate conversion is the process of changing the sampling interval of an original continuous signal to obtain a new discrete representation of the original continuous signal, which is also called resampling process.
It should be noted that, the duration of one frame of audio data is fixed, that is, the time occupied by one frame of audio data is fixed, one frame of audio data includes the same or different data (also referred to as samples, samples), the sampling rate of the audio data is the sampling frequency of sampling the original continuous signal, and if the sampling frequency is increased (that is, the sampling interval between two adjacent samples is reduced), the number of samples included in one frame of audio data is increased; conversely, if the sampling frequency decreases, the number of samples included in one frame of audio data decreases. For example, if the sampling interval of the audio system is 10s and the duration of one frame of audio data is 1min, 6 samples are included in one frame of audio data, that is, the frame length of one frame of data is 6. Accordingly, the number of samples included in one frame of audio data can be adjusted by adjusting the sampling rate of the audio data.
For example, if the sampling rate of a piece of audio data is 48kHz, but the sampling rate of the audio playing system is 44.1kHz, the sampling rate of the audio data needs to be converted into 44.1kHz, that is, the 1/48000 second sampling interval is adjusted to 1/44100 second sampling interval, so that the audio playing system can play the audio data normally, otherwise, problems such as loss and distortion of the played audio data may occur, and playing effects are reduced.
It should be noted that, in the embodiment of the present application, the conversion ratio is a ratio of a sampling rate of an audio system after conversion to a sampling rate of the audio system before conversion, for example, a sampling rate of a certain audio system before conversion to audio data (i.e., a sampling interval between two adjacent samples is 1/a), and a sampling rate of the audio system after conversion to audio data is b (i.e., a sampling interval between two adjacent samples is 1/b), then the conversion ratio is b/a. After the conversion ratio is determined, sampling rate conversion processing can be performed according to the sampling rate and the conversion ratio of the audio system before conversion, so that the sampling rate after conversion is obtained, and further the audio data can be sampled and processed by utilizing the determined sampling rate after conversion.
It should be noted that, since the duration of one frame of audio data is constant, the conversion ratio is also equal to the frame length ratio of the audio data.
In the embodiment of the application, the conversion ratio is used for carrying out sampling rate conversion processing on the audio data, specifically, the sampling rate of an audio system is converted according to the conversion ratio, and the sampling rate conversion processing is carried out on the audio data according to the converted sampling rate, so that the processed audio data is obtained. In this step, the initial conversion ratio may be set as required, and preferably, the initial conversion ratio is a ratio of a nominal sampling rate of the audio transmission system to a nominal sampling rate of the audio playing system, so that the sampling rate of the audio data after the sampling rate conversion process is relatively close to an actual sampling rate of the audio playing system, and the sampling rate is further fine-tuned (see later).
Step 120: and transmitting the processed audio data to a buffer unit of an audio playing system for buffering, so that the audio playing system acquires and plays the processed audio data from the buffer unit.
In this step, the audio data after the sampling rate conversion in step 110 is transmitted to a buffer unit of the audio playing system for buffering, so that the audio playing system obtains and plays the buffered audio data from the buffer unit.
The audio playing system can begin to play the audio data buffered in the buffer unit normally and effectively because the audio data buffered in the buffer unit is subjected to sampling rate conversion processing, namely, the sampling rate of the audio data is converted into the nominal sampling rate of the audio playing system.
The sample rate conversion process may be performed on the audio data using a processor. It should be noted that, the processor in the audio transmission system may perform sampling rate conversion processing on the audio data, that is, the audio transmission system uses the processor to perform sampling rate conversion processing on the audio data, and then transmits the processed audio data to the buffer unit of the audio playing system for buffering; the audio data may be subjected to sampling rate conversion by a processor in the audio playing system, that is, the audio sending system transmits the audio data to the processor of the audio playing system, and after the sampling rate conversion is performed on the audio data by the processor, the processed audio data is transmitted to a buffer unit of the audio playing system for buffering.
Step 130: the data amount of the processed audio data buffered in the buffer unit is acquired.
Because the audio playing system acquires and plays the cached audio data from the buffer unit, in order to ensure the normal playing of the audio data, namely, the problems of distortion, blocking, noise and the like do not occur when the audio data is played, the data amount cached in the buffer unit is ensured to be maintained within a certain range, and cache overflow caused by too much data amount or cache emptying caused by too little data amount is avoided.
However, since the clock accuracy of an audio system depends on the accuracy of the crystal oscillator that it uses, the actual clock frequency is affected by temperature, while the nominal clock frequency is the frequency measured at a certain temperature, and there is a difference between the actual operating temperature and that certain temperature; in addition, the actual parameter values and the nominal values of the components of the crystal oscillator are also deviated, so that a certain error exists between the nominal sampling rate and the actual sampling rate of the audio system. And carrying out sampling rate conversion processing on the audio data according to the initial conversion ratio determined by the nominal sampling rate of the audio transmission system and the audio playing system, and storing the processed audio data into a buffer unit so as to enable the audio playing system to acquire and play the audio data in the buffer unit, wherein if the nominal sampling rate and the actual sampling rate of the audio system have no errors, the data volume buffered in the buffer unit is in a dynamic balance state, namely the data volume obtained by carrying out the sampling rate conversion processing on the audio data and the play volume of the audio data are in a dynamic balance state. However, due to errors of the nominal sampling rate and the actual sampling rate of the audio system, a certain error exists between the actual data volume and the theoretical data volume in the buffer unit, and if the audio system is not processed, the problems of cache overflow or cache emptying and the like caused by too much data volume of the audio data cached in the buffer unit are finally caused by accumulation of errors.
Therefore, in this step, by acquiring the actual data amount of the audio data buffered in the buffer unit, the initial conversion ratio may be adjusted according to the actual data amount, and further the sampling rate may be converted according to the conversion ratio to obtain the converted sampling rate, so that the subsequent audio data may be resampled by using the converted sampling rate, so as to ensure that the data amount is maintained within a certain range, and avoid buffer overflow caused by excessive data amount or buffer emptying caused by too small data amount, thereby ensuring normal playing of the audio data.
The frequency of obtaining the data amount buffered in the buffer unit may be set according to the need, so long as the change of the data amount buffered in the buffer unit can be monitored in time, and the method is not limited herein. In the embodiment of the present application, preferably, after the buffer unit caches the audio data, the data amount cached in the buffer unit is obtained in real time.
Step 140: and adjusting the initial conversion ratio according to the size relation between the data quantity and the preset threshold value, obtaining the adjusted conversion ratio, and carrying out sampling rate conversion processing on the audio data according to the adjusted conversion ratio.
In this step, the initial conversion ratio is adjusted according to the size relationship between the data amount obtained in step 130 and the preset threshold, and the audio data is subjected to sample rate conversion processing according to the adjusted conversion ratio, so that the data amount buffered in the buffer unit is maintained within a certain range, and excessive or insufficient data is avoided. If the data volume is smaller than the preset threshold value, increasing the conversion ratio, and carrying out sampling rate conversion processing on the audio data according to the conversion ratio, so as to increase the data volume after the sampling rate conversion processing, namely increasing the data volume cached in the buffer unit, and avoiding the data volume from being too small; if the data volume is larger than the preset threshold, the conversion ratio is reduced, and the audio data is subjected to sampling rate conversion processing according to the conversion ratio, so that the data volume after the sampling rate conversion processing is reduced, namely, the data volume cached in the buffer unit is reduced, and the data overflow is avoided.
It should be noted that the preset threshold may be determined according to the total storage amount of the buffer unit, and for example, the threshold may be set to 70% of the total storage amount. In the embodiment of the present application, preferably, the preset threshold is 50% of the total storage amount of the buffer unit.
In the embodiment of the application, the situation that errors exist in the nominal sampling rate and the actual sampling rate of the audio system is fully considered, the sampling rate conversion processing is carried out on the audio data by the initial conversion ratio, the processed audio data is buffered to the buffer unit, the conversion ratio is timely adjusted according to the magnitude relation between the data quantity and the preset threshold value by acquiring the data quantity buffered in the buffer unit of the audio playing system, and then the sampling rate conversion processing is carried out on the audio data by the adjusted conversion ratio, so that the data quantity in the buffer unit is maintained within a certain range, the problem of too much or too little data quantity buffered in the buffer unit is avoided, the playing effect of the audio data is improved, and the problems of clamping, noise and the like in the audio playing process are avoided.
In order to obtain an adjusted conversion ratio with high accuracy, the embodiment of the application provides a way how to adjust the initial conversion ratio so as to obtain the adjusted conversion ratio. In an embodiment of the application, FIG. 3 shows a flow chart of substeps of step 140 of FIG. 2. As shown in fig. 3, step 140 adjusts an initial conversion ratio according to a size relationship between a data amount and a preset threshold value, obtains an adjusted conversion ratio, and performs sample rate conversion processing on audio data with the adjusted conversion ratio, and further includes:
Step 141: and judging whether the data quantity is equal to a preset threshold value. If yes, ending the flow; if not, go to step 142.
If the data amount of the audio data buffered in the buffer unit after the sampling rate conversion process is equal to the preset threshold value, the conversion ratio does not need to be adjusted, that is, the data amount does not have excessive or insufficient risk at this time.
Step 142: and judging whether the data quantity is smaller than a preset threshold value. If yes, go to step 143; if not, go to step 144.
If the data amount is not equal to the preset threshold in the step 141, in this step, it is known whether the conversion ratio needs to be increased or decreased by determining whether the data amount is smaller than the preset threshold, so that the data amount is maintained within a certain range.
Step 143: and increasing the initial conversion ratio, obtaining a first conversion ratio, and performing sampling rate conversion processing on the audio data by the first conversion ratio.
If the data amount is smaller than the preset threshold, it is indicated that there is a risk of too small data amount of the audio data buffered in the buffer unit, if the conversion ratio is not adjusted in time, the data amount in the buffer unit is eventually reduced to 0 along with the accumulation of errors, so that the normal playing of the audio data is affected. Therefore, in this step, by increasing the initial conversion ratio, the first conversion ratio is obtained, and the sampling rate conversion processing is performed on the audio data at the first conversion ratio, thereby gradually increasing the data amount in the buffer unit, and avoiding the audio data in the buffer unit from being emptied.
Step 144: and reducing the initial conversion ratio, obtaining a second conversion ratio, and performing sampling rate conversion processing on the audio data with the second conversion ratio, wherein the second conversion ratio is smaller than the first conversion ratio.
If the data amount is greater than the preset threshold, it is indicated that there is an excessive risk of the data amount of the audio data buffered in the buffer unit, if the conversion ratio is not adjusted in time, the data amount in the buffer unit is eventually excessive and the audio data overflows along with the accumulation of errors, thereby affecting the normal playing of the audio data. Therefore, in this step, by reducing the initial conversion ratio, the second conversion ratio is obtained, and the sampling rate conversion processing is performed on the audio data at the second conversion ratio, thereby gradually reducing the data amount in the buffer unit and avoiding the overflow of the audio data in the buffer unit.
Whether the data quantity is equal to a preset threshold value or not is judged firstly, if not, whether the data quantity is smaller than the preset threshold value is judged continuously, so that the size relation between the data quantity and the preset threshold value is obtained finally, and the initial conversion ratio is adjusted according to the size relation. It should be noted that, the embodiment of the present application is only described by taking the determination sequence as an example, and it is not necessary to determine whether the data amount is smaller than the preset threshold value after determining whether the data amount is equal to the preset threshold value, that is, the embodiment of the present application does not limit how to obtain the size relationship between the data amount and the preset threshold value, and can set the determination sequence according to the need, so long as the size relationship between the data amount and the preset threshold value can be obtained. For example, it may be determined whether the data amount is smaller than a preset threshold, and then whether the data amount is equal to or larger than the preset threshold, or whether the data amount is larger than the preset threshold, and then whether the data amount is equal to or smaller than the preset threshold.
In the embodiment of the application, the conversion ratio is adjusted according to the size relation between the data volume in the buffer unit and the preset threshold value, and if the data volume is smaller than the preset threshold value, the conversion ratio is increased to increase the data volume in the buffer unit, so that the audio data in the buffer unit is prevented from being emptied; if the data amount is larger than the preset threshold value, the conversion ratio is reduced so as to reduce the data amount in the buffer unit and avoid the overflow of the audio data in the buffer unit. The adjusted conversion ratio is utilized to carry out sampling rate conversion processing on the audio data, so that the data volume in the buffer unit can be effectively ensured to be maintained within a certain range, and the audio data can be normally and effectively played, namely, the adjusted conversion ratio determined by the mode is ensured, and the accuracy of the obtained adjusted conversion ratio is improved.
In a practical application scenario, data is often transmitted in frames and processed in frames. The embodiment of the application provides a resampling processing method, namely a mode of changing the frame length of audio data (namely changing the data amount in one frame of audio data) by adjusting the sampling interval, so as to achieve the purpose of adjusting the sampling rate. In the embodiment of the application, the frame length of the audio data before the sampling rate conversion processing is referred to as the original frame length, and the frame length of the audio data after the sampling rate conversion processing is referred to as the original conversion frame length. Increasing the initial conversion ratio in step 143 to obtain a first conversion ratio, further comprises:
Step a1: a first frame length is determined, wherein the first frame length is longer than the initial transition frame length.
The audio data is represented by a data frame, and in the embodiment of the application, the frame length refers to the data amount of one frame of data. The first frame length is longer than the initial conversion frame length, specifically, the data amount of the data included in the first frame length is larger than the data amount of the data included in the initial conversion frame length.
In this step, the specific length of the first frame (i.e., the number of samples) is not limited as long as the determined first frame length is longer than the initial conversion frame length.
Step a2: a first ratio of the first frame length to the original frame length is calculated and the first ratio is determined as a first conversion ratio.
Wherein the first frame length determined in step a1 is divided by the original frame length, and the obtained first ratio is determined as the first conversion ratio. Since the first frame length is longer than the initial conversion frame length, the first conversion ratio is greater than the initial conversion ratio.
The initial conversion ratio is reduced in step 144 to obtain a second conversion ratio, further comprising:
step b1: a second frame length is determined, wherein the second frame length is shorter than the initial transition frame length.
The specific length of the second frame (i.e., the number of samples) is not limited as long as the determined second frame length is shorter than the initial conversion frame length.
Step b2: a second ratio of the second frame length to the original frame length is calculated and the second ratio is determined as a second conversion ratio.
Wherein the second frame length determined in step b1 is divided by the original frame length, and the obtained second ratio is determined as the second conversion ratio. Since the second frame length is shorter than the initial conversion frame length, the second conversion ratio is smaller than the initial conversion ratio.
In the embodiment of the application, the frame length is determined according to the initial conversion ratio, and the determined frame length is divided by the original frame length to obtain the adjusted conversion ratio, and then the audio data is subjected to sampling rate conversion processing according to the adjusted conversion ratio, so that the data volume of the audio data cached in the buffer unit of the audio playing system can be effectively regulated and controlled.
In order to better regulate the data amount of the audio data buffered in the buffer unit of the audio playing system, the embodiment of the application provides a way for determining the first frame length and the second frame length. In the embodiment of the application, the first frame length is increased by one sample length compared with the initial conversion frame length; the second frame length is reduced by one sample length from the initial transition frame length.
Because the error existing between the nominal sampling rate and the actual sampling rate of the audio system is smaller, in the embodiment of the application, the first frame length and the second frame length are set to be different from the initial conversion frame length by one sample length, the ratio of the determined frame length to the original frame length is determined to be the adjusted conversion ratio, and the audio data is subjected to sampling rate conversion processing by the adjusted conversion ratio, so that the data amount buffered in the buffer unit can be finely adjusted, and the data amount is ensured to be maintained within a certain range. The problem that the obtained difference between the adjusted conversion ratio and the initial conversion ratio is large, so that the data volume buffered in the buffer unit is greatly changed, and overflow is easily caused by too much data volume or emptying is easily caused by too little data volume is avoided.
Further, this patent gives a more general representation of the first frame length and the second frame length. In the embodiment of the application, the first frame length is determined by the formula (1)L B :
,(1)
Wherein,L A is the original frame length;a nominal sampling rate of an audio transmission system for transmitting audio data; />A nominal sampling rate of an audio playback system for receiving and playing back processed audio data; arithmetic sign [x]Representing that is not greater thanxDelta is a positive integer, generally delta takes 1, and in some special cases, such as that the temperature difference between the sender and the receiver is too large, the deviation of the crystal oscillator circuit increases, and delta can be a constant larger than 1.
It should be noted that, the frame length of one frame of audio data can be adjusted by adjusting the sampling interval, so that the audio data can be converted from the original frame lengthL A Conversion to a first frame lengthL B . Here at the same nominal sampling rate of the audio transmission system and the audio reception system (i.e.) Original frame lengthL A Equal to 6, a first frame lengthL B Equal to 7, conversion ratiorThe explanation is given by taking 7/6 as an example. Setting a frame of data before sampling rate conversion of audio dataS A0 The sampling interval of (2) isT A Shortening sampling interval toT A /rObtaining a frame of data with 7 frame length after sampling rate conversion processing S B0 . FIG. 4 shows a frame of audio data before sample rate conversion according to an embodiment of the present applicationS A0 And one frame of data of the audio data after the sample rate conversionS B0 Is a schematic diagram of (a). As shown in figure 4 of the drawings,S B0 data in (a)S A0 Interleaving in data occurs byS A0 And (5) carrying out interpolation on the data to obtain the data. The following formula gives a linear interpolation method of a one-time polynomial, which is composed ofS A0 GeneratingS B0 Wherein, the method comprises the steps of, wherein,S A0 is the original audio data, its frame length isL A ;S B0 Is a frame of data after resampling, and the frame length isL B 。
,(2)
Wherein,is a natural number and->,/>,/>Arithmetic sign [x]Representing that is not greater thanxIs an integer of (a).
Determining the second frame length by the following formulaL B ’:
,(3)
Wherein,L A is the original frame length;a nominal sampling rate of an audio transmission system for transmitting audio data; />A nominal sampling rate of an audio playback system for receiving and playing back processed audio data; arithmetic sign [x]Representing that is not greater thanxDelta is a positive integer, preferably delta takes 1.
Determining the second frame length in the above mannerL B ’After that, at this time, a second conversion ratior’The method comprises the following steps:。
it is worth noting that at the second conversion ratior’One frame of data for audio dataAfter sampling rate conversion processing, obtaining the length of the sampleL B ’Is- >The method comprises the following steps:
,(4)
wherein,is a natural number and-> ,/>,/>Arithmetic sign [x]Representing that is not greater thanxIs an integer of (a).
Because the original frame length, the nominal sampling rate of the audio transmission system and the audio playing system are determined and are easy to obtain, in the embodiment of the application, the first frame length and the second frame length can be rapidly and accurately determined through the formula, and further the first conversion ratio and the second conversion ratio can be rapidly and accurately determined, thereby effectively performing sampling rate conversion processing on audio data and improving the playing effect of the audio data.
In order to better regulate the data amount of the audio data buffered in the buffer unit of the audio playing system, the embodiment of the application provides another sampling rate matching method for audio data transmission. Fig. 5 shows a flowchart of a sample rate matching method for audio data transmission according to an embodiment of the present application, as shown in fig. 5, the method includes the following steps:
step 201: and carrying out sampling rate conversion processing on the audio data by initial conversion comparison to obtain processed audio data.
Step 202: and transmitting the processed audio data to a buffer unit of an audio playing system for buffering, so that the audio playing system acquires and plays the processed audio data from the buffer unit.
Step 203: the data amount of the processed audio data buffered in the buffer unit is acquired.
Step 204: and judging whether the data quantity is equal to a preset threshold value. If yes, go to step 203; if not, go to step 205.
Step 205: and judging whether the data quantity is smaller than a preset threshold value. If yes, go to step 206; if not, go to step 207.
Step 206: and increasing the initial conversion ratio, obtaining a first conversion ratio, and performing sampling rate conversion processing on the audio data by the first conversion ratio.
Step 207: and reducing the initial conversion ratio, obtaining a second conversion ratio, and performing sampling rate conversion processing on the audio data by the second conversion ratio.
Wherein, the specific implementation manner of the steps 201 to 203 can refer to the steps 110 to 130; the specific implementation of steps 204-207 may refer to steps 141-144, and will not be described here again.
Step 208: and transmitting the audio data obtained after the sampling rate conversion processing of the audio data by the adjusted conversion ratio to a buffer unit for buffering.
In the embodiment of the present application, the adjusted conversion ratio refers to the first conversion ratio or the second conversion ratio. If the audio data is subjected to sample rate conversion at the first conversion ratio before executing step 208, the conversion ratio adjusted in this step is the first conversion ratio; if the sample rate conversion processing is performed on the audio data at the second conversion ratio before executing step 208, the conversion ratio adjusted in this step is the second conversion ratio.
Step 209: the data amount of the audio data buffered in the buffer unit is acquired.
The specific implementation of this step may refer to step 130, which is not described herein.
It should be noted that, in the embodiment of the present application, whether the audio data is subjected to the sampling rate conversion processing by the initial conversion ratio, the audio data is subjected to the sampling rate conversion processing by the first conversion ratio, or the audio data is subjected to the sampling rate conversion processing by the second conversion ratio, the audio data after the sampling rate conversion processing is buffered in the same buffer unit, that is, both the audio data and the audio data are buffered in the same buffer unit of the same audio playing system.
Therefore, the data amount of the audio data buffered in the buffer unit acquired in this step refers to the data amount of all the audio data buffered in the buffer unit, that is, the data amount of all the buffered audio data is acquired as long as the audio data is buffered in the buffer unit, regardless of whether the buffered audio data is acquired by performing the sample rate conversion processing at the initial conversion ratio, or whether the buffered audio data is acquired by performing the sample rate conversion processing at the first conversion ratio, or whether the buffered audio data is acquired by performing the sample rate conversion processing at the second conversion ratio.
Step 210: and judging whether the data quantity is equal to a preset threshold value. If yes, go to step 209; if not, go to step 211.
In this step, it is determined whether the data amount obtained in step 209 is equal to the preset threshold, if yes, the conversion ratio is not required to be adjusted, that is, the sampling rate conversion processing is performed on the audio data continuously with the current conversion ratio, and the step 209 is transferred to continue to obtain the data amount of the audio data buffered in the buffer unit at the next time; if not, go to step 211. Specific how to set the threshold value can refer to step 140, and will not be described herein.
Step 211: and judging whether the data quantity is smaller than a preset threshold value. If yes, go to step 212; if not, go to step 213.
After the data amount is determined to be not equal to the preset threshold in step 210, in this step, by continuously determining whether the data amount is less than the preset threshold, it is known how to adjust the conversion ratio, so that the data amount buffered in the buffer unit is maintained within the stable range. If the data amount is less than the preset threshold, go to step 212; if the data amount is greater than the preset threshold, go to step 213.
Step 212: and performing sample rate conversion processing on the audio data according to the first conversion ratio.
Step 213: and performing sample rate conversion processing on the audio data by using the second conversion ratio.
The specific implementation manner of steps 212 to 213 may refer to steps 143 to 144, and will not be described herein.
It should be noted that, compared with the embodiment provided in fig. 2, the embodiment of the present application adds a cyclic step of performing sample rate conversion processing on the audio data with an adjusted conversion ratio, and circularly executing storing the processed audio data in a buffer unit, obtaining the data amount of the audio data buffered in the buffer unit, and determining whether to perform sample rate conversion processing on the audio data by using the first conversion ratio or the second conversion ratio according to the size relationship between the data amount and a preset threshold, so as to better control the data amount in the buffer unit, and enable the data amount in the buffer unit to continuously meet the requirement.
Specifically, if the amount of data buffered in the buffer unit acquired in step 203 is smaller than the preset threshold, in step 206, the initial conversion ratio is increased to obtain a first conversion ratio, and the audio data is subjected to sample rate conversion processing according to the first conversion ratio, so as to increase the amount of data in the buffer unit. The data volume in the buffer unit is obtained in a circulating way, so that the audio data can be further judged to be subjected to sampling rate conversion processing by the first conversion ratio, and whether the data volume is larger than a preset threshold value or not after the data volume in the buffer unit is continuously increased, namely whether the risk of overflow is caused by excessive data volume or not is judged. If the data size is larger than the preset threshold value in the process of sampling rate conversion processing of the audio data by the first conversion ratio, the conversion ratio is adjusted in time, that is, the sampling rate conversion processing is performed on the audio data by the second conversion ratio in step 213, so as to reduce the data size in the buffer unit, and further effectively avoid the risk of overflow caused by excessive data size buffered in the buffer unit. By circularly executing the above operations, the data amount buffered in the buffer unit is effectively maintained within a certain range, thereby ensuring that the audio playing system can normally and effectively play audio data.
Similarly, if the amount of data buffered in the buffer unit obtained in step 203 is greater than the preset threshold, the initial conversion ratio is reduced in step 207 to obtain a second conversion ratio, and the sampling rate conversion process is performed on the audio data by the second conversion ratio, so as to reduce the amount of data in the buffer unit. The data volume in the buffer unit is obtained in a circulating way, so that the audio data can be further judged to be subjected to sampling rate conversion processing by the second conversion ratio, and whether the data volume in the buffer unit is smaller than a preset threshold value or not after the data volume in the buffer unit is continuously reduced, namely whether the risk of emptying is caused by too small data volume or not is judged. If the data size is smaller than the preset threshold value in the process of sampling rate conversion processing of the audio data by the second conversion ratio, the conversion ratio is adjusted in time, that is, the sampling rate conversion processing is performed on the audio data by the first conversion ratio in step 212, so as to increase the data size in the buffer unit, and further effectively avoid the risk of emptying caused by too small data size buffered in the buffer unit. By circularly executing the above operations, the data amount buffered in the buffer unit is effectively maintained within a certain range, thereby ensuring that the audio playing system can normally and effectively play audio data.
Whether the data quantity is equal to a preset threshold value or not is judged firstly, if not, whether the data quantity is smaller than the preset threshold value or not is judged continuously, and the size relation between the data quantity and the preset threshold value is obtained. It should be noted that, the embodiment of the present application is only described by taking the determination sequence as an example, and it is not necessary to determine whether the data amount is smaller than the preset threshold value after determining whether the data amount is equal to the preset threshold value, that is, the embodiment of the present application does not limit how to obtain the size relationship between the data amount and the preset threshold value, and can set the determination sequence according to the need, so long as the size relationship between the data amount and the preset threshold value can be obtained. For example, it may be determined whether the data amount is smaller than a preset threshold, and then whether the data amount is equal to or larger than the preset threshold, or whether the data amount is larger than the preset threshold, and then whether the data amount is equal to or smaller than the preset threshold.
In summary, in the embodiment of the present application, the adjusted conversion ratio is obtained in step 206 or 207, the adjusted conversion ratio performs sampling rate conversion processing on the audio data, the processed audio data is buffered in the buffer unit, then the data amount of the processed audio data buffered in the buffer unit is continuously obtained, and then the conversion ratio is adjusted in time according to the obtained data amount and the preset threshold value, so that the data amount buffered in the buffer unit is better ensured to be maintained in a stable range, and the playing effect of the audio data is improved.
In order to improve the playing effect of audio data, the embodiment of the application provides a method for determining a transition frame and a sampling interval between adjacent sampling points in the transition frame. In the embodiment of the application, when the conversion ratio is switched, if the conversion ratio is switched from the first conversion ratio to the second conversion ratio, the sampling rate conversion processing is continuously carried out on the audio data by utilizing the second conversion ratio; and if the second conversion ratio is switched to the first conversion ratio, the following steps are further executed before the sampling rate conversion processing is continued on the audio data by using the first conversion ratio:
step c1: determination of the firstkIndividual spots and the firstkSampling interval of +1 samplesWherein->,/>For preset initial value, ++>,/>),,L A For the frame length of the audio data before the sample rate conversion processing at the initial conversion ratio, +.>Nominal sample rate of audio transmission system for transmitting audio data,/->To receive and play the nominal sample rate of the audio play system of the processed audio data,kis a natural number, andk≤/>。
if the adjusted conversion ratio is different from the previous frame, that is, the conversion ratio of the previous frame is the first conversion ratio, and if the adjusted conversion ratio is the second conversion ratio, the current frame is treated as a transition frame, and then the data frame of the audio data of the next frame of the transition frame is subjected to sampling conversion treatment by the second conversion ratio; and when the conversion ratio of the previous frame is the second conversion ratio and the adjusted conversion ratio is the first conversion ratio, the current frame is treated as a transition frame, and then the data frame of the audio data of the next frame of the transition frame is subjected to sampling conversion treatment by the first conversion ratio. In the transition frame, the frame length is ,/>For the frame length of the audio data before the sample rate conversion processing at the initial conversion ratio, i.e., the original frame length,/>Nominal sample rate of audio transmission system for transmitting audio data,/->Nominal sampling rate of an audio playback system for receiving and playing back processed audio data. First, thekIndividual spots and the firstkSampling interval of +1 samples +.>Can be expressed as formula (5):
,0≤k≤/>-2,(5)
wherein,for presetting initial value-> dTRepresenting the variation of sampling interval with the increase of the number of samplesdTMay be positive or negative, representing an increment or decrement of the sampling interval).
For easy calculation, the starting time of the transition frame is set to 0, and the first transition frame isThe sampling instants of the individual samples can be expressed as (6):
0≤/>≤/>-1/>(6)
to smooth the transition, the firstThe time at which 1 sample is located and the end of the current transition frame, i.e. the time interval of the first sample of the next frame, also corresponds to the increasing or decreasing trend given by equation (5), so +.>Substitution (6), i.e. taking the first sample of the next frame as the current frameL tr Samples, the end time of the current transition frame should be obtained, noted +.>As shown in formula (7):
,(7)
at the same time, at this momentCan also be expressed as formula (8):
,(8)
wherein,T s for the average sampling interval of all samples in the transition frame,)。
substituting the formula (8) into the formula (7) can obtain the formula (9):
,(9)
Due toT s Andare all quantitative, and->Then byT 0 Determining that only +.>A variable, i.e. determine +.>The sampling time of each sample and the sampling interval of the adjacent samples can be obtained.
The sampling interval of the first two samples of the transition frame can be determined according to equation (5)And the sampling interval between the last sample of the transition frame and the first sample of the following frame, is denoted +.>. Will bekBy substituting 0 into (5), we can obtain +.>As shown in formula (10):
,(10)
will bek=L tr And (9) substituted into (5) to obtainAs shown in formula (11):
,(11)
if from the first frame lengthL B Transitioning to a second frame lengthL B ’Sampling interval for transition stabilizationAnd->Should be as close as possible to the pre-switch-conversion-ratio sampling intervalT B And switching the sampling interval after the conversion ratioT B ' this optimization objective can be expressed as finding the minimum of the result of equation (12)T 0 Value:
,(12)
wherein,。
conversely, if from the second frame lengthL B ’Transitioning to a first frame lengthL B The formula (12) is replaced by the formula (13):
,(13)
obviouslyT 0 Is between the size ofT B AndT B ' between, thus a simple and efficient solutionT 0 The method is thatT B AndT B ' inserting N values linearly between them, selecting one value minimizing the result of the formula (12) or the formula (13) as the valueT 0 Is marked as. Will->Substitution (9) of the obtained product dTAnd then substituting the samples into the formula (6) together to obtain the sampling time of each sample in the transition frame.
Step c2: in duration ofAccording to the firstkIndividual spots and the firstkSampling interval of +1 samples +.>Processing the audio data to obtain processed transition frame audio data, wherein the sampling time of the 0 th sampling point is 0,。
data from these sampling moments obtained in step c1S A Resampling, such as the linear interpolation method described above, may be performed to obtain each sample data in the transition frame.
After the adjusted conversion ratio is determined, if the sampling rate conversion processing is performed on the audio data by using the adjusted conversion ratio immediately, the obtained audio data frame will change to a certain extent after the sampling rate conversion processing is performed on the audio data by using the adjusted conversion ratio, that is, after the conversion ratio is adjusted, the frame length of the audio data frame of the next frame will change immediately, that is, the frame length of the audio data is changed fromConversion toL B Or byL B Conversion to->Even ifL B And->The difference is small, but if it is made of + ->Immediate conversion toL B Or byL B Conversion to->Abrupt changes in the sampling interval between samples in adjacent audio data frames can also result in some degree of distortion of the audio signal.
In the embodiment of the application, after the adjusted conversion ratio is determined, the frame length of the transition frame is determined firstL tr Is thatThe sampling interval between each sample point and the previous sample point in the transition frame is increased or decreased, i.e. in the transition frame, the first sample pointkIndividual spots and the firstkThe sampling interval of +1 samples is shown in expression (5). In accordance with the derivation set forth above,dTeither positive or negative, i.e. the sampling interval is incremented or decremented. If the second conversion ratio is adjusted to the first conversion ratio, the converted sampling rate determined by the first conversion ratio increases, i.e., the sampling interval decreases. In the embodiment of the application, after the transition frame is determined, the sampling interval between the adjacent sampling points in the transition frame is controlled to be gradually reduced, so that the sampling interval between the adjacent sampling points in the audio data is smoothly transited to the sampling interval after conversion, thereby avoiding the occurrence of larger abrupt change of the audio data frame obtained when the sampling rate conversion processing is carried out by utilizing the adjusted conversion ratio and avoiding the occurrence of distortion of the audio data. If the first conversion ratio is adjusted to the second conversion ratio, the converted sampling rate determined by the second conversion ratio is reduced, that is, the sampling interval is increased, in the embodiment of the application, after the transition frame is determined, the sampling interval between adjacent sampling points in the transition frame is controlled to be gradually increased so as to gradually transition the sampling interval between adjacent sampling points in the audio data to the converted sampling interval, thereby avoiding the sound obtained when the sampling rate conversion processing is performed by using the adjusted conversion ratio The frequency data frame has larger mutation, and the audio data is prevented from being distorted.
In order to improve accuracy of the acquired data amount and thus improve playing effect of audio data, the embodiment of the application provides another sampling rate matching method for audio data transmission. Fig. 6 shows a flowchart of a sample rate matching method for audio data transmission according to an embodiment of the present application, and fig. 6 is a step of adding a smoothing process to an obtained data amount based on fig. 2, as shown in fig. 6, the method includes the steps of:
step 310: and carrying out sampling rate conversion processing on the audio data by initial conversion comparison to obtain processed audio data.
Step 320: and transmitting the processed audio data to a buffer unit of an audio playing system for buffering, so that the audio playing system acquires and plays the processed audio data from the buffer unit.
Step 330: the data amount of the processed audio data buffered in the buffer unit is acquired.
The specific implementation of steps 310 to 330 may refer to steps 110 to 130, and will not be described herein.
Step 340: smoothing the data volume and obtaining the processed data volumeD(n)Wherein the data amount is smoothed by (14)
,(14)
Wherein,is a preset smoothing coefficient, and +.>,D(n1) the amount of processed data buffered by the buffer unit obtained after the smoothing process at the previous time,d(n) And the data quantity cached for the buffer unit queried at the current moment.
Ideally, the data amount in the buffer unit is queried by the query command, and the obtained data amount value is stable, i.e. the values obtained twice in adjacent shorter time intervals are relatively close. However, the system is affected by system delay when executing the query instruction, and the delay time is often uncertain, so that the data amount is abnormal or fluctuated, and the acquired numerical accuracy is not high. In addition, when the amount of data in the buffer unit is queried, there may be processed audio data being buffered in the buffer unit, or the audio playing system is acquiring and playing the audio data in the buffer unit, so that there may be fluctuation in the amount of data. In addition, if the audio system is interfered by electromagnetic waves, the working condition is unstable, and the data volume is abnormal or fluctuates.
Therefore, in this step, in order to improve the accuracy of the obtained data amount result, the influence of inaccuracy of the query result due to fluctuation of the data amount is reduced by performing smoothing processing on the queried data amount. It is to be noted that the smoothing process is performed by the formula (14), wherein, D(n) For the data amount of the audio data buffered in the buffer unit obtained after the smoothing process at the current moment, i.e. process the firstnThe amount of data obtained after the smoothing process at the time of the frame data frame,D(n1) processing the data amount buffered by the buffer unit obtained after the smoothing process at the previous time, namely processing the firstnThe amount of data obtained after smoothing at 1 frame of data,is a preset smoothing coefficient, and +.>Can be determined according to the need>The larger the value in this range, the greater the smoothing force, but with longer delay.
Step 350: and adjusting the initial conversion ratio according to the size relation between the processed data quantity and the preset threshold value, and performing sampling rate conversion processing on the audio data according to the adjusted conversion ratio.
In this step, the initial conversion ratio is adjusted according to the size relationship between the data amount obtained in step 340 and the preset threshold, and the sampling rate conversion process is performed on the audio data according to the adjusted conversion ratio. The specific implementation of this step may refer to step 140, which is not described herein.
In the embodiment of the application, the situation that delay exists when the data volume of the buffer unit is inquired and the situation that the data volume in the buffer unit is in dynamic change are fully considered, so that the accuracy of the obtained data volume is improved after the inquired data volume is subjected to smooth processing, and the accuracy of the obtained adjusted conversion ratio is improved, namely the playing effect of audio data is improved.
Fig. 7 is a schematic structural diagram of an audio transmission system according to an embodiment of the present application. As shown in fig. 7, the audio transmission system 400 includes a processor 401.
The processor 401 is configured to perform sample rate conversion processing on the audio data with an initial conversion ratio, and obtain processed audio data; transmitting the processed audio data to a buffer unit of an audio playing system for receiving and playing the processed audio data for buffering, so that the audio playing system receives and plays the processed audio data; acquiring the data quantity cached in a buffer unit of an audio playing system; and adjusting the initial conversion ratio according to the size relation between the data quantity and the preset threshold value, obtaining the adjusted conversion ratio, and carrying out sampling rate conversion processing on the audio data according to the adjusted conversion ratio.
In the embodiment of the application, the situation that errors exist in the nominal sampling rate and the actual sampling rate of the audio system is fully considered, the processor 401 performs sampling rate conversion processing on the audio data by initial conversion ratio, caches the processed audio data into the buffer unit, timely adjusts the conversion ratio according to the size relation between the data quantity and the preset threshold value by acquiring the data quantity cached in the buffer unit of the audio playing system, and further performs sampling rate conversion processing on the audio data by the adjusted conversion ratio, so that the data quantity in the buffer unit is maintained within a certain range, the problem of too much or too little data quantity cached in the buffer unit is avoided, the playing effect of the audio data is improved, and the problems of clamping, noise and the like in the audio playing process are avoided.
Fig. 8 is a schematic structural diagram of an audio playing system according to an embodiment of the present application. As shown in fig. 8, the audio transmission system 500 includes a processor 501 and a buffer unit 502.
The processor 501 is configured to perform sample rate conversion processing on received audio data in an initial conversion ratio, obtain processed audio data, and transmit the processed audio data to the buffer unit.
The buffer unit 502 is configured to receive and buffer the processed audio data.
The processor 501 is further configured to obtain a data amount of the processed audio data buffered in the buffer unit, adjust an initial conversion ratio according to a size relationship between the data amount and a preset threshold, obtain an adjusted conversion ratio, and perform sample rate conversion processing on the audio data with the adjusted conversion ratio.
In the embodiment of the application, the situation that errors exist in the nominal sampling rate and the actual sampling rate of the audio system is fully considered, the processor 501 performs sampling rate conversion processing on the audio data by initial conversion ratio, and after the processed audio data is cached in the buffer unit 502, the processor 501 timely adjusts the conversion ratio according to the magnitude relation between the data quantity and the preset threshold value by acquiring the data quantity cached in the buffer unit of the audio playing system, and then performs sampling rate conversion processing on the audio data by the adjusted conversion ratio, so that the data quantity in the buffer unit is maintained within a certain range, the problem of too much or too little data quantity cached in the buffer unit is avoided, and the playing effect of the audio data is improved, namely the problems of blocking, noise and the like in the audio playing process are avoided.
Embodiments of the present application provide a computer readable storage medium storing executable instructions that, when run on an audio system, cause the audio system to perform a sample rate matching method for audio data transmission in any of the method embodiments described above.
Claims (9)
1. A sample rate matching method for audio data transmission, the method comprising;
performing sample rate conversion processing on the audio data by initial conversion comparison to obtain processed audio data;
transmitting the processed audio data to a buffer unit of an audio playing system for buffering, so that the audio playing system acquires and plays the processed audio data from the buffer unit;
acquiring the data volume of the processed audio data cached in the buffer unit;
adjusting the initial conversion ratio according to the size relation between the data quantity and a preset threshold value to obtain an adjusted conversion ratio, and performing sample rate conversion processing on the audio data according to the adjusted conversion ratio, wherein the initial conversion ratio is adjusted according to the size relation between the data quantity and the preset threshold value to obtain an adjusted conversion ratio, and the method further comprises the following steps:
If the data volume is smaller than the preset threshold value, the initial conversion ratio is increased, and a first conversion ratio is obtained; if the data quantity is larger than the preset threshold value, reducing the initial conversion ratio to obtain a second conversion ratio, wherein the second conversion ratio is smaller than the first conversion ratio; wherein,
taking the frame length of the audio data before the sampling rate conversion processing of the initial conversion ratio as an original frame length, taking the frame length of the audio data after the sampling rate conversion processing of the initial conversion ratio as an initial conversion frame length, and increasing the initial conversion ratio to obtain a first conversion ratio, wherein the method further comprises the following steps:
determining a first frame length, wherein the first frame length is longer than the initial conversion frame length;
calculating a first ratio of the first frame length to the original frame length, and determining the first ratio as the first conversion ratio;
said reducing said initial conversion ratio to obtain a second conversion ratio, further comprising:
determining a second frame length, wherein the second frame length is shorter than the initial transition frame length;
and calculating a second ratio of the second frame length to the original frame length, and determining the second ratio as the second conversion ratio.
2. The method of claim 1, wherein the first frame length is increased by one sample length from the initial transition frame length and the second frame length is decreased by one sample length from the initial transition frame length.
3. The method of claim 1, wherein the first frame length is determined by the formula:
wherein, the method comprises the steps of, wherein,L B for the first frame length to be the same,L A for the original frame length,/a->Nominal sample rate of audio transmission system for transmitting audio data,/->To receive and play the nominal sampling rate of the audio playing system of the processed audio data, a symbol is calculatedx]Representing that is not greater thanxDelta is a positive integer;
the second frame length is determined by the following formula:
wherein, the method comprises the steps of, wherein,L B ’for the second frame length to be the same,L A for the original frame length,/a->Nominal sample rate of audio transmission system for transmitting audio data,/->To receive and play the nominal sampling rate of the audio playing system of the processed audio data, a symbol is calculatedx]Representing that is not greater thanxAnd delta is a positive integer.
4. The method of claim 1, wherein after said increasing said initial conversion ratio if said amount of data is less than said preset threshold to obtain a first conversion ratio, and after said decreasing said initial conversion ratio if said amount of data is greater than said preset threshold to obtain a second conversion ratio, said method further comprises:
Step S1, transmitting the audio data obtained by sampling rate conversion processing of the audio data according to the adjusted conversion ratio to the buffer unit for buffering;
step S2, obtaining the data volume of the audio data cached in the buffer unit;
step S3, if the data volume is larger than the preset threshold, sampling rate conversion processing is carried out on the audio data according to the second conversion ratio;
step S4, if the data volume is smaller than the preset threshold value, sampling rate conversion processing is carried out on the audio data according to the first conversion ratio;
the steps S1 to S4 are performed for each data frame of audio data to be processed.
5. The method according to claim 4, wherein when the conversion ratio switching occurs, before the sample rate conversion processing is performed on the audio data at the second conversion ratio in the step S3, and before the sample rate conversion processing is performed on the audio data at the first conversion ratio in the step S4, the steps of:
determination of the firstkIndividual spots and the firstkSampling interval of +1 samplesWherein->,/>For preset initial value, ++>,/>),/>,L A For the frame length of the audio data before the sample rate conversion processing at the initial conversion ratio, +. >Nominal sample rate of audio transmission system for transmitting audio data,/->To receive and play the nominal sample rate of the audio play system of the processed audio data,kis a natural number, andk≤/>arithmetic sign [x]Representing that is not greater thanxIs the largest integer of (2);
in duration ofAccording to the firstkIndividual spots and the firstkSampling interval of +1 samples +.>Processing the audio data to obtain processed transition frame audio data, wherein the sampling time of the 0 th sampling point is 0,。
6. the method of claim 1, wherein prior to said adjusting said initial conversion ratio based on a magnitude relationship of said data amount to a preset threshold, said method further comprises:
smoothing the data volume and obtaining the processed data volumeD(n) Wherein the smoothing process is performed on the data amount by the following formula:wherein->Is a preset smoothing coefficient and,D(n1) the amount of data buffered by said buffer unit obtained after said smoothing at the previous time,d(n) The data quantity cached by the buffer unit is queried at the current moment;
the initial conversion ratio is adjusted according to the size relation between the data quantity and a preset threshold value, and the method further comprises the following steps:
And adjusting the initial conversion ratio according to the size relation between the processed data quantity and a preset threshold value.
7. An audio transmission system, the system comprising a processor configured to:
performing sample rate conversion processing on the audio data by initial conversion comparison to obtain processed audio data;
transmitting the processed audio data to a buffer unit of an audio playing system for receiving and playing the processed audio data for buffering, so that the audio playing system receives and plays the processed audio data;
acquiring the data quantity cached in a buffer unit of the audio playing system;
adjusting the initial conversion ratio according to the size relation between the data quantity and a preset threshold value to obtain an adjusted conversion ratio, and performing sample rate conversion processing on the audio data according to the adjusted conversion ratio, wherein the initial conversion ratio is adjusted according to the size relation between the data quantity and the preset threshold value to obtain an adjusted conversion ratio, and the method further comprises the following steps:
if the data volume is smaller than the preset threshold value, the initial conversion ratio is increased, and a first conversion ratio is obtained; if the data quantity is larger than the preset threshold value, reducing the initial conversion ratio to obtain a second conversion ratio, wherein the second conversion ratio is smaller than the first conversion ratio; wherein,
Taking the frame length of the audio data before the sampling rate conversion processing of the initial conversion ratio as an original frame length, taking the frame length of the audio data after the sampling rate conversion processing of the initial conversion ratio as an initial conversion frame length, and increasing the initial conversion ratio to obtain a first conversion ratio, wherein the method further comprises the following steps:
determining a first frame length, wherein the first frame length is longer than the initial conversion frame length;
calculating a first ratio of the first frame length to the original frame length, and determining the first ratio as the first conversion ratio;
said reducing said initial conversion ratio to obtain a second conversion ratio, further comprising:
determining a second frame length, wherein the second frame length is shorter than the initial transition frame length;
and calculating a second ratio of the second frame length to the original frame length, and determining the second ratio as the second conversion ratio.
8. An audio playback system, the system comprising a processor and a buffer unit, wherein:
the processor is used for carrying out sampling rate conversion processing on the received audio data according to an initial conversion ratio to obtain processed audio data, and transmitting the processed audio data to the buffer unit;
The buffer unit is used for receiving and buffering the processed audio data;
the processor is further configured to obtain a data amount of the processed audio data buffered in the buffer unit, adjust the initial conversion ratio according to a size relationship between the data amount and a preset threshold, obtain an adjusted conversion ratio, and perform sample rate conversion processing on the audio data with the adjusted conversion ratio, where the adjusting the initial conversion ratio according to the size relationship between the data amount and the preset threshold, and obtain an adjusted conversion ratio, and further includes:
if the data volume is smaller than the preset threshold value, the initial conversion ratio is increased, and a first conversion ratio is obtained; if the data quantity is larger than the preset threshold value, reducing the initial conversion ratio to obtain a second conversion ratio, wherein the second conversion ratio is smaller than the first conversion ratio; wherein,
taking the frame length of the audio data before the sampling rate conversion processing of the initial conversion ratio as an original frame length, taking the frame length of the audio data after the sampling rate conversion processing of the initial conversion ratio as an initial conversion frame length, and increasing the initial conversion ratio to obtain a first conversion ratio, wherein the method further comprises the following steps:
Determining a first frame length, wherein the first frame length is longer than the initial conversion frame length;
calculating a first ratio of the first frame length to the original frame length, and determining the first ratio as the first conversion ratio;
said reducing said initial conversion ratio to obtain a second conversion ratio, further comprising:
determining a second frame length, wherein the second frame length is shorter than the initial transition frame length;
and calculating a second ratio of the second frame length to the original frame length, and determining the second ratio as the second conversion ratio.
9. A computer readable storage medium having stored therein at least one executable instruction for causing a processor to perform the sample rate matching method for audio data transmission of any one of claims 1-6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311044496.8A CN116778950B (en) | 2023-08-18 | 2023-08-18 | Sampling rate matching method, system and storage medium for audio data transmission |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311044496.8A CN116778950B (en) | 2023-08-18 | 2023-08-18 | Sampling rate matching method, system and storage medium for audio data transmission |
Publications (2)
Publication Number | Publication Date |
---|---|
CN116778950A CN116778950A (en) | 2023-09-19 |
CN116778950B true CN116778950B (en) | 2023-11-17 |
Family
ID=88011964
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311044496.8A Active CN116778950B (en) | 2023-08-18 | 2023-08-18 | Sampling rate matching method, system and storage medium for audio data transmission |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116778950B (en) |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108664416A (en) * | 2017-03-31 | 2018-10-16 | 上海北京大学微电子研究院 | Data recombination high speed serial parallel exchange buffer storage is exempted from a kind of coherent light communication |
CN112599148A (en) * | 2020-12-31 | 2021-04-02 | 北京声智科技有限公司 | Voice recognition method and device |
CN116230028A (en) * | 2023-02-01 | 2023-06-06 | 海宁奕斯伟集成电路设计有限公司 | Audio sampling rate adjusting device and method |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
BR122021003884B1 (en) * | 2010-08-12 | 2021-11-30 | Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e. V. | SAMPLE OUTPUT SIGNALS FROM AUDIO CODECS BASED ON QMF |
CN105847961A (en) * | 2016-03-29 | 2016-08-10 | 北京数码视讯科技股份有限公司 | Audio data processing method and apparatus |
-
2023
- 2023-08-18 CN CN202311044496.8A patent/CN116778950B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108664416A (en) * | 2017-03-31 | 2018-10-16 | 上海北京大学微电子研究院 | Data recombination high speed serial parallel exchange buffer storage is exempted from a kind of coherent light communication |
CN112599148A (en) * | 2020-12-31 | 2021-04-02 | 北京声智科技有限公司 | Voice recognition method and device |
CN116230028A (en) * | 2023-02-01 | 2023-06-06 | 海宁奕斯伟集成电路设计有限公司 | Audio sampling rate adjusting device and method |
Also Published As
Publication number | Publication date |
---|---|
CN116778950A (en) | 2023-09-19 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105812902B (en) | Method, equipment and the system of data playback | |
WO2020221028A1 (en) | Analog-to-digital conversion-based two-stage audio gain circuit and audio terminal | |
KR20150079727A (en) | Dynamic adjustment of an interrupt latency threshold and a resource supporting a processor in a portable computing device | |
WO2022179246A1 (en) | Audio playback method, device and system | |
KR20050054462A (en) | Asynchronous signal input apparatus and sampling frequency conversion apparatus | |
US20130108083A1 (en) | Audio processing system and adjusting method for audio signal buffer | |
CN116778950B (en) | Sampling rate matching method, system and storage medium for audio data transmission | |
CN103987009A (en) | Method for operating a hearing device and hearing device | |
CN106775560A (en) | Usb audio output device and its processing method | |
CN110858487A (en) | Audio signal scaling processing method and device | |
CN117407335A (en) | QSPI controller, chip and data reading method | |
CN113473425A (en) | Bluetooth low-delay transmission method for audio signals based on PC-SPDIF connection | |
CN113556153A (en) | Low-delay transmission method for converting audio data into Bluetooth signal | |
CN118555519B (en) | Self-synchronizing calibration Bluetooth headset and self-synchronizing calibration method thereof | |
US11979705B2 (en) | Bluetooth earphone adaptive audio playback speed | |
CN111478952A (en) | Communication device and method for processing sampling point | |
CN112533046A (en) | Audio data synchronization device and method thereof | |
CN220673926U (en) | High-quality audio playing system | |
CN112527237B (en) | Audio interface circuit, control method thereof and audio equipment | |
TWI825034B (en) | Method, apparatus, and computer-readable medium for resampling audio signal | |
CN117311444A (en) | Clock frequency correction method based on FIFO pointer monitoring | |
CN114255788B (en) | Asynchronous sampling conversion method and conversion device thereof | |
Akester et al. | A new audio skew detection and correction algorithm | |
JP2005292375A (en) | Audio-reproducing device and clock-frequency control method | |
CN112365897B (en) | Method, device and medium for adaptively adjusting inter-frame transmission code rate of LC3 encoder |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |