MP3-made LRC lyrics File Parsing (Appendix: source code)

Source: Internet
Author: User

LRC lyrics Synchronization

I. Preparations
Now that we want to prepare a lyrics synchronization program, we need to prepare a song first. Let's take Jay Chou-Qinghua porcelain as an example. The first download is the "C:/my player/music/blue and white porcelain ". You can also download the blue/white porcelain LRC file online (for the address, see the appendix) and save the text as "C:/my player/LRC/blue/white porcelain. LRC ". Our programs (classes and FLA) are saved in the "C:/my player/" folder.
Blue and white porcelain. LRC file:
[Ti: blue and white porcelain]
[AR: Jay Chou]
[Al: I am very busy]
[By: Zhang Qi]
[. 00] send a text message from to 291199 to download the song to your mobile phone.
[. 11] Blue and White Porcelain
[. 49]
[. 39] somei outlines the swing, and Beijing Wind Dragon turns Dan
[. 08] the screen-layer bird-painted peony looks like your makeup
[. 46] My thoughts through the window
[. 93] Half of the scale on the rice paper
[. 49] the oil-colored render lady figure is lost
[. 83] And you smile suddenly.
[. 30]
[. 77] I can't go anywhere
[. 97] [. 77]
[. 92] [. 63] [. 90] The weather is waiting for rain
[. 57] [. 91] [. 99] And I'm waiting for you
[. 92] [. 44] [. 93] The smoke volume rises
[. 76] [. 25] [. 49] Wanli
[. 36] [. 85] [. 84] the shadows in your room are carved on the ground
[. 67] [. 73] [. 87 ].
[. 83] [. 35] [. 34] The weather is waiting for rain
[. 20] [. 60] [. 68] And I'm waiting for you
[. 71] [. 01] [. 99] The Moonlight was salvaged.
[. 74] [. 10] [. 18] masks the ending
[. 33] [. 54] [. 72] the blue and white porcelain that passed the world are beautiful
[. 30] [. 67] [. 65] Your smile
[. 25] the scenes with white flowers and blue colors have jumped to the bottom of the bowl.
[. 69] You are missing when you copy the funds
[. 22] the secret you have hidden in efficacy for one thousand years
[. 75] an emergency is like a shame.
[02: 08. 32] ban on banji
[. 57] The dreamy growth pattern.
[. 84] I'm waiting for you in the South China Town.
[. 19] in Landscape Painting
[. 75] You are hidden from the dark
You can also copy the text content, create a text document under "C:/my player/LRC/", and paste the content, save the document as "blue and white porcelain. LRC ", note that the extension is". LRC ".
LRC lyrics file format description

A file with the extension of LRC is the only lyrics file that can be recognized by the MP3 player. The lyrics can be displayed in a synchronized manner in the MP3 digital player or quiet listen.
It is a specialized text-based lyrics format that contains "tags" in the form.
[B] [color = #00 CCFF] LRC lyrics contain two types of labels: [/color] [/B]
■ ID-tags)
The format is "[Identification name: value]". Case-insensitive. The following are predefined labels.
[AR: artist name]
[Ti: Qu name]
[Al: album name]
[By: Editor (the person who edits the LRC lyrics)]
[Offset: time compensation value] The unit is millisecond. A positive value indicates the overall advance, and a negative value indicates the opposite. This is used to adjust the overall display speed.
■ Time-tag)
The format is "[mm: SS]" or "[mm: Ss. fff]" (Minutes: seconds ). The number must be a non-negative integer. For example, "[. 5]" is valid, and "[0x0c:-34.5]" is invalid.
A time tag must be at the beginning of a line of lyrics. A line of lyrics can contain multiple time tags (for example, multiple sentences in the lyrics ). When a song is played at a certain time point, MP3 will look for the corresponding time tag and display the lyrics after the tag, so that the "lyrics synchronization" function is completed.
[Minute: Second. millisecond] lyrics
For example. 25] the scene of colored white flowers has jumped to the bottom of the bowl. "It means that at 1 minute and 50.25 seconds, the lyrics are" the scene of colored white flowers has jumped to the bottom of the bowl ".
Another form is. 92] [02: 25. 63] [00: 56. 90] The day is waiting for smoke and rain. "This form is often used in the authorization part (commonly known as the climax part of the song), which is expressed. 92. 63, 00: 56. the lyrics of the 90 s are "the sky is waiting for smoke and rain ". Due to the existence of this form, the subsequent programming is a little complicated, but it doesn't matter. It's okay to rely on your smart wisdom.

