This article takes the I2S interface as an example to introduce Linux kernel audio related knowledge.
1. Introduction to terms
The following are some common abbreviations used in audio debugging.
1. AEC (Acoustic Echo Cancellor): echo cancellation.
2. AGC (Automatic Gain Control): Automatic gain compensation, adjust the MIC reception volume.
3. ALSA (Advanced Linux Sound Architecture): Advanced Linux sound architecture.
4. ANS (Automatic Noise Suppression): Background noise suppression. ANS can detect background noise with fixed frequency and eliminate background noise.
5. BCK (Bit Clock Line): Bit clock, corresponding to each bit of digital audio data. The standard is called SCK (Serial Clock), serial clock. SCK = 2x sampling frequency x number of sampling bits
6. DAI (Digital Audio Interface): digital audio interface.
7. DAPM (Dynamic Audio Power Management): Dynamic power management, DAPM allows the audio subsystem on Linux-based mobile devices to operate in the minimum power consumption state at all times.
8. DRC (Dynamic Range Control): Dynamic compression, controls audio output within a certain range.
9. EQ (Equaliser): Equalizer adjusts the tone by gaining or attenuating one or more frequency bands of the sound.
10. I2S (Inter-IC Sound): An interface standard for transmitting digital audio data between ICs, which uses a serial method to transmit two groups (left and right channel) of data.
11. LRCK (Left-Right Clock): frame clock, used to switch left and right channel data, 0: left channel; 1: right channel. The standard is called WS (World Select), channel selection; or FS (Frame Sync), frame synchronization; LRCK frequency = sampling frequency.
12. MCLK (Master Clock): Master clock, generally MCLK = 256*LRCK. It is not part of the I2S standard and is mainly used to synchronize the internal operation of the analog/digital converter.
13. Mono: mono.
14. OSS (Open Sound System): Open sound system.
15. PCM (Pulse Code Modulation): Pulse Code Modulation. I2S is a subset of PCM.
16. Ramp: Gradually increase or decrease the volume level to avoid rapid changes in sound. It is used to pause or resume music.
17. Stereo: dual channel
18. TDM (Time Division Multiplexing): Time Division Multiplexing. I2S can only transmit 2 channels of data at most, while TDM supports up to 16 channels.
2. I2S interface
I2S is a digital audio transmission standard defined by Philips and is used to transmit digital audio data between internal devices of a system.
I2S is a branch of PCM, and the interface definition is the same. The sampling rate of I2S is generally 44.1/48KHZ, and the sampling frequency of PCM is generally 8/16KHZ, etc.
The I2S interface has 4 groups of signals: SCK (bit clock), LRCK (frame clock), and SDI/SDO (data).
On the I2S bus, there can only be one master device and one sending device at the same time. The master device can be a sending device or a receiving device. The common I2S block diagram is as follows:
3. I2S Protocol
Common protocol modes of the I2S interface include: I2S normal mode, I2S left-aligned mode, and I2S right-aligned mode.
1. I2S normal mode
I2S normal mode is a special case of I2S left alignment, also called Philips mode. The figure below shows the waveform of I2S normal mode.
The LRCK (i2s_LRCK_rx/i2s_LRCK_tx) signal goes low for the left channel and goes high for the right channel.
The SD (i2s_sdo, i2s_sdi) signal transmits MSB or LSB first and sends the first bit one SCLK clock cycle after LRCK changes.
SD signal width ranges from 16 to 32 bits.
2. I2S left-aligned mode
The figure below shows the waveform of I2S left-aligned mode.
The LRCK (i2s_LRCK_rx/i2s_LRCK_tx) signal goes high for the left channel and goes low for the right channel.
The SD (i2s_sdo, i2s_sdi) signal is transmitted MSB or LSB first and the first bit is sent at the same time as LRCK changes.
SD signal width ranges from 16 to 32 bits.
3. I2S right-aligned mode
The figure below shows the waveform of I2S right-aligned mode.
The LRCK (i2s_LRCK_rx/i2s_LRCK_tx) signal goes high for the left channel and goes low for the right channel.
The SD (i2s_sdo, i2s_sdi) signals are transmitted MSB or LSB first, unlike the I2S normal or left-aligned mode, where the data is aligned with the last bit at the edge of the LRCK signal.
SD signal width ranges from 16 to 32 bits.
Other protocol formats include: PCM early mode, PCM late1 mode and PCM late2 mode.
4. ALSA framework
After Linux kernel 2.6, ALSA replaced OSS and became part of the Linux kernel audio subsystem.
The ALSA system includes:
1. alsa-driver: alsa system driver.
2. alsa-lib: alsa library, user space calls, and kernel space interactions.
3. alsa-utils: command line tool.
4. alsa-plugin: alsa plug-in.
5. alsa-tools: alsa tools.
The ALSA framework consists of the following:
The related functions in alsa-driver are as follows (taking rockchip 4a board as an example):
1. Codec: The common part of the audio chip, including codec initialization function, control interface, register cache, controls, dapm components, audio routing, bias voltage setting function and other descriptive information.
Rockchip 4A single board, Codec uses ES8316 chip, the dts configuration of this chip is as follows:
2. Codec DAI: audio interface driver description on the codec, including: clock configuration, format configuration, capability description, etc.
Codec DAI related implementation is as follows:
3. CPU DAI: refers to the I2S and PCM bus controller of the SoC, which is responsible for moving audio data from the I2S tx FIFO to the codec.
The dts related configuration of RK3399 CPU DAI is as follows:
4. DAI Link: Audio data link, which specifies the codec, codec_dai, cpu_dai and platform used in the link.
The Linux 4.4 kernel supports two ways to create a sound card: one is the general simple-card framework; the other is the traditional way of creating a custom machine driver.
Simple card is a simple and universal machine driver. If the simple-card framework can meet your needs, you can choose the simple card framework first.
The DTS-related configuration of DAI Link is as follows:
The relevant implementation of DAI Link is as follows:
5. DAPM: Dynamic Power Management is based on the improved framework of kcontrol and adds corresponding power management mechanisms. Widget is the basic unit of DAPM.
The relevant implementations of kcontrol, dapm widget and dapm routes in Codec (es8316) are as follows:
6. DMA: responsible for moving the audio data in the DMA buffer to the I2S tx FIFO.
5. Debugging commands
ALSA is the basic interface for Linux to process audio, but ALSA only provides a basic interface and the operation is relatively complicated. In general, you can directly use the utils toolset provided with it. The utils toolset is some encapsulated functional modules that are provided directly in the form of commands. Users only need to type in relevant commands and parameters to implement audio operation functions.
1. Check the sound card information
root@xiaotianbsp:~# cat /proc/asound/cards
0 [rockchipes8316c]: rockchip_es8316 - rockchip,es8316-codec
rockchip,es8316-codec
1 [HDMICODEC]: HDMI-CODEC - HDMI-CODEC
HDMI-CODEC
root@xiaotianbsp:~# ls -l /dev/snd/
total 0
drwxr-xr-x 2 root root 80 Aug 16 14:43 by-path
crw-rw----+ 1 root audio 116, 2 Aug 16 14:43 controlC0
crw-rw----+ 1 root audio 116, 5 Aug 16 14:43 controlC1
crw-rw----+ 1 root audio 116, 4 Aug 16 14:43 pcmC0D0c
crw-rw----+ 1 root audio 116, 3 Aug 16 14:43 pcmC0D0p
crw-rw----+ 1 root audio 116, 6 Aug 16 14:43 pcmC1D0p
crw-rw----+ 1 root audio 116, 1 Aug 16 14:43 seq
crw-rw----+ 1 root audio 116, 33 Aug 16 14:43 timer
controlCx: control interface, providing a flexible way to manage registered sound cards and query existing sound cards.
pcmCxDxc: PCM interface, corresponding to recording device.
pcmCxDxp: PCM interface, corresponding to the sound playback device.
timer: Supports sound synchronization events by providing a timer on the sound card.
seq: sequencer interface, a high-level interface for MIDI programming and sound synchronization that is more advanced than the original MIDI interface.
2. Check the sound card acquisition and playback PCM information
root@xiaotianbsp:~# cat /proc/asound/pcm
00-00: ff880000.i2s-ES8316 HiFi ES8316 HiFi-0 : : playback 1 : capture 1
01-00: ff8a0000.i2s-i2s-hifi i2s-hifi-0 : : playback 1
3. Check the ALSA driver version
root@xiaotianbsp:~# cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version k4.4.154-90-rockchip-ga14f6502e045.
4. Check the information of sound card 0
root@xiaotianbsp:~# cat /proc/asound/card0/pcm0p/sub0/status
closed
5. Check the register
## regmap name
root@xiaotianbsp:~# cat /sys/kernel/debug/regmap/1-0011/name
es8316
root@xiaotianbsp:~# cat /sys/kernel/debug/regmap/ff880000.i2s/name
rockchip-i2s
##rk3399 i2s0 controller registers
root@xiaotianbsp:~# cat /sys/kernel/debug/regmap/ff880000.i2s/registers
00: 0000000f
04: 0000000f
08: 00033f3f
0c: 00000000
10: 000f0010
14: 01f00000
18: XXXXXXXX
1c: 00000000
20: XXXXXXXX
28: 00000000
## es8316 registers
root@xiaotianbsp:~# cat /sys/kernel/debug/regmap/1-0011/registers
00: c0
01: f3
02: 08
03: 20
04: 11
05: 00
06: 11
07: 00
08: 00
09: 04
0a: 0c
0b: 0c
0c: ff
0d: 3f
Previous article:Tips on microphone selection
Next article:Analysis of washing machine motor controller circuit
Recommended ReadingLatest update time:2024-11-16 09:17
- Popular Resources
- Popular amplifiers
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Design and implementation of RDS function based on S1473X
- 【GD32450I-EVAL】Onboard SDRAM supports LittleVGL
- I recently debugged the Fudan Micro FM33LC026N chip and am preparing to trial-produce a batch. Are there any Fudan Micro agents?
- Capacitor parallel ripple current
- MSP430 interrupt priority, open and close, interrupt nesting
- Is it necessary to use D1 bidirectional TVS in this circuit?
- DLT645 and modbus rtu wireless communication protocol introduction and comparison
- Gesture Control HMI Reference Design with mmWave Sensors and Sitara Processors
- What are resonance and resonance? What are their hazards?
- About broadband amplifier design