IOS Lame Library PCM to MP3 analysis (scenario i)

Source: Internet
Author: User

Scenario One: Use Avaudiorecorder to record the PCM data format file, and then start the sub-thread loop through the file, read the PCM data transcoding MP3 and write to the mp3 file (most of the current online information is like this)

1.lame Initialize & Open PCM, MP3 file get file pointer

Single channel does not need to set Lame_set_model, because API has been described Default:lame picks based on compression ration and input channels (according to Brate and channels default settings)

Ability to expand: Write header information such as Id3tag_set_artist = = = Author, the header information must be set before Lame_init_param ()

Ability to expand: Write a cover view (image) Id3tag_set_albumart

Open file Get file pointer (point to byte position)

2. Traverse PCM file, get byte data, transcode, write to MP3 file

Const int pcm_size = 8192;//equivalent to 8192 cartons of beer, one box of 16 bottles (beer = bytes, 8,192 16 bytes of data length)

Short int pcm_buffer[pcm_size * self. Realchannels]; How many arrays of PCM format data elements are populated

do{}while () loop Read the PCM file to determine if the number of bytes is greater than the set standard

Skip opening fseek (PCM, 4 * 1024x768, seek_cur); Filter noise

The condition is ripe to begin reading the PCM file data and depositing it into Pcm_buffer (the file pointer is offset to the end of the read byte)

Transcode data in Pcm_buffer into MP3 format data and into Mp3_buffer, differentiating between single & dual channels

Note that write has the potential to be abnormal, as the API says

Write the data in the Mp3_buffer to the mp3 file

When the while condition does not conform, jumps out, still should consider the insufficient standard remaining byte data, also must transcode and writes the MP3 file

Finally close the file

IOS Lame Library PCM to MP3 analysis (scenario i)

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.