Analysis and summary of I2S transmission PCM audio data

1. Preface
"I2S Transmission PCM Audio Data Analysis Summary" mainly introduces how PCM audio data is transmitted through I2S, which is mainly divided into 2 parts:

PCM audio data introduction
I2S protocol introduction
This article mainly introduces PCM audio data.

2. Introduction to PCM audio
PCM audio (Pulse-Code Modulation) is a method of digitally representing sampled analog signals.

To convert an audio analog signal to a digital representation, there are three steps involved:

Sampling (sampling)
Quantization (quantization)
Coding (encoding)
The screenshot below is the waveform of PCM audio 1KHz sine wave, and the sound of "dips" is played out:


3. Sampling (sampling)
Sampling (sampling) means processing, which is actually the process of making the sampled data fully represent the original signal, and the sampled data can be restored to the original signal through reconstruction.

 


Blue curve: Indicates the original audio signal.
Black vertical line segment: represents a sampling of the original signal at the current time point.
Black dots: represents a series of discrete samples obtained by sampling.
4. Sample rate (Sample rate)
The sample rate (Sample rate) indicates the number of samples per second (unit: Hz).

For PCM encoded audio streams, the sample rate is constant. For example: 1Hz means sampling the original signal once per second, 1KHz means sampling 1000 times per second.

Depending on the scene, the sampling rate is also different. The higher the sampling rate, the higher the degree of sound restoration, the better the quality, and the larger the space occupied.

For example: the sampling rate during a call is 8KHz, the commonly used media sampling rate is 44KHz, 48KHz, and the sampling rate for some Blu-ray movies is as high as 1MHz.


5. Quantization (quantization)
After the original signal is sampled, quantization is required to describe the size of the sampled data.

The quantization processing process is to process the time-continuous signal into a time-discrete signal and express it with real numbers. These real numbers will be converted into binary numbers for storage and transmission of analog signals.


The image above is an example of a 16bit bit depth quantization process. bit-depth (bit depth): Used to describe the number of bits that store digital signal values. The more commonly used analog signal bit depths are as follows:

 8-bit: 2^8 = 256 levels, there are 256 levels that can be used to measure real analog signals.
16-bit: 2^16 = 65,536 levels, there are 65,536 levels that can be used to measure real analog signals.
24-bit: 2^24 = 16,666,216 levels, there are 16,666,216 levels that can be used to measure real analog signals.
It can be seen that the greater the bit depth, the more realistic the description of the analog signal and the more accurate the description of the sound.

The following is the actual sampling rate of 44.1KHz 16bit dual-channel sine wave 1KHz PCM audio data, the quantized stored data and waveform analysis are as follows:


? ? ? Question: Why is there 44 data for one sine wave cycle quantization? ? ?

 Analysis:
