PCM Audio Sampling data processing

Source: Internet
Author: User

=====================================================

Audio-visual data Processing Primer series articles:

Getting started with visual audio data processing: RGB, YUV pixel data processing

Getting Started with AV data processing: PCM Audio sampling data processing

Getting Started with AV data processing: Analysis of video stream in H.

Getting Started with AV data processing: AAC audio bitstream parsing

Getting Started with AV data processing: FLV Encapsulation Format parsing

Getting Started with AV data processing: UDP-RTP Protocol resolution

=====================================================

The previous article recorded the RGB/YUV video pixel data processing method, this article continues the previous article the content, records the PCM audio sampling data processing method. The location of the audio sample data in the video player's decoding process is shown in the following figure.


This paper introduces several PCM audio sampling data processing functions as follows:
Separating the left and right channels of the Pcm16le two-channel audio sampled data
Half the volume of the left channel in the Pcm16le two-channel audio sample data
Increases the sound speed of pcm16le two-channel audio sampled data by one-fold
Convert Pcm16le two-channel audio sample data to PCM8 audio sampled data
Capturing part of the data from Pcm16le Mono Audio sampling data
Convert Pcm16le two-channel audio sample data to wave format audio data

Note: PCM audio data can be viewed using audio editing software. For example, pay for professional audio editing software for Adobe Audition, or free open source audio editing software audacity.


List of Functions
(1) separating the left and right channels of the Pcm16le two-channel audio sampled dataThe functions in this program can separate the left and right channel data from the Pcm16le dual channel data into two files. The code for the function is shown below.
[CPP]  View Plain  copy  /**   * split left and right channel of  16LE PCM file.   *  @param  url  Location of PCM  file.   *   */   int simplest_pcm16le_split (char *url) {        file *fp=fopen (URL, "rb+");       file *fp1=fopen (" OUTPUT_L.PCM "," wb+ ");       file *fp2=fopen (" OUTPUT_R.PCM "," wb+ ");           unsigned char *sample= (unsigned char *) malloc (4) ;          while (!feof (FP)) {            fread (SAMPLE,1,4,FP);           //L            fwrite (SAMPLE,1,2,FP1);            //r           fwrite (SAMPLE+2,1,2,FP2) ;       }          free (sample);        fclose (FP);       fclose (FP1);        fclose (FP2);       return 0;  }  
The method that invokes the above function is shown below.
[CPP]View Plain copy simplest_pcm16le_split ("NOCTURNENO2INEFLAT_44.1K_S16LE.PCM");

As can be seen from the code, the sampled values of the left and right channels in the Pcm16le two-channel data are stored at intervals. Each sample value occupies 2Byte of space. After the code is run, the data in NOCTURNENO2INEFLAT_44.1K_S16LE.PCM's pcm16le format is separated into two mono data: OUTPUT_L.PCM: Left channel data.

OUTPUT_R.PCM: Right channel data. Note: The sampling frequency of the sound sample in this paper is all 44100Hz, and the sampling format is 16LE. "16" indicates that the number of sample bits is 16bit. Because of the 1byte=8bit, a sample value of one channel occupies 2Byte. "LE" stands for little Endian, which represents a 2 byte sample value stored in a high-level presence address.

The image below is the waveform of the input two-channel PCM data. The above waveform is the left-channel graph, and the waveform below is the right channel waveform. The horizontal axis is the time, the total length is 22 seconds, the ordinate is the sampling value, the value range from 32768 to 32767.


The image below is the audio waveform of the left channel data output_l.pcm after separation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.