Native PCM recording and playback

arecord and aplay instructions

Source: https://blog.csdn.net/liupin2008/article/details/124347278

arecord and aplay are part of alsa-utils, which is very convenient for us to use frequently in audio development under Linux system.
Let me briefly introduce it first.

arecord capture raw audio
arecord -r 8000 -t raw -c 1 -f S16_BE ./test

aplay Play raw audio
aplay -t raw -r 8000 -f S16_BE -c 1 ./test

Parameter description:
-r Sampling frequency 8000 48000 44100 etc.
-t Recording file type voc, wav, raw or au
-c Number of channels, 1: Mono; 2: Dual channels
-f Sampling format, S16: 16 bits; BE: big endian; LE: little endian
and finally the file path

Note: When the playback is abnormal, check whether the parameters at the time of acquisition are consistent with those at the time of playback.
———————————————

Summarize

To sum up, pcm raw data, what parameters are used when recording, and the same parameters must be set when playing. Otherwise, all you hear is a noise.
For example, my PCM file uses parameters when recording: frequency 48000Hz, S16_LE. But use the command when playing:

aplay pcm_001.pcm

This command is to use the default parameters of aplay to play pcm_001.pcm, and the default parameters are: Unsigned 8 bit, Rate 8000 Hz, Mono

So obviously what you hear is a bunch of noise.

The following command should be used:

aplay -t raw -r 48000 -f S16_LE -c 1 ./pcm_001.pcm

analogy

1. The original data yuv during video capture also has different parameter settings such as YUV420, YUV422, YUV444, RGB16, RGB24, RGB32, and different width and height settings, etc. It also needs to be set during playback. The player does not know the width, height and data arrangement of the video file, and if the parameters are not set correctly, a blurred screen will appear.
If the format has been encapsulated, such as MP4, MKV, these are the width, height, and encoding format written at the beginning of the file, the player will set the encoder and decoder according to the parameters of the file header, display the width, height, audio parameters.

2. The original data of the picture is raw. Major camera manufacturers have different formats, such as Sony’s ARW and Canon CR2. Sony has its own software to open this kind of file, and Canon also has it. However, the camera raw of PS integrates the software of various manufacturers, and all of them can be opened and displayed. These raw data are actually a collection of binary data. Each manufacturer writes device parameters at the beginning of the file, such as device model, aperture, and shutter.
If the photo is saved in the compressed format JPEG, since JPEG is a public image format, and the width and height parameters are stored in a fixed format, any image browser can open it.

Guess you like

Origin blog.csdn.net/u013209189/article/details/127336171