Time required for 1 sampling: 1 second/sampling rate 44.1KHz = 1/44100 (seconds)
1 sine wave cycle time: 1 second/frequency 1KHz = 1/1000 (seconds)
1 sine wave cycle sampling times: `1 cycle time of sine wave / time required for 1 sample = (1 / 1000) / (1 / 44100) = 44100 / 1000 = 44.1 times Result: The figure above
shows a sine wave cycle, and the number of samples is 44 times.

Remarks: Quantization will divide the waveform into multiple equal parts, and the larger the value, the more realistic the description of the analog signal. The sampling rate is the number of samples per second, and the larger the value, the higher the degree of sound restoration. Therefore, the quality of sound is greatly affected by quantization and sampling rate.

6. Encoding

In the encoding step, we will convert each sample data on the timeline into corresponding binary data.

The binary data generated after the sampling data is encoded is the PCM data. PCM data can be stored directly on the medium, or can be stored or transmitted after codec processing.

7. PCM data commonly used quantification index
sampling rate (Sample rate) : how many times per second, in Hz.

Bit-depth : Indicates how many binary bits are used to describe the sampling data, generally 16bit.

Byte order : Indicates whether the byte order of audio PCM data storage is big-endian or little-endian. For efficient data processing, it is usually little-endian.

Channel number (channel number ): The number of channels contained in the current PCM file, such as mono, stereo, etc.

Whether the sampling data has a sign (Sign ): The meaning to be expressed is literal. It should be noted that the signed sampling data cannot be played in an unsigned way.

8. PCM audio data storage format
The arrangement format of PCM audio data is that the data of each sample point of the left and right channels are staggered.

The following is the analysis of a 16bit two-channel PCM data, as follows:

The actual analyzed PCM waveform is as follows:

From the waveform analysis, channel 1 is silent.
From the data analysis of channel 1, -7 (0xFFF9), -3 (0xFFFD), -5 (0xFFFB), etc. are basically close to 0, so they are silent.

"I2S Transmission PCM Audio Data Analysis Summary" mainly introduces how PCM audio data is transmitted through I2S, which is mainly divided into two parts:

PCM audio data introduction
I2S protocol introduction
The previous article has introduced PCM audio data, this article mainly introduces the I2S protocol.

2. Introduction to I2S
Inter-IC Sount Bus (I2S) is a bus standard developed by Philips Semiconductors (now NXP Semiconductors) for audio data transmission between digital audio devices. In Philips' I2S standard, both the hardware interface specification and the format of digital audio data are specified.

3. I2S Features
The I2S bus only handles audio data, while other control signals are transmitted separately. The commonly used CODEC audio chips are basically combined with I2S and I2C, I2S transmits audio data, and I2C transmits command control . The main features are as follows:

Support full-duplex/half-duplex: full-duplex requires 2 Data lines, half-duplex requires 1 Data line .
Support master/slave mode: Master mode needs to provide SCK and WS signals for I2S communication.
I2S supports multi-channel data transmission: the channel selection is controlled by the WS signal.
The following is a screenshot of the "I2S bus specification" protocol document. It is a typical I2S signal timing diagram. The signal end that generates SCK and WS is the master device, expressed as MASTER, as follows:

According to the above figure, we can know that the I2S bus is three data signal lines:

BCLK: serial clock, also called bit clock, corresponding to each bit of digital audio data. Corresponding to each bit of digital audio data, SCK has 1 pulse. SCK frequency = 2 × sampling frequency × sampling number of bits.
WS: field (channel) selection, frame clock LRCK (left and right clock), used to select the left and right channels. "0" indicates that the data of the left channel is being transmitted, and "1" indicates that the data of the right channel is being transmitted. The data used to switch the left and right channels. Frequency of WS = sampling frequency.
SD: Serial data, using two's complement to represent audio data (data transmission from high to low).
I2S bus half-duplex is 3 data lines, but full-duplex is 4 data lines. The screenshot below is the WM8978 CODEC audio codec chip, which uses a full-duplex 4 data line I2S interface and is controlled through the I2C interface. (Remarks: There will be a special introduction to WM8978 driver porting later)


4. I2S bus timing diagram
There are currently 4 audio protocols, which generally follow the I2S bus protocol, but there are some differences in details:

 I2S Philips Standard
MSB Alignment Standard
LSB Alignment Standard
PCM Standard

4.1 I2S Philips Standard
Use WS signal to indicate which channel the data currently being sent belongs to. This signal is valid one clock before the first bit (MSB) of the current channel's data. I2S mode is a special case of left alignment, also called PHILIPS mode , which is derived from the standard left alignment format and then delayed by one clock bit . The timing is shown in Figure 7. The data MSB of the left channel is valid on the second SCK/BCLK rising edge after the WS falling edge, and the MSB of the right channel data is valid on the second SCK/BCLK rising edge after the WS rising edge.

 

The sender changes the data on the falling edge of the clock signal (CK), and the receiver reads the data on the rising edge. The WS signal also changes on the falling edge of CK.

Example: The following is the I2S data captured by a logic analyzer when playing PCM audio data with a sampling rate of 44.1KHz 16bit dual-channel sine wave 1KHz, as follows:

 The timing diagram below shows how to send a 24bit audio data, the 24bit high bit is sent first, and the remaining 8bit is forced to be cleared . Because the general CPU is word (32Bit) alignment, the remaining 8 bits are filled with 0 during design here:


4.2 MSB alignment standard
The MSB standard generates the WS signal and the first data bit (MSBit) simultaneously . The difference between this and the I2S Philips standard is shown in the figure:

 

The sender changes data on the falling edge of the clock signal; the receiver reads data on the rising edge .

The MSB standard timing diagram below shows how to send a 24-bit audio data. As before, the 24-bit high bit is sent first, and the remaining 8 bits are forced to be cleared.

4.3 LSB Alignment Criteria
This is similar to the MSB Alignment Criteria (no difference for 16-bit and 32-bit full-precision frame formats)

 The following is the LSB standard timing diagram showing how to send a 24-bit audio data, because the LSB is left-aligned, so the upper 8 bits are forced to be cleared and sent first, and then the 24-bit valid data is sent from the upper bits.


4.4 PCM standard
For the PCM standard, no channel information is used. There are two PCM modes: short frame and long frame.

For long frame sync, the WS signal is maintained for 13 cycles in master mode.
For short frame sync, the duration of the WS sync signal is only one cycle.

9. References
What is PCM Audio?
https://samplerateconverter.com/educational/pcm-audio#how-pcm-works

Introduction to PCM data format
https://blog.csdn.net/qq_25333681/article/details/90682989
 

Guess you like

Origin blog.csdn.net/u010783226/article/details/130849054