After writing the file in notepad in the preceding format, change the extension name to LRC. LRC lyrics are a type of lyrics that are displayed in sequence when the song lyrics appear in the editor and are edited into a file by the time when the song lyrics appear. Put the same name of the song and LRC lyrics in the same directory. When playing a song with a player with the show lyrics function, the lyrics can be displayed synchronously for easy viewing and learning.

(For programmers to read)
The following lists the standards that should be followed when developing software that supports LRC format. Whether it is [color = # ff0000] or not at the beginning of the line [/color], [color = # ff0000] In the line [/color], where [color = # ff0000] "[*: *] "[/color] format should be considered as a tag. (Note: The colon is not the full-width character ":")
No labels should be displayed.
All labels separated by colons are [color = # ff0000] non-negative [/color]. it should be considered as a [color = # ff0000] Time tag [/color]. Therefore, time labels in non-standard format (not "[mm: SS]") should also be recognized (for example, "[0: 0]"). Any label that is not a time label should be considered as an identifier label. Uppercase/lowercase letters are equivalent to lowercase letters.
• For backward compatibility, new undefined labels should be ignored. Ignore the content of the same row after the annotation label. Multiple tags in a row should be allowed and can be correctly processed. Unordered tags should be correctly processed.

Examples of implementation functions:
The content of LRC is as follows:
[. 83] And you smile suddenly.
[. 30]
[. 77] I can't go anywhere
[. 92] [. 63] [. 90] The weather is waiting for rain
[. 57] [. 91] [. 99] And I'm waiting for you
[. 92] [. 44] [. 93] The smoke volume rises
[. 76] [. 25] [. 49] Wanli
Put the string into a two-dimensional array or struct and sort by Time
43830 and you smile suddenly.
48300 your beauty is shining
50770 go to a place I cannot go
56900 days are waiting for smoke and rain
58990 and I'm waiting for you
60930 smoke rises
63490 thousand miles across the river
145630 days are waiting for smoke and rain
147910 and I'm waiting for you
150440 smoke rises
152250 thousand miles across the river
181920 days are waiting for smoke and rain
183570 and I'm waiting for you
185920 smoke rises
187760 thousand miles across the river
The procedure is as follows:
1-read Sound: Blue and White Porcelain Enamel
2-Playing Sound and obtaining the current playback time (MS): time_ms
3-read external files: blue/white porcelain. LRC
-- Read the LRC file. This step is very simple and the same as reading a common text file;
-- Split the read LRC data by rows ("/N" is a linefeed). Each element of the array represents a line of LRC content;
-Simple Regular Expression application or string substring operation
-Separate strings into arrays by Separators
-- Extract the time and lyrics of each row in the array and convert the time string to the readable time (mm * 60 + SS. ff) millisecond to solve the problem of time sequence;
4-. Finally, as the music is played, the lyrics within the playing period are read. Compare the current playback time time_ms with the time in lrcarray (array or struct)
Show the lyrics in lrcarray if they are equal

Attachment:
[Url = http://download.csdn.net/source/318984120.lrcgeword reading and Sorting Algorithm (C Language Version) [/url]
LRC lyrics file format and C ++ reading (C ++)
[Url = http://download.csdn.net/source/318991620.lrc file detailed introduction and source code (ActionScript web script [/url])

-------------- ----------------------
The above code is collected by the network. Please contribute your own implementation method, which is easy to understand.
For example, you can use fscanf to format the READ function when reading the [. 77] Time tag.
Fscanf (FP, "[% d: % s]", & mm, & SS );
You can refer to the following functions:
Fp = fopen ("C:/my player/LRC/blue/white porcelain. LRC", "R"); // open the file
Fgets (STR, 80, FP); // read a row and put it in the array Str
......
......
The purpose is to parse the strings in the file. Please give us some comments. It is best to include the source code and comments !!

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.