Audio playing method and device based on I2S clock and storage medium
By calculating and comparing the reading speed of the audio relay module in the I2S system, compensating or deleting corrections, the problem of audio playback data is solved, synchronous adaptation of audio data is realized, noise and sound breakage are avoided, and the phenomenon of improvement is improved. Audio playback quality.
Patent Information
- Application Number
- CN202411324212.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2025-01-03
AI Technical Summary
In the I2S system, due to the existence of the intermediate module, the audio rates of the sending and receiving ends may be out of synchronization, resulting in noise and sound interruption of audio playback, affecting the user experience.
By obtaining the data read rate of the audio transit module as the host reading speed, determine the target buffer data amount, and compare the reading speed consistency of the host and slave. If it is inconsistent, compensate or delete and correct it to ensure audio playback Synchronization of data. The specific methods include calculating the reading speed of the master and slave, setting a preset threshold interval, determining whether the data amount is within the interval, and if not, correcting, compensating or deleting noise to adapt to the audio data.
It realizes automatic adaptation of I2S audio data, avoids empty or overflow of the audio data buffer, optimizes the audio playback effect, and provides a good user experience.
Smart Images

Figure CN119248695A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of streaming media, and in particular to an audio playback method, device and storage medium based on an I2S clock. Background Art
[0002] I2S (Inter-IC Sound) bus, also known as the integrated circuit built-in audio bus, is a bus standard developed by Philips Semiconductor for audio data transmission between digital audio devices. This bus is specifically used for data transmission between audio devices and is widely used in various multimedia systems.
[0003] The classic I2S system has only one transmitter and one receiver, without an intermediate module. In actual applications, there is often an intermediate forwarding module (such as MCU). As a result, when the intermediate module transmits I2S data, the audio acquisition rate of the transmitter and the playback rate of the receiver may be out of sync, resulting in the playback audio buff data being empty or the audio data buff overflowing, which ultimately leads to audio noise and interruption, affecting the user experience. Summary of the invention
[0004] The present invention provides an I2S clock-based audio playback method, device and storage medium, which solve the technical problem that the audio acquisition rate of a transmitting end is out of sync with the reading and playback rate of a receiving end, resulting in noise and disconnection in audio playback.
[0005] In order to solve the above technical problems, the present invention provides an audio playback method based on an I2S clock, comprising:
[0006] Acquire the data reading rate of the audio transfer module as the host reading speed, and determine the target buffer data volume of the buffer according to the host reading speed;
[0007] The host reading speed and the slave reading speed are compared according to the target buffer data volume to see whether they are consistent. If they are inconsistent, it is further determined whether the host reading speed is higher than the slave reading speed. If so, the audio playback data is compensated and corrected. Otherwise, the audio playback data is deleted and corrected.
[0008] In a further implementation scheme, the audio data information includes the I2S sampling clock clk, the number of channels a, the number of sampling bits slot and the sampling frequency fs read by the audio transfer module.
[0009] In a further embodiment, the host read speed is calculated as follows:
[0010] A=a*slot*fs
[0011] Where A is the host reading speed.
[0012] In a further implementation scheme, the host reading speed and the slave reading speed are compared to determine whether they are consistent according to the target buffer data volume, specifically:
[0013] The buff data amount of the buffer in the audio transfer module is read in real time, a preset threshold interval is set based on the target buffer data amount, and it is determined whether the buff data amount is in the preset threshold interval. If so, it is determined that the host reading speed and the slave reading speed are consistent; otherwise, it is determined that the host reading speed and the slave reading speed are inconsistent.
[0014] In a further embodiment, the compensating and correcting the audio playback data includes:
[0015] Determine the total number of audio sampling points of the audio playback data, and determine corresponding compensation noise point positions between the audio sampling points;
[0016] Acquire first audio data and second audio data of two audio sampling points adjacent to the compensation noise point position;
[0017] Compensated audio data is calculated according to the first audio data and the second audio data, and a compensated noise point is inserted at a compensated noise point position between two adjacent audio sampling points.
[0018] In a further embodiment, the deleting and correcting the audio playback data includes:
[0019] Determine the total number of audio sampling points of the audio playback data, and determine at least one set of two adjacent noise point coordinates to be merged among the audio sampling points;
[0020] Acquire first audio data and second audio data of corresponding audio sampling points according to the coordinates of the noise points to be merged;
[0021] The merged audio data is calculated according to the first audio data and the second audio data, a merged noise point is inserted according to the merged audio data, and the audio sampling points corresponding to two adjacent noise points to be merged are deleted.
[0022] The present invention provides an audio playback device based on an I2S clock, which is used to implement an audio playback method based on an I2S clock as described above, comprising an audio output module, an MCU control module, a DSP module and a correction module connected in sequence; the MCU control module is used as an audio transfer module with a built-in buffer, and the correction module is connected to the MCU control module;
[0023] The audio output module is used to output digital audio;
[0024] The MCU control module is used to write the digital audio into the buffer in I2S mode;
[0025] The DSP module is used to read the digital audio from the buffer of the MCU control module in USB mode;
[0026] The correction module is used to obtain the data reading rate of the audio transfer module as the host reading speed, and obtain the corresponding target buffer data volume, and then compare the host reading speed and the slave reading speed according to the target buffer data volume to see if they are consistent. If they are inconsistent, it is further determined whether the host reading speed is higher than the slave reading speed. If so, the audio playback data is compensated and corrected. Otherwise, the audio playback data is deleted and corrected.
[0027] The audio playback device adopts various modules to implement various steps in the audio playback method, provides a hardware basis for the audio playback method, and facilitates the implementation of the method.
[0028] The present invention also provides a storage medium on which a computer program is stored, and the computer program is used to be loaded by the above-mentioned audio playback device based on the I2S clock to implement the above-mentioned audio playback method based on the I2S clock. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).
[0029] The beneficial effects of the present invention are as follows:
[0030] This solution compares the host reading speed and the slave reading speed to see if they are consistent. If they are inconsistent, it further determines whether the host reading speed is higher than the slave reading speed. If so, the audio playback data is compensated and corrected. If not, the audio playback data is deleted and corrected. Automatic adaptation based on the deviation of the sampling module I2S clock and the audio reading module is achieved by filling or deleting the I2S audio data to solve the problem that when there is an audio transfer module transmitting I2S data, the I2S audio sampling clock of one module deviates from the I2S audio reading clock of another module, resulting in the acquisition audio rate and the reading and playback rate being out of sync, thereby avoiding the playback audio buff data being empty or the audio data buff overflowing, resulting in audio noise and disconnection, optimizing the audio playback effect, and providing a good listening experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 This is a workflow diagram of an audio playback method based on an I2S clock provided by an embodiment of the present invention;
[0032] Figure 2is a timing diagram of audio sampling points in a source sound signal provided by an embodiment of the present invention;
[0033] Figure 3 is a system block diagram of an audio playback device based on an I2S clock provided by an embodiment of the present invention;
[0034] Audio output module 1, MCU control module 2, DSP module 3, correction module 4. DETAILED DESCRIPTION
[0035] The following specifically illustrates the implementation mode of the present invention in conjunction with the accompanying drawings. The embodiments are provided for illustrative purposes only and cannot be understood as limiting the present invention. The accompanying drawings are provided for reference and illustration only and do not constitute a limitation on the scope of patent protection of the present invention, because many changes can be made to the present invention without departing from the spirit and scope of the present invention.
[0036] Example 1
[0037] An audio playback method based on an I2S clock is provided in an embodiment of the present invention, such as Figure 1 , Figure 2 As shown, in this embodiment, it includes:
[0038] S1. Obtain the data reading rate of the audio transfer module as the host reading speed, and determine the target buffer data volume of the buffer according to the host reading speed, specifically:
[0039] like Figure 2 As shown, in this embodiment, the audio transfer module is the MCU control module 2, which receives the audio data output by the audio output module 1 through the I2S bus; the host is the MUC control module 2, and the DSP module 3 is the slave.
[0040] The audio data information read by the audio transfer module is obtained, and the host reading speed is calculated according to the audio data information.
[0041] In this embodiment, the audio data information includes the I2S sampling clock clk, the number of channels a, the number of sampling bits slot and the sampling frequency fs read by the audio transfer module;
[0042] The calculation formula of the host reading speed is as follows:
[0043] A=a*slot*fs
[0044] Where A is the host reading speed.
[0045] The target buffer data volume = host reading speed * unit time * number of reads. For example, the host reads data A1 = 1000 from the audio output module per second, reads 10 times in succession and stores it in the buff, then the target buffer data volume = 10 * A1 = 10000.
[0046] S2, comparing the host reading speed and the slave reading speed according to the target buffer data volume to see whether they are consistent, if they are consistent, not taking any measures; if they are inconsistent, further determining whether the host reading speed is higher than the slave reading speed;
[0047] If the host reading speed is higher than the slave reading speed, the audio playback data is compensated and corrected; if the host reading speed is lower than the slave reading speed, the audio playback data is deleted and corrected.
[0048] In this embodiment, the host reading speed and the slave reading speed are compared to see whether they are consistent, specifically:
[0049] The buff data amount of the buffer in the audio transfer module is read in real time, a preset threshold interval is set based on the target buffer data amount, and it is determined whether the buff data amount is in the preset threshold interval. If so, it is determined that the host reading speed and the slave reading speed are consistent; otherwise, it is determined that the host reading speed and the slave reading speed are inconsistent.
[0050] The preset threshold interval is generally set to 30% to 70% of the target buffer data volume. If it is lower than 30% or higher than 70%, it is considered that the data processing speeds of the host and the slave do not match.
[0051] In this embodiment, the compensating and correcting the audio playback data includes:
[0052] Determine the total number of audio sampling points of the audio playback data, and determine corresponding compensation noise point positions between the audio sampling points;
[0053] Acquire first audio data and second audio data of two audio sampling points adjacent to the compensation noise point position;
[0054] Compensated audio data is calculated according to the first audio data and the second audio data, and a compensated noise point is inserted at a compensated noise point position between two adjacent audio sampling points.
[0055] For details, see Figure 2 , A and B are adjacent audio sampling points, A(t1,y1), B(t2,y2); point C is the compensation noise point, C(t3,y3). Insert the compensation noise point at the compensation noise point position between the two audio sampling points, that is, the audio data y=(y1+y2) / 2 of the audio sampling point C between t1 and t2 is supplemented.
[0056] In this embodiment, the calculating rate difference to delete and correct the audio playback data includes:
[0057] Determine the total number of audio sampling points of the audio playback data, and determine at least one set of two adjacent noise point coordinates to be merged among the audio sampling points;
[0058] Acquire first audio data and second audio data of corresponding audio sampling points according to the coordinates of the noise points to be merged;
[0059] The merged audio data is calculated according to the first audio data and the second audio data, a merged noise point is inserted according to the merged audio data, and the audio sampling points corresponding to two adjacent noise points to be merged are deleted.
[0060] For details, see Figure 2 , A and B are adjacent audio sampling points, A(t1,y1), B(t2,y2); C is the merged noise point, C(t3,y3). According to the merged audio data, the merged noise point is inserted and the audio sampling points corresponding to the two noise points to be merged are deleted, that is, the two sampling point data at time t1 and t2 are merged into one C audio data y=(y1+y2) / 2.
[0061] Example 2
[0062] Digital audio is output from audio output module 1 and transferred to MCU control module 2 via I2S, and then transferred to DSP module 3 for audio decoding via MCU control module 2; the radio audio provides the I2S clock, and DSP module 3 also provides the audio transmission clock; since the radio audio clock and the clock provided by DSP module 3 may deviate due to different hardware, the audio output may eventually cause noise problems after a certain period of time.
[0063] The embodiment of the present invention provides an audio playback device based on an I2S clock, which is used to implement the above-mentioned audio playback method based on an I2S clock, see Figure 3 , including an audio output module 1, an MCU control module 2, a DSP module 3 and a correction module 4 connected in sequence; the MCU control module 2 is used as an audio transfer module with a built-in buffer, and the correction module 4 is connected to the MCU control module 2;
[0064] The audio output module 1 is used to output digital audio;
[0065] The MCU control module 2 is used to write the digital audio into the buffer in an I2S manner;
[0066] The DSP module 3 is used to read the digital audio from the buffer of the MCU control module 2 in USB mode;
[0067] The correction module 4 is used to obtain the data reading rate of the audio transfer module as the host reading speed and obtain the corresponding target buffer data volume, and then compare the host reading speed and the slave reading speed according to the target buffer data volume to see if they are consistent. If they are inconsistent, it is further determined whether the host reading speed is higher than the slave reading speed. If so, the rate difference is calculated to compensate and correct the audio playback data. Otherwise, the rate difference is calculated to delete and correct the audio playback data.
[0068] The working principle of this embodiment is as follows:
[0069] According to the I2S sampling clock clk, the number of channels 2, the number of sampling bits slot and the sampling frequency fs, select the audio acquisition chip to get the ADC channel data (that is, the host reading speed), clock I2S:
[0070] 2*slot*fs=2*32*48KHz=3.072MHz; the I2S data obtained per ms is: 96 bytes;
[0071] The theoretical value of the configuration clock is 3.072MHz, and the I2S data obtained every ms is 96 bytes; first cache the data read by the MCU control module 2 into the buffer buff, the data volume is A1 (that is, the target buffer data volume), the judgment method is:
[0072] When the buff data volume is greater than 130% A1 (i.e., the upper limit of the preset threshold interval, which can be set according to actual needs), it is considered that: the I2S audio data read by the MCU control module 2 from the audio output module 1 is faster than the audio data read by the DSP module 3 from the MCU control module 2.
[0073] When the buff data volume is less than 70% A1 (i.e., the lower limit of the preset threshold interval, which can be set according to actual needs), it is considered that: the I2S audio data read by the MCU from the audio output module 1 is slower than the audio data read by the DSP module 3 from the MCU control module 2.
[0074] The audio playback device adopts various modules to implement various steps in the audio playback method, provides a hardware basis for the audio playback method, and facilitates the implementation of the method.
[0075] Example 3
[0076] The embodiment of the present invention further provides a storage medium on which a computer program is stored, and the computer program is used to be loaded by an audio playback device based on an I2S clock in the above embodiment 2 to implement an audio playback method based on an I2S clock provided in the above embodiment 1. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0077] The beneficial effects of the embodiments of the present invention are as follows:
[0078] This solution compares the host reading speed and the slave reading speed to see if they are consistent. If they are inconsistent, it further determines whether the host reading speed is higher than the slave reading speed. If so, the rate difference is calculated to compensate and correct the audio playback data. If not, the rate difference is calculated to delete and correct the audio playback data. Automatic adaptation based on the deviation of the sampling module I2S clock and the audio reading module is achieved by filling or deleting the I2S audio data to solve the problem that when there is an audio transfer module transmitting I2S data, the I2S audio sampling clock of one module deviates from the I2S audio reading clock of another module, resulting in the acquisition audio rate and the reading and playback rate being out of sync, thereby avoiding the playback audio buff data being empty or the audio data buff overflowing, resulting in noise and disconnection in the audio, optimizing the audio playback effect, and providing a good listening experience.
[0079] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.
Claims
1. An audio playback method based on I2S clock, characterized in that: include: Acquire the data reading rate of the audio transfer module as the host reading speed, and determine the target buffer data volume of the buffer according to the host reading speed; The host reading speed and the slave reading speed are compared according to the target buffer data volume to see whether they are consistent. If they are inconsistent, it is further determined whether the host reading speed is higher than the slave reading speed. If so, the audio playback data is compensated and corrected. Otherwise, the audio playback data is deleted and corrected.
2. The audio playback method based on I2S clock as claimed in claim 1, characterized in that: The audio data information includes the I2S sampling clock clk, the number of channels a, the number of sampling bits slot and the sampling frequency fs read by the audio transfer module.
3. The audio playback method based on I2S clock as claimed in claim 2, characterized in that: The calculation formula of the host reading speed is as follows: A=a*slot*fs Where A is the host reading speed.
4. The audio playback method based on I2S clock as claimed in claim 3, characterized in that: Compare the host reading speed and the slave reading speed to see whether they are consistent according to the target buffer data volume, specifically: The buff data amount of the buffer in the audio transfer module is read in real time, a preset threshold interval is set based on the target buffer data amount, and it is determined whether the buff data amount is in the preset threshold interval. If so, it is determined that the host reading speed and the slave reading speed are consistent; otherwise, it is determined that the host reading speed and the slave reading speed are inconsistent.
5. The audio playback method based on I2S clock as claimed in claim 4, characterized in that: The compensating and correcting the audio playback data includes: Determine the total number of audio sampling points of the audio playback data, and determine corresponding compensation noise point positions between the audio sampling points; Acquire first audio data and second audio data of two audio sampling points adjacent to the compensation noise point position; Compensated audio data is calculated according to the first audio data and the second audio data, and a compensated noise point is inserted at a compensated noise point position between two adjacent audio sampling points.
6. The audio playback method based on I2S clock as claimed in claim 4, characterized in that: The step of deleting and correcting the audio playback data includes: Determine the total number of audio sampling points of the audio playback data, and determine at least one set of two adjacent noise point coordinates to be merged among the audio sampling points; Acquire first audio data and second audio data of corresponding audio sampling points according to the coordinates of the noise points to be merged; The merged audio data is calculated according to the first audio data and the second audio data, a merged noise point is inserted according to the merged audio data, and the audio sampling points corresponding to two adjacent noise points to be merged are deleted.
7. An audio playback device based on an I2S clock, used to implement an audio playback method based on an I2S clock as claimed in any one of claims 1 to 6, characterized in that: It includes an audio output module, an MCU control module, a DSP module and a correction module connected in sequence; the MCU control module is used as an audio transfer module with a built-in buffer, and the correction module is connected to the MCU control module; The audio output module is used to output digital audio; The MCU control module is used to write the digital audio into the buffer in I2S mode; The DSP module is used to read the digital audio from the buffer of the MCU control module in USB mode; The correction module is used to obtain the data reading rate of the audio transfer module as the host reading speed, and obtain the corresponding target buffer data volume, and then compare the host reading speed and the slave reading speed according to the target buffer data volume to see if they are consistent. If they are inconsistent, it is further determined whether the host reading speed is higher than the slave reading speed. If so, the audio playback data is compensated and corrected. Otherwise, the audio playback data is deleted and corrected.
8. A storage medium, characterized in that: A computer program is stored thereon, characterized in that the computer program is used to be loaded by the audio playback device based on the I2S clock as described in claim 7 to implement the audio playback method based on the I2S clock as described in any one of claims 1-6.
