Audio knowledge summary (Android)

  • The range that the human ear can hear is 20Hz to 20000Hz. It means that the object vibrates 20-20000 times per second.
  • In the PCM16LE two-channel data, the sampling values ​​of the left channel and the right channel are stored at intervals. Each sample value occupies 2Byte space.

  • The sampling rate refers to the number of times the sound signal is sampled per unit time during the "analog to digital" conversion process. The sampling value refers to the integral value of the sound analog signal in each sampling period.

  • For a monophonic sound file, the sampling data is an eight-bit short integer (short int 00H-FFH), while for a two-channel stereo sound file, each sampling data is a 16-bit integer (int), and the high eight bits ( left channel) and the lower eight bits (right channel) represent two channels respectively.

  • Endianness in audio:

  • Sampling accuracy (Bit Depth) For example, 16bits in the figure below, 8 bits represent 2 to the 8th power – 256, and 16 bits represent 2 to the 16th power – 64K. Simply put, it is the range of the value of a certain point at each sampling time. It's like the chromatic accuracy on the piano is better than the sound accuracy on my broken cucurbit silk. The bit width mentioned on the graphics card is also the same, the color range that each bit can represent.

  • The principle of audio mixing: The superposition of quantized speech signals is equivalent to the superposition of sound waves in the air.

  • To adjust the audio volume, Lei Daniu's blog directly divides it by 2, and the volume is attenuated by half.

  • Time Domain Sampling Theorem, H. Nyquist.

  • A frame is the number of bytes of 1 sampling point * channel. Why make a frame out? Because for multi-channel, the number of bytes of 1 sampling point is incomplete, because the data of multiple channels must be played when playing. So for convenience, just say how many frames there are in 1 second, so that you can put aside the number of channels and express the full meaning.

  • The sampling rate, such as 192KHZ, means that 1s takes 192K points on a 1s analog signal (such as a sine wave). Each point, that is, each sample, is a frame.

  • As shown in the figure
    Write picture description here
    , the amount of data per second is 192000×16×2 (two-channel) = 6144000 (bit/s) = 6144K Kbps (that is, the Bit rate in the figure, Chinese is the bit rate) converted into bytes is 6144000 /
    8 = 768000 (byte/s)
    and the file size is: 210.0 MB (210,036,298 bytes)
    , then the sound length = 210,036,298/768000 ≈ 273.48s is approximately equal to 4m 33.48s is
    consistent with the file information in the picture (this place does not remove wav 42 bytes The size of the file header, damn, it is also said to be 44).

Attached is a picture, I will understand immediately
Write picture description here

13. Shannon sampling theorem, also known as Nyquist sampling theorem, is an important basic conclusion in information theory, especially in the disciplines of communication and signal processing. In 1924, Nyquist (Nyquist) derived the formula for the highest large-symbol transmission rate in the ideal low-pass channel: the highest large-symbol transmission rate of the ideal low-pass channel=2W*log2N (where W is the ideal low-pass channel The bandwidth, N is the level intensity).
In order to restore the analog signal without distortion, the sampling frequency should not be less than twice the highest frequency in the analog signal spectrum. fs≥2f max.

14. Stereo: The sound has a sense of direction and space.

15. The volume calculation in Gains.cpp should be based on Weber's law (as stated in Lin Xuesen's book).

16.

struct audio_patch {
  audio_patch_handle_t id; /* patch unique ID */
  unsigned int num_sources; /* number of sources in following array */
  struct audio_port_config sources[AUDIO_PATCH_PORTS_MAX];
  unsigned int num_sinks; /* number of sinks in following array */
  struct audio_port_config sinks[AUDIO_PATCH_PORTS_MAX];
};

Source and sink are opposite, one goes out and one goes in.
The entire audio_patch structure seems to contain multiple sources and multiple sinks. But the embarrassment is in createAudioPatch in AudioPolicyManager:

// only one source per audio patch supported for now
  if (patch->num_sources > 1) {
  return INVALID_OPERATION;
  }

Currently, up to 7.0, only one source is supported. But it didn't say sink! That is, many-to-many is not supported, but one-to-one and one-to-many are supported.

Guess you like

Origin blog.csdn.net/bberdong/article/details/72236686